##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2021/04/22
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:		variant, module, prereq, conflict
#   Modulefiles:    variant
#   Sub-Command:    load, unload, reload, purge
#
#   Comment:	%C{
#           Test variant over auto_handling mechanisms
#		}C%
#
##############################################################################

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

setenv_var MODULES_ADVANCED_VERSION_SPEC 1
setenv_var MODULES_IMPLICIT_DEFAULT 1


#
# conflict tests
#

setenv_var TESTSUITE_VARIANT 13

# load conflicting module (another version)
setenv_loaded_module [list vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
set tserr [msg_load vrreq1/2.0{foo=val1} [err_conflict vrreq1@1.0]]
testouterr_cmd_re sh {load --auto vrreq1/2.0 foo=val1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0:vrreq1/2.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0:$mp/vrreq1/2.0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0:vrreq1/2.0&vrreq1@1.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq1/2.0&foo|val1|0|0]
set tserr [msg_load vrreq1/2.0{foo=val1} [err_conlof vrreq1/1.0]]
testouterr_cmd_re sh {load -f --auto vrreq1/2.0 foo=val1} $ans $tserr

# load conflicting module (another version set)
set tserr [msg_load vrreq2/1.0{bar=2:foo=val3} [err_othervariantloaded {bar=1 foo=val1}]]
testouterr_cmd_re sh {load --auto vrreq2/1.0 foo=val3 bar=2} ERR $tserr
testouterr_cmd_re sh {load -f --auto vrreq2/1.0 foo=val3 bar=2} ERR $tserr

# ReqLo tentative hitting a conflict (but alternative found)
setenv_loaded_module [list vrreq2/2.0] [list $mp/vrreq2/2.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/2.0&vrreq2
unsetenv_path_var MODULES_LMPREREQ
setenv_path_var MODULES_LMVARIANT vrreq2/2.0&foo|val1|0|0&bar|1|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/2.0:vrreq3/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/2.0:$mp/vrreq3/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/2.0&foo|val1|0|0&bar|1|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/2.0&vrreq2:vrreq3/1.0&vrreq3:vrreq1/1.0&vrreq1@2.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq3/1.0:vrreq1/1.0]
lappend ans [list ERR]
set tserr [msg_top_load variant/7.0{foo=val2} {} {vrreq3/1.0{bar=1:foo=val1} vrreq1/1.0{foo=val1}} {}]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} $ans $tserr

# ReqLo tentative hitting a conflict (no alternative)
setenv_loaded_module [list vrreq1/2.0] [list $mp/vrreq1/2.0]
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0
unsetenv_path_var MODULES_LMPREREQ
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0
set tserr [msg_load vrreq1/1.0{foo=val1} [err_conflict vrreq1@2.0]]\n\n[msg_load variant/7.0{foo=val2} [err_reqlo vrreq1/1.0{foo=val1}]]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} ERR $tserr

# force ReqLo tentative hitting a conflict
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq1/2.0:vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq1/2.0:$mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
set tserr [msg_load vrreq1/1.0{foo=val1} [err_conlof vrreq1/2.0]]\n\n[msg_top_load variant/7.0{foo=val2} {} {vrreq2/1.0{bar=1:foo=val1} vrreq1/1.0{foo=val1}} {}]
testouterr_cmd_re sh {load -f --auto variant/7.0 foo=val2} $ans $tserr

# ReqLo tentative hitting another variant loaded
setenv_loaded_module [list vrreq2/1.0 vrreq1/1.0] [list $mp/vrreq2/1.0 $mp/vrreq1/1.0] [list vrreq2/1.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1}
setenv_path_var MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val2|0|0
set tserr [msg_load vrreq1/1.0{foo=val1} [err_othervariantloaded {foo=val2}]]\n\n[msg_load variant/7.0{foo=val2} [err_reqlo vrreq1/1.0{foo=val1}]]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} ERR $tserr

# force ReqLo tentative hitting another variant loaded
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val2|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list ERR]
set tserr [msg_load vrreq1/1.0{foo=val1} [err_othervariantloaded {foo=val2}]]\n\n[msg_load variant/7.0{foo=val2} [err_reqlof vrreq1/1.0{foo=val1}]]
testouterr_cmd_re sh {load -f --auto variant/7.0 foo=val2} $ans $tserr

