make/tests/scripts/options/warn

183 lines
5.5 KiB
Text
Raw Normal View History

Introduce a --warn command line option Replace the singleton --warn-undefined-variables with infrastructure to manage multiple warnings: the --warn option can take an action "ignore", "warn", or "error" (which will apply to all warnings), or a specific warning type and an action for that type. Multiple options can be provided and are consolidated. * NEWS: Announce the new option. * doc/make.1: Document in the man page. * doc/make.texi (Warnings): Document in the user's manual. * Makefile.am: Add new header warning.h. * src/warning.h: Define enum for actions and warning types, and macros to test whether they are set. Keep the default settings separate so that we can correctly reconstruct MAKEFLAGS. * src/makeint.h: Remove deprecated warn_undefined_variables_flag. * src/main.c: Create global variables to hold warning settings. (switches): Add a new switch for --warn. (initialize_warnings): Set the default warning actions. (main): Call initialize_warnings(). (encode_warning_state, decode_warning_state): Convert warning states between strings and enums. (encode_warning_name, decode_warning_name): Convert warning names between strings and enums. (decode_warn_flags): Convert a --warn option into enum values. If deprecated warn_undefined_variables_flag is set convert it to --warn. (decode_switches): Don't remove duplicates of --warn since order matters. Call decode_warn_flags() to handle --warn. (define_makeflags): Special-case handling of --warn options written to MAKEFLAGS: write out the current settings. * src/read.c (tilde_expand): Use new warning control macros. * src/variable.c (warn_undefined): Ditto. * src/job.c (construct_command_argv): Ditto. * tests/scripts/options/warn: Rename from warn-undefined-variables and add tests for --warn. * tests/scripts/variables/MAKEFLAGS: Expect the new behavior.
2023-02-26 23:04:14 +00:00
# -*-perl-*-
$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=invalid-ref,invalid-var,undefined-var' => '=ignore,invalid-ref,invalid-var,undefined-var',
'--warn=invalid-ref:ignore --warn=error --warn=invalid-var:warn,,,,,undefined-var:error,,,,,' => '=error,invalid-ref:ignore,invalid-var,undefined-var:error'
Introduce a --warn command line option Replace the singleton --warn-undefined-variables with infrastructure to manage multiple warnings: the --warn option can take an action "ignore", "warn", or "error" (which will apply to all warnings), or a specific warning type and an action for that type. Multiple options can be provided and are consolidated. * NEWS: Announce the new option. * doc/make.1: Document in the man page. * doc/make.texi (Warnings): Document in the user's manual. * Makefile.am: Add new header warning.h. * src/warning.h: Define enum for actions and warning types, and macros to test whether they are set. Keep the default settings separate so that we can correctly reconstruct MAKEFLAGS. * src/makeint.h: Remove deprecated warn_undefined_variables_flag. * src/main.c: Create global variables to hold warning settings. (switches): Add a new switch for --warn. (initialize_warnings): Set the default warning actions. (main): Call initialize_warnings(). (encode_warning_state, decode_warning_state): Convert warning states between strings and enums. (encode_warning_name, decode_warning_name): Convert warning names between strings and enums. (decode_warn_flags): Convert a --warn option into enum values. If deprecated warn_undefined_variables_flag is set convert it to --warn. (decode_switches): Don't remove duplicates of --warn since order matters. Call decode_warn_flags() to handle --warn. (define_makeflags): Special-case handling of --warn options written to MAKEFLAGS: write out the current settings. * src/read.c (tilde_expand): Use new warning control macros. * src/variable.c (warn_undefined): Ditto. * src/job.c (construct_command_argv): Ditto. * tests/scripts/options/warn: Rename from warn-undefined-variables and add tests for --warn. * tests/scripts/variables/MAKEFLAGS: Expect the new behavior.
2023-02-26 23:04:14 +00:00
);
# Verify the deprecated --warn-undefined-variables option
run_make_test(q!
$(info MF=$(MAKEFLAGS))
all:; @#HELPER# env MAKEFLAGS
!,
'--warn-undefined-variables', "MF= --warn=undefined-var\nMAKEFLAGS= --warn=undefined-var");
# sv 64115.
# Verify that -R along with --warn-undefined-variables do not warn about
# internal variables, such as GNUMAKEFLAGS.
run_make_test(q!
$(info MF=$(MAKEFLAGS))
all:; @#HELPER# env MAKEFLAGS
!,
'-R --warn-undefined-variables', "MF=rR --warn=undefined-var\nMAKEFLAGS=rR --warn=undefined-var");
Introduce a --warn command line option Replace the singleton --warn-undefined-variables with infrastructure to manage multiple warnings: the --warn option can take an action "ignore", "warn", or "error" (which will apply to all warnings), or a specific warning type and an action for that type. Multiple options can be provided and are consolidated. * NEWS: Announce the new option. * doc/make.1: Document in the man page. * doc/make.texi (Warnings): Document in the user's manual. * Makefile.am: Add new header warning.h. * src/warning.h: Define enum for actions and warning types, and macros to test whether they are set. Keep the default settings separate so that we can correctly reconstruct MAKEFLAGS. * src/makeint.h: Remove deprecated warn_undefined_variables_flag. * src/main.c: Create global variables to hold warning settings. (switches): Add a new switch for --warn. (initialize_warnings): Set the default warning actions. (main): Call initialize_warnings(). (encode_warning_state, decode_warning_state): Convert warning states between strings and enums. (encode_warning_name, decode_warning_name): Convert warning names between strings and enums. (decode_warn_flags): Convert a --warn option into enum values. If deprecated warn_undefined_variables_flag is set convert it to --warn. (decode_switches): Don't remove duplicates of --warn since order matters. Call decode_warn_flags() to handle --warn. (define_makeflags): Special-case handling of --warn options written to MAKEFLAGS: write out the current settings. * src/read.c (tilde_expand): Use new warning control macros. * src/variable.c (warn_undefined): Ditto. * src/job.c (construct_command_argv): Ditto. * tests/scripts/options/warn: Rename from warn-undefined-variables and add tests for --warn. * tests/scripts/variables/MAKEFLAGS: Expect the new behavior.
2023-02-26 23:04:14 +00:00
# Verify parsing of --warn in various forms.
while (my ($f, $r) = each %warn_test) {
run_make_test(undef, $f, "MF= --warn$r\nMAKEFLAGS= --warn$r");
}
# Verify that values set in MAKEFLAGS take effect
while (my ($f, $r) = each %warn_test) {
run_make_test(qq!
MAKEFLAGS += $f
\$(info MF=\$(MAKEFLAGS))
all:; \@#HELPER# env MAKEFLAGS
!,
'', "MF= --warn$r\nMAKEFLAGS= --warn$r");
}
# Verify that make's special variables don't warn even if they're not set
run_make_test(q!
vars := $(.VARIABLES) $(MAKECMDGOALS) $(MAKE_RESTARTS) $(CURDIR)
vars += $(GNUMAKEFLAGS) $(MAKEFLAGS) $(MFLAGS) $(MAKE_COMMAND) $(MAKE)
vars += $(MAKEFILE_LIST) $(MAKEOVERRIDES) $(-*-command-variables-*-)
vars += $(.RECIPEPREFIX) $(.LOADED) $(.FEATURES)
vars += $(SHELL) $(.SHELLFLAGS) $(MAKE_TERMOUT) $(MAKE_TERMERR)
vars += $(.DEFAULT) $(.DEFAULT_GOAL) $(-*-eval-flags-*-) $(SUFFIXES)
vars += $(VPATH) $(GPATH)
all:;
!,
'--warn=undefined-var', "#MAKE#: 'all' is up to date.");
# sv 63609.
# Test for buffer overrun in warn_undefined.
run_make_test(q!
all:;
X := $(averyveryveryloooooooooooooooooooooooooooongvariablename)
!,
'--warn=undefined-var',
"#MAKEFILE#:3: warning: reference to undefined variable 'averyveryveryloooooooooooooooooooooooooooongvariablename'
Introduce a --warn command line option Replace the singleton --warn-undefined-variables with infrastructure to manage multiple warnings: the --warn option can take an action "ignore", "warn", or "error" (which will apply to all warnings), or a specific warning type and an action for that type. Multiple options can be provided and are consolidated. * NEWS: Announce the new option. * doc/make.1: Document in the man page. * doc/make.texi (Warnings): Document in the user's manual. * Makefile.am: Add new header warning.h. * src/warning.h: Define enum for actions and warning types, and macros to test whether they are set. Keep the default settings separate so that we can correctly reconstruct MAKEFLAGS. * src/makeint.h: Remove deprecated warn_undefined_variables_flag. * src/main.c: Create global variables to hold warning settings. (switches): Add a new switch for --warn. (initialize_warnings): Set the default warning actions. (main): Call initialize_warnings(). (encode_warning_state, decode_warning_state): Convert warning states between strings and enums. (encode_warning_name, decode_warning_name): Convert warning names between strings and enums. (decode_warn_flags): Convert a --warn option into enum values. If deprecated warn_undefined_variables_flag is set convert it to --warn. (decode_switches): Don't remove duplicates of --warn since order matters. Call decode_warn_flags() to handle --warn. (define_makeflags): Special-case handling of --warn options written to MAKEFLAGS: write out the current settings. * src/read.c (tilde_expand): Use new warning control macros. * src/variable.c (warn_undefined): Ditto. * src/job.c (construct_command_argv): Ditto. * tests/scripts/options/warn: Rename from warn-undefined-variables and add tests for --warn. * tests/scripts/variables/MAKEFLAGS: Expect the new behavior.
2023-02-26 23:04:14 +00:00
#MAKE#: 'all' is up to date.\n"
);
# Check undefined variable warnings
# With no options or with ignore, nothing should happen
run_make_test('
EMPTY =
EREF = $(EMPTY)
UREF = $(UNDEFINED)
SEREF := $(EREF)
SUREF := $(UREF)
all: ; @echo ref $(EREF) $(UREF)',
'', 'ref');
run_make_test(undef, '--warn=undefined-var:ignore', 'ref');
# Check warnings
run_make_test(undef, '--warn=undefined-var',
"#MAKEFILE#:7: warning: reference to undefined variable 'UNDEFINED'
#MAKEFILE#:9: warning: reference to undefined variable 'UNDEFINED'
Introduce a --warn command line option Replace the singleton --warn-undefined-variables with infrastructure to manage multiple warnings: the --warn option can take an action "ignore", "warn", or "error" (which will apply to all warnings), or a specific warning type and an action for that type. Multiple options can be provided and are consolidated. * NEWS: Announce the new option. * doc/make.1: Document in the man page. * doc/make.texi (Warnings): Document in the user's manual. * Makefile.am: Add new header warning.h. * src/warning.h: Define enum for actions and warning types, and macros to test whether they are set. Keep the default settings separate so that we can correctly reconstruct MAKEFLAGS. * src/makeint.h: Remove deprecated warn_undefined_variables_flag. * src/main.c: Create global variables to hold warning settings. (switches): Add a new switch for --warn. (initialize_warnings): Set the default warning actions. (main): Call initialize_warnings(). (encode_warning_state, decode_warning_state): Convert warning states between strings and enums. (encode_warning_name, decode_warning_name): Convert warning names between strings and enums. (decode_warn_flags): Convert a --warn option into enum values. If deprecated warn_undefined_variables_flag is set convert it to --warn. (decode_switches): Don't remove duplicates of --warn since order matters. Call decode_warn_flags() to handle --warn. (define_makeflags): Special-case handling of --warn options written to MAKEFLAGS: write out the current settings. * src/read.c (tilde_expand): Use new warning control macros. * src/variable.c (warn_undefined): Ditto. * src/job.c (construct_command_argv): Ditto. * tests/scripts/options/warn: Rename from warn-undefined-variables and add tests for --warn. * tests/scripts/variables/MAKEFLAGS: Expect the new behavior.
2023-02-26 23:04:14 +00:00
ref");
# Check and errors
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: warning: invalid variable reference 'bad variable'
#MAKEFILE#:10: warning: invalid variable reference 'also\nbad'
#MAKEFILE#:2: warning: 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: warning: invalid variable name 'BAD VAR'
#MAKEFILE#:11: warning: invalid variable name 'NL\nVAR'
#MAKEFILE#:13: warning: invalid variable name 'BAD DEF'
#MAKEFILE#:17: warning: invalid variable name 'NL\nDEF'
ref");
run_make_test(undef, '--warn=ignore', 'ref');
run_make_test(undef, '--warn=invalid-var:ignore', 'ref');
# Check errors
run_make_test(undef, '--warn=invalid-var:error',
"#MAKEFILE#:4: *** invalid variable name 'BAD VAR'. Stop.", 512);
# Make sure unknown warnings and actions fail when given on the command line.
run_make_test(undef, '--warn=no-such-warn',
"#MAKE#: *** unknown warning 'no-such-warn'. Stop.", 512);
run_make_test(undef, '--warn=invalid-var:no-such-action',
"#MAKE#: *** unknown warning action 'no-such-action'. Stop.", 512);
# sv 65739. Circular dependency.
run_make_test(q!
hello: hello; @:
!,
'', "#MAKE#: circular hello <- hello dependency dropped\n");
run_make_test(undef, '--warn=error', "#MAKE#: *** circular hello <- hello dependency detected. Stop.\n", 512);
run_make_test(undef, '--warn=circular-dep:error', "#MAKE#: *** circular hello <- hello dependency detected. Stop.\n", 512);
run_make_test(undef, '--warn=warn', "#MAKE#: circular hello <- hello dependency dropped\n");
run_make_test(undef, '--warn=circular-dep:warn', "#MAKE#: circular hello <- hello dependency dropped\n");
run_make_test(undef, '--warn=ignore', '');
run_make_test(undef, '--warn=circular-dep:ignore', '');
Introduce a --warn command line option Replace the singleton --warn-undefined-variables with infrastructure to manage multiple warnings: the --warn option can take an action "ignore", "warn", or "error" (which will apply to all warnings), or a specific warning type and an action for that type. Multiple options can be provided and are consolidated. * NEWS: Announce the new option. * doc/make.1: Document in the man page. * doc/make.texi (Warnings): Document in the user's manual. * Makefile.am: Add new header warning.h. * src/warning.h: Define enum for actions and warning types, and macros to test whether they are set. Keep the default settings separate so that we can correctly reconstruct MAKEFLAGS. * src/makeint.h: Remove deprecated warn_undefined_variables_flag. * src/main.c: Create global variables to hold warning settings. (switches): Add a new switch for --warn. (initialize_warnings): Set the default warning actions. (main): Call initialize_warnings(). (encode_warning_state, decode_warning_state): Convert warning states between strings and enums. (encode_warning_name, decode_warning_name): Convert warning names between strings and enums. (decode_warn_flags): Convert a --warn option into enum values. If deprecated warn_undefined_variables_flag is set convert it to --warn. (decode_switches): Don't remove duplicates of --warn since order matters. Call decode_warn_flags() to handle --warn. (define_makeflags): Special-case handling of --warn options written to MAKEFLAGS: write out the current settings. * src/read.c (tilde_expand): Use new warning control macros. * src/variable.c (warn_undefined): Ditto. * src/job.c (construct_command_argv): Ditto. * tests/scripts/options/warn: Rename from warn-undefined-variables and add tests for --warn. * tests/scripts/variables/MAKEFLAGS: Expect the new behavior.
2023-02-26 23:04:14 +00:00
1;