diff options
author | Paul Smith <psmith@gnu.org> | 2023-02-26 18:24:30 -0500 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2023-04-01 11:13:12 -0400 |
commit | 03ecd94488b85adc38746ec3e7c2a297a522598e (patch) | |
tree | 26f47e9d5e1dd9ba730c24f86c099005a923bb68 /tests | |
parent | 2611e1991fabe2a3ae929c6ebd4afbd4f550f306 (diff) | |
download | make-git-03ecd94488b85adc38746ec3e7c2a297a522598e.tar.gz |
Add new warnings invalid-var and invalid-ref
The "invalid-var" warning triggers if the makefile attempts to assign
a value to an invalid variable name (a name containing whitespace).
The "invalid-ref" warning triggers if the makefile attempts to
reference an invalid variable name. Both new warnings have a default
action of "warn".
* NEWS: Add these new warnings.
* doc/make.1: Document them in the man page.
* doc/make.texi (Warnings): Document them in the user's manual.
* src/warning.h: Add enum values for the new warning types.
* src/main.c (initialize_warnings): Initialize the new warnings.
* src/variable.h (undefine_variable_in_set, undefine_variable_global):
Ask callers to provide a struct floc specifying where the variable
is undefined.
* src/read.c (do_undefine): Pass floc when undefining.
* src/variable.c (check_valid_name): If invalid-var is enabled, check
the variable name.
(define_variable_in_set): Call it.
(undefine_variable_in_set): Ditto.
(check_variable_reference): If invalid-ref is enabled, check the
variable reference.
(lookup_variable): Call it.
(lookup_variable_in_set): Ditto.
* tests/scripts/options/warn: Add tests for the new warning types.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/scripts/options/warn | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/tests/scripts/options/warn b/tests/scripts/options/warn index 98155d46..f41f84ff 100644 --- a/tests/scripts/options/warn +++ b/tests/scripts/options/warn @@ -5,8 +5,8 @@ $description = "Test the --warn option."; my %warn_test = ( '--warn' => '', '--warn=warn' => '', '--warn=error --warn=warn' => '', '--warn --warn=error' => '=error', - '--warn=ignore --warn=error --warn=ignore --warn=undefined-var' => '=ignore,undefined-var', - '--warn=undefined-var:error --warn' => '=warn,undefined-var:error' + '--warn=ignore --warn=error --warn=ignore --warn=invalid-var,invalid-ref,undefined-var' => '=ignore,invalid-var,invalid-ref,undefined-var', + '--warn=invalid-ref:ignore --warn=error --warn=invalid-var:warn,,,,,undefined-var:error,,,,,' => '=error,invalid-var,invalid-ref:ignore,undefined-var:error' ); # Verify the deprecated --warn-undefined-variables option @@ -83,4 +83,68 @@ ref"); run_make_test(undef, '--warn=undefined-var:error', "#MAKEFILE#:7: *** reference to undefined variable 'UNDEFINED'. Stop.", 512); +# Check invalid variable reference warnings + +# With no options we still check for invalid references +run_make_test(' +IREF = $(bad variable) +SIREF := $(IREF) + +define nl + + +endef + +all: ; @echo ref $(also$(nl)bad) $(IREF) $(SIREF)', + '', "#MAKEFILE#:2: invalid variable reference 'bad variable' +#MAKEFILE#:10: invalid variable reference 'also\nbad' +#MAKEFILE#:2: invalid variable reference 'bad variable' +ref"); + +run_make_test(undef, '--warn=ignore', 'ref'); + +run_make_test(undef, '--warn=invalid-ref:ignore', 'ref'); + +# Check and errors +run_make_test(undef, '--warn=invalid-ref:error', + "#MAKEFILE#:2: *** invalid variable reference 'bad variable'. Stop.", 512); + +# Check invalid variable name warnings + +# With no options we still check for invalid references +run_make_test(' +EMPTY = +SPACE = $(EMPTY) $(EMPTY) +BAD$(SPACE)VAR = foo + +define nl + + +endef + +NL$(nl)VAR = bar + +define BAD$(SPACE)DEF := +foo +endef + +define NL$(nl)DEF := +foo +endef + +all: ; @echo ref', + '', "#MAKEFILE#:4: invalid variable name 'BAD VAR' +#MAKEFILE#:11: invalid variable name 'NL\nVAR' +#MAKEFILE#:13: invalid variable name 'BAD DEF' +#MAKEFILE#:17: invalid variable name 'NL\nDEF' +ref"); + +run_make_test(undef, '--warn=ignore', 'ref'); + +run_make_test(undef, '--warn=invalid-var:ignore', 'ref'); + +# Check and errors +run_make_test(undef, '--warn=invalid-var:error', + "#MAKEFILE#:4: *** invalid variable name 'BAD VAR'. Stop.", 512); + 1; |