##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.70-maint/%M%
#   Revision:		%I%
#   First Edition:	1995/12/06
#   Last Mod.:		%U%, %G%
#
#   Authors:		Jens Hamisch, Jens.Hamisch@Strawberry.COM
#
#   Description:	Testuite testsequence
#   Command:		update
#   Modulefiles:	setenv/1.0
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the module command update
#		}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 "setenv/1.0"
set modulefile "$env(MODULEPATH)/$module"
set err_update "$warn_msgs: Invalid update subcommand - .modulesbeginenv not supported"

# this allows the test to pass, but don't know why update needs to
# set the path again
set setpath "setenv MODULEPATH $env(MODULEPATH)"

#
#  Check this only for /bin/csh
#

set ts_csh "$setpath ;setenv testsuite yes ;"

#
#  Set up the environment pointing to the single module file being loaded
#

set env(_LMFILES_) $modulefile
set env(LOADEDMODULES) $module
if { [ version_test "BEGINENV=1" ] } {
	set save_begenv $env(_MODULESBEGINENV_)
} elseif { [ version_test "BEGINENV=99" ] } {
	set save_begenv $env(_MODULESBEGINENV_)
	set save_begenvx $env(MODULESBEGINENV)
}

#
#  The tests
#

if { [ version_test "BEGINENV=1" ] } {
	set env(_MODULESBEGINENV_) "$env(TESTSUITEDIR)/.modulesbeginenv"
	test_cmd_re "csh" "update" "$ts_csh"
} elseif { [ version_test "BEGINENV=99" ] } {
	set env(_MODULESBEGINENV_) "$env(TESTSUITEDIR)/.modulesbeginenv.yyy"
	testerr_cmd_re "csh" "update" ".*Cannot open file.*"
	set env(MODULESBEGINENV) "$env(TESTSUITEDIR)/.modulesbeginenv.xxx"
	set env(_MODULESBEGINENV_) "$env(TESTSUITEDIR)/.modulesbeginenv.xxx"
	test_cmd_re "csh" "update" "$ts_csh"
} else {
	testerr_cmd_re "csh" "update" "$err_update"
}

#
#  Cleanup
#

unset env(LOADEDMODULES)
unset env(_LMFILES_)
if { [ version_test "BEGINENV=1" ] } {
	set env(_MODULESBEGINENV_) $save_begenv
} elseif { [ version_test "BEGINENV=99" ] } {
	set env(_MODULESBEGINENV_) $save_begenv
	set env(MODULESBEGINENV) $save_begenvx
}

unset ts_csh

unset modulefile
unset module
