##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2018/04/14
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:		load, unload, display, help, test
#   Modulefiles:	remove/5.0
#   Sub-Command:
#
#   Comment:	%C{
#           Check the effect of 'remove-path' command on $env() array
#           variable through the different modulefile evaluation mode
#		}C%
#
##############################################################################

set module "remove/5.0"
set modulefile "$modpath/$module"
set modulefilere "$modpathre/$module"

#
#  test load mode
#

# test with value not set to variable prior to load
set ans [list]
lappend ans [list unset TS1]
lappend ans [list set TS2 ""]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]
testouterr_cmd_re "sh" "load $module" $ans ""

# test with value set to variable prior to load (diff value than removed one)
setenv_var TS1 "no"
set ans [list]
lappend ans [list setpath TS1 "no"]
lappend ans [list set TS2 "no"]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]
testouterr_cmd_re "sh" "load $module" $ans ""

# test with value set to variable prior to load (value is removed one)
setenv_var TS1 "yes"
set ans [list]
lappend ans [list unset TS1]
lappend ans [list set TS2 ""]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]
testouterr_cmd_re "sh" "load $module" $ans ""

# test with value set to variable (as path var) prior to load (value is removed one)
setenv_path_var TS1 "yes"
set ans [list]
lappend ans [list unsetpath TS1]
lappend ans [list set TS2 ""]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]
testouterr_cmd_re "sh" "load $module" $ans ""


#
#  test unload mode
#

# test with module loaded but vanished env vars
unsetenv_path_var TS1
setenv_loaded_module $module $modulefile

set ans [list]
lappend ans [list unset TS2]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
testouterr_cmd "sh" "unload $module" $ans ""

# test with value set to variable prior to unload (diff value than removed one)
setenv_var TS1 "no"
set ans [list]
lappend ans [list unset TS2]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
testouterr_cmd "sh" "unload $module" $ans ""

# test with value set to variable prior to unload (value is removed one)
setenv_var TS1 "yes"
set ans [list]
lappend ans [list unset TS1]
lappend ans [list unset TS2]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]

# test with value set to variable (as path var) prior to load (value is removed one)
setenv_path_var TS1 "yes"
set ans [list]
lappend ans [list unsetpath TS1]
lappend ans [list unset TS2]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]

# restore environment
unsetenv_loaded_module
unsetenv_path_var TS1


#
#  test display mode
#

# test with value not set to variable prior to display
set tserr "$modlin
$modulefilere:

remove-path\tTS1 yes
setenv\t\tTS2 {}
$modlin"
testouterr_cmd_re "sh" "display $module" "" $tserr

# test with value set to variable prior to display (diff value than removed one)
setenv_var TS1 "no"
set tserr "$modlin
$modulefilere:

remove-path\tTS1 yes
setenv\t\tTS2 no
$modlin"
testouterr_cmd_re "sh" "display $module" "" $tserr

# test with value set to variable prior to display (value is removed one)
setenv_var TS1 "yes"
set tserr "$modlin
$modulefilere:

remove-path\tTS1 yes
setenv\t\tTS2 {}
$modlin"
testouterr_cmd_re "sh" "display $module" "" $tserr

# test with value set to variable (as path var) prior to display (value is removed one)
setenv_path_var TS1 "yes"
set tserr "$modlin
$modulefilere:

remove-path\tTS1 yes
setenv\t\tTS2 {}
$modlin"
testouterr_cmd_re "sh" "display $module" "" $tserr

# restore environment
unsetenv_path_var TS1


#
#  test help mode
#

# test with value not set to variable prior to help
set tserr "$modlin
Module Specific Help for $modulefilere:

$warn_msgs: Unable to find ModulesHelp in $modulefilere.
$modlin"
testouterr_cmd_re "sh" "help $module" "" $tserr

# test with value set to variable prior to help (diff value than removed one)
setenv_var TS1 "no"
testouterr_cmd_re "sh" "help $module" "" $tserr

# test with value set to variable prior to help (value is removed one)
setenv_var TS1 "yes"
testouterr_cmd_re "sh" "help $module" "" $tserr

# test with value set to variable (as path var) prior to help (value is removed one)
setenv_path_var TS1 "yes"
testouterr_cmd_re "sh" "help $module" "" $tserr

# restore environment
unsetenv_path_var TS1


#
#  test test mode
#

# test with value not set to variable prior to test
set tserr "$modlin
Module Specific Test for $modulefilere:

$warn_msgs: Unable to find ModulesTest in $modulefilere.
$modlin"
testouterr_cmd_re "sh" "test $module" "" $tserr

# test with value set to variable prior to test (diff value than removed one)
setenv_var TS1 "no"
testouterr_cmd_re "sh" "test $module" "" $tserr

# test with value set to variable prior to test (value is removed one)
setenv_var TS1 "yes"
testouterr_cmd_re "sh" "test $module" "" $tserr

# test with value set to variable (as path var) prior to test (value is removed one)
setenv_path_var TS1 "yes"
testouterr_cmd_re "sh" "test $module" "" $tserr

# restore environment
unsetenv_path_var TS1


#
#  Cleanup
#

reset_test_env
