make/tests/scripts/variables/negative
Paul Smith 6c06c547dc Add support for the POSIX :::= assignment operator.
POSIX Issue 8 will require a new assignment operator, :::=.
This operator behaves similarly to the BSD make := operator: the
right-hand side is expanded immediately, but then the value is
re-escaped (all '$' are converted to '$$') and the resulting variable
is considered a recursive variable: the value is re-expanded on use.

* src/variable.h (enum variable_flavor): Add f_expand flavor.
* src/variable.c (do_variable_definition): When defining f_expand,
post-process the result to re-escape '$' characters.
Remove default: to the compiler warns about un-handled enum values.
Set recursive values for both f_recursive and f_expand.
(parse_variable_definition): Rewrite this method.
The previous version was annoying to extend to ':::='.
(print_variable): Remove default: so the compiler warns us about
un-handled enum values.
* src/function.c (func_origin): Remove default: so the compiler warns
us about un-handled enum values.
* doc/make.texi: Add documentation for :::=.
* tests/scripts/variables/define: Add a test for define :::=.
* tests/scripts/variables/flavors: Add tests for :::=.
* tests/scripts/variables/negative: Add tests for :::=.
2021-09-20 00:29:31 -04:00

61 lines
1.5 KiB
Perl

# -*-perl-*-
$description = "Run some negative tests (things that should fail).";
# TEST #0
# Check that non-terminated variable references are detected (and
# reported using the best filename/lineno info
run_make_test('
foo = bar
x = $(foo
y = $x
all: ; @echo $y
',
'', '#MAKEFILE#:3: *** unterminated variable reference. Stop.',
512);
# TEST #1
# Bogus variable value passed on the command line.
run_make_test(undef,
['x=$(other'],
'#MAKEFILE#:4: *** unterminated variable reference. Stop.',
512);
# TEST #2
# Again, but this time while reading the makefile.
run_make_test('
foo = bar
x = $(foo
y = $x
z := $y
all: ; @echo $y
',
'', '#MAKEFILE#:3: *** unterminated variable reference. Stop.',
512);
# TEST #3
# Bogus variable value passed on the command line.
run_make_test(undef,
['x=$(other'],
'#MAKEFILE#:4: *** unterminated variable reference. Stop.',
512);
# Whitespace not allowed in variable names
run_make_test('x y =', '',
'#MAKEFILE#:1: *** missing separator. Stop.', 512);
run_make_test('x y=', '',
'#MAKEFILE#:1: *** missing separator. Stop.', 512);
# In theory an empty variable should be ignored, but during parsing it's a
# real token and so this fails. I'm not 100% sure if this is right or not.
run_make_test('x $X=', '',
'#MAKEFILE#:1: *** missing separator. Stop.', 512);
1;