# solve conflict impacting ReqLo
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
set tserr [msg_top_unload vrreq1/2.0{foo=val1} {} {} {vrreq1/1.0{foo=val1} variant/7.0{foo=val2}}]
testouterr_cmd_re sh {unload --auto vrreq1/2.0} $ans $tserr

# DepRe tentative hitting a conflict
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq1/2.0:vrreq2/1.0:vrreq1/1.0:variant/7.0:vrreq3/1.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq1/2.0:$mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0:$mp/vrreq3/1.0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0:vrreq3/1.0&vrreq3]
lappend ans [list setpath MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd_re sh {load --auto vrreq3/1.0 foo=val1 bar=1} $ans {}

# solve conflict impacting DepRe
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0 vrreq3/1.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0 $mp/vrreq3/1.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0:vrreq3/1.0&vrreq3
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq3/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq3/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq3/1.0&vrreq3:vrreq1/1.0&vrreq1@2.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
set tserr [msg_top_unload vrreq1/2.0{foo=val1} {} {} {vrreq1/1.0{foo=val1} variant/7.0{foo=val2}}]
testouterr_cmd_re sh {unload --auto vrreq1/2.0} $ans $tserr

# reload modules
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
testouterr_cmd_re sh {reload} ERR $err_unsatreload
testouterr_cmd_re sh {reload -f} ERR $err_unsatreload

# purge modules
set ans [list]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list unsetpath MODULES_LMVARIANT]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
testouterr_cmd_re sh {purge} $ans {}

unsetenv_loaded_module
unsetenv_path_var MODULES_LMCONFLICT
unsetenv_path_var MODULES_LMPREREQ
unsetenv_path_var MODULES_LMVARIANT


#
# conflict tests with requirement range
#

setenv_var TESTSUITE_VARIANT 14

# load conflicting module (another version)
setenv_loaded_module [list vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@<2.0
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
set tserr [msg_load vrreq1/2.0{foo=val1} [err_conflict vrreq1@1:]]
testouterr_cmd_re sh {load --auto vrreq1/2.0 foo=val1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0:vrreq1/2.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0:$mp/vrreq1/2.0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@<2.0:vrreq1/2.0&vrreq1@1<]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq1/2.0&foo|val1|0|0]
set tserr [msg_load vrreq1/2.0{foo=val1} [err_conlof vrreq1@1:]]
testouterr_cmd_re sh {load -f --auto vrreq1/2.0 foo=val1} $ans $tserr

# load conflicting module (another version set)
set tserr [msg_load vrreq2/1.0{bar=2:foo=val3} [err_othervariantloaded {bar=1 foo=val1}]]
testouterr_cmd_re sh {load --auto vrreq2/1.0 foo=val3 bar=2} ERR $tserr
testouterr_cmd_re sh {load -f --auto vrreq2/1.0 foo=val3 bar=2} ERR $tserr

# ReqLo tentative hitting a conflict (but alternative found)
setenv_loaded_module [list vrreq2/2.0] [list $mp/vrreq2/2.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/2.0&vrreq2
unsetenv_path_var MODULES_LMPREREQ
setenv_path_var MODULES_LMVARIANT vrreq2/2.0&foo|val1|0|0&bar|1|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/2.0:vrreq3/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/2.0:$mp/vrreq3/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/2.0&foo|val1|0|0&bar|1|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/2.0&vrreq2:vrreq3/1.0&vrreq3:vrreq1/1.0&vrreq1@<2.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq3/1.0:vrreq1/1.0]
lappend ans [list ERR]
set tserr [msg_top_load variant/7.0{foo=val2} {} {vrreq3/1.0{bar=1:foo=val1} vrreq1/1.0{foo=val1}} {}]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} $ans $tserr

# ReqLo tentative hitting a conflict (no alternative)
setenv_loaded_module [list vrreq1/2.0] [list $mp/vrreq1/2.0]
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1<
unsetenv_path_var MODULES_LMPREREQ
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0
set tserr [msg_load vrreq1/1.0{foo=val1} [err_conlo vrreq1@:2.0]]\n\n[msg_load variant/7.0{foo=val2} [err_reqlo vrreq1/1.0{foo=val1}]]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} ERR $tserr

