mirror of
https://git.savannah.gnu.org/git/make.git
synced 2024-11-24 20:20:35 +00:00
Add specific hints for errors due to invalid conditionals
* 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.
This commit is contained in:
parent
1b51ba1f5d
commit
6c1a6dd77c
3 changed files with 65 additions and 27 deletions
23
src/read.c
23
src/read.c
|
@ -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"));
|
||||
}
|
||||
|
||||
{
|
||||
|
|
49
tests/scripts/misc/failure
Normal file
49
tests/scripts/misc/failure
Normal file
|
@ -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;
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue