##############################################################################
#   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"

#
#  Set up the environment for reversal ...
#

set env(_LMFILES_) "$modulefile1"
set env(LOADEDMODULES) "$module1"
set env(MODULEPATH) "$path1:$path2"

if { $verbose > 0 } {
    send_user "Setup MODULEPATH = $env(MODULEPATH)\n"
}

#
#  For the different shells ...
#

set lmf_sh "unset _LMFILES_;"
set lm_sh "unset LOADEDMODULES;"
set mp_sh "MODULEPATH=$path1 ;export MODULEPATH;"

set lmf_csh "unsetenv _LMFILES_;"
set lm_csh "unsetenv LOADEDMODULES;"
set mp_csh "setenv MODULEPATH $path1 ;"

set lmf_perl "delete \$ENV{'_LMFILES_'};"
set lm_perl "delete \$ENV{'LOADEDMODULES'};"
set mp_perl "\$ENV{'MODULEPATH'} = '$path1';"

set lmf_cmake "unset(ENV{_LMFILES_})"
set lm_cmake "unset(ENV{LOADEDMODULES})"
set mp_cmake "set(ENV{MODULEPATH} \"$path1\")"

#
#  The tests (use - unload)
#

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

#
#  Set up the environment for reversal ...
#

set env(_LMFILES_) "$modulefile2"
set env(LOADEDMODULES) "$module2"

#
#  The tests (use --append)
#

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

#
#  Set up the environment for reversal ...
#

set env(_LMFILES_) "$modulefile3"
set env(LOADEDMODULES) "$module3"

#
#  The tests (use -a)
#

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

#
#  Set up the environment for reversal ...
#

set env(_LMFILES_) "$modulefile4"
set env(LOADEDMODULES) "$module4"

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

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

#
#  Cleanup
#

set env(MODULEPATH) "$path1"
unset env(_LMFILES_)
unset env(LOADEDMODULES)

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