# force ReqLo tentative hitting a conflict
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq1/2.0:vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq1/2.0:$mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1<:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@<2.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
set tserr [msg_load vrreq1/1.0{foo=val1} [err_conlof vrreq1@:2.0]]\n\n[msg_top_load variant/7.0{foo=val2} {} {vrreq2/1.0{bar=1:foo=val1} vrreq1/1.0{foo=val1}} {}]
testouterr_cmd_re sh {load -f --auto variant/7.0 foo=val2} $ans $tserr

# ReqLo tentative hitting another variant loaded
setenv_loaded_module [list vrreq2/1.0 vrreq1/1.0] [list $mp/vrreq2/1.0 $mp/vrreq1/1.0] [list vrreq2/1.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@<2.0
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1}
setenv_path_var MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val2|0|0
set tserr [msg_load vrreq1/1.0{foo=val1} [err_othervariantloaded {foo=val2}]]\n\n[msg_load variant/7.0{foo=val2} [err_reqlo vrreq1/1.0{foo=val1}]]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} ERR $tserr

# force ReqLo tentative hitting another variant loaded
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val2|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list ERR]
set tserr [msg_load vrreq1/1.0{foo=val1} [err_othervariantloaded {foo=val2}]]\n\n[msg_load variant/7.0{foo=val2} [err_reqlof vrreq1/1.0{foo=val1}]]
testouterr_cmd_re sh {load -f --auto variant/7.0 foo=val2} $ans $tserr

# solve conflict impacting ReqLo
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1<:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@<2.0
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@<2.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
set tserr [msg_top_unload vrreq1/2.0{foo=val1} {} {} {vrreq1/1.0{foo=val1} variant/7.0{foo=val2}}]
testouterr_cmd_re sh {unload --auto vrreq1/2.0} $ans $tserr

# DepRe tentative hitting a conflict
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1<:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@<2.0
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq1/2.0:vrreq2/1.0:vrreq1/1.0:variant/7.0:vrreq3/1.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq1/2.0:$mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0:$mp/vrreq3/1.0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1<:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@<2.0:vrreq3/1.0&vrreq3]
lappend ans [list setpath MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd_re sh {load --auto vrreq3/1.0 foo=val1 bar=1} $ans {}

# solve conflict impacting DepRe
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0 vrreq3/1.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0 $mp/vrreq3/1.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1<:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@<2.0:vrreq3/1.0&vrreq3
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq3/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq3/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq3/1.0&vrreq3:vrreq1/1.0&vrreq1@<2.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
set tserr [msg_top_unload vrreq1/2.0{foo=val1} {} {} {vrreq1/1.0{foo=val1} variant/7.0{foo=val2}}]
testouterr_cmd_re sh {unload --auto vrreq1/2.0} $ans $tserr

# reload modules
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1<:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@<2.0
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
testouterr_cmd_re sh {reload} ERR $err_unsatreload
testouterr_cmd_re sh {reload -f} ERR $err_unsatreload

# purge modules
set ans [list]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list unsetpath MODULES_LMVARIANT]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
testouterr_cmd_re sh {purge} $ans {}

unsetenv_loaded_module
unsetenv_path_var MODULES_LMCONFLICT
unsetenv_path_var MODULES_LMPREREQ
unsetenv_path_var MODULES_LMVARIANT


#
# conflict tests with module designated with use of symbol and alias
#

setenv_var TESTSUITE_VARIANT 15

# load conflicting module (another version)
setenv_loaded_module [list vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&alvrreq12
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
setenv_path_var MODULES_LMALTNAME vrreq1/1.0&vrreq1/sym
set tserr [msg_load vrreq1/2.0{foo=val1} [err_conflict vrreq1/sym]]
testouterr_cmd_re sh {load --auto vrreq1/2.0 foo=val1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0:vrreq1/2.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0:$mp/vrreq1/2.0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&alvrreq12:vrreq1/2.0&vrreq1/sym]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq1/2.0&foo|val1|0|0]
lappend ans [list setpath MODULES_LMALTNAME vrreq1/1.0&vrreq1/sym:vrreq1/2.0&al|alvrreq12]
set tserr [msg_load vrreq1/2.0{foo=val1} [err_conlof vrreq1/sym]]
testouterr_cmd_re sh {load -f --auto vrreq1/2.0 foo=val1} $ans $tserr

