##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2020/12/20
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:		load, unload, switch, reload, purge, restore
#   Modulefiles:
#   Sub-Command:
#
#   Comment:	%C{
#           Check sticky modules that should not be unloaded unless
#           forced or reloaded
#		}C%
#
##############################################################################

set mp $modpath.3
set mpre $modpathre.3
setenv_path_var MODULEPATH $mp

# disable advanced version specifiers not to get auto symbols in the way
setenv_var MODULES_ADVANCED_VERSION_SPEC 0

# ensure avail tests have implicit default enabled
setenv_var MODULES_IMPLICIT_DEFAULT 1

# basic tests with only one module loaded, tagged sticky
set anslo [list]
lappend anslo [list setpath LOADEDMODULES sticky/1.0]
lappend anslo [list setpath _LMFILES_ $mp/sticky/1.0]
lappend anslo [list setpath MODULES_LMTAG sticky/1.0&sticky]
testouterr_cmd_re sh {load sticky/1.0} $anslo {}

setenv_loaded_module [list sticky/1.0] [list $mp/sticky/1.0]
setenv_path_var MODULES_LMTAG sticky/1.0&sticky

set tserr [msg_unload sticky/1.0 $err_stickyunload]
testouterr_cmd_re sh {unload sticky/1.0} ERR $tserr
testouterr_cmd_re sh {purge} ERR $tserr

testouterr_cmd_re sh {switch sticky} ERR [msg_switch sticky/1.0 sticky $err_stickyunload]
testouterr_cmd_re sh {switch sticky/1.0 foo} ERR [msg_switch sticky/1.0 foo $err_stickyunload]

testouterr_cmd_re sh {reload} $anslo {}

set ans [list]
lappend ans [list setpath LOADEDMODULES sticky/1.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/sticky/1.0:$mp/foo/2.0]
lappend ans [list ERR]
set tserr [msg_unload sticky/1.0 $err_stickyunload]\n\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore testsuite/home/coll-sticky-0} $ans $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES foo/2.0:sticky/1.0]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0:$mp/sticky/1.0]
lappend ans [list setpath MODULES_LMTAG sticky/1.0&sticky]
testouterr_cmd_re sh {restore testsuite/home/coll-sticky-1} $ans [msg_unload sticky/1.0]\n[msg_load foo/2.0]\n[msg_load sticky/1.0]

# force commands
set ansun [list]
lappend ansun [list unsetpath LOADEDMODULES]
lappend ansun [list unsetpath _LMFILES_]
lappend ansun [list unsetpath MODULES_LMTAG]
set tserr [msg_unload sticky/1.0 $err_stickyunloadf]
testouterr_cmd_re sh {unload -f sticky/1.0} $ansun $tserr
testouterr_cmd_re sh {purge -f} $ansun $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0]
lappend ans [list unsetpath MODULES_LMTAG]
testouterr_cmd_re sh {switch -f sticky/1.0 foo} $ans [msg_unload sticky/1.0 $err_stickyunloadf]

testouterr_cmd_re sh {reload -f} $anslo {}

set ans [list]
lappend ans [list setpath LOADEDMODULES foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0]
lappend ans [list unsetpath MODULES_LMTAG]
set tserr [msg_unload sticky/1.0 $err_stickyunloadf]\n\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore -f testsuite/home/coll-sticky-0} $ans $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES foo/2.0:sticky/1.0]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0:$mp/sticky/1.0]
lappend ans [list setpath MODULES_LMTAG sticky/1.0&sticky]
testouterr_cmd_re sh {restore -f testsuite/home/coll-sticky-1} $ans [msg_unload sticky/1.0]\n[msg_load foo/2.0]\n[msg_load sticky/1.0]

# test with multiple module loaded, one is sticky
setenv_loaded_module [list foo/2.0 sticky/1.0 bar/2.0] [list $mp/foo/2.0 $mp/sticky/1.0 $mp/bar/2.0]
setenv_path_var MODULES_LMTAG sticky/1.0&sticky

set tserr [msg_unload sticky/1.0 $err_stickyunload]
testouterr_cmd_re sh {unload sticky/1.0} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES foo/2.0:bar/2.0]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0:$mp/bar/2.0]
lappend ans [list unsetpath MODULES_LMTAG]
set tserr [msg_unload sticky/1.0 $err_stickyunloadf]
testouterr_cmd_re sh {unload -f sticky/1.0} $ans $tserr

