##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.70-maint/%M%
#   Revision:		%I%
#   First Edition:	2020/03/14
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:
#   Modulefiles:
#   Sub-Command:
#
#   Comment:	%C{
#           Test impact of space in names or versions when mixed with
#           advanced version specifiers
#		}C%
#
##############################################################################

# ensure avail -t tests have implicit default enabled
setenv_var MODULES_IMPLICIT_DEFAULT 1

# ensure regular avail search match is set for these tests
setenv_var MODULES_SEARCH_MATCH starts_with

# ensure avail tests are made using in depth mode
setenv_var MODULES_AVAIL_INDEPTH 1

# ensure last matching element is returned when unloading modules
setenv_var MODULES_UNLOAD_MATCH_ORDER returnlast

set mp "$modpath wspace"

# setup specific environment
setenv_path_var MODULEPATH $mp

if {!$is_symlink_supported} {
    send_user "\tskipping tests over '$mp' modulepath as symbolic links are not supported on filesystem\n"
} else {

# generate modulefiles that cannot be recorded in git repository
create_endspace_test_modulefiles

# enable advanced version spec for next tests
setenv_var MODULES_ADVANCED_VERSION_SPEC 1

# mix spaces in advanced version specifiers and dependencies
set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:space yd/5.0"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/space yd/5.0"]
lappend ans [list setpath MODULES_LMPREREQ "space yd/5.0&{sp.ce y+@2.5<2.7}"]
lappend ans [list setpath MODULES_LMNOTUASKED "sp.ce y+/2.7"]
lappend ans [list setpath MODULES_LMALTNAME "space yd/5.0&as|space yd/default&as|space yd/latest"]
testouterr_cmd_re sh {load --auto space\ yd@4:} $ans [msg_top_load {'space yd/5.0'} {} "{'sp\\.ce y\\+/2.7'}" {}]
setenv_loaded_module [list "sp.ce y+/2.6"] [list "$mp/sp.ce y+/2.6"]
set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.6:space yd/5.0"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.6:$mp/space yd/5.0"]
lappend ans [list setpath MODULES_LMPREREQ "space yd/5.0&{sp.ce y+@2.5<2.7}"]
lappend ans [list setpath MODULES_LMALTNAME "space yd/5.0&as|space yd/default&as|space yd/latest"]
testouterr_cmd_re sh {load --auto space\ yd@4:5} $ans {}
setenv_loaded_module [list "sp.ce y+/2.6" "space yd/5.0"] [list "$mp/sp.ce y+/2.6" "$mp/space yd/5.0"] [list "sp.ce y+/2.6"]
setenv_path_var MODULES_LMPREREQ "space yd/5.0&{sp.ce y+@2.5<2.7}"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
testouterr_cmd sh {unload --auto sp.ce\ y+@:2} $ans [msg_top_unload {'sp.ce y+/2.6'} {'space yd/5.0'} {} {}]
testouterr_cmd sh {unload --auto space\ yd@4:} $ans [msg_top_unload {'space yd/5.0'} {} "{'sp.ce y+/2.6'}" {}]
unsetenv_loaded_module
unsetenv_path_var MODULES_LMPREREQ


# try various syntaxes when spaces, advanced version specifiers and dependencies are mixed
# various syntaxes on command line

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7"]
testouterr_cmd sh {load sp.ce y+@2.5:2.7} ERR "$err_path'sp.ce'\n$err_path'y+@2.5:2.7'"
testouterr_cmd sh {load sp.ce y+ @2.5:2.7} ERR "$err_path'sp.ce'\n$err_path'y+ @2.5:2.7'"
testouterr_cmd sh {load sp.ce\ y+ @2.5:2.7} $ans {}
testouterr_cmd sh {load sp.ce\ y+@2.5:2.7} $ans {}
testouterr_cmd sh {load sp.ce\ y+@1.2 @2.5:2.7} $ans {}
testouterr_cmd sh {load sp.ce\ y+ @1.2 @2.5:2.7} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/0 2"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/0 2"]
testouterr_cmd sh {load sp.ce\ y+ @0\ 2} $ans {}
testouterr_cmd sh {load sp.ce\ y+@0\ 2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space y /1 "]
lappend ans [list setpath _LMFILES_ "$mp/space y /1 "]
lappend ans [list setpath MODULES_LMALTNAME "space y /1 &space y /n &al|space y /a "]
testouterr_cmd sh {load space\ y\  @1\ } $ans {}
testouterr_cmd sh {load space\ y\ @1\ } $ans {}

# test on unknown modulefiles
testouterr_cmd sh {load sp.ce\ z+@0\ 3} ERR "$err_path'{sp.ce z+@0 3}'"
testouterr_cmd sh {load sp.ce\ z+ @0\ 3} ERR "$err_path'{sp.ce z+} {@0 3}'"
testouterr_cmd sh {load space\ z\ @2\ } ERR "$err_path'{space z @2 }'"
testouterr_cmd sh {load space\ z\  @2\ } ERR "$err_path'{space z } {@2 }'"

# various syntaxes on prereq modulefile command

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.0"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.0"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.0&sp.ce|y+@2.5<2.7|baz @<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "baz/1"]
lappend ans [list ERR]
testouterr_cmd_re sh {load --auto space\ ye@1.0} $ans [msg_top_load {'space ye/1.0'} {} baz/1 {} $err_path'sp.ce' $err_path'y\\+@2.5:2.7']

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.1"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.1"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.1&sp.ce|y+ @2.5<2.7|baz @<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "baz/1"]
lappend ans [list ERR]
testouterr_cmd_re sh {load --auto space\ ye@1.1} $ans [msg_top_load {'space ye/1.1'} {} baz/1 {} $err_path'sp.ce' "$err_path'y\\+ @2.5:2.7'"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:space ye/1.2"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/space ye/1.2"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.2&{sp.ce y+} @2.5<2.7|baz @<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "sp.ce y+/2.7"]
testouterr_cmd_re sh {load --auto space\ ye@1.2} $ans [msg_top_load {'space ye/1.2'} {} {'sp.ce y\\+/2.7'} {}]

