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

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


setenv_var MODULES_ADVANCED_VERSION_SPEC 1


#
# test boolean variant definition
#

# test bad definitions
if {[cmpversion $tclsh_version 8.5] > -1} {

setenv_var TESTSUITE_VARIANT bool1
set tserr [msg_load variant/1.0{+foo} [err_invalvarval foo 1 --boolean]]
testouterr_cmd sh {load variant/1.0 +foo} ERR $tserr

setenv_var TESTSUITE_VARIANT bool2
set linenum [expr {[cmpversion $tclsh_version 8.5] > 0 ? 104 : 3}]
set tserr [escre [msg_load variant/1.0{+foo} [msg_moderr [err_boolvarval foo] {variant --boolean foo 0 1<EXM>} $mp/variant/1.0 $linenum]]]
testouterr_cmd_re sh {load variant/1.0 +foo} ERR $tserr

setenv_var TESTSUITE_VARIANT bool3
set linenum [expr {[cmpversion $tclsh_version 8.5] > 0 ? 107 : 3}]
set tserr [escre [msg_load variant/1.0{+foo} [msg_moderr [err_boolvarval foo] {variant --boolean foo val1 val2 val3<EXM>} $mp/variant/1.0 $linenum]]]
testouterr_cmd_re sh {load variant/1.0 +foo} ERR $tserr

setenv_var TESTSUITE_VARIANT bool4
set linenum [expr {[cmpversion $tclsh_version 8.5] > 0 ? 110 : 3}]
set tserr [escre [msg_load variant/1.0{+foo} [msg_moderr [err_boolvarval foo] {variant --boolean --default val1 foo val1 val2 val3<EXM>} $mp/variant/1.0 $linenum]]]
testouterr_cmd_re sh {load variant/1.0 +foo} ERR $tserr

setenv_var TESTSUITE_VARIANT bool5
set linenum [expr {[cmpversion $tclsh_version 8.5] > 0 ? 113 : 3}]
set tserr [escre [msg_load variant/1.0{+foo} [msg_moderr [err_booldflvarval foo] {variant --default val1 --boolean foo<EXM>} $mp/variant/1.0 $linenum]]]
testouterr_cmd_re sh {load variant/1.0 +foo} ERR $tserr

}

# test variant redefinition
setenv_var TESTSUITE_VARIANT bool6
set ans [list]
lappend ans [list set TS0 foo]
lappend ans [list set TS1 foo=1]
lappend ans [list set TS2 true]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|1|0|0&foo|1|1|0]
testouterr_cmd sh {load variant/1.0 +foo} $ans {}

setenv_var TESTSUITE_VARIANT bool7
set ans [list]
lappend ans [list set TS0 foo]
lappend ans [list set TS1 foo=1]
lappend ans [list set TS2 true]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|1|1|0&foo|1|0|0]
testouterr_cmd sh {load variant/1.0 +foo} $ans {}


# regular definition
setenv_var TESTSUITE_VARIANT bool8
set ans [list]
lappend ans [list set TS0 foo]
lappend ans [list set TS1 foo=1]
lappend ans [list set TS2 true]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|1|1|0]
testouterr_cmd sh {load variant/1.0 +foo} $ans {}

# variant specified multiple times
set ans [list]
lappend ans [list set TS0 foo]
lappend ans [list set TS1 foo=1]
lappend ans [list set TS2 true]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|1|1|0]
set tserr [msg_load variant/1.0{+foo}]
testouterr_cmd sh {load -v variant/1.0 foo=true +foo} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 -foo foo=true} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 foo=false +foo} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 foo=no foo=on} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 foo=off foo=1} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 ~foo+foo} $ans $tserr

set ans [list]
lappend ans [list set TS0 foo]
lappend ans [list set TS1 foo=0]
lappend ans [list set TS2 false]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|0|1|0]
set tserr [msg_load variant/1.0{-foo}]
testouterr_cmd sh {load -v variant/1.0 +foo foo=false} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 foo=false foo=off} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 foo=true foo=no} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 -foo foo=t foo=0} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 +foo~foo} $ans $tserr


