]> The Tcpdump Group git mirrors - tcpdump/commitdiff
TESTrun: clean up printing of files.
authorGuy Harris <[email protected]>
Sat, 13 Jun 2020 07:08:49 +0000 (00:08 -0700)
committerGuy Harris <[email protected]>
Sat, 13 Jun 2020 07:08:49 +0000 (00:08 -0700)
Many Windows commands only accept paths using backslashes, because
slashes are option separators.

Add a showfile() function that takes a pathname as an argument and:

on Windows, converts the pathname to canonical form - which
means any slashes will be converted to backslashes - and run
"type" on it;

on UN*X, run "cat" on it.

Convert

cat foo | diff bar -

to

diff bar foo

to avoid using cat at all.  (Note also that the closest built-in Windows
equivalent of diff, fc, does *not* support reading the standard input as
one of the files to compare, so it also will avoid that when we change
those to use fc on Windows.)

The one remaining use of cat is in a command with pathnames, so use a
type command, with backslash-separated paths, on Windows, and cat, with
slash-separated paths, on UN*X.

We might just want to do that directly in Perl; add a comment about
that.

tests/TESTrun

index c0020e0250300464170a3c0631d0de15ca6b4954..b5d2aa84424d1e91d4acd782f8397ac0686d283b 100755 (executable)
@@ -22,6 +22,7 @@ use File::Basename;
 use POSIX qw( WEXITSTATUS WIFEXITED);
 use Cwd qw(abs_path getcwd);
 use File::Path qw(mkpath);   # mkpath works with ancient perl, as well as newer perl
+use File::Spec;
 use Data::Dumper;            # for debugging.
 
 # these are created in the directory where we are run, which might be
@@ -32,11 +33,6 @@ mkpath($newdir);
 mkpath($diffdir);
 my $origdir = getcwd();
 my $srcdir  = $ENV{'srcdir'} || ".";
-if ($^O eq 'MSWin32') {
-    $printcmd = "type";
-} else {
-    $printcmd = "cat";
-}
 
 #
 # Force UTC, so time stamps are printed in a standard time zone, and
@@ -69,6 +65,20 @@ close(FAILUREOUTPUT);
 
 $confighhash = undef;
 
+sub showfile {
+    local($path) = @_;
+
+    #
+    # XXX - just do this directly in Perl?
+    #
+    if ($^O eq 'MSWin32') {
+        my $winpath = File::Spec->canonpath($path);
+        system "type $winpath";
+    } else {
+        system "cat $path";
+    }
+}
+
 sub runtest {
     local($name, $input, $output, $options) = @_;
     my $r;
@@ -115,7 +125,7 @@ sub runtest {
             $r = 0;
         }
         if($r == 0) {
-            $r = system "${printcmd} tests/NEW/$outputbase | diff $output - >tests/DIFF/$outputbase.diff";
+            $r = system "diff $output tests/NEW/$outputbase >tests/DIFF/$outputbase.diff";
             $diffstat = WEXITSTATUS($r);
         }
 
@@ -137,7 +147,7 @@ sub runtest {
         close(ERRORRAW);
 
         if ( -f "$output.stderr" ) {
-            $nr = system "${printcmd} $stderrlog | diff $output.stderr - >tests/DIFF/$outputbase.stderr.diff";
+            $nr = system "diff $output.stderr $stderrlog >tests/DIFF/$outputbase.stderr.diff";
             if($r == 0) {
                 $r = $nr;
             }
@@ -160,7 +170,7 @@ sub runtest {
             printf "    %-40s: passed\n", $name;
         } else {
             printf "    %-40s: passed with error messages:\n", $name;
-            system "${printcmd} $stderrlog";
+            showfile($stderrlog);
         }
         unlink "tests/DIFF/$outputbase.diff";
         return 0;
@@ -171,7 +181,14 @@ sub runtest {
     printf FOUT "\nFailed test: $name\n\n";
     close FOUT;
     if(-f "tests/DIFF/$outputbase.diff") {
-        system "${printcmd} tests/DIFF/$outputbase.diff >> tests/failure-outputs.txt";
+        #
+        # XXX - just do this directly in Perl?
+        #
+        if ($^O eq 'MSWin32') {
+            system "type tests\\DIFF\\$outputbase.diff >> tests\\failure-outputs.txt";
+        } else {
+            system "cat tests/DIFF/$outputbase.diff >> tests/failure-outputs.txt";
+        }
     }
 
     if($r == -1) {
@@ -194,7 +211,7 @@ sub runtest {
             print "\n";
         } else {
             print " with error messages:\n";
-            system "${printcmd} $stderrlog";
+            showfile($stderrlog);
         }
         return(($r & 128) ? 10 : 20);
     }
@@ -202,7 +219,7 @@ sub runtest {
         print "\n";
     } else {
         print " with error messages:\n";
-        system "${printcmd} $stderrlog";
+        showfile($stderrlog);
     }
 }