tests: replace hard-coded /dev/null with variable

- add variable for the null device filename and use that in Perl code.
- initialize this variable with `NUL` on native Windows.
- add `%DEV_NULL` variable and use it in tests.

Fixes `The system cannot find the path specified.` messages seen when
running `runtests.pl` with native Windows Perl.

Also adjust code to not break mcedit syntax highlighting.

Cherry-picked from #14949
Closes #15098
This commit is contained in:
Viktor Szakats 2024-10-01 00:41:43 +02:00
parent 31a29fc6bd
commit 68c358619f
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
11 changed files with 25 additions and 15 deletions

View File

@ -126,6 +126,7 @@ Available substitute variables include:
- `%CLIENTIP` - IPv4 address of the client running curl - `%CLIENTIP` - IPv4 address of the client running curl
- `%CURL` - Path to the curl executable - `%CURL` - Path to the curl executable
- `%DATE` - current YYYY-MM-DD date - `%DATE` - current YYYY-MM-DD date
- `%DEV_NULL` - Null device (e.g. /dev/null)
- `%FILE_PWD` - Current directory, on Windows prefixed with a slash - `%FILE_PWD` - Current directory, on Windows prefixed with a slash
- `%FTP6PORT` - IPv6 port number of the FTP server - `%FTP6PORT` - IPv6 port number of the FTP server
- `%FTPPORT` - Port number of the FTP server - `%FTPPORT` - Port number of the FTP server

View File

@ -31,7 +31,7 @@ http
HTTP RFC1867-formpost a file from stdin with "faked" filename HTTP RFC1867-formpost a file from stdin with "faked" filename
</name> </name>
<command> <command>
http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER -F field1=contents1 -F "fileupload=@-;filename=/dev/null;type=text/x-null;format=x-curl" http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER -F field1=contents1 -F "fileupload=@-;filename=%DEV_NULL;type=text/x-null;format=x-curl"
</command> </command>
<stdin> <stdin>
@ -64,7 +64,7 @@ Content-Disposition: form-data; name="field1"
contents1 contents1
------------------------------5dbea401cd8c ------------------------------5dbea401cd8c
Content-Disposition: form-data; name="fileupload"; filename="/dev/null" Content-Disposition: form-data; name="fileupload"; filename="%DEV_NULL"
Content-Type: text/x-null;format=x-curl Content-Type: text/x-null;format=x-curl
line1 line1

View File

@ -50,7 +50,7 @@ http
HTTP GET -w num_headers with redirected fetch (2 connects) HTTP GET -w num_headers with redirected fetch (2 connects)
</name> </name>
<command> <command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER -w "%{num_headers}\n" -L -o/dev/null http://%HOSTIP:%HTTPPORT/%TESTNUMBER -w "%{num_headers}\n" -L -o%DEV_NULL
</command> </command>
</client> </client>

View File