if {[cmpversion $tclsh_version 8.6] == -1} {
    set errcmd "prereq {sp.ce y+}@2.5:2.7 baz @:1\n"
} else {
    set errcmd {prereq {sp.ce y+}@}
}
testouterr_cmd sh {load --auto space\ ye@1.3} ERR [msg_load {'space ye/1.3'} [msg_moderr {extra characters after close-brace} $errcmd "$mp/space ye/1.3" 2]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:space ye/1.4"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/space ye/1.4"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.4&{sp.ce y+@1.2} @2.5<2.7|baz @<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "sp.ce y+/2.7"]
testouterr_cmd_re sh {load --auto space\ ye@1.4} $ans [msg_top_load {'space ye/1.4'} {} {'sp.ce y\\+/2.7'} {}]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:space ye/1.5"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/space ye/1.5"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.5&{sp.ce y+} @1.2 @2.5<2.7|baz @<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "sp.ce y+/2.7"]
testouterr_cmd_re sh {load --auto space\ ye@1.5} $ans [msg_top_load {'space ye/1.5'} {} {'sp.ce y\\+/2.7'} {}]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/0 2:space ye/1.6"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/0 2:$mp/space ye/1.6"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.6&{sp.ce y+} {@0 2}|baz @<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "sp.ce y+/0 2"]
testouterr_cmd_re sh {load --auto space\ ye@1.6} $ans [msg_top_load {'space ye/1.6'} {} {'sp.ce y\\+/0 2'} {}]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/0 2:space ye/1.7"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/0 2:$mp/space ye/1.7"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.7&{sp.ce y+@0 2}|baz @<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "sp.ce y+/0 2"]
testouterr_cmd_re sh {load --auto space\ ye@1.7} $ans [msg_top_load {'space ye/1.7'} {} {'sp.ce y\\+/0 2'} {}]

set ans [list]
lappend ans [list setpath LOADEDMODULES "space y /1 :space ye/1.8"]
lappend ans [list setpath _LMFILES_ "$mp/space y /1 :$mp/space ye/1.8"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.8&{space y @1 }|baz @<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "space y /1 "]
lappend ans [list setpath MODULES_LMALTNAME "space y /1 &space y /n &al|space y /a "]
testouterr_cmd_re sh {load --auto space\ ye@1.8} $ans [msg_top_load {'space ye/1.8'} {} "{'space y /1 '}" {}]

set ans [list]
lappend ans [list setpath LOADEDMODULES "space y /1 :space ye/1.9"]
lappend ans [list setpath _LMFILES_ "$mp/space y /1 :$mp/space ye/1.9"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.9&{space y @a }|baz @<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "space y /1 "]
lappend ans [list setpath MODULES_LMALTNAME "space y /1 &space y /n &al|space y /a "]
testouterr_cmd_re sh {load --auto space\ ye@1.9} $ans [msg_top_load {'space ye/1.9'} {} "{'space y /1 '}" {}]

setenv_loaded_module [list {sp.ce y+/2.7}] [list "$mp/sp.ce y+/2.7"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:baz/1:space ye/1.0"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/baz/1:$mp/space ye/1.0"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.0&sp.ce|y+@2.5<2.7|baz @<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "baz/1"]
lappend ans [list ERR]
testouterr_cmd_re sh {load --auto space\ ye@1.0} $ans [msg_top_load {'space ye/1.0'} {} baz/1 {} $err_path'sp.ce' $err_path'y\\+@2.5:2.7']

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:baz/1:space ye/1.1"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/baz/1:$mp/space ye/1.1"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.1&sp.ce|y+ @2.5<2.7|baz @<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "baz/1"]
lappend ans [list ERR]
testouterr_cmd_re sh {load --auto space\ ye@1.1} $ans [msg_top_load {'space ye/1.1'} {} baz/1 {} $err_path'sp.ce' "$err_path'y\\+ @2.5:2.7'"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:space ye/1.2"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/space ye/1.2"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.2&{sp.ce y+} @2.5<2.7|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:space ye/1.4"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/space ye/1.4"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.4&{sp.ce y+@1.2} @2.5<2.7|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.4} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:space ye/1.5"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/space ye/1.5"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.5&{sp.ce y+} @1.2 @2.5<2.7|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.5} $ans {}

setenv_loaded_module [list {sp.ce y+/0 2}] [list "$mp/sp.ce y+/0 2"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/0 2:space ye/1.6"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/0 2:$mp/space ye/1.6"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.6&{sp.ce y+} {@0 2}|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.6} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/0 2:space ye/1.7"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/0 2:$mp/space ye/1.7"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.7&{sp.ce y+@0 2}|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.7} $ans {}

setenv_loaded_module [list {space y /1 }] [list "$mp/space y /1 "]
setenv_path_var MODULES_LMALTNAME "space y /1 &space y /n &al|space y /a "

set ans [list]
lappend ans [list setpath LOADEDMODULES "space y /1 :space ye/1.8"]
lappend ans [list setpath _LMFILES_ "$mp/space y /1 :$mp/space ye/1.8"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.8&{space y @1 }|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.8} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space y /1 :space ye/1.9"]
lappend ans [list setpath _LMFILES_ "$mp/space y /1 :$mp/space ye/1.9"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.9&{space y @a }|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.9} $ans {}

setenv_loaded_module [list {baz/1}] [list "$mp/baz/1"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.0"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.0"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.0&sp.ce|y+@2.5<2.7|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.0} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.1"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.1"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.1&sp.ce|y+ @2.5<2.7|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.2"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.2"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.2&{sp.ce y+} @2.5<2.7|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.2} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.4"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.4"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.4&{sp.ce y+@1.2} @2.5<2.7|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.4} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.5"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.5"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.5&{sp.ce y+} @1.2 @2.5<2.7|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.5} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.6"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.6"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.6&{sp.ce y+} {@0 2}|baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@1.6} $ans {}

# unload dependent module {sp.ce y+/2.7}

setenv_loaded_module [list {sp.ce y+/2.7} {space ye/1.0}] [list "$mp/sp.ce y+/2.7" "$mp/space ye/1.0"]
setenv_path_var MODULES_LMPREREQ "space ye/1.0&sp.ce|y+@2.5<2.7|baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/1.0"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/1.0"]
testouterr_cmd sh {unload --auto sp.ce\ y+/2.7} $ans {}

setenv_loaded_module [list {sp.ce y+/2.7} {space ye/1.1}] [list "$mp/sp.ce y+/2.7" "$mp/space ye/1.1"]
setenv_path_var MODULES_LMPREREQ "space ye/1.1&sp.ce|y+ @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/1.1"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/1.1"]
testouterr_cmd sh {unload --auto sp.ce\ y+/2.7} $ans {}

setenv_loaded_module [list {sp.ce y+/2.7} {space ye/1.2}] [list "$mp/sp.ce y+/2.7" "$mp/space ye/1.2"]
setenv_path_var MODULES_LMPREREQ "space ye/1.2&{sp.ce y+} @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto sp.ce\ y+/2.7} $ans [msg_top_unload {'sp.ce y+/2.7'} {'space ye/1.2'} {} {}]

setenv_loaded_module [list {sp.ce y+/2.7} {space ye/1.4}] [list "$mp/sp.ce y+/2.7" "$mp/space ye/1.4"]
setenv_path_var MODULES_LMPREREQ "space ye/1.4&{sp.ce y+@1.2} @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto sp.ce\ y+/2.7} $ans [msg_top_unload {'sp.ce y+/2.7'} {'space ye/1.4'} {} {}]

