ts: format OS name to ease comparisons

This commit is contained in:
Xavier Delaruelle
2025-03-25 08:05:03 +01:00
parent 2c06df5ea1
commit 39e8e941c4
15 changed files with 38 additions and 35 deletions

View File

@@ -53,12 +53,11 @@ if {$sh_kind eq {sh} && ![catch {exec /bin/sh -c {echo $BASH_VERSION}} errMsg] &
}
send_user "\tsh_kind is '$sh_kind'\n"
# extract and format os name
set os_name [string tolower [lindex [split $tcl_platform(os) _] 0]]
# determine if sh-shell is a strict sh implementation
if {$sh_kind eq "dash" || ($tcl_platform(os) ne "Linux"\
&& $tcl_platform(os) ne "Darwin"\
&& ![string match "CYGWIN*" $tcl_platform(os)]\
&& ![string match "MINGW*" $tcl_platform(os)]\
&& ![string match "MSYS_NT*" $tcl_platform(os)])} {
if {$sh_kind eq "dash" || $os_name ni {linux darwin cygwin mingw msys}} {
set sh_strict 1
} else {
set sh_strict 0
@@ -74,7 +73,7 @@ if {$bashbin ne {}} {
}
# check SIP is enabled or not on OS X
if {$tcl_platform(os) eq "Darwin"} {
if {$os_name eq "darwin"} {
catch {
regexp {System Integrity Protection status: enabled.} [exec csrutil status] csrutil_enabled
} errMsg
@@ -131,7 +130,7 @@ foreach shell [list sh bash basheu ksh zsh csh tcsh fish tcl perl python ruby cm
}
pwsh {
# Don't test pwsh in cygwin or msys (pwsh.exe won't work properly)
if {![regexp "(CYGWIN|MINGW|MSYS_NT).*" $tcl_platform(os)]} {
if {$os_name ni {cygwin mingw msys}} {
set shellbin [find_bin pwsh]
} else {
set shellbin ""

View File

@@ -26,7 +26,7 @@ set zsh_nf "command not found: module"
set zsh_nf_ml "command not found: ml"
set tcsh_nf "module: Command not found."
set tcsh_nf_ml "ml: Command not found."
if {$tcl_platform(os) eq "SunOS"} {
if {$os_name eq "sunos"} {
set csh_nf "module: Command not found"
set csh_nf_ml "ml: Command not found"
} else {
@@ -35,10 +35,10 @@ if {$tcl_platform(os) eq "SunOS"} {
}
set fish_nf "fish: Unknown command:? '?module"
set fish_nf_ml "fish: Unknown command:? '?ml"
if {$tcl_platform(os) eq "SunOS"} {
if {$os_name eq "sunos"} {
set sh_nf "module: not found \\\[No such file or directory\\\]"
set sh_nf_ml "ml: not found \\\[No such file or directory\\\]"
} elseif {$tcl_platform(os) eq "FreeBSD"} {
} elseif {$os_name eq "freebsd"} {
set sh_nf "eval: module: not found"
set sh_nf_ml "eval: ml: not found"
} else {

View File

@@ -23,9 +23,9 @@
set bad_cmd "$error_msgs: Invalid command 'foo'"
set bash_nf "(.*: )?module: command not found"
if {$tcl_platform(os) eq "SunOS"} {
if {$os_name eq "sunos"} {
set cmd_nf "module: not found \\\[No such file or directory\\\]"
} elseif {$tcl_platform(os) eq "FreeBSD"} {
} elseif {$os_name eq "freebsd"} {
set cmd_nf "eval: module: not found"
} elseif {$sh_kind eq "dash"} {
set cmd_nf "(.*: )?module: not found"
@@ -36,7 +36,7 @@ if {$tcl_platform(os) eq "SunOS"} {
set ksh_nf "(.*: )?module: (inaccessible or )?not found( \\\[No such file or directory\\\])?"
set zsh_nf "(\\\(eval\\\):1: )?command not found: module"
set tcsh_nf "module: Command not found."
if {$tcl_platform(os) eq "SunOS"} {
if {$os_name eq "sunos"} {
set csh_nf "module: Command not found"
} else {
set csh_nf $tcsh_nf
@@ -75,7 +75,7 @@ foreach subshell $shell_list {
}
ksh {
# sh is a ksh on Solaris
if {$tcl_platform(os) eq "SunOS"} {
if {$os_name eq "sunos"} {
testall_cmd_re "$shell" "module --version" "" "^Modules Release \\S+ (\\S+)" 0
} else {
testall_cmd_re "$shell" "module --version" "" "$cmd_nf" 127
@@ -129,7 +129,7 @@ foreach subshell $shell_list {
}
ksh {
# sh is a ksh on Solaris
if {$tcl_platform(os) eq "SunOS"} {
if {$os_name eq "sunos"} {
testall_cmd_re "$shell" "module --version" "" "^Modules Release \\S+ (\\S+)" 0
} else {
testall_cmd_re "$shell" "module --version" "" "$cmd_nf" 127

View File

@@ -34,7 +34,7 @@ foreach sh $shtomod_supported_shells {
if {$shbin ne {}} {
# mksh flavor of ksh is not supported
# sh from FreeBSD is not supported too
if {($sh ne {ksh} || !$ksh_is_mksh) && ($sh ne {sh} || $tcl_platform(os) ne {FreeBSD})} {
if {($sh ne {ksh} || !$ksh_is_mksh) && ($sh ne {sh} || $os_name ne {freebsd})} {
lappend shtomod_avail_shells $sh
}
if {[lsearch -exact $shtomod_supported_fshells $sh] != -1} {
@@ -86,7 +86,7 @@ foreach sh $shtomod_avail_shells {
# no shell mix for csh, as a function or alias defined for a sh/fish shell will not work on csh
# disable test if wa277 is enabled as in this case csh module alias has no protection against special chars in output
if {($fsh eq {csh} || $fsh eq {tcsh}) && ($sh eq {csh} || $sh eq {tcsh}) && $install_wa277 eq {n}} {
set tserr [expr {$tcl_platform(os) eq {Darwin} || $tcl_platform(os) eq {FreeBSD} ? {} : {tr: warning: an unescaped backslash at end of string is not portable}}]
set tserr [expr {$os_name in {darwin freebsd} ? {} : {tr: warning: an unescaped backslash at end of string is not portable}}]
testall_cmd $fsh "module sh-to-mod $sh $testscriptcsh $testscriptshargs_csh >& shtomod\; module load ./shtomod\; $testshenvcmds_csh" $tsout_csh $tserr 0
}
} elseif {$sh eq {dash} || ($sh eq {sh} && $sh_kind eq {dash})} {

View File

@@ -36,12 +36,15 @@ if {[file type /bin/sh] eq {link}} {
set sh_kind sh
}
# extract and format os name
set os_name [string tolower [lindex [split $tcl_platform(os) _] 0]]
# get current terminal width
proc getTtyCols {} {
set nbcols {}
switch -- $::tcl_platform(os) {
{SunOS} {
switch -- $::os_name {
{sunos} {
catch {regexp {columns = (\d+);} [exec stty] match nbcols} errMsg
}
default {
@@ -85,7 +88,7 @@ proc find_bin {name} {
}
# check SIP is enabled or not on OS X
if {$tcl_platform(os) eq "Darwin"} {
if {$os_name eq "darwin"} {
catch {
regexp {System Integrity Protection status: enabled.} [exec csrutil status] csrutil_enabled
} errMsg
@@ -294,7 +297,8 @@ proc cmpversion {str1 str2} {
# report current system information
send_user "\tMachine hardware name is '$tcl_platform(machine)'\n"
send_user "\tOS name is '$tcl_platform(os)'\n"
send_user "\tOS code name is '$tcl_platform(os)'\n"
send_user "\tOS cleaned name is '$os_name'\n"
send_user "\tOS version is '$tcl_platform(osVersion)'\n"
send_user "\tPlatform name is '$tcl_platform(platform)'\n"

View File

@@ -71,7 +71,7 @@ if {[info exists tclextlib_file]} {
file rename $tclextlib_file $tclextlib_file.orig
file copy lib/envmodules.c $tclextlib_file
set tclextlib_file_abs_re [regsub -all "\(\[.+?\]\)" [file normalize $tclextlib_file] {\\\1}]
if {$tcl_platform(os) eq {Darwin}} {
if {$os_name eq {darwin}} {
set tserr "$error_msgs: dlopen\\\($tclextlib_file_abs_re,.*"
} else {
set tserr "$error_msgs: couldn't load file \"$tclextlib_file_abs_re\":.*"

View File

@@ -29,8 +29,8 @@ skip_if_quick_mode
# - when running on Cygwin/MinGW/MSYS which are unaffected by cwd removal
# - when running on Tcl 8.5 where test outputs are saved in files located in
# current working directory
if {![info exists env(COVERAGE)] && ![regexp {^(CYGWIN|MINGW|MSYS_NT).*}\
$tcl_platform(os)] && [cmpversion $tclsh_version 8.6] > -1} {
if {![info exists env(COVERAGE)] && $os_name ni {cygwin mingw msys}\
&& [cmpversion $tclsh_version 8.6] > -1} {
# change MODULECMD for the test to make it an absolute path name
set MODULECMD $env(TESTSUITEDIR)/../$MODULECMD

View File

@@ -89,7 +89,7 @@ set modavail_8 ""
set modwhatis_8 ""
set modpaths_8 [list]
# a directory can be opened on FreeBSD <= 12.1, so another err message is obtained
if {$tcl_platform(os) eq "FreeBSD" && [cmpversion [lindex [split $tcl_platform(osVersion) -] 0] 12.1] < 1} {
if {$os_name eq "freebsd" && [cmpversion [lindex [split $tcl_platform(osVersion) -] 0] 12.1] < 1} {
set moderr_8 "$err_magic'$modulefile_8'\n$err_contact"
set modunerr_8 [msg_unload $module_8 "$err_magicns'$modulefile_8'\n$err_contactns"]
} else {
@@ -104,7 +104,7 @@ set modulefilere_9 [regsub -all "\(\[.+?\]\)" $modulefile_9 {\\\1}]
set modavail_9 ""
set modwhatis_9 ""
set modpaths_9 [list]
if {$tcl_platform(os) eq "FreeBSD" && [cmpversion [lindex [split $tcl_platform(osVersion) -] 0] 12.1] < 1} {
if {$os_name eq "freebsd" && [cmpversion [lindex [split $tcl_platform(osVersion) -] 0] 12.1] < 1} {
set moderr_9 "$err_magic'$modulefile_9'\n$err_contact"
set modunerr_9 [msg_unload $module_9 "$err_magicns'$modulefile_9'\n$err_contactns"]
} else {

View File

@@ -640,7 +640,7 @@ set mp "$modpath wspac "
set mpre "$modpathre wspac "
# create modulepath finishing by space on the file (it crashes git checkout on Windows if saved in repo)
# MSYS environment does not support anymore such test
if {!$is_symlink_supported || [string match MSYS_NT* $tcl_platform(os)] || [catch {file link -symbolic $mp modulefiles.2}]} {
if {!$is_symlink_supported || $os_name eq {msys} || [catch {file link -symbolic $mp modulefiles.2}]} {
send_user "\tskipping tests over '$mp' modulepath as symbolic links are not supported on filesystem\n"
} else {

View File

@@ -284,7 +284,7 @@ file delete $mp2
# test over a modulepath containing a space character
# skip test on MSYS platform or if symlink creation is not supported
if {$is_symlink_supported && ![regexp {^MSYS_NT.*} $tcl_platform(os)]} {
if {$is_symlink_supported && $os_name ne {msys}} {
set mpws "$env(HOME)/mp ws"
set mpwscache $mpws/.modulecache
file link -symbolic $mpws $mp1

View File

@@ -39,8 +39,8 @@ set modulefile "$modpath/$module"
#
regsub -all \# $u_version {\\\#} u_version
switch -- $tcl_platform(os) {
{Darwin} {
switch -- $os_name {
{darwin} {
regsub -all {;} $u_version {\\\;} u_version
}
}

View File

@@ -1402,7 +1402,7 @@ lappend ans [list chdir $mp]
# following test is expected to fail on CYGWIN due to a packaging issue:
# fish shell initialization script uses pgrep utility which is not available
# see https://cygwin.com/pipermail/cygwin/2024-January/255154.html
testouterr_cmd fish {load source-sh/7.2} $ans {} [expr {[string match "CYGWIN*" $tcl_platform(os)] ? {xfail} : {}}]
testouterr_cmd fish {load source-sh/7.2} $ans {} [expr {$os_name eq {cygwin} ? {xfail} : {}}]
if {[info exists fish_version_ge31] && $fish_version_ge31} {
set tserr_disp72 "-------------------------------------------------------------------

View File

@@ -63,7 +63,7 @@ setenv_path_var FOO bar
set ans [list]
# different result output order is expected on MSYS/CYGWIN platforms
if {[regexp {^(CYGWIN|MSYS_NT).*} $tcl_platform(os)]} {
if {$os_name in {cygwin msys}} {
lappend ans [list unset __MODULES_LMVARIANT]
lappend ans [list unset __MODULES_LMALTNAME]
lappend ans [list unset __MODULES_LMCONFLICT]

View File

@@ -55,7 +55,7 @@ foreach sh $shtomod_supported_shells {
set shbin [lindex [auto_execok $sh] 0]
# mksh flavor of ksh is not supported
# sh from FreeBSD is not supported too
if {$shbin ne {} && ($sh ne {ksh} || !$ksh_is_mksh) && ($sh ne {sh} || $tcl_platform(os) ne {FreeBSD})} {
if {$shbin ne {} && ($sh ne {ksh} || !$ksh_is_mksh) && ($sh ne {sh} || $os_name ne {freebsd})} {
lappend shtomod_avail_shells $sh
set shell_pathname($sh) $shbin
}
@@ -809,7 +809,7 @@ if {$is_modules_defined} {
} else {
set extratserr {}
}
if {$is_modules_defined_fish && ![string match "CYGWIN*" $tcl_platform(os)]} {
if {$is_modules_defined_fish && $os_name ne {cygwin}} {
set extratserr_fish "\nunset-function\tml\nunset-function\tmodule"
if {$is_mogui_defined} {
append extratserr_fish "\nunset-function\tmogui"

View File

@@ -264,7 +264,7 @@ testouterr_cmd sh {avail -t space\ ya} OK "$mp:\n'space ya'/"
set mp "$modpath wspac "
# create modulepath finishing by space on the file (it crashes git checkout on Windows if saved in repo)
# MSYS environment does not support anymore such test
if {!$is_symlink_supported || [string match MSYS_NT* $tcl_platform(os)] || [catch {file link -symbolic $mp modulefiles.2}]} {
if {!$is_symlink_supported || $os_name eq {msys} || [catch {file link -symbolic $mp modulefiles.2}]} {
send_user "\tskipping tests over '$mp' modulepath as symbolic links are not supported on filesystem or cannot be created\n"
} else {