testouterr_cmd_re sh {purge -f} $ansun $tserr
set ans [list]
lappend ans [list setpath _LMFILES_ $mp/sticky/1.0]
lappend ans [list setpath LOADEDMODULES sticky/1.0]
lappend ans [list ERR]
set tserr [msg_unload sticky/1.0 $err_stickyunload]
testouterr_cmd_re sh {purge} $ans $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES foo/2.0:sticky/1.0:bar/2.0]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0:$mp/sticky/1.0:$mp/bar/2.0]
lappend ans [list setpath MODULES_LMTAG sticky/1.0&sticky]
testouterr_cmd_re sh {reload} $ans {}
testouterr_cmd_re sh {reload -f} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES foo/2.0:bar/2.0:baz/2.0]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0:$mp/bar/2.0:$mp/baz/2.0]
lappend ans [list unsetpath MODULES_LMTAG]

testouterr_cmd_re sh {switch sticky baz} ERR [msg_switch sticky/1.0 baz $err_stickyunload]
testouterr_cmd_re sh {switch -f sticky baz} $ans [msg_unload sticky/1.0 $err_stickyunloadf]

set ans [list]
lappend ans [list setpath LOADEDMODULES sticky/1.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/sticky/1.0:$mp/foo/2.0]
lappend ans [list setpath MODULES_LMTAG sticky/1.0&sticky]
set tserr [msg_unload bar/2.0]\n[msg_unload sticky/1.0]\n[msg_unload foo/2.0]\n[msg_load sticky/1.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore testsuite/home/coll-sticky-2} $ans $tserr
testouterr_cmd_re sh {restore -f testsuite/home/coll-sticky-2} $ans $tserr

set ans [list]
lappend ans [list setpath _LMFILES_ $mp/sticky/1.0:$mp/sticky/4.0:$mp/foo/2.0]
lappend ans [list setpath LOADEDMODULES sticky/1.0:sticky/4.0:foo/2.0]
lappend ans [list ERR]
set tserr [msg_unload bar/2.0]\n\n[msg_unload sticky/1.0 $err_stickyunload]\n\n[msg_unload foo/2.0]\n[msg_load sticky/4.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore testsuite/home/coll-sticky-3} $ans $tserr
set ans [list]
lappend ans [list setpath LOADEDMODULES sticky/4.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/sticky/4.0:$mp/foo/2.0]
lappend ans [list unsetpath MODULES_LMTAG]
set tserr [msg_unload bar/2.0]\n\n[msg_unload sticky/1.0 $err_stickyunloadf]\n\n[msg_unload foo/2.0]\n[msg_load sticky/4.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore -f testsuite/home/coll-sticky-3} $ans $tserr

# test over *Dependency Reload* mechanism
setenv_var TESTSUITE_STICKY_DEP 1
setenv_loaded_module [list foo/2.0 sticky/1.0 bar/2.0] [list $mp/foo/2.0 $mp/sticky/1.0 $mp/bar/2.0]
setenv_path_var MODULES_LMTAG sticky/1.0&sticky
setenv_path_var MODULES_LMPREREQ sticky/1.0&foo|baz:bar/2.0&sticky/1.0

set ans [list]
lappend ans [list setpath LOADEDMODULES foo/2.0:baz/2.0:sticky/1.0:bar/2.0]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0:$mp/baz/2.0:$mp/sticky/1.0:$mp/bar/2.0]
lappend ans [list setpath MODULES_LMTAG sticky/1.0&sticky]
lappend ans [list setpath MODULES_LMPREREQ sticky/1.0&foo|baz:bar/2.0&sticky/1.0]
testouterr_cmd_re sh {load --auto baz/2.0} $ans [msg_top_load baz/2.0 {} {} {sticky/1.0 bar/2.0}]

set ans [list]
lappend ans [list setpath LOADEDMODULES baz/2.0:sticky/1.0:bar/2.0]
lappend ans [list setpath _LMFILES_ $mp/baz/2.0:$mp/sticky/1.0:$mp/bar/2.0]
lappend ans [list setpath MODULES_LMTAG sticky/1.0&sticky]
lappend ans [list setpath MODULES_LMPREREQ sticky/1.0&foo|baz:bar/2.0&sticky/1.0]
testouterr_cmd_re sh {switch --auto foo/2.0 baz/2.0} $ans [msg_top_switch foo/2.0 baz/2.0 {} {} {} {} {sticky/1.0 bar/2.0}]

