##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2019/02/23
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:		load & unload
#   Modulefiles:	versions/1.1, versions/1.2, versions/1.3
#   Sub-Command:
#
#   Comment:	%C{
#			Setting a full path entry in MODULEPATH using a variable reference.
#		}C%
#
##############################################################################

# variable equals to a fully qualified path
set full_path $env(TESTSUITEDIR)/modulefiles.2/$version1
setenv_var MODULE_PATH_VAR $full_path
unsetenv_path_var MODULEPATH

# use test
set ans [list]
lappend ans [list setpath MODULEPATH \$MODULE_PATH_VAR]
test_cmd sh {use $MODULE_PATH_VAR} $ans

setenv_path_var MODULEPATH \$MODULE_PATH_VAR

# unuse test
set ans [list]
lappend ans [list unsetpath MODULEPATH]
test_cmd sh {unuse $MODULE_PATH_VAR} $ans

# load test
set ans [list]
lappend ans [list set TESTSUITE $version1]
lappend ans [list setpath LOADEDMODULES version]
lappend ans [list setpath _LMFILES_ $full_path/version]
test_cmd sh {load version} $ans

# unload test
setenv_loaded_module [list version] [list $full_path/version]
setenv_var TESTSUITE 1.3
set ans [list]
lappend ans [list unset TESTSUITE]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
test_cmd sh {unload version} $ans


# variable equals to a relative path
set rel_path testsuite/modulefiles.2/$version1
setenv_var MODULE_PATH_VAR $rel_path
unsetenv_path_var MODULEPATH
unsetenv_loaded_module
unsetenv_var TESTSUITE

# use test
set ans [list]
lappend ans [list setpath MODULEPATH \$MODULE_PATH_VAR]
test_cmd sh {use $MODULE_PATH_VAR} $ans

setenv_path_var MODULEPATH \$MODULE_PATH_VAR

# unuse test
set ans [list]
lappend ans [list unsetpath MODULEPATH]
test_cmd sh {unuse $MODULE_PATH_VAR} $ans

# load test
set ans [list]
lappend ans [list set TESTSUITE $version1]
lappend ans [list setpath LOADEDMODULES version]
lappend ans [list setpath _LMFILES_ $full_path/version]
test_cmd sh {load version} $ans

# unload test
setenv_loaded_module [list version] [list $full_path/version]
setenv_var TESTSUITE 1.3
set ans [list]
lappend ans [list unset TESTSUITE]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
test_cmd sh {unload version} $ans


#
#  Cleanup
#

reset_test_env