# load conflicting module (another version set)
set tserr [msg_load vrreq2/1.0{bar=2:foo=val3} [err_othervariantloaded {bar=1 foo=val1}]]
testouterr_cmd_re sh {load --auto vrreq2/1.0 foo=val3 bar=2} ERR $tserr
testouterr_cmd_re sh {load -f --auto vrreq2/1.0 foo=val3 bar=2} ERR $tserr

# ReqLo tentative hitting a conflict (but alternative found)
setenv_loaded_module [list vrreq2/2.0] [list $mp/vrreq2/2.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/2.0&vrreq2
unsetenv_path_var MODULES_LMPREREQ
setenv_path_var MODULES_LMVARIANT vrreq2/2.0&foo|val1|0|0&bar|1|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/2.0:vrreq3/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/2.0:$mp/vrreq3/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/2.0&foo|val1|0|0&bar|1|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/2.0&vrreq2:vrreq3/1.0&vrreq3:vrreq1/1.0&alvrreq12]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq3/1.0:vrreq1/1.0]
lappend ans [list setpath MODULES_LMALTNAME vrreq1/1.0&vrreq1/sym]
lappend ans [list ERR]
set tserr [msg_top_load variant/7.0{foo=val2} {} {vrreq3/1.0{bar=1:foo=val1} vrreq1/1.0{foo=val1}} {}]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} $ans $tserr

# ReqLo tentative hitting a conflict (no alternative)
setenv_loaded_module [list vrreq1/2.0] [list $mp/vrreq1/2.0]
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1/sym
unsetenv_path_var MODULES_LMPREREQ
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0
setenv_path_var MODULES_LMALTNAME vrreq1/2.0&al|alvrreq12
set tserr [msg_load vrreq1/1.0{foo=val1} [err_conflict alvrreq12]]\n\n[msg_load variant/7.0{foo=val2} [err_reqlo vrreq1/1.0{foo=val1}]]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} ERR $tserr

# force ReqLo tentative hitting a conflict
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq1/2.0:vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq1/2.0:$mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq1/2.0&vrreq1/sym:vrreq2/1.0&vrreq2:vrreq1/1.0&alvrreq12]
lappend ans [list setpath MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
lappend ans [list setpath MODULES_LMALTNAME vrreq1/2.0&al|alvrreq12:vrreq1/1.0&vrreq1/sym]
set tserr [msg_load vrreq1/1.0{foo=val1} [err_conlof alvrreq12]]\n\n[msg_top_load variant/7.0{foo=val2} {} {vrreq2/1.0{bar=1:foo=val1} vrreq1/1.0{foo=val1}} {}]
testouterr_cmd_re sh {load -f --auto variant/7.0 foo=val2} $ans $tserr

# ReqLo tentative hitting another variant loaded
setenv_loaded_module [list vrreq2/1.0 vrreq1/1.0] [list $mp/vrreq2/1.0 $mp/vrreq1/1.0] [list vrreq2/1.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&alvrreq12
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1}
setenv_path_var MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val2|0|0
setenv_path_var MODULES_LMALTNAME vrreq1/1.0&vrreq1/sym
set tserr [msg_load vrreq1/1.0{foo=val1} [err_othervariantloaded {foo=val2}]]\n\n[msg_load variant/7.0{foo=val2} [err_reqlo vrreq1/1.0{foo=val1}]]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} ERR $tserr

# force ReqLo tentative hitting another variant loaded
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val2|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list ERR]
set tserr [msg_load vrreq1/1.0{foo=val1} [err_othervariantloaded {foo=val2}]]\n\n[msg_load variant/7.0{foo=val2} [err_reqlof vrreq1/1.0{foo=val1}]]
testouterr_cmd_re sh {load -f --auto variant/7.0 foo=val2} $ans $tserr

# solve conflict impacting ReqLo
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1/sym:vrreq2/1.0&vrreq2:vrreq1/1.0&alvrreq12
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
setenv_path_var MODULES_LMALTNAME vrreq1/2.0&al|alvrreq12:vrreq1/1.0&vrreq1/sym
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&alvrreq12]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
lappend ans [list setpath MODULES_LMALTNAME vrreq1/1.0&vrreq1/sym]
set tserr [msg_top_unload vrreq1/2.0{foo=val1} {} {} {vrreq1/1.0{foo=val1} variant/7.0{foo=val2}}]
testouterr_cmd_re sh {unload --auto vrreq1/2.0} $ans $tserr

