##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2018/06/24
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:        switch
#   Modulefiles:
#   Sub-Command:    prereq, conflict
#
#   Comment:	%C{
#           Test automatic resolution of modulefile dependencies on switch
#           command when the auto-handling mode is enabled (dependent modules
#           handling)
#		}C%
#
##############################################################################

# enable auto_handling with environment variable
setenv_var MODULES_AUTO_HANDLING 1

set mp "$modpath.deps"

# setup specific environment
setenv_path_var MODULEPATH $mp

# dependency chain loaded with first-operational-in-list prereq module loaded
setenv_loaded_module [list dd df dg] [list "$mp/dd" "$mp/df" "$mp/dg"] [list dd df]
setenv_path_var MODULES_LMPREREQ "df&da|db|dc|dd|de" "dg&df"
setenv_path_var MODULES_LMCONFLICT "dg&db"

# switch first-operational-in-list prereq module by second-operational-in-list
set ans [list]
lappend ans [list setpath LOADEDMODULES "de:df:dg"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/df:$mp/dg"]
lappend ans [list setpath MODULES_LMCONFLICT "dg&db"]
lappend ans [list setpath MODULES_LMPREREQ "df&da|db|dc|dd|de:dg&df"]
lappend ans [list setpath MODULES_LMNOTUASKED "df"]
set tserr [list "unload dg" "unload df" "unload dd" "load de" "load df" "load dg"]
testouterr_cmd_re "sh" "switch dd de" $ans [join $tserr "\n"]\n\n[msg_top_switch dd de {} {} {} {} [list df dg]]


# dependency chain loaded with second-operational-in-list prereq module loaded
setenv_loaded_module [list de df dg] [list "$mp/de" "$mp/df" "$mp/dg"] [list de df]
setenv_path_var MODULES_LMPREREQ "df&da|db|dc|dd|de" "dg&df"
setenv_path_var MODULES_LMCONFLICT "dg&db"

# switch second-operational-in-list prereq module by first-operational-in-list
set ans [list]
lappend ans [list setpath LOADEDMODULES "dd:df:dg"]
lappend ans [list setpath _LMFILES_ "$mp/dd:$mp/df:$mp/dg"]
lappend ans [list setpath MODULES_LMCONFLICT "dg&db"]
lappend ans [list setpath MODULES_LMPREREQ "df&da|db|dc|dd|de:dg&df"]
lappend ans [list setpath MODULES_LMNOTUASKED "df"]
set tserr [list "unload dg" "unload df" "unload de" "load dd" "load df" "load dg"]
testouterr_cmd_re "sh" "switch de dd" $ans [join $tserr "\n"]\n\n[msg_top_switch de dd {} {} {} {} [list df dg]]

# switch second-operational-in-list prereq module by broken or conflicting module
set ans [list]
lappend ans [list setpath LOADEDMODULES "da"]
lappend ans [list setpath _LMFILES_ "$mp/da"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list setpath MODULES_LMCONFLICT "da&df"]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de" "load da" "load df"]
testouterr_cmd_re "sh" "switch de da" $ans [join $tserr "\n"]\n\n[msg_load df [err_conlo da]]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch de da {} {} {} {} [list [list dg df] [list]] [err_depref df] [err_depref dg]]

set ans [list]
lappend ans [list setpath MODULES_LMPREREQ "df&da|db|dc|dd|de"]
lappend ans [list setpath _LMFILES_ "$mp/db:$mp/df"]
lappend ans [list setpath LOADEDMODULES "db:df"]
lappend ans [list setpath MODULES_LMNOTUASKED "df"]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de" "load db" "load df"]
testouterr_cmd_re "sh" "switch de db" $ans [join $tserr "\n"]\n\n[msg_load dg [err_conlo db]]\n\n[msg_top_switch de db {} {} {} {} [list [list dg df] [list df]] [err_depref dg]]

set ans [list]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath _LMFILES_]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de" "load dc"]
testouterr_cmd_re "sh" "switch de dc" $ans [join $tserr "\n"]\n\n[msg_load dc $err_evalabort]\n\n[msg_load df [err_reqmis da db dc dd de]]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch de dc {} {} {} {} [list [list dg df] [list]] [err_swon dc] [err_depref df] [err_depref dg]]


