##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2021/05/12
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:		variant, module-hide, module-forbid, module-tag
#   Modulefiles:    variant
#   Sub-Command:    load
#
#   Comment:	%C{
#           Test variant over hide/forbid/tag modules
#		}C%
#
##############################################################################

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

setenv_var MODULES_IMPLICIT_DEFAULT 1
setenv_var MODULES_ADVANCED_VERSION_SPEC 1


#
# module-hide test
#

setenv_var TESTSUITE_VARIANT_TAG 1

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}


# test hidden-loaded silent messages
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {variant/7.0&variant/8.0 foo=val1}]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
lappend ans [list setpath MODULES_LMNOTUASKED variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
testouterr_cmd_re sh {load variant@7.0} $ans {}

setenv_loaded_module [list variant/8.0 variant/7.0] [list $mp/variant/8.0 $mp/variant/7.0] [list variant/8.0]
setenv_path_var MODULES_LMPREREQ {variant/7.0&variant/8.0 foo=val1}
setenv_path_var MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2
setenv_path_var MODULES_LMTAG variant/8.0&hidden-loaded
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMVARIANT]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list unsetpath MODULES_LMTAG]
testouterr_cmd sh {unload variant@7.0} $ans {}

# reload to another variant set
setenv_loaded_module [list variant/8.0] [list $mp/variant/8.0]
unsetenv_path_var MODULES_LMPREREQ
setenv_path_var MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0
setenv_path_var MODULES_LMTAG variant/8.0&hidden-loaded

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
lappend ans [list unsetpath MODULES_LMTAG]
testouterr_cmd sh {switch variant@8.0 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
testouterr_cmd sh {switch variant@8.0 foo=val1} $ans {}

unsetenv_loaded_module
unsetenv_path_var MODULES_LMVARIANT
unsetenv_path_var MODULES_LMTAG


# test when module-hide is hard mode and applies to a variant default value specifically
setenv_var TESTSUITE_VARIANT_TAG 2

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=1} $ans {}


setenv_var TESTSUITE_VARIANT_TAG 3
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}


setenv_var TESTSUITE_VARIANT_TAG 4
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}


# test when module-hide applies to generic module name
setenv_var TESTSUITE_VARIANT_TAG 5
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}


setenv_var TESTSUITE_VARIANT_TAG 6
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

testouterr_cmd sh {load variant@7.5:8.5 foo=val2} ERR "$err_path'variant@7.5:8.5 foo=val2'"

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} ERR "$err_path'variant@7.5:8.5 foo=val1 bar=1'"

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}


# dot hidden file
setenv_var TESTSUITE_VARIANT_TAG 7

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/.w\ s]
lappend ans [list setpath _LMFILES_ $mp/variant/.w\ s]
lappend ans [list setpath MODULES_LMTAG variant/.w\ s&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/.w\ s&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant/.w\ s foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/.w\ s]
lappend ans [list setpath _LMFILES_ $mp/variant/.w\ s]
lappend ans [list setpath MODULES_LMTAG variant/.w\ s&hidden-loaded]
lappend ans [list setpath MODULES_LMVARIANT variant/.w\ s&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant/.w\ s foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/.w\ s]
lappend ans [list setpath _LMFILES_ $mp/variant/.w\ s]
lappend ans [list setpath MODULES_LMVARIANT variant/.w\ s&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant/.w\ s foo=val2} $ans {}


#
# module-forbid test
#

setenv_var TESTSUITE_VARIANT_TAG 11

set tserr [err_accessdenied variant/8.0{foo=val1}]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set tserr [err_accessdenied variant/8.0{bar=2:foo=val1}]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=2} ERR $tserr

set tserr [err_accessdenied variant/8.0{bar=1:foo=val1}]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2 bar=1} $ans {}

set tserr [err_accessdenied variant/8.0{foo=val1}]
testouterr_cmd sh {load variant@8.0 foo=val1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val2} $ans {}