# DepRe tentative hitting a conflict
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1/sym:vrreq2/1.0&vrreq2:vrreq1/1.0&alvrreq12
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
setenv_path_var MODULES_LMALTNAME vrreq1/2.0&al|alvrreq12:vrreq1/1.0&vrreq1/sym
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq1/2.0:vrreq2/1.0:vrreq1/1.0:variant/7.0:vrreq3/1.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq1/2.0:$mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0:$mp/vrreq3/1.0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq1/2.0&vrreq1/sym:vrreq2/1.0&vrreq2:vrreq1/1.0&alvrreq12:vrreq3/1.0&vrreq3]
lappend ans [list setpath MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd_re sh {load --auto vrreq3/1.0 foo=val1 bar=1} $ans {}

# solve conflict impacting DepRe
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0 vrreq3/1.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0 $mp/vrreq3/1.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1/sym:vrreq2/1.0&vrreq2:vrreq1/1.0&alvrreq12:vrreq3/1.0&vrreq3
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0
setenv_path_var MODULES_LMALTNAME vrreq1/2.0&al|alvrreq12:vrreq1/1.0&vrreq1/sym
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq3/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq3/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq3/1.0&vrreq3:vrreq1/1.0&alvrreq12]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
lappend ans [list setpath MODULES_LMALTNAME vrreq1/1.0&vrreq1/sym]
set tserr [msg_top_unload vrreq1/2.0{foo=val1} {} {} {vrreq1/1.0{foo=val1} variant/7.0{foo=val2}}]
testouterr_cmd_re sh {unload --auto vrreq1/2.0} $ans $tserr

# reload modules
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1/sym:vrreq2/1.0&vrreq2:vrreq1/1.0&alvrreq12
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
setenv_path_var MODULES_LMALTNAME vrreq1/2.0&al|alvrreq12:vrreq1/1.0&vrreq1/sym
testouterr_cmd_re sh {reload} ERR $err_unsatreload
testouterr_cmd_re sh {reload -f} ERR $err_unsatreload

# purge modules
set ans [list]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list unsetpath MODULES_LMVARIANT]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMALTNAME]
testouterr_cmd_re sh {purge} $ans {}

unsetenv_loaded_module
unsetenv_path_var MODULES_LMCONFLICT
unsetenv_path_var MODULES_LMPREREQ
unsetenv_path_var MODULES_LMVARIANT
unsetenv_path_var MODULES_LMALTNAME


#
# requirements specified with module unload instead of conflict
#

setenv_var TESTSUITE_VARIANT 16

# load conflicting module (another version)
setenv_loaded_module [list vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
set tserr [msg_unload vrreq1/1.0{foo=val1} [err_prerequn variant/7.0]]\n\n[msg_load vrreq1/2.0{foo=val1} [err_conun vrreq1/1.0]]
testouterr_cmd_re sh {load --auto vrreq1/2.0 foo=val1} ERR $tserr

set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0:vrreq1/2.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0:$mp/vrreq1/2.0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0:vrreq1/2.0&vrreq1@1.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq1/2.0&foo|val1|0|0]
lappend ans [list ERR]
set tserr [msg_unload vrreq1/1.0{foo=val1} [err_prerequn variant/7.0]]\n\n[msg_load vrreq1/2.0{foo=val1} [err_conunf vrreq1/1.0]]
testouterr_cmd_re sh {load -f --auto vrreq1/2.0 foo=val1} $ans $tserr

# load conflicting module (another version set)
set tserr [msg_load vrreq2/1.0{bar=2:foo=val3} [err_othervariantloaded {bar=1 foo=val1}]]
testouterr_cmd_re sh {load --auto vrreq2/1.0 foo=val3 bar=2} ERR $tserr
testouterr_cmd_re sh {load -f --auto vrreq2/1.0 foo=val3 bar=2} ERR $tserr

