##############################################################################
#   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 "$modpath/$module"
set err_update "$error_msgs: Invalid command 'update'\n$err_typehelp"

#
#  Check this only for /bin/csh
#

lappend ans [list set testsuite yes]
# this allows the test to pass, but don't know why update needs to
# set the path again
lappend ans [list setpath MODULEPATH $modpath]
lappend ans [list setpath LOADEDMODULES "$module:"]
lappend ans [list setpath _LMFILES_ "$env(TESTSUITEDIR)/modulefiles/$module:"]

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

setenv_loaded_module $module $modulefile
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" $ans
} elseif { [ version_test "BEGINENV=99" ] } {
	set env(_MODULESBEGINENV_) "$env(TESTSUITEDIR)/.modulesbeginenv.yyy"
	testouterr_cmd_re "csh" "update" "ERR" ".*Cannot open file.*"
	set env(MODULESBEGINENV) "$env(TESTSUITEDIR)/.modulesbeginenv.xxx"
	set env(_MODULESBEGINENV_) "$env(TESTSUITEDIR)/.modulesbeginenv.xxx"
	test_cmd_re "csh" "update" $ans
} else {
    # different behavior than C-version: on Tcl-version 'update'
    # sub-command is not known
	testouterr_cmd_re "csh" "update" "ERR" "$err_update"
}

#
#  Cleanup
#

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
}

reset_test_env
