]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests: replace hard-coded `/dev/null` with variable
authorViktor Szakats <commit@vsz.me>
Mon, 30 Sep 2024 22:41:43 +0000 (00:41 +0200)
committerViktor Szakats <commit@vsz.me>
Tue, 1 Oct 2024 10:07:19 +0000 (12:07 +0200)
- 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

tests/FILEFORMAT.md
tests/data/test173
tests/data/test3015
tests/devtest.pl
tests/globalconfig.pm
tests/http2-server.pl
tests/http3-server.pl
tests/pathhelp.pm
tests/runtests.pl
tests/servers.pm
tests/testutil.pm

index 67f36613d952eafa339c4b98a7f78fcb6ec953c8..d3eadede5dd54a31b8884df6dd3194868f4b6887 100644 (file)
@@ -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
index a4bffcd9a8ab20a4d95d0d0f6458caf27a2af96a..5e6f7516976615658dc7799bc81060acdeaa4c21 100644 (file)
@@ -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"
 \r
 contents1\r
 ------------------------------5dbea401cd8c\r
-Content-Disposition: form-data; name="fileupload"; filename="/dev/null"\r
+Content-Disposition: form-data; name="fileupload"; filename="%DEV_NULL"\r
 Content-Type: text/x-null;format=x-curl\r
 \r
 line1
index 5b59bba3205c78afa55f6d2d0cedbb51f76c079f..41e0640bc239fd10f7c7fba53c650b1cfd21fe25 100644 (file)
@@ -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>
 
index 99a25ab66ea0e6703d8900cd812ebcf95187a6c0..4fb0934e98ed80119340f3599a8d441d5d37f2fa 100755 (executable)
@@ -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);
         }
index d9d18e93130f1d9981aec4c8c0f1b081d10f4dad..dec828e01881eefe0dd507949ac7ac15e1eba159 100644 (file)
@@ -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
index 8058641c17c5583ed80d6cd05521a0a532f3150f..fef17680afd632973941e62c94d753144a034ad3 100755 (executable)
@@ -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");
index 6c8baccb9bfef0ce9852c66620eb8d02a5b1d324..489053c1937c45e11f0850dd86b0bb18931785a7 100755 (executable)
@@ -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");
index 34961f2c11248711d8360d4f2db69d623a371620..04076cd8b95015932c3abca5da15bcff37e18b6f 100644 (file)
@@ -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;
index ae53f0e5fae13611f3a3f2de0425b0085b6e6a86..e2b9c0b9d9b2f2e2355620a61bb4317918715184 100755 (executable)
@@ -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="";
         }
index c73a21b093722fd462dd4de8002c0cb97d4f2012..95bed71724e25934213e936ad456ee24855964bc 100644 (file)
@@ -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;
index 4d68c5d2802ecb84d6c3ff8ac7911ae5b95020f7..51b1ba16ec82c1a59d41c33660e09124e8d2d563 100644 (file)
@@ -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\'`;