setenv_loaded_module [list foo/2.0 baz/2.0 sticky/1.0 bar/2.0] [list $mp/foo/2.0 $mp/baz/2.0 $mp/sticky/1.0 $mp/bar/2.0]
testouterr_cmd_re sh {unload --auto foo/2.0} $ans [msg_top_unload foo/2.0 {} {} {sticky/1.0 bar/2.0}]

# test over *Dependency Unload* mechanism
setenv_loaded_module [list foo/2.0 sticky/1.0 bar/2.0] [list $mp/foo/2.0 $mp/sticky/1.0 $mp/bar/2.0]
setenv_path_var MODULES_LMTAG sticky/1.0&sticky
setenv_path_var MODULES_LMPREREQ sticky/1.0&foo|baz:bar/2.0&sticky/1.0

testouterr_cmd_re sh {unload --auto foo/2.0} ERR [msg_unload foo/2.0 $err_stickyunload [err_depun sticky/1.0]]

set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMTAG]
testouterr_cmd_re sh {unload -f --auto foo/2.0} $ans [msg_unload sticky/1.0 $err_stickyunloadf]\n\n[msg_top_unload foo/2.0 {bar/2.0 sticky/1.0} {} {}]

# test over *Useless Requirement Unload* mechanism
setenv_loaded_module [list foo/2.0 sticky/1.0 bar/2.0] [list $mp/foo/2.0 $mp/sticky/1.0 $mp/bar/2.0] [list foo/2.0 sticky/1.0]
setenv_path_var MODULES_LMTAG sticky/1.0&sticky
setenv_path_var MODULES_LMPREREQ sticky/1.0&foo|baz:bar/2.0&sticky/1.0

set ans [list]
lappend ans [list setpath MODULES_LMPREREQ sticky/1.0&foo|baz]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0:$mp/sticky/1.0]
lappend ans [list setpath LOADEDMODULES foo/2.0:sticky/1.0]
lappend ans [list ERR]
testouterr_cmd_re sh {unload --auto bar/2.0} $ans [msg_unload bar/2.0 $err_stickyunload [err_urequn sticky/1.0]]

set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list unsetpath MODULES_LMTAG]
testouterr_cmd_re sh {unload -f --auto bar/2.0} $ans [msg_unload sticky/1.0 $err_stickyunloadf]\n\n[msg_top_unload bar/2.0 {} {sticky/1.0 foo/2.0} {}]

set ans [list]
lappend ans [list setpath MODULES_LMPREREQ sticky/1.0&foo|baz]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0:$mp/sticky/1.0:$mp/bar/1.0]
lappend ans [list setpath LOADEDMODULES foo/2.0:sticky/1.0:bar/1.0]
lappend ans [list ERR]
testouterr_cmd_re sh {switch --auto bar/2.0 bar/1.0} $ans [msg_switch bar/2.0 bar/1.0 $err_stickyunload [err_urequn sticky/1.0]]

set ans [list]
lappend ans [list setpath LOADEDMODULES bar/1.0]
lappend ans [list setpath _LMFILES_ $mp/bar/1.0]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list unsetpath MODULES_LMTAG]
testouterr_cmd_re sh {switch -f --auto bar/2.0 bar/1.0} $ans [msg_unload sticky/1.0 $err_stickyunloadf]\n\n[msg_top_switch bar/2.0 bar/1.0 {} {sticky/1.0 foo/2.0} {} {} {}]

# test when stickyness is defined over generic module name
unsetenv_var TESTSUITE_STICKY_DEP
setenv_var TESTSUITE_STICKY_GENERIC 1
setenv_loaded_module [list sticky/1.0] [list $mp/sticky/1.0]
setenv_path_var MODULES_LMTAG sticky/1.0&sticky
unsetenv_path_var MODULES_LMPREREQ

