##############################################################################
#   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:		load
#   Modulefiles:	info/isloaded
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the 'is-loaded name' 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 "info/name"
set modulefile "$env(MODULEPATH)/$module"
set modulex "info/isloaded"
set modulefilex "$env(MODULEPATH)/$modulex"
set modules "$module:$modulex"
set modulefiles "$modulefile:$modulefilex"

#
# Test the case when the given module is loaded
#

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

#
#  For the different shells ...
#

set lmf_sh "_LMFILES_=$modulefiles ;export _LMFILES_;"
set lm_sh "LOADEDMODULES=$modules ;export LOADEDMODULES;"
set ts_sh "testsuite=1 ;export testsuite;"

set lmf_csh "setenv _LMFILES_ $modulefiles ;"
set lm_csh "setenv LOADEDMODULES $modules ;"
set ts_csh "setenv testsuite 1 ;"

set lmf_perl "\$ENV{'_LMFILES_'} = '$modulefiles';"
set lm_perl "\$ENV{'LOADEDMODULES'} = '$modules';"
set ts_perl "\$ENV{'testsuite'} = '1';"

set lmf_cmake "set(ENV{_LMFILES_} \"$modulefiles\")"
set lm_cmake "set(ENV{LOADEDMODULES} \"$modules\")"
set ts_cmake "set(ENV{testsuite} \"1\")"

#
#  The tests
#

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

#
# Test the case when the given module is not loaded
#

#
# set up the environment
#
unset env(_LMFILES_)
unset env(LOADEDMODULES)

#
#  For the different shells ...
#

set lmf_sh "_LMFILES_=$modulefilex ;export _LMFILES_;"
set lm_sh "LOADEDMODULES=$modulex ;export LOADEDMODULES;"
set ts_sh "testsuite=0 ;export testsuite;"

set lmf_csh "setenv _LMFILES_ $modulefilex ;"
set lm_csh "setenv LOADEDMODULES $modulex ;"
set ts_csh "setenv testsuite 0 ;"

set lmf_perl "\$ENV{'_LMFILES_'} = '$modulefilex';"
set lm_perl "\$ENV{'LOADEDMODULES'} = '$modulex';"
set ts_perl "\$ENV{'testsuite'} = '0';"

set lmf_cmake "set(ENV{_LMFILES_} \"$modulefilex\")"
set lm_cmake "set(ENV{LOADEDMODULES} \"$modulex\")"
set ts_cmake "set(ENV{testsuite} \"0\")"

#
#  The tests
#

test_cmd "sh" "load $modulex" "$lm_sh$lmf_sh$ts_sh"
test_cmd "ksh" "load $modulex" "$lm_sh$lmf_sh$ts_sh"
test_cmd "zsh" "load $modulex" "$lm_sh$lmf_sh$ts_sh"
test_cmd "csh" "load $modulex" "$lm_csh$lmf_csh$ts_csh"
test_cmd "tcsh" "load $modulex" "$lm_csh$lmf_csh$ts_csh"
test_cmd "perl" "load $modulex" "$lm_perl$lmf_perl$ts_perl"
test_cmd "cmake" "load $modulex" "$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
unset modulefilex
unset modulex
unset modulefiles
unset modules
