##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	1995/12/06
#   Last Mod.:		%U%, %G%
#
#   Authors:		Jens Hamisch, Jens.Hamisch@Strawberry.COM
#
#   Description:	Testuite testsequence
#   Command:		unload
#   Modulefiles:	unsetenv/1.0
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the reverse 'unsetenv' module subcommand for all
#			allowed shell types.
#		}C%
#
#   Trouble:	%T{
#			Removal of a 'unsetenv' command *SHOULD* result in
#			the once removed variable being restored.
#			
#			To be discussed:
#			
#			    - We cannot determine, if the variable really 
#			      *HAS BEEN* removed or if it has never been 
#			      set up before.
#
#			    - We cannot determine, what the former value of 
#			      he varibale was.
#
#			    Should there be a 'default value' in the module
#			    file? This would let us do the following:
#
#				if { [info exists env(tmpvar) ] } {
#				    set saveme $env(tmpvar)
#				} else {
#				    set saveme ""
#				}
#				setenv env(tmpvar) $env(SHELLVARIABLE)
#				unsetenv SHELLVARIABLE $saveme
#		}T%
#
##############################################################################

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

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

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

if { [info exists env(testsuite)] } {
    unset env(testsuite)
}
set env(_LMFILES_) "$modulefile"
set env(LOADEDMODULES) "$module"

#
#  For the different shells ...
#

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

set lmf_csh "unsetenv _LMFILES_;"
set lm_csh "unsetenv LOADEDMODULES;"
# set ts_csh "setenv testsuite yes ;"
set ts_csh "unsetenv testsuite;"

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

set lmf_cmake "unset(ENV{_LMFILES_})"
set lm_cmake "unset(ENV{LOADEDMODULES})"
# set ts_cmake "set(ENV{testsuite} YES)"
set ts_cmake "unset(ENV{testsuite})"

#
#  The tests
#

test_cmd "sh" "unload $module" "$lm_sh$lmf_sh$ts_sh"
test_cmd "ksh" "unload $module" "$lm_sh$lmf_sh$ts_sh"
test_cmd "zsh" "unload $module" "$lm_sh$lmf_sh$ts_sh"
test_cmd "csh" "unload $module" "$lm_csh$lmf_csh$ts_csh"
test_cmd "tcsh" "unload $module" "$lm_csh$lmf_csh$ts_csh"
test_cmd "perl" "unload $module" "$lm_perl$lmf_perl$ts_perl"
test_cmd "cmake" "unload $module" "$lm_cmake\n$lmf_cmake\n$ts_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(_LMFILES_)
unset env(LOADEDMODULES)