#
# test boolean variant specification
#

# default value test
set anst [list]
lappend anst [list set TS0 foo]
lappend anst [list set TS1 foo=1]
lappend anst [list set TS2 true]
lappend anst [list setpath LOADEDMODULES variant/1.0]
lappend anst [list setpath _LMFILES_ $mp/variant/1.0]
lappend anst [list setpath MODULES_LMVARIANT variant/1.0&foo|1|1|2]
set ansf [list]
lappend ansf [list set TS0 foo]
lappend ansf [list set TS1 foo=0]
lappend ansf [list set TS2 false]
lappend ansf [list setpath LOADEDMODULES variant/1.0]
lappend ansf [list setpath _LMFILES_ $mp/variant/1.0]
lappend ansf [list setpath MODULES_LMVARIANT variant/1.0&foo|0|1|2]

setenv_var TESTSUITE_VARIANT bool10
testouterr_cmd sh {load variant/1.0} $anst {}
setenv_var TESTSUITE_VARIANT bool11
testouterr_cmd sh {load variant/1.0} $ansf {}
setenv_var TESTSUITE_VARIANT bool12
testouterr_cmd sh {load variant/1.0} $anst {}
setenv_var TESTSUITE_VARIANT bool13
testouterr_cmd sh {load variant/1.0} $ansf {}
setenv_var TESTSUITE_VARIANT bool14
testouterr_cmd sh {load variant/1.0} $anst {}
setenv_var TESTSUITE_VARIANT bool15
testouterr_cmd sh {load variant/1.0} $ansf {}
setenv_var TESTSUITE_VARIANT bool16
testouterr_cmd sh {load variant/1.0} $anst {}
setenv_var TESTSUITE_VARIANT bool17
testouterr_cmd sh {load variant/1.0} $ansf {}
setenv_var TESTSUITE_VARIANT bool18
testouterr_cmd sh {load variant/1.0} $anst {}
setenv_var TESTSUITE_VARIANT bool19
testouterr_cmd sh {load variant/1.0} $ansf {}


setenv_var TESTSUITE_VARIANT bool12
# default value specified (true)
set ans [list]
lappend ans [list set TS0 foo]
lappend ans [list set TS1 foo=1]
lappend ans [list set TS2 true]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|1|1|1]
testouterr_cmd sh {load variant/1.0 +foo} $ans {}
testouterr_cmd sh {load variant/1.0 foo=true} $ans {}
testouterr_cmd sh {load variant/1.0 foo=1} $ans {}
# non-default value specified (false)
set ans [list]
lappend ans [list set TS0 foo]
lappend ans [list set TS1 foo=0]
lappend ans [list set TS2 false]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|0|1|0]
testouterr_cmd sh {load variant/1.0 -foo} $ans {}
testouterr_cmd sh {load variant/1.0 foo=off} $ans {}
testouterr_cmd sh {load variant/1.0 foo=0} $ans {}

setenv_var TESTSUITE_VARIANT bool13
# default value specified (false)
set ans [list]
lappend ans [list set TS0 foo]
lappend ans [list set TS1 foo=0]
lappend ans [list set TS2 false]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|0|1|1]
set tserr [msg_load variant/1.0{-foo}]
testouterr_cmd sh {load -v variant/1.0 ~foo} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 foo=f} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 foo=0} $ans $tserr
# non-default value specified (true)
set ans [list]
lappend ans [list set TS0 foo]
lappend ans [list set TS1 foo=1]
lappend ans [list set TS2 true]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|1|1|0]
set tserr [msg_load variant/1.0{+foo}]
testouterr_cmd sh {load -v variant/1.0 +foo} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 foo=t} $ans $tserr
testouterr_cmd sh {load -v variant/1.0 foo=on} $ans $tserr


# specify boolean variant whereas variant is not defined as boolean
setenv_var TESTSUITE_VARIANT bool20
set ans [list]
lappend ans [list set TS0 foo]
lappend ans [list set TS1 foo=1]
lappend ans [list set TS2 true]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|1|0|1]
testouterr_cmd sh {load -v variant/1.0 +foo} $ans [msg_load variant/1.0{foo=1}]

