##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2009/08/22
#   Last Mod.:		%U%, %G%
#
#   Authors:		R.K. Owen, <rk@owen.sj.ca.us>
#
#   Description:	Testuite testsequence
#   Command:		load
#   Modulefiles:	chdir/1.0,
#   			chdir/2.0,
#   			chdir/3.0,
#   Sub-Command:
#
#   Comment:	%C{
#			Tries the Tcl "exit" to skip loading a module,
#			but not affecting the other loaded modules.
#		}C%
#
##############################################################################

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

set mod1 "chdir/1.0"
set mod2 "chdir/2.0"
set mod3 "chdir/3.0"
set mod4 "chdir/4.0"

set mod1p "$modpath/$mod1"
set mod2p "$modpath/$mod2"
set mod3p "$modpath/$mod3"
set mod4p "$modpath/$mod4"

set err_chdir	"$warn_msgs: Cannot chdir to '/foo/bar/baz' for 'chdir/2.0'"

#
# set up an empty environment
#
setenv_loaded_module {} {}

#
#  The tests
#
# test 1	(/tmp)
lappend ans [list chdir /tmp]
lappend ans [list setpath LOADEDMODULES $mod1]
lappend ans [list setpath _LMFILES_ $mod1p]

test_cmd_re "ALL" "load $mod1" $ans

# test 2	(/foo/bar/baz)
set ans [list]
lappend ans [list setpath LOADEDMODULES $mod2]
lappend ans [list setpath _LMFILES_ $mod2p]

testouterr_cmd_re "ALL" "load $mod2" $ans [msg_load $mod2 $err_chdir]

# test 3	(/ & /tmp)
set ans [list]
lappend ans [list chdir /tmp]
lappend ans [list setpath LOADEDMODULES $mod3]
lappend ans [list setpath _LMFILES_ $mod3p]

test_cmd_re "ALL" "load $mod3" $ans

# test 4	(/tmp, /)
set ans [list]
lappend ans [list chdir /]
lappend ans [list setpath LOADEDMODULES "$mod1:$mod4"]
lappend ans [list setpath _LMFILES_ "$mod1p:$mod4p"]

test_cmd_re "ALL" "load $mod1 $mod4" $ans

# test 5	(/ /tmp)
set ans [list]
lappend ans [list chdir /tmp]
lappend ans [list setpath LOADEDMODULES "$mod4:$mod1"]
lappend ans [list setpath _LMFILES_ "$mod4p:$mod1p"]

test_cmd_re "ALL" "load $mod4 $mod1" $ans

# test 6	(/tmp, /foo/bar/baz)
set ans [list]
lappend ans [list chdir /tmp]
lappend ans [list setpath LOADEDMODULES "$mod1:$mod2"]
lappend ans [list setpath _LMFILES_ "$mod1p:$mod2p"]

testouterr_cmd_re "ALL" "load $mod1 $mod2" $ans [msg_load $mod2 $err_chdir]

# test 7	(/tmp, /foo/bar/baz)
set ans [list]
lappend ans [list chdir /tmp]
lappend ans [list setpath LOADEDMODULES "$mod2:$mod1"]
lappend ans [list setpath _LMFILES_ "$mod2p:$mod1p"]

testouterr_cmd_re "ALL" "load $mod2 $mod1" $ans [msg_load $mod2 $err_chdir]

#
#  Cleanup
#

reset_test_env