# dependency chain loaded with second-operational-in-list prereq module loaded and an individual module loaded
setenv_loaded_module [list de df dg dh] [list "$mp/de" "$mp/df" "$mp/dg" "$mp/dh"] [list de df]
setenv_path_var MODULES_LMPREREQ "df&da|db|dc|dd|de" "dg&df"
setenv_path_var MODULES_LMCONFLICT "dg&db"

set ans [list]
lappend ans [list setpath LOADEDMODULES "dh"]
lappend ans [list setpath _LMFILES_ "$mp/dh"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de" "load ea"]
testouterr_cmd_re "sh" "switch df ea" $ans [join $tserr "\n"]\n\n[msg_load ea $err_evalabort]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df ea {} de {} {} [list [list dg] [list]] [err_swon ea] [err_depref dg]]

set ans [list]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list setpath _LMFILES_ "$mp/dh:$mp/eb"]
lappend ans [list setpath LOADEDMODULES "dh:eb"]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list setpath MODULES_LMCONFLICT "eb&dg"]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de" "load eb"]
# as load is attempted to see if conflict solves, returned error for dg is about missing prereq
testouterr_cmd_re "sh" "switch df eb" $ans [join $tserr "\n"]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df eb {} de {} {} [list [list dg] [list]] [err_depref dg]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "dh"]
lappend ans [list setpath _LMFILES_ "$mp/dh"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de" "load ea"]
testouterr_cmd_re "sh" "switch df ec" $ans [join $tserr "\n"]\n\n[msg_load ea $err_evalabort]\n\n[msg_load ec [err_reqmis ea]]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df ec {} de {} {} [list [list dg] [list]] [err_reqlo ea] [err_swon ec] [err_depref dg]]

set ans [list]
lappend ans [list setpath MODULES_LMPREREQ "ed&eb"]
lappend ans [list setpath _LMFILES_ "$mp/dh:$mp/eb:$mp/ed"]
lappend ans [list setpath LOADEDMODULES "dh:eb:ed"]
lappend ans [list setpath MODULES_LMNOTUASKED "eb"]
lappend ans [list setpath MODULES_LMCONFLICT "eb&dg"]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de" "load eb" "load ed"]
# as load is attempted to see if conflict solves, returned error for dg is about missing prereq
testouterr_cmd_re "sh" "switch df ed" $ans [join $tserr "\n"]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df ed {} de {} eb [list [list dg] [list]] [err_depref dg]]

set ans [list]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list setpath _LMFILES_ "$mp/dh:$mp/ee"]
lappend ans [list setpath LOADEDMODULES "dh:ee"]
lappend ans [list setpath MODULES_LMCONFLICT "ee&de"]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de" "load ee"]
testouterr_cmd_re "sh" "switch df ee" $ans [join $tserr "\n"]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df ee {} de {} {} [list [list dg] [list]] [err_depref dg]]

set ans [list]
lappend ans [list setpath MODULES_LMNOTUASKED "ee"]
lappend ans [list setpath MODULES_LMCONFLICT "ee&de"]
lappend ans [list setpath MODULES_LMPREREQ "ef&ee"]
lappend ans [list setpath _LMFILES_ "$mp/dh:$mp/ee:$mp/ef"]
lappend ans [list setpath LOADEDMODULES "dh:ee:ef"]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de" "load ee" "load ef"]
testouterr_cmd_re "sh" "switch df ef" $ans [join $tserr "\n"]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df ef {} de {} ee [list [list dg] [list]] [err_depref dg]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "dh"]
lappend ans [list setpath _LMFILES_ "$mp/dh"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de"]
testouterr_cmd_re "sh" "switch df eg" $ans [join $tserr "\n"]\n\n[msg_load eg [err_conflict dh]]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df eg {} de {} {} [list [list dg] [list]] [err_swon eg] [err_depref dg]]

set ans [list]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list setpath _LMFILES_ "$mp/dh"]
lappend ans [list setpath LOADEDMODULES "dh"]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de" "load ea"]
testouterr_cmd_re "sh" "switch dg ea" $ans [join $tserr "\n"]\n\n[msg_load ea $err_evalabort]\n\n[msg_top_switch dg ea {} [list df de] {} {} {} [err_swon ea]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "dh:eb"]
lappend ans [list setpath _LMFILES_ "$mp/dh:$mp/eb"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list setpath MODULES_LMCONFLICT "eb&dg"]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
set tserr [list "unload dg" "unload df" "unload de" "load eb"]
testouterr_cmd_re "sh" "switch dg eb" $ans [join $tserr "\n"]\n\n[msg_top_switch dg eb {} [list df de] {} {} {}]

