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

set module "unsetenv/0.6"
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 "sh" "load $module" $ans ""

# test with value set to variable prior to load
setenv_var TS1 "no"
testouterr_cmd "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 TS1]
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
setenv_var TS1 "no"
testouterr_cmd "sh" "unload $module" $ans ""

# 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:

unsetenv\tTS1
setenv\t\tTS2 {}
$modlin"
testouterr_cmd_re "sh" "display $module" "" $tserr

# test with value set to variable prior to display
setenv_var TS1 "no"
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 load
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 load
setenv_var TS1 "no"
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 load
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 load
setenv_var TS1 "no"
testouterr_cmd_re "sh" "test $module" "" $tserr

# restore environment
unsetenv_path_var TS1


#
#  Cleanup
#

reset_test_env
