From 39e8e941c4f8c19f4a181624ec31a294580e588a Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Tue, 25 Mar 2025 08:05:03 +0100 Subject: [PATCH] ts: format OS name to ease comparisons --- testsuite/install.00-init/005-init_ts.exp | 13 ++++++------- testsuite/install.00-init/040-subshell.exp | 6 +++--- testsuite/install.00-init/050-crossshell.exp | 10 +++++----- testsuite/install.00-init/090-sh-to-mod.exp | 4 ++-- testsuite/modules.00-init/005-init_ts.exp | 12 ++++++++---- testsuite/modules.00-init/150-access-init.exp | 2 +- testsuite/modules.00-init/170-cwd.exp | 4 ++-- testsuite/modules.20-locate/043-virtual.exp | 4 ++-- testsuite/modules.20-locate/100-wspace.exp | 2 +- testsuite/modules.30-cache/040-cache-use.exp | 2 +- testsuite/modules.50-cmds/095-uname.exp | 4 ++-- testsuite/modules.50-cmds/400-source-sh.exp | 2 +- testsuite/modules.70-maint/210-clear.exp | 2 +- testsuite/modules.70-maint/310-sh-to-mod.exp | 4 ++-- testsuite/modules.90-avail/080-noindepth.exp | 2 +- 15 files changed, 38 insertions(+), 35 deletions(-) diff --git a/testsuite/install.00-init/005-init_ts.exp b/testsuite/install.00-init/005-init_ts.exp index 97990bf1..4869f2dc 100644 --- a/testsuite/install.00-init/005-init_ts.exp +++ b/testsuite/install.00-init/005-init_ts.exp @@ -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 "" diff --git a/testsuite/install.00-init/040-subshell.exp b/testsuite/install.00-init/040-subshell.exp index dfab2370..c37e2ad8 100644 --- a/testsuite/install.00-init/040-subshell.exp +++ b/testsuite/install.00-init/040-subshell.exp @@ -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 { diff --git a/testsuite/install.00-init/050-crossshell.exp b/testsuite/install.00-init/050-crossshell.exp index b9f2c8c3..6c340eec 100644 --- a/testsuite/install.00-init/050-crossshell.exp +++ b/testsuite/install.00-init/050-crossshell.exp @@ -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 diff --git a/testsuite/install.00-init/090-sh-to-mod.exp b/testsuite/install.00-init/090-sh-to-mod.exp index f2888dbc..726a7a75 100644 --- a/testsuite/install.00-init/090-sh-to-mod.exp +++ b/testsuite/install.00-init/090-sh-to-mod.exp @@ -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})} { diff --git a/testsuite/modules.00-init/005-init_ts.exp b/testsuite/modules.00-init/005-init_ts.exp index a0c315a8..92cbccdf 100644 --- a/testsuite/modules.00-init/005-init_ts.exp +++ b/testsuite/modules.00-init/005-init_ts.exp @@ -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" diff --git a/testsuite/modules.00-init/150-access-init.exp b/testsuite/modules.00-init/150-access-init.exp index aa00b484..5c3ce696 100644 --- a/testsuite/modules.00-init/150-access-init.exp +++ b/testsuite/modules.00-init/150-access-init.exp @@ -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\":.*" diff --git a/testsuite/modules.00-init/170-cwd.exp b/testsuite/modules.00-init/170-cwd.exp index 353e785c..7eebf121 100644 --- a/testsuite/modules.00-init/170-cwd.exp +++ b/testsuite/modules.00-init/170-cwd.exp @@ -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 diff --git a/testsuite/modules.20-locate/043-virtual.exp b/testsuite/modules.20-locate/043-virtual.exp index 4e11f08e..10249444 100644 --- a/testsuite/modules.20-locate/043-virtual.exp +++ b/testsuite/modules.20-locate/043-virtual.exp @@ -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 { diff --git a/testsuite/modules.20-locate/100-wspace.exp b/testsuite/modules.20-locate/100-wspace.exp index 104ff5e5..aa3d093d 100644 --- a/testsuite/modules.20-locate/100-wspace.exp +++ b/testsuite/modules.20-locate/100-wspace.exp @@ -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 { diff --git a/testsuite/modules.30-cache/040-cache-use.exp b/testsuite/modules.30-cache/040-cache-use.exp index f57d6a44..e444491e 100644 --- a/testsuite/modules.30-cache/040-cache-use.exp +++ b/testsuite/modules.30-cache/040-cache-use.exp @@ -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 diff --git a/testsuite/modules.50-cmds/095-uname.exp b/testsuite/modules.50-cmds/095-uname.exp index 8c1f2030..ec467434 100644 --- a/testsuite/modules.50-cmds/095-uname.exp +++ b/testsuite/modules.50-cmds/095-uname.exp @@ -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 } } diff --git a/testsuite/modules.50-cmds/400-source-sh.exp b/testsuite/modules.50-cmds/400-source-sh.exp index 753975c2..6b9feb45 100644 --- a/testsuite/modules.50-cmds/400-source-sh.exp +++ b/testsuite/modules.50-cmds/400-source-sh.exp @@ -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 "------------------------------------------------------------------- diff --git a/testsuite/modules.70-maint/210-clear.exp b/testsuite/modules.70-maint/210-clear.exp index a86a910f..3ee91249 100644 --- a/testsuite/modules.70-maint/210-clear.exp +++ b/testsuite/modules.70-maint/210-clear.exp @@ -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] diff --git a/testsuite/modules.70-maint/310-sh-to-mod.exp b/testsuite/modules.70-maint/310-sh-to-mod.exp index 2a449f43..bf017da1 100644 --- a/testsuite/modules.70-maint/310-sh-to-mod.exp +++ b/testsuite/modules.70-maint/310-sh-to-mod.exp @@ -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" diff --git a/testsuite/modules.90-avail/080-noindepth.exp b/testsuite/modules.90-avail/080-noindepth.exp index 3e1a8af3..92e4426c 100644 --- a/testsuite/modules.90-avail/080-noindepth.exp +++ b/testsuite/modules.90-avail/080-noindepth.exp @@ -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 {