make/tests/scripts/options/warn

87 lines
2.6 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=undefined-var' => '=ignore,undefined-var',
'--warn=undefined-var:error --warn' => '=warn,undefined-var:error'
);
# 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");
# 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: reference to undefined variable 'averyveryveryloooooooooooooooooooooooooooongvariablename'
#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: reference to undefined variable 'UNDEFINED'
#MAKEFILE#:9: reference to undefined variable 'UNDEFINED'
ref");
# Check and errors
run_make_test(undef, '--warn=undefined-var:error',
"#MAKEFILE#:7: *** reference to undefined variable 'UNDEFINED'. Stop.", 512);
1;