setenv_loaded_module [list {sp.ce y+/2.7} {space ye/1.5}] [list "$mp/sp.ce y+/2.7" "$mp/space ye/1.5"]
setenv_path_var MODULES_LMPREREQ "space ye/1.5&{sp.ce y+} @1.2 @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto sp.ce\ y+/2.7} $ans [msg_top_unload {'sp.ce y+/2.7'} {'space ye/1.5'} {} {}]

setenv_loaded_module [list {sp.ce y+/0 2} {space ye/1.6}] [list "$mp/sp.ce y+/0 2" "$mp/space ye/1.6"]
setenv_path_var MODULES_LMPREREQ "space ye/1.6&{sp.ce y+} {@0 2}|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto sp.ce\ y+/0\ 2} $ans [msg_top_unload {'sp.ce y+/0 2'} {'space ye/1.6'} {} {}]

setenv_loaded_module [list {sp.ce y+/0 2} {space ye/1.7}] [list "$mp/sp.ce y+/0 2" "$mp/space ye/1.7"]
setenv_path_var MODULES_LMPREREQ "space ye/1.7&{sp.ce y+@0 2}|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto sp.ce\ y+/0\ 2} $ans [msg_top_unload {'sp.ce y+/0 2'} {'space ye/1.7'} {} {}]

setenv_loaded_module [list {space y /1 } {space ye/1.8}] [list "$mp/space y /1 " "$mp/space ye/1.8"]
setenv_path_var MODULES_LMPREREQ "space ye/1.8&{space y @1 }|baz @<1"
setenv_path_var MODULES_LMALTNAME "space y /1 &space y /n &al|space y /a "
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMALTNAME]
testouterr_cmd sh {unload --auto space\ y\ /1\ } $ans [msg_top_unload {'space y /1 '} {'space ye/1.8'} {} {}]
testouterr_cmd sh {unload --auto space\ y\ /a\ } $ans [msg_top_unload {'space y /1 '} {'space ye/1.8'} {} {}]

setenv_loaded_module [list {space y /1 } {space ye/1.9}] [list "$mp/space y /1 " "$mp/space ye/1.9"]
setenv_path_var MODULES_LMPREREQ "space ye/1.9&{space y @a }|baz @<1"
setenv_path_var MODULES_LMALTNAME "space y /1 &space y /n &al|space y /a "
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMALTNAME]
testouterr_cmd sh {unload --auto space\ y\ /1\ } $ans [msg_top_unload {'space y /1 '} {'space ye/1.9'} {} {}]
testouterr_cmd sh {unload --auto space\ y\ /a\ } $ans [msg_top_unload {'space y /1 '} {'space ye/1.9'} {} {}]
unsetenv_path_var MODULES_LMALTNAME

# unload dependent module baz/1

setenv_loaded_module [list {baz/1} {space ye/1.0}] [list "$mp/baz/1" "$mp/space ye/1.0"]
setenv_path_var MODULES_LMPREREQ "space ye/1.0&sp.ce|y+@2.5<2.7|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto baz/1} $ans [msg_top_unload baz/1 {'space ye/1.0'} {} {}]

setenv_loaded_module [list {baz/1} {space ye/1.1}] [list "$mp/baz/1" "$mp/space ye/1.1"]
setenv_path_var MODULES_LMPREREQ "space ye/1.1&sp.ce|y+ @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto baz/1} $ans [msg_top_unload baz/1 {'space ye/1.1'} {} {}]

setenv_loaded_module [list {baz/1} {space ye/1.2}] [list "$mp/baz/1" "$mp/space ye/1.2"]
setenv_path_var MODULES_LMPREREQ "space ye/1.2&{sp.ce y+} @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto baz/1} $ans [msg_top_unload baz/1 {'space ye/1.2'} {} {}]

setenv_loaded_module [list {baz/1} {space ye/1.4}] [list "$mp/baz/1" "$mp/space ye/1.4"]
setenv_path_var MODULES_LMPREREQ "space ye/1.4&{sp.ce y+@1.2} @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto baz/1} $ans [msg_top_unload baz/1 {'space ye/1.4'} {} {}]

setenv_loaded_module [list {baz/1} {space ye/1.5}] [list "$mp/baz/1" "$mp/space ye/1.5"]
setenv_path_var MODULES_LMPREREQ "space ye/1.5&{sp.ce y+} @1.2 @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto baz/1} $ans [msg_top_unload baz/1 {'space ye/1.5'} {} {}]

setenv_loaded_module [list {baz/1} {space ye/1.6}] [list "$mp/baz/1" "$mp/space ye/1.6"]
setenv_path_var MODULES_LMPREREQ "space ye/1.6&{sp.ce y+} {@0 2}|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto baz/1} $ans [msg_top_unload baz/1 {'space ye/1.6'} {} {}]

setenv_loaded_module [list {baz/1} {space ye/1.7}] [list "$mp/baz/1" "$mp/space ye/1.7"]
setenv_path_var MODULES_LMPREREQ "space ye/1.7&{sp.ce y+@0 2}|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto baz/1} $ans [msg_top_unload baz/1 {'space ye/1.7'} {} {}]

setenv_loaded_module [list {baz/1} {space ye/1.8}] [list "$mp/baz/1" "$mp/space ye/1.8"]
setenv_path_var MODULES_LMPREREQ "space ye/1.8&{space y @1 }|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto baz/1} $ans [msg_top_unload baz/1 {'space ye/1.8'} {} {}]

setenv_loaded_module [list {baz/1} {space ye/1.9}] [list "$mp/baz/1" "$mp/space ye/1.9"]
setenv_path_var MODULES_LMPREREQ "space ye/1.9&{space y @a }|baz @<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto baz/1} $ans [msg_top_unload baz/1 {'space ye/1.9'} {} {}]

# load depedent module {sp.ce y+/2.7}

setenv_loaded_module [list {baz/1} {space ye/1.0}] [list "$mp/baz/1" "$mp/space ye/1.0"]
setenv_path_var MODULES_LMPREREQ "space ye/1.0&sp.ce|y+@2.5<2.7|baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.0:sp.ce y+/2.7"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.0:$mp/sp.ce y+/2.7"]
testouterr_cmd_re sh {load --auto sp.ce\ y+/2.7} $ans {}

setenv_loaded_module [list {baz/1} {space ye/1.1}] [list "$mp/baz/1" "$mp/space ye/1.1"]
setenv_path_var MODULES_LMPREREQ "space ye/1.1&sp.ce|y+ @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.1:sp.ce y+/2.7"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.1:$mp/sp.ce y+/2.7"]
testouterr_cmd_re sh {load --auto sp.ce\ y+/2.7} $ans {}

