]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Clean up errors for invalid commands and add regression tests.
authorPaul Smith <psmith@gnu.org>
Sat, 4 Aug 2018 16:20:11 +0000 (12:20 -0400)
committerPaul Smith <psmith@gnu.org>
Sat, 4 Aug 2018 16:37:19 +0000 (12:37 -0400)
* src/function.c (func_shell_base): Use error() instead of recreating
the error output.
* src/job.c (exec_command): Show more standard error messages.
* src/load.c (unload_file): Fix whitespace in the error message.
* tests/scripts/features/errors: Add tests for starting non-
existent commands and new error message formats.
* tests/scripts/features/output-sync: New error message formats.
* tests/scripts/functions/shell: Ditto.

src/function.c
src/job.c
src/load.c
tests/scripts/features/errors
tests/scripts/features/output-sync
tests/scripts/functions/shell

index 12e0ef2f6167b76079f20fe440a47b6a9cda2e2b..4602ebb215ee16c643076494bb757cc2bb568a63 100644 (file)
@@ -1699,7 +1699,6 @@ func_shell_base (char *o, char **argv, int trim_newlines)
   FILE *fpipe;
 #endif
   char **command_argv = NULL;
-  const char *error_prefix;
   char **envp;
   int pipedes[2];
   pid_t pid;
@@ -1739,17 +1738,6 @@ func_shell_base (char *o, char **argv, int trim_newlines)
 
   envp = environ;
 
-  /* For error messages.  */
-  if (reading_file && reading_file->filenm)
-    {
-      char *p = alloca (strlen (reading_file->filenm)+11+4);
-      sprintf (p, "%s:%lu: ", reading_file->filenm,
-               reading_file->lineno + reading_file->offset);
-      error_prefix = p;
-    }
-  else
-    error_prefix = "";
-
   /* Set up the output in case the shell writes something.  */
   output_start ();
 
@@ -1760,7 +1748,7 @@ func_shell_base (char *o, char **argv, int trim_newlines)
   fpipe = msdos_openpipe (pipedes, &pid, argv[0]);
   if (pipedes[0] < 0)
     {
-      perror_with_name (error_prefix, "pipe");
+      OS (error, reading_file, "pipe: %s", strerror (errno));
       pid = -1;
       goto done;
     }
@@ -1774,7 +1762,7 @@ func_shell_base (char *o, char **argv, int trim_newlines)
     {
       /* Open of the pipe failed, mark as failed execution.  */
       shell_completed (127, 0);
-      perror_with_name (error_prefix, "pipe");
+      OS (error, reading_file, "pipe: %s", strerror (errno));
       pid = -1;
       goto done;
     }
@@ -1782,7 +1770,7 @@ func_shell_base (char *o, char **argv, int trim_newlines)
 #else
   if (pipe (pipedes) < 0)
     {
-      perror_with_name (error_prefix, "pipe");
+      OS (error, reading_file, "pipe: %s", strerror (errno));
       pid = -1;
       goto done;
     }
@@ -1801,7 +1789,10 @@ func_shell_base (char *o, char **argv, int trim_newlines)
   }
 
   if (pid < 0)
-    goto done;
+    {
+      shell_completed (127, 0);
+      goto done;
+    }
 #endif
 
   {
index 0cd13eb51ebdf97b464c328079b532c7998ba43c..d8d5b7ce7c0de006ed6c62c98bc68bf66b0364fb 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -2213,6 +2213,9 @@ child_execute_job (struct output *out, int good_stdin, char **argv, char **envp)
         close (save_fderr);
     }
 
+  if (pid < 0)
+    OSS (error, NILF, "%s: %s", argv[0], strerror (errno));
+
   return pid;
 }
 
@@ -2286,7 +2289,7 @@ exec_command (char **argv, char **envp)
 #endif
   /* Run the program.  */
   execve (argv[0], argv, envp);
-  perror_with_name ("execve: ", argv[0]);
+  OSS (error, NILF, "%s: %s", argv[0], strerror (errno));
   _exit (EXIT_FAILURE);
 #else
 #ifdef WINDOWS32
