]> git.ipfire.org Git - thirdparty/make.git/commitdiff
tests: Enhance output to contain filename/line number info
authorPaul Smith <psmith@gnu.org>
Sat, 27 Nov 2021 19:03:44 +0000 (14:03 -0500)
committerPaul Smith <psmith@gnu.org>
Sat, 27 Nov 2021 19:03:44 +0000 (14:03 -0500)
* 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.

tests/run_make_tests.pl
tests/scripts/options/dash-I
tests/test_driver.pl

index d248ec97d47f48c8f08640fdceb6b04312a8d68a..cc46af1fea800727112c2ed7731a0a76feecf676 100644 (file)
@@ -310,7 +310,7 @@ sub create_command {
 # Using a ref should be preferred as it's more portable but all the older
 # invocations use strings.
 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;
   my $code;
   my $command = create_command($options);
@@ -364,13 +364,8 @@ sub run_make_with_options {
     $command = add_options($command, $options);
   }
 
-  my $cmdstr = ref($command) ? "'".join("' '", @$command)."'" : $command;
-
-  if (@call) {
-    $command_string = "#$call[1]:$call[2]\n$cmdstr\n";
-  } else {
-    $command_string = $cmdstr;
-  }
+  my $cmdstr = cmd2str($command);
+  $command_string = "# $call[1]:$call[2]:\n$cmdstr\n";
 
   if ($valgrind) {
     print VALGRIND "\n\nExecuting: $cmdstr\n";
@@ -409,9 +404,9 @@ sub run_make_with_options {
   }
 
   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;
-    &create_file (&get_runfile, $command_string);
+    &create_file(get_runfile(), $command_string);
     # If it's a SIGINT, stop here
     if ($code & 127) {
       print STDERR "\nCaught signal ".($code & 127)."!\n";
index e46460142791028fbc77061945ad225b789116d5..64ee7c58165a4de337c5178fcb8f99f6714abec7 100644 (file)
@@ -92,7 +92,7 @@ unlink('defaultdirs.mk');
 my $fn = undef;
 foreach my $dn (split ' ', $dirs) {
     # On Windows the default is "." which is bogus!
-    if ($dn != '.') {
+    if ($dn ne '.') {
         my @files = glob(File::Spec->catfile($dn, "*"));
         if (@files) {
             (undef, undef, $fn) = File::Spec->splitpath($files[0]);
index ec17be1feb6477eb8969c5799dafc964058579ca..686f52394ba6b6602251df3f220895efeecfda04 100644 (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
 {
   # Pull in benign variables from the user's environment
@@ -733,7 +754,7 @@ sub error
 
 sub compare_output
 {
-  my ($answer,$logfile) = @_;
+  my ($answer, $logfile) = @_;
   my ($slurp, $answer_matched) = ('', 0);
 
   ++$tests_run;
@@ -899,15 +920,15 @@ sub compare_output
   if (! $answer_matched) {
     print "DIFFERENT OUTPUT\n" if $debug;
 
-    &create_file (&get_basefile, $answer);
-    &create_file (&get_runfile, $command_string);
+    &create_file(&get_basefile, $answer);
+    &create_file(&get_runfile, $command_string);
 
     print "\nCreating Difference File ...\n" if $debug;
 
     # Create the difference file
 
     my $command = "diff -c " . &get_basefile . " " . $logfile;
-    &run_command_with_output(&get_difffile,$command);
+    &run_command_with_output(get_difffile(), $command);
   }
 
   return 0;
@@ -938,7 +959,7 @@ sub attach_default_output
   if ($vos)
   {
     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;
   }