setenv_loaded_module [list {baz/1} {space ye/1.2}] [list "$mp/baz/1" "$mp/space ye/1.2"]
setenv_path_var MODULES_LMPREREQ "space ye/1.2&{sp.ce y+} @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:sp.ce y+/2.7:space ye/1.2"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/sp.ce y+/2.7:$mp/space ye/1.2"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.2&{sp.ce y+} @2.5<2.7|baz @<1"]
testouterr_cmd_re sh {load --auto sp.ce\ y+/2.7} $ans [msg_top_load {'sp.ce y\+/2.7'} {} {} "{'space ye/1.2'}"]

setenv_loaded_module [list {baz/1} {space ye/1.4}] [list "$mp/baz/1" "$mp/space ye/1.4"]
setenv_path_var MODULES_LMPREREQ "space ye/1.4&{sp.ce y+@1.2} @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:sp.ce y+/2.7:space ye/1.4"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/sp.ce y+/2.7:$mp/space ye/1.4"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.4&{sp.ce y+@1.2} @2.5<2.7|baz @<1"]
testouterr_cmd_re sh {load --auto sp.ce\ y+/2.7} $ans [msg_top_load {'sp.ce y\+/2.7'} {} {} "{'space ye/1.4'}"]

setenv_loaded_module [list {baz/1} {space ye/1.5}] [list "$mp/baz/1" "$mp/space ye/1.5"]
setenv_path_var MODULES_LMPREREQ "space ye/1.5&{sp.ce y+} @1.2 @2.5<2.7|baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:sp.ce y+/2.7:space ye/1.5"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/sp.ce y+/2.7:$mp/space ye/1.5"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.5&{sp.ce y+} @1.2 @2.5<2.7|baz @<1"]
testouterr_cmd_re sh {load --auto sp.ce\ y+/2.7} $ans [msg_top_load {'sp.ce y\+/2.7'} {} {} "{'space ye/1.5'}"]

setenv_loaded_module [list {baz/1} {space ye/1.6}] [list "$mp/baz/1" "$mp/space ye/1.6"]
setenv_path_var MODULES_LMPREREQ "space ye/1.6&{sp.ce y+} {@0 2}|baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:sp.ce y+/0 2:space ye/1.6"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/sp.ce y+/0 2:$mp/space ye/1.6"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.6&{sp.ce y+} {@0 2}|baz @<1"]
testouterr_cmd_re sh {load --auto sp.ce\ y+/0\ 2} $ans [msg_top_load {'sp.ce y\+/0 2'} {} {} "{'space ye/1.6'}"]

setenv_loaded_module [list {baz/1} {space ye/1.7}] [list "$mp/baz/1" "$mp/space ye/1.7"]
setenv_path_var MODULES_LMPREREQ "space ye/1.7&{sp.ce y+@0 2}|baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:sp.ce y+/0 2:space ye/1.7"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/sp.ce y+/0 2:$mp/space ye/1.7"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.7&{sp.ce y+@0 2}|baz @<1"]
testouterr_cmd_re sh {load --auto sp.ce\ y+/0\ 2} $ans [msg_top_load {'sp.ce y\+/0 2'} {} {} "{'space ye/1.7'}"]

setenv_loaded_module [list {baz/1} {space ye/1.8}] [list "$mp/baz/1" "$mp/space ye/1.8"]
setenv_path_var MODULES_LMPREREQ "space ye/1.8&{space y @1 }|baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space y /1 :space ye/1.8"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space y /1 :$mp/space ye/1.8"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.8&{space y @1 }|baz @<1"]
lappend ans [list setpath MODULES_LMALTNAME "space y /1 &space y /n &al|space y /a "]
testouterr_cmd_re sh {load --auto space\ y\ /1\ } $ans [msg_top_load {'space y /1 '} {} {} "{'space ye/1.8'}"]
testouterr_cmd_re sh {load --auto space\ y\ /a\ } $ans [msg_top_load {'space y /1 '} {} {} "{'space ye/1.8'}"]

setenv_loaded_module [list {baz/1} {space ye/1.9}] [list "$mp/baz/1" "$mp/space ye/1.9"]
setenv_path_var MODULES_LMPREREQ "space ye/1.9&{space y @a }|baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space y /1 :space ye/1.9"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space y /1 :$mp/space ye/1.9"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.9&{space y @a }|baz @<1"]
lappend ans [list setpath MODULES_LMALTNAME "space y /1 &space y /n &al|space y /a "]
testouterr_cmd_re sh {load --auto space\ y\ /1\ } $ans [msg_top_load {'space y /1 '} {} {} "{'space ye/1.9'}"]
testouterr_cmd_re sh {load --auto space\ y\ /a\ } $ans [msg_top_load {'space y /1 '} {} {} "{'space ye/1.9'}"]