set tserr [err_accessdenied variant/8.0{bar=2:foo=val1}]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} ERR $tserr

set tserr [err_accessdenied variant/8.0{bar=1:foo=val1}]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}


setenv_var TESTSUITE_VARIANT_TAG 12

set tserr [msg_load variant/8.0{foo=val1} [err_accessdenied variant/8.0{bar=2:foo=val1}]]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set tserr [err_accessdenied variant/8.0{bar=2:foo=val1}]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=2} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set tserr [msg_load variant/8.0{foo=val1} [err_accessdenied variant/8.0{bar=2:foo=val1}]]
testouterr_cmd sh {load variant@8.0 foo=val1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val2} $ans {}

set tserr [err_accessdenied variant/8.0{bar=2:foo=val1}]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=1} $ans {}


setenv_var TESTSUITE_VARIANT_TAG 13
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set tserr [err_accessdenied variant/8.0{bar=1:foo=val1} {forbidden message}]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}


# skip tests on Tcl 8.4 as --after option is unsupported there
if {[cmpversion $tclsh_version 8.5] != -1} {

setenv_var TESTSUITE_VARIANT_TAG 14
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&nearly-forbidden]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
set tomorrow [clock format [expr {[clock seconds]+86400}] -format %Y-%m-%d]
set tserr [msg_load variant/8.0{bar=2:foo=val1} [err_accessnearlydenied $tomorrow {nearly message}]]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&nearly-forbidden]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
set tserr [msg_load variant/8.0{bar=2:foo=val1} [err_accessnearlydenied $tomorrow {nearly message}]]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}

}


setenv_var TESTSUITE_VARIANT_TAG 15
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set tserr [err_accessdenied variant/8.0{bar=1:foo=val1}]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}


setenv_var TESTSUITE_VARIANT_TAG 16
set tserr [err_accessdenied variant/8.0{foo=val1}]
testouterr_cmd sh {load variant@8.0 foo=val1} ERR $tserr

set tserr [err_accessdenied variant/8.0{foo=val2}]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} ERR $tserr

set tserr [err_accessdenied variant/8.0{bar=2:foo=val1}]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} ERR $tserr

set tserr [err_accessdenied variant/8.0{bar=1:foo=val1}]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} ERR $tserr

set tserr [err_accessdenied variant/8.0{bar=1:foo=val2}]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} ERR $tserr


#
# module-tag test (sticky/super-sticky)
#

setenv_var TESTSUITE_VARIANT_TAG 21

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}

# unload sticky module
setenv_loaded_module [list variant/8.0] [list $mp/variant/8.0]
setenv_path_var MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0
setenv_path_var MODULES_LMTAG variant/8.0&sticky
set tserr [msg_unload variant/8.0{bar=1:foo=val1} $err_stickyunload]
testouterr_cmd sh {unload variant@8.0} ERR $tserr
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMVARIANT]
lappend ans [list unsetpath MODULES_LMTAG]
set tserr [msg_unload variant/8.0{bar=1:foo=val1} $err_stickyunloadf]
testouterr_cmd sh {unload -f variant@8.0} $ans $tserr

# switch to a sticky variant
set tserr [msg_switch variant/8.0{bar=1:foo=val1} variant/8.0{bar=2:foo=val1} $err_stickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val1 bar=2} ERR $tserr
set tserr [msg_switch variant/8.0{bar=1:foo=val1} variant/8.0{foo=val1} $err_stickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val1} ERR $tserr

# switch to a non-sticky variant
set tserr [msg_switch variant/8.0{bar=1:foo=val1} variant/8.0{foo=val2} $err_stickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val2} ERR $tserr

# reload
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {reload} $ans {}

unsetenv_loaded_module
unsetenv_path_var MODULES_LMVARIANT
unsetenv_path_var MODULES_LMTAG


setenv_var TESTSUITE_VARIANT_TAG 22

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=1} $ans {}