set ans [list]
lappend ans [list set TS0 foo]
lappend ans [list set TS1 foo=0]
lappend ans [list set TS2 false]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|0|0|0]
testouterr_cmd sh {load -v variant/1.0 ~foo} $ans [msg_load variant/1.0{foo=0}]

if {[cmpversion $tclsh_version 8.5] > -1} {

setenv_var TESTSUITE_VARIANT bool21
set linenum [expr {[cmpversion $tclsh_version 8.5] > 0 ? 160 : 3}]
set tserr [escre [msg_load variant/1.0{+foo} [msg_moderr [err_boolonnonbool foo] {variant foo false true<EXM>} $mp/variant/1.0 $linenum]]]
testouterr_cmd_re sh {load -v variant/1.0 +foo} ERR $tserr
set tserr [escre [msg_load variant/1.0{-foo} [msg_moderr [err_boolonnonbool foo] {variant foo false true<EXM>} $mp/variant/1.0 $linenum]]]
testouterr_cmd_re sh {load -v variant/1.0~foo} ERR $tserr

setenv_var TESTSUITE_VARIANT bool22
set linenum [expr {[cmpversion $tclsh_version 8.5] > 0 ? 163 : 3}]
set tserr [escre [msg_load variant/1.0{+foo} [msg_moderr [err_boolonnonbool foo] {variant foo yes no y n<EXM>} $mp/variant/1.0 $linenum]]]
testouterr_cmd_re sh {load -v variant/1.0 +foo} ERR $tserr
set tserr [escre [msg_load variant/1.0{-foo} [msg_moderr [err_boolonnonbool foo] {variant foo yes no y n<EXM>} $mp/variant/1.0 $linenum]]]
testouterr_cmd_re sh {load -v variant/1.0~foo} ERR $tserr

}


#
# getvariant test on boolean
#

setenv_var TESTSUITE_VARIANT bool1
set ans [list]
lappend ans [list setpath TS0 {foo=1}]
lappend ans [list setpath TS1 {foo=1}]
lappend ans [list setpath LOADEDMODULES variant/5.0]
lappend ans [list setpath _LMFILES_ $mp/variant/5.0]
lappend ans [list setpath MODULES_LMVARIANT variant/5.0&foo|1|1|0]
testouterr_cmd_re sh {load variant/5.0 +foo} $ans {}


#
# is-loaded tests
#

setenv_var TESTSUITE_VARIANT bool8
setenv_loaded_module [list variant/1.0] [list $mp/variant/1.0]
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1|1|0

testouterr_cmd sh {is-loaded variant@1.0} OK {}
testouterr_cmd sh {is-loaded variant@1.0 +foo} OK {}
testouterr_cmd sh {is-loaded variant@1.0 foo=on} OK {}
testouterr_cmd sh {is-loaded variant@1.0 foo=1} OK {}
testouterr_cmd sh {is-loaded variant@1.0 -foo} ERR {}
testouterr_cmd sh {is-loaded variant@1.0 foo=off} ERR {}
testouterr_cmd sh {is-loaded variant@1.0 foo=0} ERR {}

setenv_path_var MODULES_LMVARIANT variant/1.0&foo|0|1|0

testouterr_cmd sh {is-loaded variant@1.0} OK {}
testouterr_cmd sh {is-loaded variant@1.0~foo} OK {}
testouterr_cmd sh {is-loaded variant@1.0 foo=false} OK {}
testouterr_cmd sh {is-loaded variant@1.0+foo} ERR {}
testouterr_cmd sh {is-loaded variant@1.0 foo=true} ERR {}

# non-boolean variant with boolean-like value
setenv_var TESTSUITE_VARIANT bool20
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1|0|0
testouterr_cmd sh {is-loaded variant@1.0 foo=1} OK {}
testouterr_cmd sh {is-loaded variant@1.0 +foo} OK {}
testouterr_cmd sh {is-loaded variant@1.0 foo=on} OK {}
testouterr_cmd sh {is-loaded variant@1.0 foo=0} ERR {}
testouterr_cmd sh {is-loaded variant@1.0 -foo} ERR {}
testouterr_cmd sh {is-loaded variant@1.0 foo=off} ERR {}

