##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2001/07/25
#   Last Mod.:		%U%, %G%
#
#   Authors:		R.K. Owen, <rk@owen.sj.ca.us>
#
#   Description:	Testuite testsequence
#   Command:		swap
#   Modulefiles:	loc_dv1/1.0, loc_dv1/2.0, 
#   			loc_dv2/1.0, loc_dv2/2.0, 
#   			loc_dv3/1.0, loc_dv3/2.0, 
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the 'swap' module subcommand for all allowed
#			shell types.
#		}C%
#
##############################################################################

set mod11 "loc_dv1/1.0"
set mod12 "loc_dv1/2.0"
set mod21 "loc_dv2/1.0"
set mod22 "loc_dv2/2.0"
set mod31 "loc_dv3/1.0"
set mod32 "loc_dv3/2.0"

set mod11p "$env(MODULEPATH)/$mod11"
set mod12p "$env(MODULEPATH)/$mod12"
set mod21p "$env(MODULEPATH)/$mod21"
set mod22p "$env(MODULEPATH)/$mod22"
set mod31p "$env(MODULEPATH)/$mod31"
set mod32p "$env(MODULEPATH)/$mod32"

set module "$mod11:$mod21:$mod31"
set modulefile "$mod11p:$mod21p:$mod31p"

#
# set up the environment
#
set env(_LMFILES_) "$modulefile"
set env(LOADEDMODULES) "$module"

#
#  Swap the 1st in list
#  For the different shells ...
#

set module "$mod12:$mod21:$mod31"
set modulefile "$mod12p:$mod21p:$mod31p"

set lmf_sh "_LMFILES_=$modulefile ;export _LMFILES_;"
set lm_sh "LOADEDMODULES=$module ;export LOADEDMODULES;"

set lmf_csh "setenv _LMFILES_ $modulefile ;"
set lm_csh "setenv LOADEDMODULES $module ;"

set lmf_perl "\$ENV{'_LMFILES_'} = '$modulefile';"
set lm_perl "\$ENV{'LOADEDMODULES'} = '$module';"

set lmf_cmake "set(ENV{_LMFILES_} \"$modulefile\")"
set lm_cmake "set(ENV{LOADEDMODULES} \"$module\")"

#
#  The tests
#

test_cmd "sh" "swap $mod11 $mod12" "$lm_sh$lmf_sh"
test_cmd "ksh" "swap $mod11 $mod12" "$lm_sh$lmf_sh"
test_cmd "zsh" "swap $mod11 $mod12" "$lm_sh$lmf_sh"
test_cmd "csh" "swap $mod11 $mod12" "$lm_csh$lmf_csh"
test_cmd "tcsh" "swap $mod11 $mod12" "$lm_csh$lmf_csh"
test_cmd "perl" "swap $mod11 $mod12" "$lm_perl$lmf_perl"
test_cmd "cmake" "swap $mod11 $mod12" "$lm_cmake\n$lmf_cmake"

#
#  Test the one argument form.
#

test_cmd "sh" "swap $mod12" "$lm_sh$lmf_sh"
test_cmd "ksh" "swap $mod12" "$lm_sh$lmf_sh"
test_cmd "zsh" "swap $mod12" "$lm_sh$lmf_sh"
test_cmd "csh" "swap $mod12" "$lm_csh$lmf_csh"
test_cmd "tcsh" "swap $mod12" "$lm_csh$lmf_csh"
test_cmd "perl" "swap $mod12" "$lm_perl$lmf_perl"
test_cmd "cmake" "swap $mod12" "$lm_cmake\n$lmf_cmake"

#
#  Swap the 2nd in list
#  For the different shells ...
#

set module "$mod11:$mod22:$mod31"
set modulefile "$mod11p:$mod22p:$mod31p"

set lmf_sh "_LMFILES_=$modulefile ;export _LMFILES_;"
set lm_sh "LOADEDMODULES=$module ;export LOADEDMODULES;"

set lmf_csh "setenv _LMFILES_ $modulefile ;"
set lm_csh "setenv LOADEDMODULES $module ;"

set lmf_perl "\$ENV{'_LMFILES_'} = '$modulefile';"
set lm_perl "\$ENV{'LOADEDMODULES'} = '$module';"

