##############################################################################
#   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:	uname
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the 'uname' module command
#		}C%
#
##############################################################################

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

#
#  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 "uname"
set modulefile "$modpath/$module"

#
#  The tests
#

regsub -all \# $u_version {\\\#} u_version
switch -- $tcl_platform(os) {
    {Darwin} {
        regsub -all {;} $u_version {\\\;} u_version
    }
}
regsub -all { } $u_version {\\\ } u_version
regsub -all {\(} $u_version {\\\\\(} u_version
regsub -all {\)} $u_version {\\\\\)} u_version
regsub -all {\+} $u_version {\\+} u_version
regsub -all {\(} $u_domain {\\\\\(} u_domain
regsub -all {\)} $u_domain {\\\\\)} u_domain
regsub -all {\(} $u_release {\\\\\(} u_release
regsub -all {\)} $u_release {\\\\\)} u_release
regsub -all {\+} $u_release {\\+} u_release


foreach field [list sysname release machine] {
    set ans [list]
    lappend ans [list set testsuite [set "u_$field"] noescval]
    lappend ans [list setpath LOADEDMODULES "$module/$field"]
    lappend ans [list setpath _LMFILES_ "$modulefile/$field"]
    test_cmd_re "csh" "load $module/$field" $ans
}

foreach field [list nodename version] {
    if {$uname ne ""} {
        set ans [list]
        lappend ans [list set testsuite [set "u_$field"] noescval]
        lappend ans [list setpath LOADEDMODULES "$module/$field"]
        lappend ans [list setpath _LMFILES_ "$modulefile/$field"]
        test_cmd_re "csh" "load $module/$field" $ans
    } else {
        testouterr_cmd "csh" "load $module/$field" "ERR" [msg_load $module/$field $uname_warn]
    }
}

if {$domainname ne ""} {
    set ans [list]
    lappend ans [list set testsuite $u_domain noescval]
    lappend ans [list setpath LOADEDMODULES "$module/domain"]
    lappend ans [list setpath _LMFILES_ "$modulefile/domain"]
	test_cmd_re "csh" "load $module/domain" $ans
} else {
    testouterr_cmd "csh" "load $module/domain" "ERR" [msg_load $module/domain $domainname_warn]
}

# check internal uname value cache mechanism
set ans [list]
lappend ans [list set testsuite1 [set "u_machine"] noescval]
lappend ans [list set testsuite2 [set "u_machine"] noescval]
lappend ans [list setpath LOADEDMODULES "$module/cache"]
lappend ans [list setpath _LMFILES_ "$modulefile/cache"]
test_cmd_re "csh" "load $module/cache" $ans

# bad uname subcommand
set custom {uname unk}
if {[cmpversion $tclsh_version 8.6] == -1} {
append custom {"
    invoked from within
"setenv testsuite "[uname unk]"}
}
if {[cmpversion $tclsh_version 8.5] == -1} {
    set custom [msg_moderr {uname unk not supported} "<EXM>$custom" $modulefile/unk 26]
    testouterr_cmd_re "csh" "load $module/unk" "ERR" [escre [msg_load $module/unk $custom]]
} else {
    testouterr_cmd "csh" "load $module/unk" "ERR" [msg_load $module/unk [msg_moderr {uname unk not supported} $custom $modulefile/unk 26]]
}

# setup an empty path
if { $verbose > 0 } {
    send_user "\tSetup PATH = \n"
}
set env(PATH) ""

# no change for these fields
foreach field [list sysname release machine] {
    set ans [list]
    lappend ans [list set testsuite [set "u_$field"] noescval]
    lappend ans [list setpath LOADEDMODULES "$module/$field"]
    lappend ans [list setpath _LMFILES_ "$modulefile/$field"]
    test_cmd_re "csh" "load $module/$field" $ans
}

# cannot find bin for those fields
foreach field [list nodename version] {
    testouterr_cmd "csh" "load $module/$field" "ERR" [msg_load $module/$field $uname_warn]
}
testouterr_cmd "csh" "load $module/domain" "ERR" [msg_load $module/domain $domainname_warn]


#
#  Cleanup
#

reset_test_env