set ans [list]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list setpath _LMFILES_ "$mp/dh"]
lappend ans [list setpath LOADEDMODULES "dh"]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de" "load ea"]
testouterr_cmd_re "sh" "switch dg ec" $ans [join $tserr "\n"]\n\n[msg_load ea $err_evalabort]\n\n[msg_load ec [err_reqmis ea]]\n\n[msg_top_switch dg ec {} [list df de] {} {} {} [err_reqlo ea] [err_swon ec]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "dh:eb:ed"]
lappend ans [list setpath _LMFILES_ "$mp/dh:$mp/eb:$mp/ed"]
lappend ans [list setpath MODULES_LMPREREQ "ed&eb"]
lappend ans [list setpath MODULES_LMCONFLICT "eb&dg"]
lappend ans [list setpath MODULES_LMNOTUASKED "eb"]
set tserr [list "unload dg" "unload df" "unload de" "load eb" "load ed"]
testouterr_cmd_re "sh" "switch dg ed" $ans [join $tserr "\n"]\n\n[msg_top_switch dg ed {} [list df de] {} eb {}]

set ans [list]
lappend ans [list setpath LOADEDMODULES "dh:ee"]
lappend ans [list setpath _LMFILES_ "$mp/dh:$mp/ee"]
lappend ans [list setpath MODULES_LMCONFLICT "ee&de"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
set tserr [list "unload dg" "unload df" "unload de" "load ee"]
testouterr_cmd_re "sh" "switch dg ee" $ans [join $tserr "\n"]\n\n[msg_top_switch dg ee {} [list df de] {} {} {}]

set ans [list]
lappend ans [list setpath LOADEDMODULES "dh:ee:ef"]
lappend ans [list setpath _LMFILES_ "$mp/dh:$mp/ee:$mp/ef"]
lappend ans [list setpath MODULES_LMCONFLICT "ee&de"]
lappend ans [list setpath MODULES_LMPREREQ "ef&ee"]
lappend ans [list setpath MODULES_LMNOTUASKED "ee"]
set tserr [list "unload dg" "unload df" "unload de" "load ee" "load ef"]
testouterr_cmd_re "sh" "switch dg ef" $ans [join $tserr "\n"]\n\n[msg_top_switch dg ef {} [list df de] {} ee {}]

set ans [list]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list setpath _LMFILES_ "$mp/dh"]
lappend ans [list setpath LOADEDMODULES "dh"]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "unload de"]
testouterr_cmd_re "sh" "switch dg eg" $ans [join $tserr "\n"]\n\n[msg_load eg [err_conflict dh]]\n\n[msg_top_switch dg eg {} [list df de] {} {} {} [err_swon eg]]


# dependency chain loaded with second-operational-in-list prereq module loaded and an individual module loaded (everything user asked)
setenv_loaded_module [list de df dg dh] [list "$mp/de" "$mp/df" "$mp/dg" "$mp/dh"]
setenv_path_var MODULES_LMPREREQ "df&da|db|dc|dd|de" "dg&df"
setenv_path_var MODULES_LMCONFLICT "dg&db"

set ans [list]
lappend ans [list setpath LOADEDMODULES "de:dh"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/dh"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "load ea"]
testouterr_cmd_re "sh" "switch df ea" $ans [join $tserr "\n"]\n\n[msg_load ea $err_evalabort]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df ea {} {} {} {} [list [list dg] [list]] [err_swon ea] [err_depref dg]]

set ans [list]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/dh:$mp/eb"]
lappend ans [list setpath LOADEDMODULES "de:dh:eb"]
lappend ans [list setpath MODULES_LMCONFLICT "eb&dg"]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "load eb"]
# as load is attempted to see if conflict solves, returned error for dg is about missing prereq
testouterr_cmd_re "sh" "switch df eb" $ans [join $tserr "\n"]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df eb {} {} {} {} [list [list dg] [list]] [err_depref dg]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "de:dh"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/dh"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "load ea"]
testouterr_cmd_re "sh" "switch df ec" $ans [join $tserr "\n"]\n\n[msg_load ea $err_evalabort]\n\n[msg_load ec [err_reqmis ea]]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df ec {} {} {} {} [list [list dg] [list]] [err_reqlo ea] [err_swon ec] [err_depref dg]]