setenv_path_var MODULES_LMVARIANT variant/1.0&foo|0|0|0
testouterr_cmd sh {is-loaded variant@1.0} OK {}
testouterr_cmd sh {is-loaded variant@1.0~foo} OK {}
testouterr_cmd sh {is-loaded variant@1.0 foo=false} OK {}
testouterr_cmd sh {is-loaded variant@1.0+foo} ERR {}
testouterr_cmd sh {is-loaded variant@1.0 foo=true} ERR {}

setenv_path_var MODULES_LMVARIANT variant/1.0&foo|2|0|0
testouterr_cmd sh {is-loaded variant@1.0~foo} ERR {}
testouterr_cmd sh {is-loaded variant@1.0 -foo} ERR {}
testouterr_cmd sh {is-loaded variant@1.0 foo=0} ERR {}


#
# unload tests
#

setenv_var TESTSUITE_VARIANT bool8
setenv_loaded_module [list variant/1.0] [list $mp/variant/1.0]
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1|1|0

set ans [list]
lappend ans [list unset TS0]
lappend ans [list unset TS1]
lappend ans [list unset TS2]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMVARIANT]
set tserr [msg_unload variant/1.0{+foo}]
testouterr_cmd sh {unload -v variant@1.0} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0+foo} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 foo=yes} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0~foo} OK {}
testouterr_cmd sh {unload -v variant@1.0 foo=no} OK {}

setenv_path_var MODULES_LMVARIANT variant/1.0&foo|0|1|0
set tserr [msg_unload variant/1.0{-foo}]
testouterr_cmd sh {unload -v variant@1.0} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 -foo} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 foo=f} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 foo=0} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 +foo} OK {}
testouterr_cmd sh {unload -v variant@1.0 foo=t} OK {}
testouterr_cmd sh {unload -v variant@1.0 foo=1} OK {}

# bad data stored in persistency variable
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|str|1|0
set tserr [msg_unload variant/1.0{-foo}]
testouterr_cmd sh {unload -v variant@1.0 -foo} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 foo=0} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 +foo} OK {}
testouterr_cmd sh {unload -v variant@1.0 foo=1} OK {}
setenv_path_var MODULES_LMVARIANT variant/1.0&foo||1|0
testouterr_cmd sh {unload -v variant@1.0 foo=f} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 foo=off} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 foo=t} OK {}
testouterr_cmd sh {unload -v variant@1.0 foo=on} OK {}
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1|str|0
testouterr_cmd sh {unload -v variant@1.0 -foo} OK {}
testouterr_cmd sh {unload -v variant@1.0 foo=0} OK {}
set tserr [msg_unload variant/1.0{foo=1}]
testouterr_cmd sh {unload -v variant@1.0 +foo} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 foo=1} $ans $tserr
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1||0
testouterr_cmd sh {unload -v variant@1.0 foo=false} OK {}
testouterr_cmd sh {unload -v variant@1.0 foo=no} OK {}
testouterr_cmd sh {unload -v variant@1.0 foo=true} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 foo=yes} $ans $tserr
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1
testouterr_cmd sh {unload -v variant@1.0 ~foo} OK {}
testouterr_cmd sh {unload -v variant@1.0 foo=off} OK {}
testouterr_cmd sh {unload -v variant@1.0+foo} $ans $tserr
testouterr_cmd sh {unload -v variant@1.0 foo=on} $ans $tserr


#
# switch tests
#

setenv_var TESTSUITE_VARIANT bool8
setenv_loaded_module [list variant/1.0] [list $mp/variant/1.0]

set ansf [list]
lappend ansf [list set TS0 foo]
lappend ansf [list set TS1 foo=0]
lappend ansf [list set TS2 false]
lappend ansf [list setpath LOADEDMODULES variant/1.0]
lappend ansf [list setpath _LMFILES_ $mp/variant/1.0]
lappend ansf [list setpath MODULES_LMVARIANT variant/1.0&foo|0|1|0]