# ReqLo tentative hitting a conflict (but alternative found)
setenv_loaded_module [list vrreq2/2.0] [list $mp/vrreq2/2.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/2.0&vrreq2
unsetenv_path_var MODULES_LMPREREQ
setenv_path_var MODULES_LMVARIANT vrreq2/2.0&foo|val1|0|0&bar|1|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/2.0:vrreq3/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/2.0:$mp/vrreq3/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/2.0&foo|val1|0|0&bar|1|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/2.0&vrreq2:vrreq3/1.0&vrreq3:vrreq1/1.0&vrreq1@2.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq3/1.0:vrreq1/1.0]
lappend ans [list ERR]
set tserr [msg_top_load variant/7.0{foo=val2} {} {vrreq3/1.0{bar=1:foo=val1} vrreq1/1.0{foo=val1}} {}]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} $ans $tserr

# ReqLo tentative hitting a conflict (no alternative)
setenv_loaded_module [list vrreq1/2.0] [list $mp/vrreq1/2.0]
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0
unsetenv_path_var MODULES_LMPREREQ
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
set tserr [msg_top_load variant/7.0{foo=val2} {vrreq1/2.0{foo=val1}} {} {} {Loading requirement: vrreq2/1.0{bar=1:foo=val1} vrreq1/1.0{foo=val1}}]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} $ans $tserr

# force ReqLo tentative hitting a conflict
testouterr_cmd_re sh {load -f --auto variant/7.0 foo=val2} $ans $tserr

# ReqLo tentative hitting another variant loaded
setenv_loaded_module [list vrreq2/1.0 vrreq1/1.0] [list $mp/vrreq2/1.0 $mp/vrreq1/1.0] [list vrreq2/1.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1}
setenv_path_var MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val2|0|0
set tserr [msg_load vrreq1/1.0{foo=val1} [err_othervariantloaded {foo=val2}]]\n\n[msg_load variant/7.0{foo=val2} [err_reqlo vrreq1/1.0{foo=val1}]]
testouterr_cmd_re sh {load --auto variant/7.0 foo=val2} ERR $tserr

# force ReqLo tentative hitting another variant loaded
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val2|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list ERR]
set tserr [msg_load vrreq1/1.0{foo=val1} [err_othervariantloaded {foo=val2}]]\n\n[msg_load variant/7.0{foo=val2} [err_reqlof vrreq1/1.0{foo=val1}]]
testouterr_cmd_re sh {load -f --auto variant/7.0 foo=val2} $ans $tserr

# solve conflict impacting ReqLo
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
set tserr [msg_top_unload vrreq1/2.0{foo=val1} {} {} {vrreq1/1.0{foo=val1} variant/7.0{foo=val2}}]
testouterr_cmd_re sh {unload --auto vrreq1/2.0} $ans $tserr

# DepRe tentative hitting a conflict
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq1/2.0:vrreq2/1.0:vrreq1/1.0:variant/7.0:vrreq3/1.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq1/2.0:$mp/vrreq2/1.0:$mp/vrreq1/1.0:$mp/variant/7.0:$mp/vrreq3/1.0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0:vrreq3/1.0&vrreq3]
lappend ans [list setpath MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0]
testouterr_cmd_re sh {load --auto vrreq3/1.0 foo=val1 bar=1} $ans {}

# solve conflict impacting DepRe
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0 vrreq3/1.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0 $mp/vrreq3/1.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0:vrreq3/1.0&vrreq3
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0:vrreq3/1.0:vrreq1/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0:$mp/vrreq3/1.0:$mp/vrreq1/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2:vrreq3/1.0&vrreq3:vrreq1/1.0&vrreq1@2.0]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq3/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0]
lappend ans [list setpath MODULES_LMNOTUASKED vrreq2/1.0:vrreq1/1.0]
set tserr [msg_top_unload vrreq1/2.0{foo=val1} {} {} {vrreq1/1.0{foo=val1} variant/7.0{foo=val2}}]
testouterr_cmd_re sh {unload --auto vrreq1/2.0} $ans $tserr

