##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	1995/12/06
#   Last Mod.:		%U%, %G%
#
#   Authors:		Jens Hamisch, Jens.Hamisch@Strawberry.COM
#
#   Description:	Testuite testsequence
#   Command:		load, switch
#   Modulefiles:	prereq/module, trace/all_on, trace/all_off
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the 'prereq' command using a category
#			module name. This tests the reactions of modulecmd
#			if the prerequired module is not load and if one
#			of the modules of the required category is load.
#		}C%
#
##############################################################################

# ensure auto symbolic versions are not set for these tests
setenv_var MODULES_ADVANCED_VERSION_SPEC 0

#
#  Variables. This test forces a module load command. It will result in the
#    environment variables "_LMFILES_", "LOADEDMODULES" and "testsuite" to
#    be set up
#

set module "prereq/module"
set modulefile "$modpath/$module"

set module_tron "trace/all_on"
set modulefile_tron "$modpath/$module_tron"

set module_troff "trace/all_off"
set modulefile_troff "$modpath/$module_troff"

set module_set "setenv/1.0"
set modulefile_set "$modpath/$module_set"

#
#  Error messages
#

set err_pre [msg_load $module [err_prereq trace]]
set err_trace "$warn_msgs: 'module-trace' command not implemented"
set err_trace_lo [msg_load $module_tron $err_trace]

#
#  The tests
#

# prereq is loaded automatically when autohandling is enabled
set ans [list]
lappend ans [list setpath LOADEDMODULES "$module_tron:$module"]
lappend ans [list setpath _LMFILES_ "$modulefile_tron:$modulefile"]
lappend ans [list set testsuite yes]
lappend ans [list setpath MODULES_LMPREREQ "$module&trace"]
lappend ans [list setpath MODULES_LMNOTUASKED $module_tron]
if {$install_implicitdefault eq {y}} {
    set tserr $err_trace_lo\n\n[msg_top_load $module {} $module_tron {}]
} else {
    set tserr [msg_load $module $err_nodefault'trace' [err_reqlo trace]]
}
testouterr_cmd_re "ALL" "load --auto $module" [if_implicitdefault $ans ERR] $tserr

testouterr_cmd "ALL" "load --no-auto $module" "ERR" $err_pre

set ans [list]
lappend ans [list setpath LOADEDMODULES "$module_troff:$module"]
lappend ans [list setpath _LMFILES_ "$modulefile_troff:$modulefile"]
lappend ans [list set testsuite yes]
lappend ans [list setpath MODULES_LMPREREQ "$module&trace"]
testouterr_cmd_re "ALL" "load $module_troff $module" $ans ""

set ans [list]
lappend ans [list setpath LOADEDMODULES "$module_tron:$module"]
lappend ans [list setpath _LMFILES_ "$modulefile_tron:$modulefile"]
lappend ans [list set testsuite yes]
lappend ans [list setpath MODULES_LMPREREQ "$module&trace"]
testouterr_cmd_re "ALL" "load $module_tron $module" $ans $err_trace_lo

#
# Tests playing with OR prereq list
#

set module "prereq/orlist"
set modulefile "$modpath/$module"
set err_pre [msg_load $module [err_prereqor trace setenv loc_dv1]]

# prereq is loaded automatically when autohandling is enabled (first in or list)
set ans [list]
lappend ans [list setpath LOADEDMODULES "$module_tron:$module"]
lappend ans [list setpath _LMFILES_ "$modulefile_tron:$modulefile"]
lappend ans [list set testsuite yes]
lappend ans [list setpath MODULES_LMPREREQ "$module&trace|setenv|loc_dv1"]
lappend ans [list setpath MODULES_LMNOTUASKED $module_tron]
if {$install_implicitdefault eq {y}} {
    set tserr $err_trace_lo\n\n[msg_top_load $module {} $module_tron {}]
} else {
    set tserr [msg_load $module $err_nodefault'trace' $err_nodefault'setenv' $err_nodefault'loc_dv1' [err_reqlo trace setenv loc_dv1]]
}
testouterr_cmd_re "ALL" "load --auto $module" [if_implicitdefault $ans ERR] $tserr

testouterr_cmd "ALL" "load --no-auto $module" "ERR" $err_pre

set ans [list]
lappend ans [list setpath LOADEDMODULES "$module_tron:$module"]
lappend ans [list setpath _LMFILES_ "$modulefile_tron:$modulefile"]
lappend ans [list set testsuite yes]
lappend ans [list setpath MODULES_LMPREREQ "$module&trace|setenv|loc_dv1"]
testouterr_cmd_re "ALL" "load $module_tron $module" $ans $err_trace_lo

# set situation where a module has been loaded with its prerequirement
setenv_loaded_module [list $module_set $module_troff $module] [list $modulefile_set $modulefile_troff $modulefile]
setenv_path_var MODULES_LMPREREQ "$module&trace|setenv|loc_dv1"
set ans [list]
lappend ans [list unset testsuite]
lappend ans [list setpath LOADEDMODULES "$module_troff:$module:$module_tron"]
lappend ans [list setpath _LMFILES_ "$modulefile_troff:$modulefile:$modulefile_tron"]
testouterr_cmd_re "sh" "switch --no-auto $module_set $module_tron" $ans [msg_load $module_tron $err_trace]

set ans [list]
lappend ans [list set testsuite yes]
lappend ans [list setpath LOADEDMODULES "$module_troff:$module_tron:$module"]
lappend ans [list setpath _LMFILES_ "$modulefile_troff:$modulefile_tron:$modulefile"]
lappend ans [list setpath MODULES_LMPREREQ "$module&trace|setenv|loc_dv1"]
testouterr_cmd_re "sh" "switch --auto $module_set $module_tron" $ans [msg_load $module_tron $err_trace]\n\n[msg_top_switch $module_set $module_tron {} {} {} {} $module]

#
#  Cleanup
#

reset_test_env
