##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   First Edition:	2008/02/19
#
#   Authors:		R.K. Owen, <rk@owen.sj.ca.us>
#
#   Description:	Testuite testsequence
#   Command:		swap
#
#   Comment:	%C{
#			Tests the 'swap' module subcommand where there are
#			double prepends or appends.
#		}C%
#
##############################################################################

set path21   "/modules/testsuite2.1"
set path2121 "/modules/testsuite2.1/2.1"
set path22   "/modules/testsuite2.2"
set path2222 "/modules/testsuite2.2/2.2"
set pathpre  "/test/pre"
set pathpost "/test/post"

#
# Prepend test
#
set mod21 "prepend/2.1"
set mod22 "prepend/2.2"

set mod21p "$modpath/$mod21"
set mod22p "$modpath/$mod22"

set module "$mod21"
set modulefile "$mod21p"

#
# set up the environment
#

setenv_loaded_module $module $modulefile
set old_path $env(PATH)
set env(PATH) "$pathpre:$path21:$path2121:$pathpost"

#
#  For the different shells ...
#

set module "$mod22"
set modulefile "$mod22p"

# different behavior than C-version: on Tcl-version loaded PATH is not
# prepended or appended only within the space occupied by the unloaded
# module but through the whole space of the variable. So prepended stuff
# will go at the beginning of the variable and appended stuff will go
# at the end.
lappend ans [list setpath PATH "$path22:$path2222:$pathpre:$pathpost"]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]

#
#  The tests
#

test_cmd_re "ALL" "swap $mod21 $mod22" $ans

#
# Append test
#
set mod21 "append/2.1"
set mod22 "append/2.2"

set mod21p "$modpath/$mod21"
set mod22p "$modpath/$mod22"

set module "$mod21"
set modulefile "$mod21p"

#
# set up the environment
#

setenv_loaded_module $module $modulefile
set env(PATH) "$pathpre:$path21:$path2121:$pathpost"

#
#  For the different shells ...
#

set module "$mod22"
set modulefile "$mod22p"

# different behavior than C-version: same remark than above
set ans [list]
lappend ans [list setpath PATH "$pathpre:$pathpost:$path22:$path2222"]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]

#
#  The tests
#

test_cmd_re "ALL" "swap $mod21 $mod22" $ans

#
# clean up
#

reset_test_env