set anst [list]
lappend anst [list set TS0 foo]
lappend anst [list set TS1 foo=1]
lappend anst [list set TS2 true]
lappend anst [list setpath LOADEDMODULES variant/1.0]
lappend anst [list setpath _LMFILES_ $mp/variant/1.0]
lappend anst [list setpath MODULES_LMVARIANT variant/1.0&foo|1|1|0]

setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1|1|0
set tserr [msg_unload variant/1.0{+foo}]\n[msg_load variant/1.0{-foo}]\n[msg_switch variant/1.0{+foo} variant/1.0{-foo}]
testouterr_cmd sh {switch -v variant@1.0~foo} $ansf $tserr
testouterr_cmd sh {switch -v variant@1.0 foo=0} $ansf $tserr
testouterr_cmd sh {switch -v variant@1.0 foo=false} $ansf $tserr
set tserr [msg_unload variant/1.0{+foo}]\n[msg_load variant/1.0{+foo}]\n[msg_switch variant/1.0{+foo} variant/1.0{+foo}]
testouterr_cmd sh {switch -v variant@1.0+foo} $anst $tserr
testouterr_cmd sh {switch -v variant@1.0 foo=1} $anst $tserr
testouterr_cmd sh {switch -v variant@1.0 foo=true} $anst $tserr

setenv_path_var MODULES_LMVARIANT variant/1.0&foo|0|1|0
set tserr [msg_unload variant/1.0{-foo}]\n[msg_load variant/1.0{+foo}]\n[msg_switch variant/1.0{-foo} variant/1.0{+foo}]
testouterr_cmd sh {switch -v variant@1.0 +foo} $anst $tserr
testouterr_cmd sh {switch -v variant@1.0 foo=yes} $anst $tserr
testouterr_cmd sh {switch -v variant@1.0 foo=on} $anst $tserr
set tserr [msg_unload variant/1.0{-foo}]\n[msg_load variant/1.0{-foo}]\n[msg_switch variant/1.0{-foo} variant/1.0{-foo}]
testouterr_cmd sh {switch -v variant@1.0 -foo} $ansf $tserr
testouterr_cmd sh {switch -v variant@1.0 foo=no} $ansf $tserr
testouterr_cmd sh {switch -v variant@1.0 foo=off} $ansf $tserr


#
# test @loaded version specifier
#

setenv_var TESTSUITE_VARIANT bool8
setenv_loaded_module [list variant/1.0] [list $mp/variant/1.0]
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1|1|0

testouterr_cmd sh {load -v variant@loaded} OK {}
testouterr_cmd sh {load -v variant@loaded +foo} OK {}
testouterr_cmd sh {load -v variant@loaded foo=t} OK {}
testouterr_cmd sh {load -v variant@loaded -foo} OK {}
testouterr_cmd sh {load -v variant@loaded foo=f} OK {}

set ans [list]
lappend ans [list unset TS0]
lappend ans [list unset TS1]
lappend ans [list unset TS2]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMVARIANT]
set tserr [msg_unload variant/1.0{+foo}]
testouterr_cmd sh {unload -v variant@loaded} $ans $tserr
testouterr_cmd sh {unload -v variant@loaded -foo} $ans $tserr
testouterr_cmd sh {unload -v variant@loaded foo=0} $ans $tserr
testouterr_cmd sh {unload -v variant@loaded +foo} $ans $tserr
testouterr_cmd sh {unload -v variant@loaded foo=1} $ans $tserr

# bad data stored in persistency variable
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|str|1|0
testouterr_cmd sh {load -v variant@loaded} OK {}
setenv_path_var MODULES_LMVARIANT variant/1.0&foo||1|0
set tserr [msg_unload variant/1.0{-foo}]
testouterr_cmd sh {unload -v variant@loaded} $ans $tserr
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1|str|0
testouterr_cmd sh {load -v variant@loaded} OK {}
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1||0
set tserr [msg_unload variant/1.0{foo=1}]
testouterr_cmd sh {unload -v variant@loaded} $ans $tserr
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1
testouterr_cmd sh {load -v variant@loaded} OK {}


#
# test bad boolean variant specification
#