# unload sticky module
setenv_loaded_module [list variant/8.0] [list $mp/variant/8.0]
setenv_path_var MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2
setenv_path_var MODULES_LMTAG variant/8.0&sticky
set tserr [msg_unload variant/8.0{bar=2:foo=val1} $err_stickyunload]
testouterr_cmd sh {unload variant@8.0} ERR $tserr

# switch to a sticky variant
set tserr [msg_switch variant/8.0{bar=2:foo=val1} variant/8.0{bar=3:foo=val1} $err_stickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val1 bar=3} ERR $tserr
set tserr [msg_switch variant/8.0{bar=2:foo=val1} variant/8.0{foo=val1} $err_stickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val1} ERR $tserr

# switch to a non-sticky variant
set tserr [msg_switch variant/8.0{bar=2:foo=val1} variant/8.0{foo=val2} $err_stickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val2} ERR $tserr

# reload
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {reload} $ans {}

unsetenv_loaded_module
unsetenv_path_var MODULES_LMVARIANT
unsetenv_path_var MODULES_LMTAG


setenv_var TESTSUITE_VARIANT_TAG 23
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}

# unload sticky module
setenv_loaded_module [list variant/8.0] [list $mp/variant/8.0]
setenv_path_var MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0
setenv_path_var MODULES_LMTAG variant/8.0&sticky
set tserr [msg_unload variant/8.0{bar=1:foo=val1} $err_stickyunload]
testouterr_cmd sh {unload variant@8.0} ERR $tserr

# switch to a non-sticky variant
set tserr [msg_switch variant/8.0{bar=1:foo=val1} variant/8.0{foo=val2} $err_stickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val2} ERR $tserr
set tserr [msg_switch variant/8.0{bar=1:foo=val1} variant/8.0{bar=1:foo=val2} $err_stickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val2 bar=1} ERR $tserr

unsetenv_loaded_module
unsetenv_path_var MODULES_LMVARIANT
unsetenv_path_var MODULES_LMTAG


setenv_var TESTSUITE_VARIANT_TAG 24
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&super-sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&super-sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}


setenv_var TESTSUITE_VARIANT_TAG 25
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&super-sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}

# unload sticky module
setenv_loaded_module [list variant/8.0] [list $mp/variant/8.0]
setenv_path_var MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0
setenv_path_var MODULES_LMTAG variant/8.0&super-sticky
set tserr [msg_unload variant/8.0{bar=1:foo=val1} $err_superstickyunload]
testouterr_cmd sh {unload variant@8.0} ERR $tserr