# reload modules
setenv_loaded_module [list vrreq1/2.0 vrreq2/1.0 vrreq1/1.0 variant/7.0] [list $mp/vrreq1/2.0 $mp/vrreq2/1.0 $mp/vrreq1/1.0 $mp/variant/7.0] [list vrreq2/1.0 vrreq1/1.0]
setenv_path_var MODULES_LMPREREQ {vrreq1/1.0&vrreq2@1.0 bar=1 foo=val1|vrreq3@1.0 bar=1 foo=val1:variant/7.0&vrreq1@1.0 foo=val1}
setenv_path_var MODULES_LMCONFLICT vrreq1/2.0&vrreq1@1.0:vrreq2/1.0&vrreq2:vrreq1/1.0&vrreq1@2.0
setenv_path_var MODULES_LMVARIANT vrreq1/2.0&foo|val1|0|0:vrreq2/1.0&foo|val1|0|0&bar|1|0|0:vrreq1/1.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
testouterr_cmd_re sh {reload} ERR $err_unsatreload
testouterr_cmd_re sh {reload -f} ERR $err_unsatreload

# purge modules
set ans [list]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list unsetpath MODULES_LMVARIANT]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
testouterr_cmd_re sh {purge} $ans {}

unsetenv_loaded_module
unsetenv_path_var MODULES_LMCONFLICT
unsetenv_path_var MODULES_LMPREREQ
unsetenv_path_var MODULES_LMVARIANT


#
# switch tests with auto_handling
#

setenv_var TESTSUITE_VARIANT 17

# replace a requirement by an alternative: wrong variant to unload (2-arg form)
setenv_loaded_module [list vrreq2/2.0 vrreq1/2.0 variant/7.0] [list $mp/vrreq2/2.0 $mp/vrreq1/2.0 $mp/variant/7.0] [list vrreq2/2.0 vrreq1/2.0]
setenv_path_var MODULES_LMCONFLICT vrreq2/2.0&vrreq2:vrreq1/2.0&vrreq1
setenv_path_var MODULES_LMPREREQ {vrreq1/2.0&vrreq2@<2.0 bar=1|vrreq3@1.0< foo=val1:variant/7.0&vrreq1@1< foo=val1}
setenv_path_var MODULES_LMVARIANT vrreq2/2.0&foo|val2|0|1&bar|1|0|0:vrreq1/2.0&foo|val1|0|0:variant/7.0&foo|val2|0|0
set tserr [msg_load vrreq2/1.0{bar=2} [err_conlo vrreq2]]\n\n[msg_switch vrreq2/2.0{bar=2} vrreq2/1.0{bar=2} [err_swon vrreq2/1.0{bar=2}]]
testouterr_cmd_re sh {switch --auto vrreq2/2.0 bar=2 vrreq2/1.0 bar=2} ERR $tserr
testouterr_cmd_re sh {switch --no-auto vrreq2/2.0 bar=2 vrreq2/1.0 bar=2} ERR $tserr

# replace a requirement by an alternative: wrong variant to unload (1-arg form)
set ans [list]
lappend ans [list setpath LOADEDMODULES vrreq2/1.0]
lappend ans [list setpath _LMFILES_ $mp/vrreq2/1.0]
lappend ans [list setpath MODULES_LMCONFLICT vrreq2/1.0&vrreq2]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list setpath MODULES_LMVARIANT vrreq2/1.0&foo|val1|0|2&bar|2|0|0]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list ERR]
set tserr [msg_load vrreq1/2.0{foo=val1} [err_reqmis vrreq2@:2.0{bar=1} vrreq3@1.0:{foo=val1}]]\n\n[msg_load variant/7.0{foo=val2} [err_reqmis vrreq1@1:{foo=val1}]]\n\n[msg_top_switch vrreq2/2.0{bar=1:foo=val2} vrreq2/1.0{bar=2:foo=val1} {variant/7.0{foo=val2} vrreq1/2.0{foo=val1}} {} {} {} {} [err_depref vrreq1/2.0{foo=val1}] [err_depref variant/7.0{foo=val2}]]
testouterr_cmd_re sh {switch --auto vrreq2/1.0 bar=2} $ans $tserr
set tserr [msg_unload vrreq2/2.0{bar=1:foo=val2} [err_prerequn vrreq1/2.0]]\n\n[msg_switch vrreq2/2.0{bar=1:foo=val2} vrreq2/1.0{bar=2} [err_swoff vrreq2/2.0{bar=1:foo=val2}]]
testouterr_cmd_re sh {switch --no-auto vrreq2/1.0 bar=2} ERR $tserr


#
#  Cleanup
#

reset_test_env