setenv_var TESTSUITE_VARIANT bool8
unsetenv_loaded_module
unsetenv_path_var MODULES_LMVARIANT

testouterr_cmd sh {load variant@1.0 =} ERR "$error_msgs: No variant name defined in argument '='"
testouterr_cmd sh {load variant@1.0=} ERR $err_path'variant@1.0='
testouterr_cmd sh {load variant@=} ERR $err_path'variant@='
testouterr_cmd sh {load variant++} ERR $err_path'variant++'
testouterr_cmd sh {load variant@++} ERR $err_path'variant@++'

setenv_var MODULES_IMPLICIT_DEFAULT 1
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_LMALTNAME variant/w\ s&as|variant/default\&as|variant/latest]
testouterr_cmd sh {load variant@@} $ans {}
unsetenv_var MODULES_IMPLICIT_DEFAULT

testouterr_cmd sh {load variant@1.0 +foo=true} ERR [err_varspec +foo=true]
testouterr_cmd sh {load variant@1.0 +foo=false} ERR [err_varspec +foo=false]
testouterr_cmd sh {load variant@1.0 +foo=0} ERR [err_varspec +foo=0]
testouterr_cmd sh {load variant@1.0-foo} ERR $err_path'variant@1.0-foo'

testouterr_cmd sh {ml variant@1.0 -foo} ERR [msg_load variant/1.0 [err_novarval foo {1 0 yes no true false on off}]]

testouterr_cmd sh {load variant@1.0 -foo+} ERR [msg_load variant/1.0{-foo+} [err_novarval foo {1 0 yes no true false on off}]]
testouterr_cmd sh {load variant@1.0 +foo+} ERR [msg_load variant/1.0{+foo+} [err_novarval foo {1 0 yes no true false on off}]]

setenv_var TESTSUITE_VARIANT bool23
set ans [list]
lappend ans [list set TS0 {bar foo}]
lappend ans [list set TS1 {bar=1:foo=0}]
lappend ans [list set TS2 false]
lappend ans [list setpath LOADEDMODULES variant/1.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|0|1|0&bar|1|1|0]
testouterr_cmd sh {load variant@1.0 -foo+bar} $ans {}

testouterr_cmd sh {load variant@1.0 +bar-foo} ERR [msg_load variant/1.0{+bar-foo} [err_novarval foo {1 0 yes no true false on off}]]


#
# boolean variant prereq
#

setenv_var TESTSUITE_VARIANT bool23
set ans [list]
lappend ans [list set TS0 {bar foo}]
lappend ans [list set TS1 {bar=0:foo=1}]
lappend ans [list set TS2 true]
lappend ans [list setpath LOADEDMODULES variant/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMNOTUASKED variant/1.0]
lappend ans [list setpath MODULES_LMVARIANT variant/1.0&foo|1|1|0&bar|0|1|0]
lappend ans [list setpath MODULES_LMPREREQ {variant/7.0&variant@1.0 +foo bar=false}]
set tserr [msg_top_load variant/7.0 {} {variant/1.0{-bar:\\+foo}} {}]
testouterr_cmd_re sh {load --auto variant@7.0} $ans $tserr

setenv_loaded_module [list variant/1.0] [list $mp/variant/1.0]
setenv_path_var MODULES_LMVARIANT variant/1.0&foo|1|1|0&bar|0|1|0

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/1.0:variant/7.0]
lappend ans [list setpath _LMFILES_ $mp/variant/1.0:$mp/variant/7.0]
lappend ans [list setpath MODULES_LMPREREQ {variant/7.0&variant@1.0 +foo bar=false}]
testouterr_cmd_re sh {load --auto variant@7.0} $ans {}

setenv_path_var MODULES_LMVARIANT variant/1.0&foo|0|1|0&bar|1|1|0
set tserr [msg_load variant/1.0{-bar:+foo} [err_othervariantloaded +bar:-foo]]\n\n[msg_load variant/7.0 [err_reqlo variant/1.0{-bar:+foo}]]
testouterr_cmd sh {load --auto variant@7.0} ERR $tserr


#
#  Cleanup
#

reset_test_env