# switch to a sticky variant
set tserr [msg_switch variant/8.0{bar=1:foo=val1} 'variant/.w\ s'{bar=1:foo=val1} $err_superstickyunload]
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/.w\ s]
lappend ans [list setpath _LMFILES_ $mp/variant/.w\ s]
lappend ans [list setpath MODULES_LMTAG variant/.w\ s&super-sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/.w\ s&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {switch variant@.w\ s foo=val1 bar=1} $ans {}
testouterr_cmd sh {switch variant@.w\ s bar=1 foo=val1} $ans {}
set tserr [msg_switch variant/8.0{bar=1:foo=val1} 'variant/.w\ s'{foo=val1} $err_superstickyunload]
testouterr_cmd sh {switch variant@.w\ s foo=val1} ERR $tserr
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&super-sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {switch variant@8.0 foo=val1 bar=1} $ans {}

# switch to a non-sticky variant
set tserr [msg_switch variant/8.0{bar=1:foo=val1} variant/8.0{foo=val2} $err_superstickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val2} ERR $tserr

unsetenv_loaded_module
unsetenv_path_var MODULES_LMVARIANT
unsetenv_path_var MODULES_LMTAG


setenv_var TESTSUITE_VARIANT_TAG 26
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@8.0 foo=val1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {load variant@7.5:8.5 foo=val2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {load variant@8.0 foo=val1 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@7.5:8.5 foo=val1 bar=1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {load variant@8.0 foo=val2 bar=1} $ans {}

# unload sticky module
setenv_loaded_module [list variant/8.0] [list $mp/variant/8.0]
setenv_path_var MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0
setenv_path_var MODULES_LMTAG variant/8.0&sticky
set tserr [msg_unload variant/8.0{bar=1:foo=val1} $err_stickyunload]
testouterr_cmd sh {unload variant@8.0} ERR $tserr

# switch to a sticky variant
set tserr [msg_switch variant/8.0{bar=1:foo=val1} variant/8.0{bar=1:foo=val2} $err_stickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val2 bar=1} ERR $tserr
set tserr [msg_switch variant/8.0{bar=1:foo=val1} variant/8.0{foo=val1} $err_stickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val1} ERR $tserr
set tserr [msg_switch variant/8.0{bar=1:foo=val1} variant/8.0{foo=val2} $err_stickyunload]
testouterr_cmd sh {switch variant@8.0 foo=val2} ERR $tserr

# switch to a non-sticky variant
set tserr [msg_switch variant/8.0{bar=1:foo=val1} 'variant/.w\ s'{foo=val2} $err_stickyunload]
testouterr_cmd sh {switch variant@.w\ s foo=val2} ERR $tserr

unsetenv_loaded_module
unsetenv_path_var MODULES_LMVARIANT
unsetenv_path_var MODULES_LMTAG


setenv_var TESTSUITE_VARIANT_TAG 27
setenv_loaded_module [list variant/8.0] [list $mp/variant/8.0]
setenv_path_var MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|1|0|0
setenv_path_var MODULES_LMTAG variant/8.0&sticky

# switch to a sticky variant
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|1|0|0]
testouterr_cmd sh {switch variant@8.0 foo=val2 bar=1} $ans {}
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2]
testouterr_cmd sh {switch variant@8.0 foo=val1} $ans {}
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/8.0]
lappend ans [list setpath _LMFILES_ $mp/variant/8.0]
lappend ans [list setpath MODULES_LMTAG variant/8.0&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/8.0&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {switch variant@8.0 foo=val2} $ans {}
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/.w\ s]
lappend ans [list setpath _LMFILES_ $mp/variant/.w\ s]
lappend ans [list setpath MODULES_LMTAG variant/.w\ s&sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/.w\ s&foo|val2|0|0&bar|2|0|2]
testouterr_cmd sh {switch variant@.w\ s foo=val2} $ans {}

unsetenv_loaded_module
unsetenv_path_var MODULES_LMVARIANT
unsetenv_path_var MODULES_LMTAG


setenv_var TESTSUITE_VARIANT_TAG 28
setenv_loaded_module [list variant/8.0] [list $mp/variant/8.0]
setenv_path_var MODULES_LMVARIANT variant/8.0&foo|val1|0|0&bar|2|0|2
setenv_path_var MODULES_LMTAG variant/8.0&super-sticky

# switch to a sticky variant
# CORNER CASE: stickyness swap do not know that default value of variant bar matches sticky rule
set tserr [msg_switch variant/8.0{bar=2:foo=val1} 'variant/.w\ s'{foo=val1} $err_superstickyunload]
testouterr_cmd sh {switch variant@.w\ s foo=val1} ERR $tserr
set ans [list]
lappend ans [list setpath LOADEDMODULES variant/.w\ s]
lappend ans [list setpath _LMFILES_ $mp/variant/.w\ s]
lappend ans [list setpath MODULES_LMTAG variant/.w\ s&super-sticky]
lappend ans [list setpath MODULES_LMVARIANT variant/.w\ s&foo|val1|0|0&bar|2|0|1]
testouterr_cmd sh {switch variant@.w\ s foo=val1 bar=2} $ans {}

unsetenv_loaded_module
unsetenv_path_var MODULES_LMVARIANT
unsetenv_path_var MODULES_LMTAG


#
#  Cleanup
#

reset_test_env
