##############################################################################
#   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:		load
#   Modulefiles:	system/2.0
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the 'system' module subcommand
#		}C%
#
##############################################################################

# ensure auto symbolic versions are not set for these tests
setenv_var MODULES_ADVANCED_VERSION_SPEC 0

#
#  The tests
#

set module "system/2.0"
set modulefile "$modpath/$module"

lappend ans [list set _LMFILES__modshare "$modulefile:1"]
lappend ans [list set LOADEDMODULES_modshare "$module:1"]
lappend ans [list set testsuite2 109]
lappend ans [list set testsuite3 109]
lappend ans [list set _LMFILES_ $modulefile]
lappend ans [list set LOADEDMODULES $module]
lappend ans [list set testsuite4 0]
lappend ans [list set testsuite 123]
lappend ans [list set testsuite5 0]

testouterr_cmd "csh" "load $module" $ans "str:/path/to/str:dir/file\nstr:/path/to/str:dir/file"

#
# Test a command returning 0 exit code
#

set module "system/1.0"
set modulefile "$modpath/$module"
set modulefilere "$modpathre/$module"

set ans [list]
lappend ans [list set _LMFILES__modshare "$modulefile:1"]
lappend ans [list set LOADEDMODULES_modshare "$module:1"]
lappend ans [list set _LMFILES_ $modulefile]
lappend ans [list set LOADEDMODULES $module]
lappend ans [list set testsuite 0]

test_cmd "csh" "load $module" $ans

#
# Display system command with multiple arguments
#

# system call is resolved and reported standalone to stderr rather
# part of the setenv call
set testsuitedirre [regsub -all "\(\[.+?\]\)" $env(TESTSUITEDIR) {\\\1}]
set disp "$modlin
$modulefilere:

system\t\t$testsuitedirre/systest0 foo bar
setenv\t\ttestsuite {}
$modlin"

testouterr_cmd_re "csh" "display $module" "OK" $disp

#
# Test system command in a simulated Windows OS environment
#

# check excepted siteconfig file is installed
if {[siteconfig_isStderrTty]} {
# fake Windows platform with a cmd.exe tool to execute system commands
setenv_var TESTSUITE_ENABLE_SITECONFIG_WINDOWS_MODE 1
setenv_var TESTSUITE_ENABLE_SITECONFIG_WINDOWS_PLATFORM 1

set ans [list]
lappend ans [list set testsuite 0]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]
testouterr_cmd_re sh "load $module" $ans {}

unsetenv_var TESTSUITE_ENABLE_SITECONFIG_WINDOWS_PLATFORM
unsetenv_var TESTSUITE_ENABLE_SITECONFIG_WINDOWS_MODE
}


#
#  Cleanup
#

reset_test_env