# various syntaxes on conflict modulefile command
unsetenv_loaded_module
unsetenv_path_var MODULES_LMPREREQ

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.0"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.0"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.0&sp.ce&y+@2.5<2.7&baz @<1"]
testouterr_cmd sh {load --auto space\ ye@2.0} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.1"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.1"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.1&sp.ce&y+ @2.5<2.7&baz @<1"]
testouterr_cmd sh {load --auto space\ ye@2.1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.2"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.2"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.2&{sp.ce y+} @2.5<2.7&baz @<1"]
testouterr_cmd sh {load --auto space\ ye@2.2} $ans {}

if {[cmpversion $tclsh_version 8.6] == -1} {
    set errcmd "conflict {sp.ce y+}@2.5:2.7 baz @:1\n"
} else {
    set errcmd {conflict {sp.ce y+}@}
}
testouterr_cmd sh {load --auto space\ ye@2.3} ERR [msg_load {'space ye/2.3'} [msg_moderr {extra characters after close-brace} $errcmd "$mp/space ye/2.3" 2]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.4"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.4"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.4&{sp.ce y+@1.2} @2.5<2.7&baz @<1"]
testouterr_cmd sh {load --auto space\ ye@2.4} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.5"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.5"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.5&{sp.ce y+} @1.2 @2.5<2.7&baz @<1"]
testouterr_cmd sh {load --auto space\ ye@2.5} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.6"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.6"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.6&{sp.ce y+} {@0 2}&baz @<1"]
testouterr_cmd sh {load --auto space\ ye@2.6} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.7"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.7"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.7&{sp.ce y+@0 2}&baz @<1"]
testouterr_cmd sh {load --auto space\ ye@2.7} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.8"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.8"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.8&{space y @1 }&baz @<1"]
testouterr_cmd sh {load --auto space\ ye@2.8} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.9"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.9"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.9&{space y @n }&baz @<1"]
lappend ans [list setpath MODULES_LMALTNAME "space ye/2.9&as|space ye/default&as|space ye/latest"]
testouterr_cmd sh {load --auto space\ ye@2.9} $ans {}

# load conflicting module {sp.ce y+/2.7}

setenv_loaded_module [list {space ye/2.0}] [list "$mp/space ye/2.0"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.0&sp.ce&y+@2.5<2.7&baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.0:sp.ce y+/2.7"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.0:$mp/sp.ce y+/2.7"]
testouterr_cmd_re sh {load --auto sp.ce\ y+@2.7} $ans {}

setenv_loaded_module [list {space ye/2.1}] [list "$mp/space ye/2.1"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.1&sp.ce&y+ @2.5<2.7&baz @<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.1:sp.ce y+/2.7"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.1:$mp/sp.ce y+/2.7"]
testouterr_cmd_re sh {load --auto sp.ce\ y+@2.7} $ans {}

setenv_loaded_module [list {space ye/2.2}] [list "$mp/space ye/2.2"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.2&{sp.ce y+} @2.5<2.7&baz @<1"
testouterr_cmd sh {load --auto sp.ce\ y+@2.7} ERR [msg_load {'sp.ce y+/2.7'} [err_conflict space\ ye/2.2]]

setenv_loaded_module [list {space ye/2.4}] [list "$mp/space ye/2.4"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.4&{sp.ce y+@1.2} @2.5<2.7&baz @<1"
testouterr_cmd sh {load --auto sp.ce\ y+@2.7} ERR [msg_load {'sp.ce y+/2.7'} [err_conflict space\ ye/2.4]]

setenv_loaded_module [list {space ye/2.5}] [list "$mp/space ye/2.5"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.5&{sp.ce y+} @1.2 @2.5<2.7&baz @<1"
testouterr_cmd sh {load --auto sp.ce\ y+@2.7} ERR [msg_load {'sp.ce y+/2.7'} [err_conflict space\ ye/2.5]]

setenv_loaded_module [list {space ye/2.6}] [list "$mp/space ye/2.6"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.6&{sp.ce y+} {@0 2}&baz @<1"
testouterr_cmd sh {load --auto sp.ce\ y+@0\ 2} ERR [msg_load {'sp.ce y+/0 2'} [err_conflict space\ ye/2.6]]

setenv_loaded_module [list {space ye/2.7}] [list "$mp/space ye/2.7"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.7&{sp.ce y+@0 2}&baz @<1"
testouterr_cmd sh {load --auto sp.ce\ y+@0\ 2} ERR [msg_load {'sp.ce y+/0 2'} [err_conflict space\ ye/2.7]]

setenv_loaded_module [list {space ye/2.8}] [list "$mp/space ye/2.8"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.8&{space y @1 }&baz @<1"
testouterr_cmd sh {load --auto space\ y\ @1\ } ERR [msg_load {'space y /1 '} [err_conflict space\ ye/2.8]]
testouterr_cmd sh {load --auto space\ y\ @n\ } ERR [msg_load {'space y /1 '} [err_conflict space\ ye/2.8]]

setenv_loaded_module [list {space ye/2.9}] [list "$mp/space ye/2.9"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.9&{space y @n }&baz @<1"
testouterr_cmd sh {load --auto space\ y\ @1\ } ERR [msg_load {'space y /1 '} [err_conflict space\ ye/2.9]]
testouterr_cmd sh {load --auto space\ y\ @n\ } ERR [msg_load {'space y /1 '} [err_conflict space\ ye/2.9]]

# load conflicting module baz/1

setenv_loaded_module [list {space ye/2.0}] [list "$mp/space ye/2.0"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.0&sp.ce&y+@2.5<2.7&baz @<1"
testouterr_cmd sh {load --auto baz/1} ERR [msg_load {baz/1} [err_conflict space\ ye/2.0]]

setenv_loaded_module [list {space ye/2.1}] [list "$mp/space ye/2.1"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.1&sp.ce&y+ @2.5<2.7&baz @<1"
testouterr_cmd sh {load --auto baz/1} ERR [msg_load {baz/1} [err_conflict space\ ye/2.1]]

setenv_loaded_module [list {space ye/2.2}] [list "$mp/space ye/2.2"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.2&{sp.ce y+} @2.5<2.7&baz @<1"
testouterr_cmd sh {load --auto baz/1} ERR [msg_load {baz/1} [err_conflict space\ ye/2.2]]

setenv_loaded_module [list {space ye/2.4}] [list "$mp/space ye/2.4"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.4&{sp.ce y+@1.2} @2.5<2.7&baz @<1"
testouterr_cmd sh {load --auto baz/1} ERR [msg_load {baz/1} [err_conflict space\ ye/2.4]]

setenv_loaded_module [list {space ye/2.5}] [list "$mp/space ye/2.5"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.5&{sp.ce y+} @1.2 @2.5<2.7&baz @<1"
testouterr_cmd sh {load --auto baz/1} ERR [msg_load {baz/1} [err_conflict space\ ye/2.5]]

setenv_loaded_module [list {space ye/2.6}] [list "$mp/space ye/2.6"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.6&{sp.ce y+} {@0 2}&baz @<1"
testouterr_cmd sh {load --auto baz/1} ERR [msg_load {baz/1} [err_conflict space\ ye/2.6]]

setenv_loaded_module [list {space ye/2.7}] [list "$mp/space ye/2.7"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.7&{sp.ce y+@0 2}&baz @<1"
testouterr_cmd sh {load --auto baz/1} ERR [msg_load {baz/1} [err_conflict space\ ye/2.7]]

setenv_loaded_module [list {space ye/2.8}] [list "$mp/space ye/2.8"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.8&{space y @1 }&baz @<1"
testouterr_cmd sh {load --auto baz/1} ERR [msg_load {baz/1} [err_conflict space\ ye/2.8]]

setenv_loaded_module [list {space ye/2.9}] [list "$mp/space ye/2.9"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.9&{space y @n }&baz @<1"
testouterr_cmd sh {load --auto baz/1} ERR [msg_load {baz/1} [err_conflict space\ ye/2.9]]

# conflicting module {sp.ce y+/2.7} loaded prior conflict definition
unsetenv_path_var MODULES_LMCONFLICT
setenv_loaded_module [list {sp.ce y+/2.7}] [list "$mp/sp.ce y+/2.7"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:space ye/2.0"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/space ye/2.0"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.0&sp.ce&y+@2.5<2.7&baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@2.0} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:space ye/2.1"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/space ye/2.1"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.1&sp.ce&y+ @2.5<2.7&baz @<1"]
testouterr_cmd_re sh {load --auto space\ ye@2.1} $ans {}

testouterr_cmd sh {load --auto space\ ye@2.2} ERR [msg_load {'space ye/2.2'} [err_conflict {sp.ce y+ @2.5:2.7}]]
testouterr_cmd sh {load --auto space\ ye@2.4} ERR [msg_load {'space ye/2.4'} [err_conflict {sp.ce y+@1.2 @2.5:2.7}]]
testouterr_cmd sh {load --auto space\ ye@2.5} ERR [msg_load {'space ye/2.5'} [err_conflict {sp.ce y+ @1.2 @2.5:2.7}]]

setenv_loaded_module [list {sp.ce y+/0 2}] [list "$mp/sp.ce y+/0 2"]

testouterr_cmd sh {load --auto space\ ye@2.6} ERR [msg_load {'space ye/2.6'} [err_conflict {sp.ce y+ @0 2}]]
testouterr_cmd sh {load --auto space\ ye@2.7} ERR [msg_load {'space ye/2.7'} [err_conflict {sp.ce y+@0 2}]]

setenv_loaded_module [list {space y /1 }] [list "$mp/space y /1 "]
setenv_path_var MODULES_LMALTNAME "space y /1 &space y /n &al|space y /a "

testouterr_cmd sh {load --auto space\ ye@2.8} ERR [msg_load {'space ye/2.8'} [err_conflict {space y @1 }]]
testouterr_cmd sh {load --auto space\ ye@2.9} ERR [msg_load {'space ye/2.9'} [err_conflict {space y @n }]]

# conflicting module baz/1 loaded prior conflict definition
unsetenv_path_var MODULES_LMCONFLICT
unsetenv_path_var MODULES_LMALTNAME
setenv_loaded_module [list baz/1] [list "$mp/baz/1"]

testouterr_cmd sh {load --auto space\ ye@2.0} ERR [msg_load {'space ye/2.0'} [err_conflict {baz @:1}]]
testouterr_cmd sh {load --auto space\ ye@2.1} ERR [msg_load {'space ye/2.1'} [err_conflict {baz @:1}]]
testouterr_cmd sh {load --auto space\ ye@2.2} ERR [msg_load {'space ye/2.2'} [err_conflict {baz @:1}]]
testouterr_cmd sh {load --auto space\ ye@2.4} ERR [msg_load {'space ye/2.4'} [err_conflict {baz @:1}]]
testouterr_cmd sh {load --auto space\ ye@2.5} ERR [msg_load {'space ye/2.5'} [err_conflict {baz @:1}]]
testouterr_cmd sh {load --auto space\ ye@2.6} ERR [msg_load {'space ye/2.6'} [err_conflict {baz @:1}]]
testouterr_cmd sh {load --auto space\ ye@2.7} ERR [msg_load {'space ye/2.7'} [err_conflict {baz @:1}]]
testouterr_cmd sh {load --auto space\ ye@2.8} ERR [msg_load {'space ye/2.8'} [err_conflict {baz @:1}]]
testouterr_cmd sh {load --auto space\ ye@2.9} ERR [msg_load {'space ye/2.9'} [err_conflict {baz @:1}]]


# redo the above mixed test with adv_vers_spec disabled
setenv_var MODULES_ADVANCED_VERSION_SPEC 0
unsetenv_loaded_module

# various syntaxes on command line

testouterr_cmd sh {load sp.ce y+@2.5:2.7} ERR "$err_path'sp.ce'\n$err_path'y+@2.5:2.7'"
testouterr_cmd sh {load sp.ce y+ @2.5:2.7} ERR "$err_path'sp.ce'\n$err_path'y+'\n$err_path'@2.5:2.7'"
set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.10"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.10"]
lappend ans [list ERR]
testouterr_cmd sh {load sp.ce\ y+ @2.5:2.7} $ans $err_path'@2.5:2.7'
testouterr_cmd sh {load sp.ce\ y+@2.5:2.7} ERR "$err_path'{sp.ce\ y+@2.5:2.7}'"
testouterr_cmd sh {load sp.ce\ y+@1.2 @2.5:2.7} ERR "$err_path'{sp.ce\ y+@1.2}'\n$err_path'@2.5:2.7'"
testouterr_cmd sh {load sp.ce\ y+ @1.2 @2.5:2.7} $ans "$err_path'@1.2'\n$err_path'@2.5:2.7'"

testouterr_cmd sh {load sp.ce\ y+ @0\ 2} $ans "$err_path'{@0 2}'"
testouterr_cmd sh {load sp.ce\ y+@0\ 2} ERR "$err_path'{sp.ce y+@0 2}'"

set ans [list]
lappend ans [list setpath LOADEDMODULES "space y /2.2"]
lappend ans [list setpath _LMFILES_ "$mp/space y /2.2"]
lappend ans [list setpath MODULES_LMALTNAME "space y /2.2&space y /default&space y "]
lappend ans [list ERR]
testouterr_cmd sh {load space\ y\  @1\ } $ans "$err_path'{@1 }'"
testouterr_cmd sh {load space\ y\ @1\ } ERR "$err_path'{space y @1 }'"

# test on unknown modulefiles
testouterr_cmd sh {load sp.ce\ z+@0\ 3} ERR "$err_path'{sp.ce z+@0 3}'"
testouterr_cmd sh {load sp.ce\ z+ @0\ 3} ERR "$err_path'{sp.ce z+}'\n$err_path'{@0 3}'"
testouterr_cmd sh {load space\ z\ @2\ } ERR "$err_path'{space z @2 }'"
testouterr_cmd sh {load space\ z\  @2\ } ERR "$err_path'{space z }'\n$err_path'{@2 }'"

# various syntaxes on prereq modulefile command

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/2:space ye/1.0"]
lappend ans [list setpath _LMFILES_ "$mp/baz/2:$mp/space ye/1.0"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.0&sp.ce|y+@2.5<2.7|baz|@<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "baz/2"]
lappend ans [list ERR]
testouterr_cmd_re sh {load --auto space\ ye/1.0} $ans [msg_top_load {'space ye/1.0'} {} baz/2 {} $err_path'sp.ce' $err_path'y\\+@2.5:2.7']

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/2:space ye/1.1"]
lappend ans [list setpath _LMFILES_ "$mp/baz/2:$mp/space ye/1.1"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.1&sp.ce|y+|@2.5<2.7|baz|@<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "baz/2"]
lappend ans [list ERR]
testouterr_cmd_re sh {load --auto space\ ye/1.1} $ans [msg_top_load {'space ye/1.1'} {} baz/2 {} $err_path'sp.ce' "$err_path'y\\+'" "$err_path'@2.5:2.7'"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.10:space ye/1.2"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.10:$mp/space ye/1.2"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.2&{sp.ce y+}|@2.5<2.7|baz|@<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "sp.ce y+/2.10"]
testouterr_cmd_re sh {load --auto space\ ye/1.2} $ans [msg_top_load {'space ye/1.2'} {} {'sp.ce y\\+/2.10'} {}]

if {[cmpversion $tclsh_version 8.6] == -1} {
    set errcmd "prereq {sp.ce y+}@2.5:2.7 baz @:1\n"
} else {
    set errcmd {prereq {sp.ce y+}@}
}
testouterr_cmd sh {load --auto space\ ye/1.3} ERR [msg_load {'space ye/1.3'} [msg_moderr {extra characters after close-brace} $errcmd "$mp/space ye/1.3" 2]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/2:space ye/1.4"]
lappend ans [list setpath _LMFILES_ "$mp/baz/2:$mp/space ye/1.4"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.4&{sp.ce y+@1.2}|@2.5<2.7|baz|@<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "baz/2"]
lappend ans [list ERR]
testouterr_cmd_re sh {load --auto space\ ye/1.4} $ans [msg_top_load {'space ye/1.4'} {} {baz/2} {} "$err_path'{sp.ce y\\+@1.2}'" "$err_path'@2.5:2.7'"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.10:space ye/1.5"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.10:$mp/space ye/1.5"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.5&{sp.ce y+}|@1.2|@2.5<2.7|baz|@<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "sp.ce y+/2.10"]
testouterr_cmd_re sh {load --auto space\ ye/1.5} $ans [msg_top_load {'space ye/1.5'} {} {'sp.ce y\\+/2.10'} {}]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.10:space ye/1.6"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.10:$mp/space ye/1.6"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.6&{sp.ce y+}|{@0 2}|baz|@<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "sp.ce y+/2.10"]
testouterr_cmd_re sh {load --auto space\ ye/1.6} $ans [msg_top_load {'space ye/1.6'} {} {'sp.ce y\\+/2.10'} {}]

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/2:space ye/1.7"]
lappend ans [list setpath _LMFILES_ "$mp/baz/2:$mp/space ye/1.7"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.7&{sp.ce y+@0 2}|baz|@<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "baz/2"]
lappend ans [list ERR]
testouterr_cmd_re sh {load --auto space\ ye/1.7} $ans [msg_top_load {'space ye/1.7'} {} {baz/2} {} "$err_path'{sp.ce y\\+@0 2}'"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/2:space ye/1.8"]
lappend ans [list setpath _LMFILES_ "$mp/baz/2:$mp/space ye/1.8"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.8&{space y @1 }|baz|@<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "baz/2"]
lappend ans [list ERR]
testouterr_cmd_re sh {load --auto space\ ye/1.8} $ans [msg_top_load {'space ye/1.8'} {} {baz/2} {} "$err_path'{space y @1 }'"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/2:space ye/1.9"]
lappend ans [list setpath _LMFILES_ "$mp/baz/2:$mp/space ye/1.9"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.9&{space y @a }|baz|@<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "baz/2"]
lappend ans [list ERR]
testouterr_cmd_re sh {load --auto space\ ye/1.9} $ans [msg_top_load {'space ye/1.9'} {} {baz/2} {} "$err_path'{space y @a }'"]

setenv_loaded_module [list {sp.ce y+/2.7}] [list "$mp/sp.ce y+/2.7"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:baz/2:space ye/1.1"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/baz/2:$mp/space ye/1.1"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.1&sp.ce|y+|@2.5<2.7|baz|@<1"]
lappend ans [list setpath MODULES_LMNOTUASKED "baz/2"]
lappend ans [list ERR]
testouterr_cmd_re sh {load --auto space\ ye/1.1} $ans [msg_top_load {'space ye/1.1'} {} baz/2 {} $err_path'sp.ce' "$err_path'y\\+'" "$err_path'@2.5:2.7'"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:space ye/1.5"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/space ye/1.5"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.5&{sp.ce y+}|@1.2|@2.5<2.7|baz|@<1"]
testouterr_cmd_re sh {load --auto space\ ye/1.5} $ans {}

setenv_loaded_module [list {baz/1}] [list "$mp/baz/1"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.1"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.1"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.1&sp.ce|y+|@2.5<2.7|baz|@<1"]
testouterr_cmd_re sh {load --auto space\ ye/1.1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.5"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.5"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.5&{sp.ce y+}|@1.2|@2.5<2.7|baz|@<1"]
testouterr_cmd_re sh {load --auto space\ ye/1.5} $ans {}

# unload dependent module {sp.ce y+/2.7}

setenv_loaded_module [list {sp.ce y+/2.7} {space ye/1.1}] [list "$mp/sp.ce y+/2.7" "$mp/space ye/1.1"]
setenv_path_var MODULES_LMPREREQ "space ye/1.1&sp.ce|y+|@2.5<2.7|baz|@<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/1.1"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/1.1"]
testouterr_cmd sh {unload --auto sp.ce\ y+/2.7} $ans {}

setenv_loaded_module [list {sp.ce y+/2.7} {space ye/1.5}] [list "$mp/sp.ce y+/2.7" "$mp/space ye/1.5"]
setenv_path_var MODULES_LMPREREQ "space ye/1.5&{sp.ce y+}|@1.2|@2.5<2.7|baz|@<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto sp.ce\ y+/2.7} $ans [msg_top_unload {'sp.ce y+/2.7'} {'space ye/1.5'} {} {}]

# unload dependent module baz/1

setenv_loaded_module [list {baz/1} {space ye/1.1}] [list "$mp/baz/1" "$mp/space ye/1.1"]
setenv_path_var MODULES_LMPREREQ "space ye/1.1&sp.ce|y+|@2.5<2.7|baz|@<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto baz/1} $ans [msg_top_unload baz/1 {'space ye/1.1'} {} {}]

setenv_loaded_module [list {baz/1} {space ye/1.5}] [list "$mp/baz/1" "$mp/space ye/1.5"]
setenv_path_var MODULES_LMPREREQ "space ye/1.5&{sp.ce y+}|@1.2|@2.5<2.7|baz|@<1"
set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath MODULES_LMPREREQ]
testouterr_cmd sh {unload --auto baz/1} $ans [msg_top_unload baz/1 {'space ye/1.5'} {} {}]

# load depedent module {sp.ce y+/2.7}

setenv_loaded_module [list {baz/1} {space ye/1.1}] [list "$mp/baz/1" "$mp/space ye/1.1"]
setenv_path_var MODULES_LMPREREQ "space ye/1.1&sp.ce|y+|@2.5<2.7|baz|@<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:space ye/1.1:sp.ce y+/2.7"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/space ye/1.1:$mp/sp.ce y+/2.7"]
testouterr_cmd_re sh {load --auto sp.ce\ y+/2.7} $ans {}

setenv_loaded_module [list {baz/1} {space ye/1.5}] [list "$mp/baz/1" "$mp/space ye/1.5"]
setenv_path_var MODULES_LMPREREQ "space ye/1.5&{sp.ce y+}|@1.2|@2.5<2.7|baz|@<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:sp.ce y+/2.7:space ye/1.5"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/sp.ce y+/2.7:$mp/space ye/1.5"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.5&{sp.ce y+}|@1.2|@2.5<2.7|baz|@<1"]
testouterr_cmd_re sh {load --auto sp.ce\ y+/2.7} $ans [msg_top_load {'sp.ce y\+/2.7'} {} {} "{'space ye/1.5'}"]

# load depedent module {sp.ce y+/0 2}

setenv_loaded_module [list {baz/1} {space ye/1.6}] [list "$mp/baz/1" "$mp/space ye/1.6"]
setenv_path_var MODULES_LMPREREQ "space ye/1.6&{sp.ce y+}|{@0 2}|baz|@<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "baz/1:sp.ce y+/0 2:space ye/1.6"]
lappend ans [list setpath _LMFILES_ "$mp/baz/1:$mp/sp.ce y+/0 2:$mp/space ye/1.6"]
lappend ans [list setpath MODULES_LMPREREQ "space ye/1.6&{sp.ce y+}|{@0 2}|baz|@<1"]
testouterr_cmd_re sh {load --auto sp.ce\ y+/0\ 2} $ans [msg_top_load {'sp.ce y\+/0 2'} {} {} "{'space ye/1.6'}"]

# various syntaxes on conflict modulefile command
unsetenv_loaded_module
unsetenv_path_var MODULES_LMPREREQ

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.0"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.0"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.0&sp.ce&y+@2.5<2.7&baz&@<1"]
testouterr_cmd sh {load --auto space\ ye/2.0} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.1"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.1"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.1&sp.ce&y+&@2.5<2.7&baz&@<1"]
testouterr_cmd sh {load --auto space\ ye/2.1} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.2"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.2"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.2&{sp.ce y+}&@2.5<2.7&baz&@<1"]
testouterr_cmd sh {load --auto space\ ye/2.2} $ans {}

if {[cmpversion $tclsh_version 8.6] == -1} {
    set errcmd "conflict {sp.ce y+}@2.5:2.7 baz @:1\n"
} else {
    set errcmd {conflict {sp.ce y+}@}
}
testouterr_cmd sh {load --auto space\ ye/2.3} ERR [msg_load {'space ye/2.3'} [msg_moderr {extra characters after close-brace} $errcmd "$mp/space ye/2.3" 2]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.4"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.4"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.4&{sp.ce y+@1.2}&@2.5<2.7&baz&@<1"]
testouterr_cmd sh {load --auto space\ ye/2.4} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.5"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.5"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.5&{sp.ce y+}&@1.2&@2.5<2.7&baz&@<1"]
testouterr_cmd sh {load --auto space\ ye/2.5} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.6"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.6"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.6&{sp.ce y+}&{@0 2}&baz&@<1"]
testouterr_cmd sh {load --auto space\ ye/2.6} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.7"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.7"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.7&{sp.ce y+@0 2}&baz&@<1"]
testouterr_cmd sh {load --auto space\ ye/2.7} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.8"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.8"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.8&{space y @1 }&baz&@<1"]
testouterr_cmd sh {load --auto space\ ye/2.8} $ans {}

set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.9"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.9"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.9&{space y @n }&baz&@<1"]
testouterr_cmd sh {load --auto space\ ye/2.9} $ans {}

# load conflicting module {sp.ce y+/2.7}

setenv_loaded_module [list {space ye/2.1}] [list "$mp/space ye/2.1"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.1&sp.ce&y+&@2.5<2.7&baz&@<1"
set ans [list]
lappend ans [list setpath LOADEDMODULES "space ye/2.1:sp.ce y+/2.7"]
lappend ans [list setpath _LMFILES_ "$mp/space ye/2.1:$mp/sp.ce y+/2.7"]
testouterr_cmd_re sh {load --auto sp.ce\ y+/2.7} $ans {}

setenv_loaded_module [list {space ye/2.5}] [list "$mp/space ye/2.5"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.5&{sp.ce y+}&@1.2&@2.5<2.7&baz&@<1"
testouterr_cmd sh {load --auto sp.ce\ y+/2.7} ERR [msg_load {'sp.ce y+/2.7'} [err_conflict space\ ye/2.5]]

# load conflicting module baz/1

setenv_loaded_module [list {space ye/2.1}] [list "$mp/space ye/2.1"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.1&sp.ce&y+&@2.5<2.7&baz&@<1"
testouterr_cmd sh {load --auto baz/1} ERR [msg_load {baz/1} [err_conflict space\ ye/2.1]]

setenv_loaded_module [list {space ye/2.5}] [list "$mp/space ye/2.5"]
setenv_path_var MODULES_LMCONFLICT "space ye/2.5&{sp.ce y+}&@1.2&@2.5<2.7&baz&@<1"
testouterr_cmd sh {load --auto baz/1} ERR [msg_load {baz/1} [err_conflict space\ ye/2.5]]

# conflicting module {sp.ce y+/2.7} loaded prior conflict definition
unsetenv_path_var MODULES_LMCONFLICT
setenv_loaded_module [list {sp.ce y+/2.7}] [list "$mp/sp.ce y+/2.7"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "sp.ce y+/2.7:space ye/2.1"]
lappend ans [list setpath _LMFILES_ "$mp/sp.ce y+/2.7:$mp/space ye/2.1"]
lappend ans [list setpath MODULES_LMCONFLICT "space ye/2.1&sp.ce&y+&@2.5<2.7&baz&@<1"]
testouterr_cmd_re sh {load --auto space\ ye/2.1} $ans {}

testouterr_cmd sh {load --auto space\ ye/2.5} ERR [msg_load {'space ye/2.5'} [err_conflict {sp.ce y+}]]

# conflicting module {sp.ce y+/2.7} loaded prior conflict definition
unsetenv_path_var MODULES_LMCONFLICT
setenv_loaded_module [list {sp.ce y+/0 2}] [list "$mp/sp.ce y+/0 2"]

testouterr_cmd sh {load --auto space\ ye/2.6} ERR [msg_load {'space ye/2.6'} [err_conflict {sp.ce y+}]]

# conflicting module baz/1 loaded prior conflict definition
unsetenv_path_var MODULES_LMCONFLICT
setenv_loaded_module [list baz/1] [list "$mp/baz/1"]

testouterr_cmd sh {load --auto space\ ye/2.1} ERR [msg_load {'space ye/2.1'} [err_conflict {baz}]]
testouterr_cmd sh {load --auto space\ ye/2.5} ERR [msg_load {'space ye/2.5'} [err_conflict {baz}]]

# delete generated modulefiles
delete_endspace_test_modulefiles

}

#
#  Cleanup
#

reset_test_env