set ans [list]
lappend ans [list setpath LOADEDMODULES sticky/2.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/sticky/2.0:$mp/foo/2.0]
lappend ans [list setpath MODULES_LMTAG sticky/2.0&sticky]
set tserr [msg_unload sticky/1.0]\n[msg_load sticky/2.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore testsuite/home/coll-sticky-4} $ans $tserr
testouterr_cmd_re sh {restore -f testsuite/home/coll-sticky-4} $ans $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES sticky/4.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/sticky/4.0:$mp/foo/2.0]
lappend ans [list setpath MODULES_LMTAG sticky/4.0&sticky]
set tserr [msg_unload sticky/1.0]\n[msg_load sticky/4.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore testsuite/home/coll-sticky-5} $ans $tserr
testouterr_cmd_re sh {restore -f testsuite/home/coll-sticky-5} $ans $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES sticky/2.0]
lappend ans [list setpath _LMFILES_ $mp/sticky/2.0]
lappend ans [list setpath MODULES_LMTAG sticky/2.0&sticky]
testouterr_cmd_re sh {switch sticky/2.0} $ans {}
testouterr_cmd_re sh {switch sticky sticky/2.0} $ans {}
testouterr_cmd_re sh {switch -f sticky sticky/2.0} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES sticky/4.0]
lappend ans [list setpath _LMFILES_ $mp/sticky/4.0]
lappend ans [list setpath MODULES_LMTAG sticky/4.0&sticky]
testouterr_cmd_re sh {switch sticky} $ans {}
testouterr_cmd_re sh {switch sticky sticky} $ans {}
testouterr_cmd_re sh {switch -f sticky sticky} $ans {}

set tserr [msg_switch sticky/1.0 foo $err_stickyunload]
testouterr_cmd_re sh {switch sticky foo} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0]
lappend ans [list unsetpath MODULES_LMTAG]
set tserr [msg_unload sticky/1.0 $err_stickyunloadf]
testouterr_cmd_re sh {switch -f sticky foo} $ans $tserr

# test when stickyness is defined over generic module name with deep module
setenv_var TESTSUITE_STICKY_GENERIC 1
setenv_loaded_module [list stickysub/dir1/1.0] [list $mp/stickysub/dir1/1.0]
setenv_path_var MODULES_LMTAG stickysub/dir1/1.0&sticky

set ans1 [list]
lappend ans1 [list setpath LOADEDMODULES stickysub/dir1/2.0]
lappend ans1 [list setpath _LMFILES_ $mp/stickysub/dir1/2.0]
lappend ans1 [list setpath MODULES_LMTAG stickysub/dir1/2.0&sticky]
testouterr_cmd_re sh {switch stickysub/dir1/2.0} $ans1 {}
testouterr_cmd_re sh {switch stickysub stickysub/dir1/2.0} $ans1 {}
testouterr_cmd_re sh {switch stickysub/dir1 stickysub/dir1/2.0} $ans1 {}

set ans2 [list]
lappend ans2 [list setpath LOADEDMODULES stickysub/dir2/3.0]
lappend ans2 [list setpath _LMFILES_ $mp/stickysub/dir2/3.0]
lappend ans2 [list setpath MODULES_LMTAG stickysub/dir2/3.0&sticky]
testouterr_cmd_re sh {switch stickysub/dir2/3.0} $ans2 {}

set ans3 [list]
lappend ans3 [list setpath LOADEDMODULES stickysub/dir2/4.0]
lappend ans3 [list setpath _LMFILES_ $mp/stickysub/dir2/4.0]
lappend ans3 [list setpath MODULES_LMTAG stickysub/dir2/4.0&sticky]
testouterr_cmd_re sh {switch stickysub} $ans3 {}
testouterr_cmd_re sh {switch stickysub/dir2} $ans3 {}

setenv_var TESTSUITE_STICKY_GENERIC 2
testouterr_cmd_re sh {switch stickysub/dir1/2.0} $ans1 {}
testouterr_cmd_re sh {switch stickysub/dir1} $ans1 {}