set lmf_cmake "set(ENV{_LMFILES_} \"$modulefile\")"
set lm_cmake "set(ENV{LOADEDMODULES} \"$module\")"

#
#  The tests
#

test_cmd "sh" "swap $mod21 $mod22" "$lm_sh$lmf_sh"
test_cmd "ksh" "swap $mod21 $mod22" "$lm_sh$lmf_sh"
test_cmd "zsh" "swap $mod21 $mod22" "$lm_sh$lmf_sh"
test_cmd "csh" "swap $mod21 $mod22" "$lm_csh$lmf_csh"
test_cmd "tcsh" "swap $mod21 $mod22" "$lm_csh$lmf_csh"
test_cmd "perl" "swap $mod21 $mod22" "$lm_perl$lmf_perl"
test_cmd "cmake" "swap $mod21 $mod22" "$lm_cmake\n$lmf_cmake"

#
#  Test the one argument form.
#

test_cmd "sh" "swap $mod22" "$lm_sh$lmf_sh"
test_cmd "ksh" "swap $mod22" "$lm_sh$lmf_sh"
test_cmd "zsh" "swap $mod22" "$lm_sh$lmf_sh"
test_cmd "csh" "swap $mod22" "$lm_csh$lmf_csh"
test_cmd "tcsh" "swap $mod22" "$lm_csh$lmf_csh"
test_cmd "perl" "swap $mod22" "$lm_perl$lmf_perl"
test_cmd "cmake" "swap $mod22" "$lm_cmake\n$lmf_cmake"

#
#  Swap the last in list
#  For the different shells ...
#

set module "$mod11:$mod21:$mod32"
set modulefile "$mod11p:$mod21p:$mod32p"

set lmf_sh "_LMFILES_=$modulefile ;export _LMFILES_;"
set lm_sh "LOADEDMODULES=$module ;export LOADEDMODULES;"

set lmf_csh "setenv _LMFILES_ $modulefile ;"
set lm_csh "setenv LOADEDMODULES $module ;"

set lmf_perl "\$ENV{'_LMFILES_'} = '$modulefile';"
set lm_perl "\$ENV{'LOADEDMODULES'} = '$module';"

set lmf_cmake "set(ENV{_LMFILES_} \"$modulefile\")"
set lm_cmake "set(ENV{LOADEDMODULES} \"$module\")"

#
#  The tests
#

test_cmd "sh" "swap $mod31 $mod32" "$lm_sh$lmf_sh"
test_cmd "ksh" "swap $mod31 $mod32" "$lm_sh$lmf_sh"
test_cmd "zsh" "swap $mod31 $mod32" "$lm_sh$lmf_sh"
test_cmd "csh" "swap $mod31 $mod32" "$lm_csh$lmf_csh"
test_cmd "tcsh" "swap $mod31 $mod32" "$lm_csh$lmf_csh"
test_cmd "perl" "swap $mod31 $mod32" "$lm_perl$lmf_perl"
test_cmd "cmake" "swap $mod31 $mod32" "$lm_cmake\n$lmf_cmake"

#
#  Test the one argument form.
#

test_cmd "sh" "swap $mod32" "$lm_sh$lmf_sh"
test_cmd "ksh" "swap $mod32" "$lm_sh$lmf_sh"
test_cmd "zsh" "swap $mod32" "$lm_sh$lmf_sh"
test_cmd "csh" "swap $mod32" "$lm_csh$lmf_csh"
test_cmd "tcsh" "swap $mod32" "$lm_csh$lmf_csh"
test_cmd "perl" "swap $mod32" "$lm_perl$lmf_perl"
test_cmd "cmake" "swap $mod32" "$lm_cmake\n$lmf_cmake"

#
#  Cleanup
#

unset env(_LMFILES_)
unset env(LOADEDMODULES)

unset lm_sh
unset lmf_sh

unset lm_csh
unset lmf_csh

unset lm_perl
unset lmf_perl

unset lm_cmake
unset lmf_cmake

unset modulefile
unset module

unset mod11
unset mod12
unset mod21
unset mod22
unset mod31
unset mod32
unset mod11p
unset mod12p
unset mod21p
unset mod22p
unset mod31p
unset mod32p
