tests: Enhance output to contain filename/line number info

* tests/scripts/options/dash-I: Use string comparison operator.
* tests/test_driver.pl (cmd2str): New method to convert a
command line to a string with proper quoting.
* tests/run_make_tests.pl (create_command): Call cmd2str() to format
the command.  Add the filename/line number to the output.
This commit is contained in:
Paul Smith 2021-11-27 14:03:44 -05:00
parent f8f9d371ff
commit 29d92d4091
3 changed files with 32 additions and 16 deletions

View File

@ -310,7 +310,7 @@ sub create_command {
# Using a ref should be preferred as it's more portable but all the older # Using a ref should be preferred as it's more portable but all the older
# invocations use strings. # invocations use strings.
sub run_make_with_options { sub run_make_with_options {
my ($filename,$options,$logname,$expected_code,$timeout,@call) = @_; my ($filename, $options, $logname, $expected_code, $timeout, @call) = @_;
@call = caller unless @call; @call = caller unless @call;
my $code; my $code;
my $command = create_command($options); my $command = create_command($options);
@ -364,13 +364,8 @@ sub run_make_with_options {
$command = add_options($command, $options); $command = add_options($command, $options);
} }
my $cmdstr = ref($command) ? "'".join("' '", @$command)."'" : $command; my $cmdstr = cmd2str($command);
$command_string = "# $call[1]:$call[2]:\n$cmdstr\n";
if (@call) {
$command_string = "#$call[1]:$call[2]\n$cmdstr\n";
} else {
$command_string = $cmdstr;
}
if ($valgrind) { if ($valgrind) {
print VALGRIND "\n\nExecuting: $cmdstr\n"; print VALGRIND "\n\nExecuting: $cmdstr\n";
@ -409,9 +404,9 @@ sub run_make_with_options {
} }
if ($code != $expected_code) { if ($code != $expected_code) {
print "Error running @make_command (expected $expected_code; got $code): $cmdstr\n"; print "Error running @make_command (expected $expected_code; got $code)\n$call[1]:$call[2]: $cmdstr\n";
$test_passed = 0; $test_passed = 0;
&create_file (&get_runfile, $command_string); &create_file(get_runfile(), $command_string);
# If it's a SIGINT, stop here # If it's a SIGINT, stop here
if ($code & 127) { if ($code & 127) {
print STDERR "\nCaught signal ".($code & 127)."!\n"; print STDERR "\nCaught signal ".($code & 127)."!\n";

View File

@ -92,7 +92,7 @@ unlink('defaultdirs.mk');
my $fn = undef; my $fn = undef;
foreach my $dn (split ' ', $dirs) { foreach my $dn (split ' ', $dirs) {
# On Windows the default is "." which is bogus! # On Windows the default is "." which is bogus!
if ($dn != '.') { if ($dn ne '.') {
my @files = glob(File::Spec->catfile($dn, "*")); my @files = glob(File::Spec->catfile($dn, "*"));
if (@files) { if (@files) {
(undef, undef, $fn) = File::Spec->splitpath($files[0]); (undef, undef, $fn) = File::Spec->splitpath($files[0]);

View File

@ -148,6 +148,27 @@ sub resetENV
} }
} }
# Returns a string-ified version of cmd which is a value provided to exec()
# so it can either be a ref of a list or a string.
sub cmd2str
{
my $cmd = $_[0];
if (!ref($cmd)) {
return $cmd;
}
my @c;
foreach (@$cmd) {
if (/[][#;"*?&|<>(){}\$`^~!]/) {
s/\'/\'\\'\'/g;
push @c, "'$_'";
} else {
push @c, $_;
}
}
return join(' ', @c);
}
sub toplevel sub toplevel
{ {
# Pull in benign variables from the user's environment # Pull in benign variables from the user's environment
@ -733,7 +754,7 @@ sub error
sub compare_output sub compare_output
{ {
my ($answer,$logfile) = @_; my ($answer, $logfile) = @_;
my ($slurp, $answer_matched) = ('', 0); my ($slurp, $answer_matched) = ('', 0);
++$tests_run; ++$tests_run;
@ -899,15 +920,15 @@ sub compare_output
if (! $answer_matched) { if (! $answer_matched) {
print "DIFFERENT OUTPUT\n" if $debug; print "DIFFERENT OUTPUT\n" if $debug;
&create_file (&get_basefile, $answer); &create_file(&get_basefile, $answer);
&create_file (&get_runfile, $command_string); &create_file(&get_runfile, $command_string);
print "\nCreating Difference File ...\n" if $debug; print "\nCreating Difference File ...\n" if $debug;
# Create the difference file # Create the difference file
my $command = "diff -c " . &get_basefile . " " . $logfile; my $command = "diff -c " . &get_basefile . " " . $logfile;
&run_command_with_output(&get_difffile,$command); &run_command_with_output(get_difffile(), $command);
} }
return 0; return 0;
@ -938,7 +959,7 @@ sub attach_default_output
if ($vos) if ($vos)
{ {
my $code = system "++attach_default_output_hack $filename"; my $code = system "++attach_default_output_hack $filename";
$code == -2 or &error ("adoh death\n", 1); $code == -2 or &error ("ado death\n", 1);
return 1; return 1;
} }