set tserr [msg_switch stickysub/dir1/1.0 stickysub $err_stickyunload]
testouterr_cmd_re sh {switch stickysub} ERR $tserr
set tserr [msg_switch stickysub/dir1/1.0 stickysub/dir2 $err_stickyunload]
testouterr_cmd_re sh {switch stickysub/dir2} ERR $tserr
set tserr [msg_switch stickysub/dir1/1.0 stickysub/dir2/4.0 $err_stickyunload]
testouterr_cmd_re sh {switch stickysub/dir2/4.0} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir2/4.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir2/4.0]
lappend ans [list unsetpath MODULES_LMTAG]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunloadf]
testouterr_cmd_re sh {switch -f stickysub} $ans $tserr
testouterr_cmd_re sh {switch -f stickysub/dir2} $ans $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir1/1.0:stickysub/dir2/4.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir1/1.0:$mp/stickysub/dir2/4.0:$mp/foo/2.0]
lappend ans [list ERR]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunload]\n\n[msg_load stickysub/dir2/4.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore testsuite/home/coll-sticky-6} $ans $tserr
set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir2/4.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir2/4.0:$mp/foo/2.0]
lappend ans [list unsetpath MODULES_LMTAG]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunloadf]\n\n[msg_load stickysub/dir2/4.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore -f testsuite/home/coll-sticky-6} $ans $tserr

setenv_var TESTSUITE_STICKY_GENERIC 3
set tserr [msg_switch stickysub/dir1/1.0 stickysub $err_stickyunload]
testouterr_cmd_re sh {switch stickysub} ERR $tserr
set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir2/4.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir2/4.0]
lappend ans [list unsetpath MODULES_LMTAG]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunloadf]
testouterr_cmd_re sh {switch -f stickysub} $ans $tserr

set tserr [msg_switch stickysub/dir1/1.0 stickysub/dir1/2.0 $err_stickyunload]
testouterr_cmd_re sh {switch stickysub/dir1/2.0} ERR $tserr
set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir1/2.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir1/2.0]
lappend ans [list unsetpath MODULES_LMTAG]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunloadf]
testouterr_cmd_re sh {switch -f stickysub/dir1/2.0} $ans $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir1/1.0:stickysub/dir2/4.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir1/1.0:$mp/stickysub/dir2/4.0:$mp/foo/2.0]
lappend ans [list ERR]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunload]\n\n[msg_load stickysub/dir2/4.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore testsuite/home/coll-sticky-6} $ans $tserr
set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir2/4.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir2/4.0:$mp/foo/2.0]
lappend ans [list unsetpath MODULES_LMTAG]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunloadf]\n\n[msg_load stickysub/dir2/4.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore -f testsuite/home/coll-sticky-6} $ans $tserr

setenv_var MODULES_ADVANCED_VERSION_SPEC 1
setenv_var TESTSUITE_STICKY_GENERIC 4
set tserr [msg_switch stickysub/dir1/1.0 stickysub/dir1/2.0 $err_stickyunload]
testouterr_cmd_re sh {switch stickysub/dir1/2.0} ERR $tserr
set tserr [msg_switch stickysub/dir1/1.0 stickysub/dir1 $err_stickyunload]
testouterr_cmd_re sh {switch stickysub/dir1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir1/2.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir1/2.0]
lappend ans [list setpath MODULES_LMTAG stickysub/dir1/2.0&sticky]
lappend ans [list setpath MODULES_LMALTNAME stickysub/dir1/2.0&as|stickysub/dir1/default&as|stickysub/dir1/latest]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunloadf]
testouterr_cmd_re sh {switch -f stickysub/dir1/2.0} $ans $tserr
testouterr_cmd_re sh {switch -f stickysub/dir1} $ans $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir1/1.0:stickysub/dir2/4.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir1/1.0:$mp/stickysub/dir2/4.0:$mp/foo/2.0]
lappend ans [list setpath MODULES_LMALTNAME stickysub/dir2/4.0&as|stickysub/default&as|stickysub/latest&as|stickysub/dir2/default&as|stickysub/dir2/latest:foo/2.0&as|foo/default&as|foo/latest]
lappend ans [list ERR]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunload]\n\n[msg_load stickysub/dir2/4.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore testsuite/home/coll-sticky-6} $ans $tserr
set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir2/4.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir2/4.0:$mp/foo/2.0]
lappend ans [list unsetpath MODULES_LMTAG]
lappend ans [list setpath MODULES_LMALTNAME stickysub/dir2/4.0&as|stickysub/default&as|stickysub/latest&as|stickysub/dir2/default&as|stickysub/dir2/latest:foo/2.0&as|foo/default&as|foo/latest]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunloadf]\n\n[msg_load stickysub/dir2/4.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore -f testsuite/home/coll-sticky-6} $ans $tserr