@@ -2375,13 +2378,7 @@ exec_command (char **argv, char **envp)
   switch (errno)
     {
     case ENOENT:
-      /* We are in the child: don't use the output buffer.
-         It's not right to run fprintf() here!  */
-      if (makelevel == 0)
-        fprintf (stderr, _("%s: %s: Command not found\n"), program, argv[0]);
-      else
-        fprintf (stderr, _("%s[%u]: %s: Command not found\n"),
-                 program, makelevel, argv[0]);
+      OSS (error, NILF, "%s: %s", argv[0], strerror (errno));
       break;
     case ENOEXEC:
       {
@@ -2439,10 +2436,7 @@ exec_command (char **argv, char **envp)
 # else
         execvp (shell, new_argv);
 # endif
-        if (errno == ENOENT)
-          OS (error, NILF, _("%s: Shell program not found"), shell);
-        else
-          perror_with_name ("execvp: ", shell);
+        OSS (error, NILF, "%s: %s", new_argv[0], strerror (errno));
         break;
       }
 
@@ -2454,7 +2448,7 @@ exec_command (char **argv, char **envp)
 # endif
 
     default:
-      perror_with_name ("execvp: ", argv[0]);
+      OSS (error, NILF, "%s: %s", argv[0], strerror (errno));
       break;
     }
 
index ecf66cbae171bda5e0649aaf10f9fdb0fc1cf949..5ec87c6b3bf79271d5b9805fff24d8c079663af9 100644 (file)
@@ -240,7 +240,7 @@ unload_file (const char *name)
     if (streq (d->name, name) && d->dlp)
       {
         if (dlclose (d->dlp))
-          perror_with_name ("dlclose", d->name);
+          perror_with_name ("dlclose", d->name);
         d->dlp = NULL;
         break;
       }
index 5c570790a6d0268de48d142c2f30c0d540531927..eac64ed9b069ea111126272f3a21112c2ce488d2 100644 (file)
 #                                                                    -*-perl-*-
 
-$description = "The following tests the -i option and the '-' in front of \n"
-              ."commands to test that make ignores errors in these commands\n"
-              ."and continues processing.";
-
-$details = "This test runs two makes.  The first runs on a target with a \n"
-          ."command that has a '-' in front of it (and a command that is \n"
-          ."intended to fail) and then a delete command after that is \n"
-          ."intended to succeed.  If make ignores the failure of the first\n"
-          ."command as it is supposed to, then the second command should \n"
-          ."delete a file and this is what we check for.  The second make\n"
-          ."that is run in this test is identical except that the make \n"
-          ."command is given with the -i option instead of the '-' in \n"
-          ."front of the command.  They should run the same. ";
-
-if ($vos)
-{
-   $rm_command = "delete_file";
-}
-else
-{
-   $rm_command = "rm";
-}
-
-open(MAKEFILE,"> $makefile");
-
-# The Contents of the MAKEFILE ...
-
-print MAKEFILE "clean:\n"
-              ."\t-$rm_command cleanit\n"
-              ."\t$rm_command foo\n"
-              ."clean2: \n"
-              ."\t$rm_command cleanit\n"
-              ."\t$rm_command foo\n";
-
-# END of Contents of MAKEFILE
-
-close(MAKEFILE);
-
-&touch("foo");
-
-unlink("cleanit");
-$cleanit_error = `sh -c "$rm_command cleanit 2>&1"`;
-chomp $cleanit_error;
-$delete_error_code = $? >> 8;
+$description = "Test ignored failures in recipe command lines";
+
+run_make_test(qq!
+one:
+\t-exit 1
+\texit 0
+two:
+\texit 1
+\texit 0
+!,
+              "one", "exit 1\n#MAKE#: [#MAKEFILE#;3: one] Error 1 (ignored)\nexit 0\n");
 
 # TEST #1
 # -------
 
-$answer = "$rm_command cleanit
-$cleanit_error
-$make_name: [$makefile;2: clean] Error $delete_error_code (ignored)
-$rm_command foo\n";
+run_make_test(undef, " -i two",
+              "exit 1\n#MAKE#: [#MAKEFILE#;6: two] Error 1 (ignored)\nexit 0\n");
 
-&run_make_with_options($makefile,"",&get_logfile);
+# TEST #2
+# -------
 