set ans [list]
lappend ans [list setpath MODULES_LMPREREQ "ed&eb"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/dh:$mp/eb:$mp/ed"]
lappend ans [list setpath LOADEDMODULES "de:dh:eb:ed"]
lappend ans [list setpath MODULES_LMNOTUASKED "eb"]
lappend ans [list setpath MODULES_LMCONFLICT "eb&dg"]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df" "load eb" "load ed"]
# as load is attempted to see if conflict solves, returned error for dg is about missing prereq
testouterr_cmd_re "sh" "switch df ed" $ans [join $tserr "\n"]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df ed {} {} {} eb [list [list dg] [list]] [err_depref dg]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "de:dh"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/dh"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df"]
testouterr_cmd_re "sh" "switch df ee" $ans [join $tserr "\n"]\n\n[msg_load ee [err_conflict de]]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df ee {} {} {} {} [list [list dg] [list]] [err_swon ee] [err_depref dg]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "de:dh"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/dh"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df"]
testouterr_cmd_re "sh" "switch df ef" $ans [join $tserr "\n"]\n\n[msg_load ee [err_conflict de]]\n\n[msg_load ef [err_reqmis ee]]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df ef {} {} {} {} [list [list dg] [list]] [err_reqlo ee] [err_swon ef] [err_depref dg]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "de:dh"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/dh"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg" "unload df"]
testouterr_cmd_re "sh" "switch df eg" $ans [join $tserr "\n"]\n\n[msg_load eg [err_conflict dh]]\n\n[msg_load dg [err_reqmis df]]\n\n[msg_top_switch df eg {} {} {} {} [list [list dg] [list]] [err_swon eg] [err_depref dg]]

set ans [list]
lappend ans [list setpath MODULES_LMPREREQ "df&da|db|dc|dd|de"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/df:$mp/dh"]
lappend ans [list setpath LOADEDMODULES "de:df:dh"]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg" "load ea" \n[msg_load ea $err_evalabort] \n[msg_switch dg ea [err_swon ea]]]
testouterr_cmd_re "sh" "switch dg ea" $ans [join $tserr "\n"]

set ans [list]
lappend ans [list setpath LOADEDMODULES "de:df:dh:eb"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/df:$mp/dh:$mp/eb"]
lappend ans [list setpath MODULES_LMPREREQ "df&da|db|dc|dd|de"]
lappend ans [list setpath MODULES_LMCONFLICT "eb&dg"]
set tserr [list "unload dg" "load eb"]
testouterr_cmd_re "sh" "switch dg eb" $ans [join $tserr "\n"]

set ans [list]
lappend ans [list setpath MODULES_LMPREREQ "df&da|db|dc|dd|de"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/df:$mp/dh"]
lappend ans [list setpath LOADEDMODULES "de:df:dh"]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg" "load ea"]
testouterr_cmd_re "sh" "switch dg ec" $ans [join $tserr "\n"]\n\n[msg_load ea $err_evalabort]\n\n[msg_load ec [err_reqmis ea]]\n\n[msg_switch dg ec [err_reqlo ea] [err_swon ec]]

set ans [list]
lappend ans [list setpath LOADEDMODULES "de:df:dh:eb:ed"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/df:$mp/dh:$mp/eb:$mp/ed"]
lappend ans [list setpath MODULES_LMPREREQ "df&da|db|dc|dd|de:ed&eb"]
lappend ans [list setpath MODULES_LMCONFLICT "eb&dg"]
lappend ans [list setpath MODULES_LMNOTUASKED "eb"]
set tserr [list "unload dg" "load eb" "load ed"]
testouterr_cmd_re "sh" "switch dg ed" $ans [join $tserr "\n"]\n\n[msg_top_switch dg ed {} {} {} eb {}]

set ans [list]
lappend ans [list setpath MODULES_LMPREREQ "df&da|db|dc|dd|de"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/df:$mp/dh"]
lappend ans [list setpath LOADEDMODULES "de:df:dh"]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg"]
testouterr_cmd_re "sh" "switch dg ee" $ans [join $tserr "\n"]\n\n[msg_load ee [err_conflict de]]\n\n[msg_switch dg ee [err_swon ee]]

set ans [list]
lappend ans [list setpath MODULES_LMPREREQ "df&da|db|dc|dd|de"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/df:$mp/dh"]
lappend ans [list setpath LOADEDMODULES "de:df:dh"]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg"]
testouterr_cmd_re "sh" "switch dg ef" $ans [join $tserr "\n"]\n\n[msg_load ee [err_conflict de]]\n\n[msg_load ef [err_reqmis ee]]\n\n[msg_switch dg ef [err_reqlo ee] [err_swon ef]]

set ans [list]
lappend ans [list setpath MODULES_LMPREREQ "df&da|db|dc|dd|de"]
lappend ans [list setpath _LMFILES_ "$mp/de:$mp/df:$mp/dh"]
lappend ans [list setpath LOADEDMODULES "de:df:dh"]
lappend ans [list unsetpath MODULES_LMCONFLICT]
lappend ans [list ERR]
set tserr [list "unload dg"]
testouterr_cmd_re "sh" "switch dg eg" $ans [join $tserr "\n"]\n\n[msg_load eg [err_conflict dh]]\n\n[msg_switch dg eg [err_swon eg]]


# test situation where DepUn modules impact UReqUn list (those are not unloaded during switch)
setenv_loaded_module [list h60 h61 h62] [list "$mp/h60" "$mp/h61" "$mp/h62"] [list h60 h61]
setenv_path_var MODULES_LMPREREQ "h62&h60&h61"
set ans [list]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list setpath _LMFILES_ "$mp/h61:$mp/h68"]
lappend ans [list setpath LOADEDMODULES "h61:h68"]
lappend ans [list setpath MODULES_LMNOTUASKED "h61"]
lappend ans [list ERR]
set tserr [list "unload h62" "unload h60" "load h68"]
testouterr_cmd_re "sh" "switch h60 h68" $ans [join $tserr "\n"]\n\n[msg_load h62 [err_reqmis h60]]\n\n[msg_top_switch h60 h68 {} {} {} {} [list [list h62] [list]] [err_depref h62]]

# test situation where UReqUn modules impact DepRe list (conflict solving reload)
setenv_loaded_module [list h30 h31 h32 h38] [list "$mp/h30" "$mp/h31" "$mp/h32" "$mp/h38"] [list h30 h31]
setenv_path_var MODULES_LMPREREQ "h31&h30" "h32&h31"
setenv_path_var MODULES_LMCONFLICT "h38&h30&h31"
set ans [list]
lappend ans [list setpath LOADEDMODULES "h68:h38"]
lappend ans [list setpath _LMFILES_ "$mp/h68:$mp/h38"]
lappend ans [list setpath MODULES_LMCONFLICT "h38&h30&h31"]
lappend ans [list unsetpath MODULES_LMPREREQ]
lappend ans [list unsetpath MODULES_LMNOTUASKED]
set tserr [list "unload h38" "unload h32" "unload h31" "unload h30" "load h68" "load h38"]
testouterr_cmd_re "sh" "switch h32 h68" $ans [join $tserr "\n"]\n\n[msg_top_switch h32 h68 {} [list h31 h30] {} {} h38]

# test situation where DepUn modules impact DepRe list
setenv_loaded_module [list h60 h61 h62 h71 h73 h74] [list "$mp/h60" "$mp/h61" "$mp/h62" "$mp/h71" "$mp/h73" "$mp/h74"] [list h60 h61]
setenv_path_var MODULES_LMPREREQ "h62&h60&h61" "h71&h62" "h74&h73|h62|h63|h71"
unsetenv_path_var MODULES_LMCONFLICT
set ans [list]
lappend ans [list setpath LOADEDMODULES "h60:h73:h68:h74"]
lappend ans [list setpath _LMFILES_ "$mp/h60:$mp/h73:$mp/h68:$mp/h74"]
lappend ans [list setpath MODULES_LMPREREQ "h74&h73|h62|h63|h71"]
lappend ans [list setpath MODULES_LMNOTUASKED "h60"]
set tserr [list "unload h74" "unload h71" "unload h62" "unload h61" "load h68" \n[msg_load h62 [err_reqmis h61]] \n[msg_load h71 [err_reqmis h62]] "\nload h74"]
lappend ans [list ERR]
testouterr_cmd_re "sh" "switch h61 h68" $ans [join $tserr "\n"]\n\n[msg_top_switch h61 h68 {} {} {} {} [list [list h74 h71 h62] [list h74]] [err_depref h62] [err_depref h71]]


#
#  Cleanup
#

reset_test_env
