##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2012/05/17
#   Last Mod.:		%U%, %G%
#
#   Authors:		R.K. Owen, <rk@owen.sj.ca.us>
#
#   Description:	recursive load/unload test
#   Command:		load
#   Modulefiles:	recurs/modA
#   			recurs/modA
#   Sub-Command:
#
#   Comment:	%C{
#			Recursive load a modulefile
#		}C%
#
##############################################################################

# ensure auto symbolic versions are not set for these tests
setenv_var MODULES_ADVANCED_VERSION_SPEC 0

set modA "recurs/modA"
set modB "recurs/modB"

set modAp "$modpath/$modA"
set modBp "$modpath/$modB"

#
# set up an empty environment
#
set module ""
set modulefile ""
setenv_loaded_module $module $modulefile

#
#  load
#  For the different shells ...
#
set module "$modB:$modA"
set modulefile "$modBp:$modAp"
set moderr "modA load\nmodB load\n\n[msg_top_load $modA {} $modB {}]"

lappend ans [list set MODA_LOADED 1]
lappend ans [list set MODB_LOADED 1]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]
lappend ans [list setpath MODULES_LMNOTUASKED "$modB"]
lappend ans [list setpath MODULES_LMPREREQ "$modA&$modB"]
lappend ans [list setpath MODULES_LMCONFLICT "$modA&modA"]

#
#  The load tests
#
testouterr_cmd_re "ALL" "load $modA" $ans "$moderr"

#
# set-up a loaded environment
#
setenv_loaded_module [list "foobar/1.0" $module] [list "/some/path/foobar/1.0" $modulefile] [list $modB]
setenv_path_var MODULES_LMPREREQ $modA&$modB
set module "foobar/1.0"
set modulefile "/some/path/foobar/1.0"
set moderr "modA unload\nmodB unload\n\n[msg_top_unload $modA {} $modB {}]"

set ans [list]
# interpretation is done sequentially not cascaded when auto_handling is enabled (change result order)
if {$install_autohandling eq {n}} {
lappend ans [list unset MODA_LOADED]
lappend ans [list unset MODB_LOADED]
}
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]
lappend ans [list unsetpath MODULES_LMPREREQ]
if {$install_autohandling eq {y}} {
lappend ans [list unset MODA_LOADED]
lappend ans [list unset MODB_LOADED]
}
lappend ans [list unsetpath MODULES_LMNOTUASKED]

#
#  The unload tests
#
testouterr_cmd_re "ALL" "unload $modA" $ans "$moderr"

#
#  Cleanup
#

reset_test_env