-# If make acted as planned, it should ignore the error from the first
-# command in the target and execute the second which deletes the file "foo"
-# This file, therefore, should not exist if the test PASSES.
-if (-f "foo") {
-  $test_passed = 0;
-}
+# Test that error line offset works
 
-# The output for this on VOS is too hard to replicate, so we only check it
-# on unix.
-if (!$vos)
-{
-   &compare_output($answer,&get_logfile(1));
-}
+run_make_test(qq!
+all:
+\t\@echo hi
+\t\@echo there
+\t\@exit 1
+!,
+              '', "hi\nthere\n#MAKE#: *** [#MAKEFILE#;5: all] Error 1", 512);
 
+# TEST #3
+# -------
 
-&touch("foo");
+# Try failing due to unknown command
+my $unk = './foobarbazbozblat';
+unlink($unk);
 
-# TEST #2
+my $err = $ERR_no_such_file;
+
+run_make_test(qq!
+one: ; -$unk xx yy
+two: ; $unk aa bb
+!,
+              'one', "$unk xx yy\n#MAKE#: $unk: $err\n#MAKE#: [#MAKEFILE#;2: one] Error 127 (ignored)\n");
+
+# TEST #4
 # -------
 
-$answer = "$rm_command cleanit
-$cleanit_error
-$make_name: [$makefile;5: clean2] Error $delete_error_code (ignored)
-$rm_command foo\n";
+run_make_test(undef, 'two -i',
+              "$unk aa bb\n#MAKE#: $unk: $err\n#MAKE#: [#MAKEFILE#;3: two] Error 127 (ignored)\n");
 
-&run_make_with_options($makefile,"clean2 -i",&get_logfile);
+# TEST #5
+# -------
 
-if (-f "foo") {
-  $test_passed = 0;
-}
+run_make_test(undef, 'two',
+              "$unk aa bb\n#MAKE#: $unk: $err\n#MAKE#: *** [#MAKEFILE#;3: two] Error 127\n", 512);
 
-if (!$vos) {
-   &compare_output($answer,&get_logfile(1));
-}
+# Try failing due to non-executable file
 
-# Test that error line offset works
+my $noexe = './barfooblatboz';
+touch($noexe);
 
-run_make_test(q!
-all:
-       @echo hi
-       @echo there
-       @exit 1
+run_make_test(qq!
+one: ; -$noexe xx yy
+two: ; $noexe aa bb
 !,
-              '', "hi\nthere\n#MAKE#: *** [#MAKEFILE#;5: all] Error 1", 512);
+              'one', "$noexe xx yy\n#MAKE#: $noexe: Permission denied\n#MAKE#: [#MAKEFILE#;2: one] Error 127 (ignored)\n");
 
-1;
+unlink($noexe);
 
-### Local Variables:
-### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
-### End:
+1;
index 1407e81a9dcaf62d0c1e1c64bcf33dc39022cbeb..49d3be2c54f06b6686700a4f4a5e4f16c2e4a678 100644 (file)
@@ -343,7 +343,7 @@ if ($port_type ne 'W32') {
     run_make_test(q!
 all:: ; @./foo bar baz
 !,
-              '-O', "#MAKE#: ./foo: Command not found\n#MAKE#: *** [#MAKEFILE#;2: all] Error 127\n", 512);
+              '-O', "#MAKE#: ./foo: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#;2: all] Error 127\n", 512);
 }
 
 # This tells the test driver that the perl test script executed properly.
index bbb25dd9218e074e2af9747ce2fe742026a6aff5..3ffa1d8d6f437f42a120e2dc980aa89f26992958 100644 (file)
@@ -49,9 +49,15 @@ if ($port_type ne 'W32') {
 all:
        @echo hi
        $(shell ./basdfdfsed there)
-       @echo there
+       @echo $(.SHELLSTATUS)
 ',
-                  '', "#MAKE#: ./basdfdfsed: Command not found\nhi\nthere\n");
+                  '', "#MAKE#: ./basdfdfsed: $ERR_no_such_file\nhi\n127\n");
+
+    run_make_test('
+$(shell ./basdfdfsed where)
+all: ; @echo $(.SHELLSTATUS)
+',
+                  '', "#MAKE#: ./basdfdfsed: $ERR_no_such_file\n127\n");
 
     # Test SHELLSTATUS for kill.
     # This test could be ported to Windows, using taskkill ... ?