]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Add specific hints for errors due to invalid conditionals
authorPaul Smith <psmith@gnu.org>
Tue, 15 Nov 2022 15:50:34 +0000 (10:50 -0500)
committerPaul Smith <psmith@gnu.org>
Tue, 15 Nov 2022 15:50:34 +0000 (10:50 -0500)
* src/read.c (eval): If "missing separator" appears to be due to
missing space after ifeq/ifneq, give a hint about the error.
* tests/scripts/misc/failure: Check for these types of failures.
* tests/scripts/variables/special: Move error checking unrelated
to special variables, to misc/failure.

src/read.c
tests/scripts/misc/failure [new file with mode: 0644]
tests/scripts/variables/special

index 0743124087f250f36195b86f8f28c85a5aa71f6f..15f58ecf24eb21fe65d830879969f65beffa9bba 100644 (file)
@@ -1140,20 +1140,29 @@ eval (struct ebuffer *ebuf, int set_default)
 
         p2 = next_token (variable_buffer);
 
-        /* If the word we're looking at is EOL, see if there's _anything_
-           on the line.  If not, a variable expanded to nothing, so ignore
-           it.  If so, we can't parse this line so punt.  */
+        /* If we're at EOL we didn't find a separator so we don't know what
+           kind of line this is.  */
         if (wtype == w_eol)
           {
+            /* Ignore an empty line.  */
             if (*p2 == '\0')
               continue;
 
-            /* There's no need to be ivory-tower about this: check for
-               one of the most common bugs found in makefiles...  */
+            /* Check for spaces instead of TAB.  */
             if (cmd_prefix == '\t' && strneq (line, "        ", 8))
               O (fatal, fstart, _("missing separator (did you mean TAB instead of 8 spaces?)"));
-            else
-              O (fatal, fstart, _("missing separator"));
+
+            /* Check for conditionals without whitespace afterward.
+               We don't check ifdef/ifndef because there's no real way to miss
+               whitespace there.  */
+            p2 = next_token (line);
+            if (strneq (p2, "if", 2) &&
+                ((strneq (&p2[2], "neq", 3) && !STOP_SET (p2[5], MAP_BLANK))
+                 || (strneq (&p2[2], "eq", 2) && !STOP_SET (p2[4], MAP_BLANK))))
+              O (fatal, fstart, _("missing separator (ifeq/ifneq must be followed by whitespace)"));
+
+            /* No idea...  */
+            O (fatal, fstart, _("missing separator"));
           }
 
         {
diff --git a/tests/scripts/misc/failure b/tests/scripts/misc/failure
new file mode 100644 (file)
index 0000000..edd90fb
--- /dev/null
@@ -0,0 +1,49 @@
+#                                                                    -*-perl-*-
+
+$description = "Test miscellaneous failures.";
+
+
+# Test that the "did you mean TAB" message is printed properly
+
+run_make_test(q!
+$x.
+!,
+              '', '#MAKEFILE#:2: *** missing separator.  Stop.', 512);
+
+run_make_test(q!
+foo:
+        bar
+!,
+              '', '#MAKEFILE#:3: *** missing separator (did you mean TAB instead of 8 spaces?).  Stop.', 512);
+
+run_make_test(q!
+.RECIPEPREFIX = :
+foo:
+        bar
+!,
+              '', '#MAKEFILE#:4: *** missing separator.  Stop.', 512);
+
+for my $kw ('eq', 'neq') {
+run_make_test(qq!
+if$kw(foo,bar)
+\$(error ouch)
+endif
+!,
+              '', '#MAKEFILE#:2: *** missing separator (ifeq/ifneq must be followed by whitespace).  Stop.', 512);
+
+run_make_test(qq!
+if$kw
+\$(error ouch)
+endif
+!,
+              '', '#MAKEFILE#:2: *** invalid syntax in conditional.  Stop.', 512);
+
+run_make_test(qq!
+if$kw blah
+\$(error ouch)
+endif
+!,
+              '', '#MAKEFILE#:2: *** invalid syntax in conditional.  Stop.', 512);
+}
+
+1;
index 68f3128cf7b9722bbc1d37c37edc51c5ba850b19..abe9fc0c3472eda817533d2d0dd186f9193e7e03 100644 (file)
@@ -122,26 +122,6 @@ reset-four \
 : foo-three
 : foo-four');
 
-# Test that the "did you mean TAB" message is printed properly
-
-run_make_test(q!
-$x.
-!,
-              '', '#MAKEFILE#:2: *** missing separator.  Stop.', 512);
-
-run_make_test(q!
-foo:
-        bar
-!,
-              '', '#MAKEFILE#:3: *** missing separator (did you mean TAB instead of 8 spaces?).  Stop.', 512);
-
-run_make_test(q!
-.RECIPEPREFIX = :
-foo:
-        bar
-!,
-              '', '#MAKEFILE#:4: *** missing separator.  Stop.', 512);
-
 1;
 
 ### Local Variables: