##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2001/06/20
#   Last Mod.:		%U%, %G%
#
#   Authors:		R.K. Owen,  rk@owen.sj.ca.us
#
#   Description:	Testuite testsequence
#   Command:		load & unload
#   Modulefiles:	unsetenv/0.9
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the newer features of the 'unsetenv' module
#			subcommand for all allowed shell types.
#		}C%
#
##############################################################################

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

set module "unsetenv/0.9"
set modulefile "$env(MODULEPATH)/$module"

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

set env(testsuite) "'yes'"

#
#  For the different shells ...
#

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

set lmf_csh "setenv _LMFILES_ $modulefile ;"
set lm_csh "setenv LOADEDMODULES $module ;"
set ts_csh "unsetenv testsuite;"

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

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

#
#  The tests
#
# load

test_cmd "sh" "load $module" "$lm_sh$lmf_sh$ts_sh"
test_cmd "ksh" "load $module" "$lm_sh$lmf_sh$ts_sh"
test_cmd "zsh" "load $module" "$lm_sh$lmf_sh$ts_sh"
test_cmd "csh" "load $module" "$lm_csh$lmf_csh$ts_csh"
test_cmd "tcsh" "load $module" "$lm_csh$lmf_csh$ts_csh"
test_cmd "perl" "load $module" "$lm_perl$lmf_perl$ts_perl"
test_cmd "cmake" "load $module" "$lm_cmake\n$lmf_cmake\n$ts_cmake"

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

set lmf_sh "unset _LMFILES_;"
set lm_sh "unset LOADEDMODULES;"
set ts_sh "testsuite=UNSET ;export testsuite;"

set lmf_csh "unsetenv _LMFILES_;"
set lm_csh "unsetenv LOADEDMODULES;"
set ts_csh "setenv testsuite UNSET ;"

set lmf_perl "delete \$ENV{'_LMFILES_'};"
set lm_perl "delete \$ENV{'LOADEDMODULES'};"
set ts_perl "\$ENV{'testsuite'} = 'UNSET';"

set lmf_cmake "unset(ENV{_LMFILES_})"
set lm_cmake "unset(ENV{LOADEDMODULES})"
set ts_cmake "set(ENV{testsuite} \"UNSET\")"

test_cmd "sh" "unload $module" "$ts_sh$lm_sh$lmf_sh"
test_cmd "ksh" "unload $module" "$ts_sh$lm_sh$lmf_sh"
test_cmd "zsh" "unload $module" "$ts_sh$lm_sh$lmf_sh"
test_cmd "csh" "unload $module" "$ts_csh$lm_csh$lmf_csh"
test_cmd "tcsh" "unload $module" "$ts_csh$lm_csh$lmf_csh"
test_cmd "perl" "unload $module" "$ts_perl$lm_perl$lmf_perl"
test_cmd "cmake" "unload $module" "$ts_cmake\n$lm_cmake\n$lmf_cmake"

#
#  Cleanup
#

unset ts_sh
unset lm_sh
unset lmf_sh

unset ts_csh
unset lm_csh
unset lmf_csh

unset ts_perl
unset lm_perl
unset lmf_perl

unset ts_cmake
unset lm_cmake
unset lmf_cmake

unset modulefile
unset module

#
#  Clean up the environment, too
#

unset env(testsuite)
unset env(_LMFILES_)
unset env(LOADEDMODULES)