@ -110,7 +110,7 @@ sub parseprotocols {
# Initialize @protocols from the curl binary under test # Initialize @protocols from the curl binary under test
# #
sub init_protocols { sub init_protocols {
for (`$CURL -V 2>/dev/null`) { for (`$CURL -V 2>$dev_null`) {
if(m/^Protocols: (.*)$/) { if(m/^Protocols: (.*)$/) {
parseprotocols($1); parseprotocols($1);
} }

View File

@ -67,6 +67,7 @@ BEGIN {
%keywords %keywords
@protocols @protocols
$bundle $bundle
$dev_null
); );
} }
use pathhelp qw(exe_ext); use pathhelp qw(exe_ext);
@ -106,6 +107,7 @@ our $VCURL=$CURL; # what curl binary to use to verify the servers with
our $memanalyze="$perl $srcdir/memanalyze.pl"; our $memanalyze="$perl $srcdir/memanalyze.pl";
our $valgrind; # path to valgrind, or empty if disabled our $valgrind; # path to valgrind, or empty if disabled
our $bundle = 0; # use bundled server, libtest, unit binaries our $bundle = 0; # use bundled server, libtest, unit binaries
our $dev_null = ($^O eq 'MSWin32' ? 'NUL' : '/dev/null');
# paths in $LOGDIR # paths in $LOGDIR
our $LOCKDIR = "lock"; # root of the server directory with lock files our $LOCKDIR = "lock"; # root of the server directory with lock files

View File

@ -38,6 +38,7 @@ my $listenport2 = 9016;
my $connect = "127.0.0.1,8990"; my $connect = "127.0.0.1,8990";
my $conf = "nghttpx.conf"; my $conf = "nghttpx.conf";
my $cert = "Server-localhost-sv"; my $cert = "Server-localhost-sv";
my $dev_null = ($^O eq 'MSWin32' ? 'NUL' : '/dev/null');
#*************************************************************************** #***************************************************************************
# Process command line options # Process command line options
@ -117,4 +118,4 @@ my $cmdline="$nghttpx --backend=$connect ".
"--errorlog-file=$logfile ". "--errorlog-file=$logfile ".
"$keyfile $certfile"; "$keyfile $certfile";
print "RUN: $cmdline\n" if($verbose); print "RUN: $cmdline\n" if($verbose);
exec("exec $cmdline 2>/dev/null"); exec("exec $cmdline 2>$dev_null");

View File

@ -38,6 +38,7 @@ my $listenport = 9017;
my $connect = "127.0.0.1,8990"; my $connect = "127.0.0.1,8990";
my $cert = "Server-localhost-sv"; my $cert = "Server-localhost-sv";
my $conf = "nghttpx.conf"; my $conf = "nghttpx.conf";
my $dev_null = ($^O eq 'MSWin32' ? 'NUL' : '/dev/null');
#*************************************************************************** #***************************************************************************
# Process command line options # Process command line options
@ -117,4 +118,4 @@ my $cmdline="$nghttpx --http2-proxy --backend=$connect ".
"--conf=$conf ". "--conf=$conf ".
"$keyfile $certfile"; "$keyfile $certfile";
print "RUN: $cmdline\n" if($verbose); print "RUN: $cmdline\n" if($verbose);
exec("exec $cmdline 2>/dev/null"); exec("exec $cmdline 2>$dev_null");

View File

@ -97,6 +97,8 @@ BEGIN {
} }
} }
my $dev_null = ($^O eq 'MSWin32' ? 'NUL' : '/dev/null');
my $use_cygpath; # Only for Windows: my $use_cygpath; # Only for Windows:
# undef - autodetect # undef - autodetect
# 0 - do not use cygpath # 0 - do not use cygpath
@ -106,7 +108,7 @@ my $use_cygpath; # Only for Windows:
sub should_use_cygpath { sub should_use_cygpath {
return $use_cygpath if defined $use_cygpath; return $use_cygpath if defined $use_cygpath;
if(os_is_win()) { if(os_is_win()) {
$use_cygpath = (qx{cygpath -u '.\\' 2>/dev/null} eq "./\n" && $? == 0); $use_cygpath = (qx{cygpath -u '.\\' 2>$dev_null} eq "./\n" && $? == 0);
} else { } else {
$use_cygpath = 0; $use_cygpath = 0;
} }
@ -714,7 +716,7 @@ sub do_dumb_guessed_transform {
while(1) { while(1) {
if(-d $check_path) { if(-d $check_path) {
my $res = my $res =
`(cd "$check_path" && cmd /c "echo %__CD__%") 2>/dev/null`; `(cd "$check_path" && cmd /c "echo %__CD__%") 2>$dev_null`;
if($? == 0 && substr($path, 0, 1) ne '%') { if($? == 0 && substr($path, 0, 1) ne '%') {
# Remove both '\r' and '\n'. # Remove both '\r' and '\n'.
$res =~ s{\n|\r}{}g; $res =~ s{\n|\r}{}g;

View File

@ -318,7 +318,8 @@ if (!$ENV{"NGHTTPX"}) {
$ENV{"NGHTTPX"} = checktestcmd("nghttpx"); $ENV{"NGHTTPX"} = checktestcmd("nghttpx");
} }
if ($ENV{"NGHTTPX"}) { if ($ENV{"NGHTTPX"}) {
my $nghttpx_version=join(' ', `"$ENV{'NGHTTPX'}" -v 2>/dev/null`); my $cmd = "\"$ENV{'NGHTTPX'}\" -v 2>$dev_null";
my $nghttpx_version=join(' ', `$cmd`);
$nghttpx_h3 = $nghttpx_version =~ /nghttp3\//; $nghttpx_h3 = $nghttpx_version =~ /nghttp3\//;
chomp $nghttpx_h3; chomp $nghttpx_h3;
} }
@ -410,10 +411,10 @@ sub showdiff {
print $temp "\n"; print $temp "\n";
} }
close($temp) || die "Failure writing diff file"; close($temp) || die "Failure writing diff file";
my @out = `diff -u $file2 $file1 2>/dev/null`; my @out = `diff -u $file2 $file1 2>$dev_null`;
if(!$out[0]) { if(!$out[0]) {
@out = `diff -c $file2 $file1 2>/dev/null`; @out = `diff -c $file2 $file1 2>$dev_null`;
} }
return @out; return @out;
@ -2529,7 +2530,7 @@ if(!$randseed) {
# seed of the month. December 2019 becomes 201912 # seed of the month. December 2019 becomes 201912
$randseed = ($year+1900)*100 + $mon+1; $randseed = ($year+1900)*100 + $mon+1;
print "Using curl: $CURL\n"; print "Using curl: $CURL\n";
open(my $curlvh, "-|", shell_quote($CURL) . " --version 2>/dev/null") || open(my $curlvh, "-|", shell_quote($CURL) . " --version 2>$dev_null") ||
die "could not get curl version!"; die "could not get curl version!";
my @c = <$curlvh>; my @c = <$curlvh>;
close($curlvh) || die "could not get curl version!"; close($curlvh) || die "could not get curl version!";
@ -2547,7 +2548,7 @@ if($valgrind) {
# we have found valgrind on the host, use it # we have found valgrind on the host, use it
# verify that we can invoke it fine # verify that we can invoke it fine
my $code = runclient("valgrind >/dev/null 2>&1"); my $code = runclient("valgrind >$dev_null 2>&1");
if(($code>>8) != 1) { if(($code>>8) != 1) {
#logmsg "Valgrind failure, disable it\n"; #logmsg "Valgrind failure, disable it\n";
@ -2558,7 +2559,7 @@ if($valgrind) {
# use it, if it is supported by the version installed on the system # use it, if it is supported by the version installed on the system
# (this happened in 2003, so we could probably don't need to care about # (this happened in 2003, so we could probably don't need to care about
# that old version any longer and just delete this check) # that old version any longer and just delete this check)
runclient("valgrind --help 2>&1 | grep -- --tool > /dev/null 2>&1"); runclient("valgrind --help 2>&1 | grep -- --tool >$dev_null 2>&1");
if (($? >> 8)) { if (($? >> 8)) {
$valgrind_tool=""; $valgrind_tool="";
} }

View File

@ -3123,6 +3123,7 @@ sub subvariables {
$$thing =~ s/${prefix}SSH_PWD/$ssh_pwd/g; $$thing =~ s/${prefix}SSH_PWD/$ssh_pwd/g;
$$thing =~ s/${prefix}SRCDIR/$srcdir/g; $$thing =~ s/${prefix}SRCDIR/$srcdir/g;
$$thing =~ s/${prefix}USER/$USER/g; $$thing =~ s/${prefix}USER/$USER/g;
$$thing =~ s/${prefix}DEV_NULL/$dev_null/g;
$$thing =~ s/${prefix}SSHSRVMD5/$SSHSRVMD5/g; $$thing =~ s/${prefix}SSHSRVMD5/$SSHSRVMD5/g;
$$thing =~ s/${prefix}SSHSRVSHA256/$SSHSRVSHA256/g; $$thing =~ s/${prefix}SSHSRVSHA256/$SSHSRVSHA256/g;

View File

@ -56,6 +56,7 @@ use MIME::Base64;
use globalconfig qw( use globalconfig qw(
$torture $torture
$verbose $verbose
$dev_null
); );
my $logfunc; # optional reference to function for logging my $logfunc; # optional reference to function for logging
@ -195,7 +196,7 @@ sub runclient {
# #
sub runclientoutput { sub runclientoutput {
my ($cmd)=@_; my ($cmd)=@_;
return `$cmd 2>/dev/null`; return `$cmd 2>$dev_null`;
# This is one way to test curl on a remote machine # This is one way to test curl on a remote machine
# my @out = `ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'`; # my @out = `ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'`;