setenv_var TESTSUITE_STICKY_GENERIC 5
set tserr [msg_switch stickysub/dir1/1.0 stickysub/dir1/2.0 $err_stickyunload]
testouterr_cmd_re sh {switch stickysub/dir1/2.0} ERR $tserr
set tserr [msg_switch stickysub/dir1/1.0 stickysub/dir1 $err_stickyunload]
testouterr_cmd_re sh {switch stickysub/dir1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir1/2.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir1/2.0]
lappend ans [list setpath MODULES_LMTAG stickysub/dir1/2.0&sticky]
lappend ans [list setpath MODULES_LMALTNAME stickysub/dir1/2.0&as|stickysub/dir1/default&as|stickysub/dir1/latest]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunloadf]
testouterr_cmd_re sh {switch -f stickysub/dir1/2.0} $ans $tserr
testouterr_cmd_re sh {switch -f stickysub/dir1} $ans $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir1/1.0:stickysub/dir2/4.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir1/1.0:$mp/stickysub/dir2/4.0:$mp/foo/2.0]
lappend ans [list setpath MODULES_LMALTNAME stickysub/dir2/4.0&as|stickysub/default&as|stickysub/latest&as|stickysub/dir2/default&as|stickysub/dir2/latest:foo/2.0&as|foo/default&as|foo/latest]
lappend ans [list ERR]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunload]\n\n[msg_load stickysub/dir2/4.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore testsuite/home/coll-sticky-6} $ans $tserr
set ans [list]
lappend ans [list setpath LOADEDMODULES stickysub/dir2/4.0:foo/2.0]
lappend ans [list setpath _LMFILES_ $mp/stickysub/dir2/4.0:$mp/foo/2.0]
lappend ans [list unsetpath MODULES_LMTAG]
lappend ans [list setpath MODULES_LMALTNAME stickysub/dir2/4.0&as|stickysub/default&as|stickysub/latest&as|stickysub/dir2/default&as|stickysub/dir2/latest:foo/2.0&as|foo/default&as|foo/latest]
set tserr [msg_unload stickysub/dir1/1.0 $err_stickyunloadf]\n\n[msg_load stickysub/dir2/4.0]\n[msg_load foo/2.0]
testouterr_cmd_re sh {restore -f testsuite/home/coll-sticky-6} $ans $tserr

# test purge and reload when sticky module has a dependency
unsetenv_var TESTSUITE_STICKY_GENERIC
setenv_var MODULES_ADVANCED_VERSION_SPEC 0
setenv_var TESTSUITE_STICKY_DEP 1
setenv_loaded_module [list foo/2.0 sticky/1.0 bar/2.0] [list $mp/foo/2.0 $mp/sticky/1.0 $mp/bar/2.0]
setenv_path_var MODULES_LMTAG sticky/1.0&sticky
setenv_path_var MODULES_LMPREREQ sticky/1.0&foo|baz:bar/2.0&sticky/1.0

set ans [list]
lappend ans [list setpath LOADEDMODULES foo/2.0:sticky/1.0:bar/2.0]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0:$mp/sticky/1.0:$mp/bar/2.0]
lappend ans [list setpath MODULES_LMTAG sticky/1.0&sticky]
lappend ans [list setpath MODULES_LMPREREQ sticky/1.0&foo|baz:bar/2.0&sticky/1.0]
testouterr_cmd_re sh {reload} $ans {}
testouterr_cmd_re sh {reload -f} $ans {}

set ans [list]
lappend ans [list setpath MODULES_LMPREREQ sticky/1.0&foo|baz]
lappend ans [list setpath _LMFILES_ $mp/foo/2.0:$mp/sticky/1.0]
lappend ans [list setpath LOADEDMODULES foo/2.0:sticky/1.0]
lappend ans [list ERR]
set tserr [msg_unload sticky/1.0 $err_stickyunload]\n\n[msg_unload foo/2.0 [err_deplo sticky/1.0]]
testouterr_cmd_re sh {purge} $ans $tserr
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMTAG]
set tserr [msg_unload sticky/1.0 $err_stickyunloadf]
testouterr_cmd_re sh {purge -f} $ans $tserr


#
#  Cleanup
#

reset_test_env
