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

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

set path1 "$env(MODULEPATH)"
set path2 "$env(TESTSUITEDIR)/modulefiles.other"
set module1 "use/1.0"
set module2 "use/2.0"
set module3 "use/2.1"
set module4 "use/2.2"
set modulefile1 "$path1/$module1"
set modulefile2 "$path1/$module2"
set modulefile3 "$path1/$module3"
set modulefile4 "$path1/$module4"

#
#  For the different shells ...
#

set lmf_sh "_LMFILES_=$modulefile1 ;export _LMFILES_;"
set lm_sh "LOADEDMODULES=$module1 ;export LOADEDMODULES;"
set mp_sh "MODULEPATH=$path2:$path1 ;export MODULEPATH;"

set lmf_csh "setenv _LMFILES_ $modulefile1 ;"
set lm_csh "setenv LOADEDMODULES $module1 ;"
set mp_csh "setenv MODULEPATH $path2:$path1 ;"

set lmf_perl "\$ENV{'_LMFILES_'} = '$modulefile1';"
set lm_perl "\$ENV{'LOADEDMODULES'} = '$module1';"
set mp_perl "\$ENV{'MODULEPATH'} = '$path2:$path1';"

set lmf_cmake "set(ENV{_LMFILES_} \"$modulefile1\")"
set lm_cmake "set(ENV{LOADEDMODULES} \"$module1\")"
set mp_cmake "set(ENV{MODULEPATH} \"$path2:$path1\")"

#
#  The tests (use)
#

test_cmd "sh" "load $module1" "$lm_sh$mp_sh$lmf_sh"
test_cmd "ksh" "load $module1" "$lm_sh$mp_sh$lmf_sh"
test_cmd "zsh" "load $module1" "$lm_sh$mp_sh$lmf_sh"
test_cmd "csh" "load $module1" "$lm_csh$mp_csh$lmf_csh"
test_cmd "tcsh" "load $module1" "$lm_csh$mp_csh$lmf_csh"
test_cmd "perl" "load $module1" "$lm_perl$mp_perl$lmf_perl"
test_cmd "cmake" "load $module1" "$lm_cmake\n$mp_cmake\n$lmf_cmake"

#
#  For the different shells ...
#

set lmf_sh "_LMFILES_=$modulefile2 ;export _LMFILES_;"
set lm_sh "LOADEDMODULES=$module2 ;export LOADEDMODULES;"
set mp_sh "MODULEPATH=$path1:$path2 ;export MODULEPATH;"

set lmf_csh "setenv _LMFILES_ $modulefile2 ;"
set lm_csh "setenv LOADEDMODULES $module2 ;"
set mp_csh "setenv MODULEPATH $path1:$path2 ;"

set lmf_perl "\$ENV{'_LMFILES_'} = '$modulefile2';"
set lm_perl "\$ENV{'LOADEDMODULES'} = '$module2';"
set mp_perl "\$ENV{'MODULEPATH'} = '$path1:$path2';"

set lmf_cmake "set(ENV{_LMFILES_} \"$modulefile2\")"
set lm_cmake "set(ENV{LOADEDMODULES} \"$module2\")"
set mp_cmake "set(ENV{MODULEPATH} \"$path1:$path2\")"

#
#  The tests (use --append)
#

test_cmd "sh" "load $module2" "$lm_sh$mp_sh$lmf_sh"
test_cmd "ksh" "load $module2" "$lm_sh$mp_sh$lmf_sh"
test_cmd "zsh" "load $module2" "$lm_sh$mp_sh$lmf_sh"
test_cmd "csh" "load $module2" "$lm_csh$mp_csh$lmf_csh"
test_cmd "tcsh" "load $module2" "$lm_csh$mp_csh$lmf_csh"
test_cmd "perl" "load $module2" "$lm_perl$mp_perl$lmf_perl"
test_cmd "cmake" "load $module2" "$lm_cmake\n$mp_cmake\n$lmf_cmake"

#
#  For the different shells ...
#

set lmf_sh "_LMFILES_=$modulefile3 ;export _LMFILES_;"
set lm_sh "LOADEDMODULES=$module3 ;export LOADEDMODULES;"

set lmf_csh "setenv _LMFILES_ $modulefile3 ;"
set lm_csh "setenv LOADEDMODULES $module3 ;"

set lmf_perl "\$ENV{'_LMFILES_'} = '$modulefile3';"
set lm_perl "\$ENV{'LOADEDMODULES'} = '$module3';"

set lmf_cmake "set(ENV{_LMFILES_} \"$modulefile3\")"
set lm_cmake "set(ENV{LOADEDMODULES} \"$module3\")"

#
#  The tests (use -a)
#

test_cmd "sh" "load $module3" "$lm_sh$mp_sh$lmf_sh"
test_cmd "ksh" "load $module3" "$lm_sh$mp_sh$lmf_sh"
test_cmd "zsh" "load $module3" "$lm_sh$mp_sh$lmf_sh"
test_cmd "csh" "load $module3" "$lm_csh$mp_csh$lmf_csh"
test_cmd "tcsh" "load $module3" "$lm_csh$mp_csh$lmf_csh"
test_cmd "perl" "load $module3" "$lm_perl$mp_perl$lmf_perl"
test_cmd "cmake" "load $module3" "$lm_cmake\n$mp_cmake\n$lmf_cmake"

#
#  For the different shells ...
#

set lmf_sh "_LMFILES_=$modulefile4 ;export _LMFILES_;"
set lm_sh "LOADEDMODULES=$module4 ;export LOADEDMODULES;"

set lmf_csh "setenv _LMFILES_ $modulefile4 ;"
set lm_csh "setenv LOADEDMODULES $module4 ;"

set lmf_perl "\$ENV{'_LMFILES_'} = '$modulefile4';"
set lm_perl "\$ENV{'LOADEDMODULES'} = '$module4';"

set lmf_cmake "set(ENV{_LMFILES_} \"$modulefile4\")"
set lm_cmake "set(ENV{LOADEDMODULES} \"$module4\")"

#
#  The tests (use -append)
#	for backward compatibility
#

test_cmd "sh" "load $module4" "$lm_sh$mp_sh$lmf_sh"
test_cmd "ksh" "load $module4" "$lm_sh$mp_sh$lmf_sh"
test_cmd "zsh" "load $module4" "$lm_sh$mp_sh$lmf_sh"
test_cmd "csh" "load $module4" "$lm_csh$mp_csh$lmf_csh"
test_cmd "tcsh" "load $module4" "$lm_csh$mp_csh$lmf_csh"
test_cmd "perl" "load $module4" "$lm_perl$mp_perl$lmf_perl"
test_cmd "cmake" "load $module4" "$lm_cmake\n$mp_cmake\n$lmf_cmake"

#
#  Cleanup
#

unset mp_sh
unset lm_sh
unset lmf_sh

unset mp_csh
unset lm_csh
unset lmf_csh

unset mp_perl
unset lm_perl
unset lmf_perl

unset mp_cmake
unset lm_cmake
unset lmf_cmake

unset modulefile4
unset modulefile3
unset modulefile2
unset modulefile1
unset module4
unset module3
unset module2
unset module1
