2
0
mirror of https://github.com/curl/curl.git synced 2025-04-24 16:40:32 +08:00

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 
Closes 
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

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

@ -31,7 +31,7 @@ http
HTTP RFC1867-formpost a file from stdin with "faked" filename
</name>
<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>
<stdin>
@ -64,7 +64,7 @@ Content-Disposition: form-data; name="field1"
contents1
------------------------------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
line1

@ -50,7 +50,7 @@ http
HTTP GET -w num_headers with redirected fetch (2 connects)
</name>
<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>
</client>

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

@ -67,6 +67,7 @@ BEGIN {
%keywords
@protocols
$bundle
$dev_null
);
}
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 $valgrind; # path to valgrind, or empty if disabled
our $bundle = 0; # use bundled server, libtest, unit binaries
our $dev_null = ($^O eq 'MSWin32' ? 'NUL' : '/dev/null');
# paths in $LOGDIR
our $LOCKDIR = "lock"; # root of the server directory with lock files

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

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

@ -97,6 +97,8 @@ BEGIN {
}
}
my $dev_null = ($^O eq 'MSWin32' ? 'NUL' : '/dev/null');
my $use_cygpath; # Only for Windows:
# undef - autodetect
# 0 - do not use cygpath
@ -106,7 +108,7 @@ my $use_cygpath; # Only for Windows:
sub should_use_cygpath {
return $use_cygpath if defined $use_cygpath;
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 {
$use_cygpath = 0;
}
@ -714,7 +716,7 @@ sub do_dumb_guessed_transform {
while(1) {
if(-d $check_path) {
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 '%') {
# Remove both '\r' and '\n'.
$res =~ s{\n|\r}{}g;

@ -318,7 +318,8 @@ if (!$ENV{"NGHTTPX"}) {
$ENV{"NGHTTPX"} = checktestcmd("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\//;
chomp $nghttpx_h3;
}
@ -410,10 +411,10 @@ sub showdiff {
print $temp "\n";
}
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]) {
@out = `diff -c $file2 $file1 2>/dev/null`;
@out = `diff -c $file2 $file1 2>$dev_null`;
}
return @out;
@ -2529,7 +2530,7 @@ if(!$randseed) {
# seed of the month. December 2019 becomes 201912
$randseed = ($year+1900)*100 + $mon+1;
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!";
my @c = <$curlvh>;
close($curlvh) || die "could not get curl version!";
@ -2547,7 +2548,7 @@ if($valgrind) {
# we have found valgrind on the host, use it
# 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) {
#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
# (this happened in 2003, so we could probably don't need to care about
# 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)) {
$valgrind_tool="";
}

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

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