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

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


setenv_var MODULES_ADVANCED_VERSION_SPEC 1


#
# alias and symbolic version resolution
#

setenv_var TESTSUITE_VARIANT aliassym1

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/6.0]
lappend ans [list setpath _LMFILES_ $mp/variant/6.0]
lappend ans [list setpath MODULES_LMVARIANT variant/6.0&foo|val2|0|2&bar|2|0|0]
lappend ans [list setpath MODULES_LMALTNAME variant/6.0&variant/sym&al|alvariant60&al|variant/al60]
testouterr_cmd sh {load alvariant60 bar=2} $ans {}
testouterr_cmd sh {load variant/sym bar=2} $ans {}
testouterr_cmd sh {load variant/al60 bar=2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES variant/6.0]
lappend ans [list setpath _LMFILES_ $mp/variant/6.0]
lappend ans [list setpath MODULES_LMVARIANT variant/6.0&foo|val3|0|0&bar|1|0|0]
lappend ans [list setpath MODULES_LMALTNAME variant/6.0&variant/sym&al|alvariant60&al|variant/al60]
testouterr_cmd sh {load alvariant60 bar=1 foo=val3} $ans {}
testouterr_cmd sh {load variant/sym bar=1 foo=val3} $ans {}
testouterr_cmd sh {load variant/al60 bar=1 foo=val3} $ans {}


#
# specify variant in alias/symbol/virtual definition
#

setenv_var TESTSUITE_VARIANT aliassym2

# variant set on module-alias is ignored (everything after arg-2 is ignored)
testouterr_cmd sh {load alvariantbar} ERR [msg_load variant/6.0 [err_novarval bar {1 2 3}]]

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


setenv_var TESTSUITE_VARIANT aliassym3

# variant set on module-version are considered as other symbolic versions
testouterr_cmd sh {load variant/sym} ERR [msg_load variant/6.0 [err_novarval bar {1 2 3}]]

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


setenv_var TESTSUITE_VARIANT aliassym4

# variant set on module-virtual is ignored (everything after arg-2 is ignored)
testouterr_cmd sh {load variant/virt bar=1} ERR $err_file'$mp/bar=1'


setenv_var TESTSUITE_VARIANT aliassym5

testouterr_cmd sh {load alvariantbar} ERR "$err_path'variant/6.0 bar=1'"


setenv_var TESTSUITE_VARIANT aliassym6

testouterr_cmd sh {load variant/sym} ERR "$err_path'variant/6.0 bar=1'"


setenv_var TESTSUITE_VARIANT aliassym7

testouterr_cmd sh {load variant/virt bar=1} ERR "$err_path'variant/virt bar=1'"


#
# test module-info {alias,version,symbols}
#

setenv_var TESTSUITE_VARIANT aliassym8

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

# module-info takes 2 arguments at most
set ln [expr {[cmpversion $tclsh_version 8.5] < 1 ? {2} : {56}}]
set tserr [escre [msg_load variant/6.0{bar=1} "$moderr_msgs: wrong # args: should be \"module-info what ?more?\"\n    invoked from within\n\"module-info alias variant/6.0 bar=1 foo=val2<EXM>\"\n    (file \"$mp/variant/6.0\" line $ln)\n$err_contactns"]]
testouterr_cmd_re sh {load variant/6.0 bar=1} ERR $tserr

}

setenv_var TESTSUITE_VARIANT aliassym9

# variant designation does not match any alias or symbol
set ans [list]
lappend ans [list set TS1 {}]
lappend ans [list set TS2 {variant/6.0 bar=1 foo=val2}]
lappend ans [list set TS3 {}]
lappend ans [list setpath LOADEDMODULES variant/6.0]
lappend ans [list setpath _LMFILES_ $mp/variant/6.0]
lappend ans [list setpath MODULES_LMVARIANT variant/6.0&foo|val2|0|2&bar|1|0|0]
lappend ans [list setpath MODULES_LMALTNAME variant/6.0&variant/sym&al|alvariant60]
testouterr_cmd sh {load variant/6.0 bar=1} $ans {}


#
#  Cleanup
#

reset_test_env
