diff options
author | Guy Harris <gharris@sonic.net> | 2020-06-13 00:08:49 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2020-06-13 00:08:49 -0700 |
commit | f28d5b06872ae9ab7dd9216f9cd56cba1ec7178b (patch) | |
tree | b83e75cf0dfa60dbf210e3ddd4fd22f8b9137c83 /tests | |
parent | 27ede6609cad295a3100fe7c11fca35192da8d74 (diff) | |
download | tcpdump-f28d5b06872ae9ab7dd9216f9cd56cba1ec7178b.tar.gz |
TESTrun: clean up printing of files.
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.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/TESTrun | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/tests/TESTrun b/tests/TESTrun index c0020e02..b5d2aa84 100755 --- a/tests/TESTrun +++ b/tests/TESTrun @@ -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); } } |