make/tests/scripts/features/se_statpat
Dmitry Goncharov 8c2aa889bb [SV 62324] Simplify set_file_variables by passing in the stem
Previously we always used the file->stem value as our stem in
set_file_variables(); when that wasn't correct we had to temporarily
set that value while the function was called, then reset it afterward.
This led to issues (for example when we assumed the stem was a cached
string but it wasn't).

Avoid this by passing in the stem as an argument so that different
values can be provided.

Add tests to verify this.

* src/commands.c (set_file_variables): Take second parameter stem to
relieve the callers of set_file_variables() from setting/restoring
file->stem.
* src/commands.h (set_file_variables): Ditto.
(execute_file_commands): Pass file->stem to set_file_variables().
* src/file.c (expand_deps): Pass d->stem to set_file_variables() and
remove set and restore of file->stem.
* src/implicit.c (pattern_search): Pass stem to set_file_variables()
and remove set and restore of file->stem.
* tests/scripts/features/se_explicit: Add new tests.
* tests/scripts/features/se_implicit: Ditto.
* tests/scripts/features/se_statpat: Ditto.
* tests/scripts/variables/automatic: Ditto.
2022-04-24 10:39:32 -04:00

114 lines
1.8 KiB
Perl

# -*-perl-*-
$description = "Test second expansion in static pattern rules.";
$details = "";
# Test #1: automatic variables.
#
run_make_test(q!
.SECONDEXPANSION:
.DEFAULT: ; @echo '$@'
foo.a foo.b: foo.%: bar.% baz.%
foo.a foo.b: foo.%: biz.% | buz.%
foo.a foo.b: foo.%: $$@.1 \
$$<.2 \
$$(addsuffix .3,$$^) \
$$(addsuffix .4,$$+) \
$$|.5 \
$$*.6
!,
'', 'bar.a
baz.a
biz.a
buz.a
foo.a.1
bar.a.2
bar.a.3
baz.a.3
biz.a.3
bar.a.4
baz.a.4
biz.a.4
buz.a.5
a.6
');
# Test #2: target/pattern -specific variables.
#
run_make_test(q!
.SECONDEXPANSION:
.DEFAULT: ; @echo '$@'
foo.x foo.y: foo.%: $$(%_a) $$($$*_b)
foo.x: x_a := bar
%.x: x_b := baz
!,
'', "bar\nbaz\n");
# Test #3: order of prerequisites.
#
run_make_test(q!
.SECONDEXPANSION:
.DEFAULT: ; @echo '$@'
all: foo.a bar.a baz.a
# Subtest #1
foo.a foo.b: foo.%: foo.%.1; @:
foo.a foo.b: foo.%: foo.%.2
foo.a foo.b: foo.%: foo.%.3
# Subtest #2
bar.a bar.b: bar.%: bar.%.2
bar.a bar.b: bar.%: bar.%.1; @:
bar.a bar.b: bar.%: bar.%.3
# Subtest #3
baz.a baz.b: baz.%: baz.%.1
baz.a baz.b: baz.%: baz.%.2
baz.a baz.b: ; @:
!,
'', 'foo.a.1
foo.a.2
foo.a.3
bar.a.1
bar.a.2
bar.a.3
baz.a.1
baz.a.2
');
# Test #4: Make sure stem triple-expansion does not happen.
#
run_make_test(q!
.SECONDEXPANSION:
foo$$bar: f%r: % $$*.1
@echo '$*'
oo$$ba oo$$ba.1:
@echo '$@'
!,
'', 'oo$ba
oo$ba.1
oo$ba
');
# sv 62324.
# Integrity self check.
run_make_test(q!
.SECONDEXPANSION:
all: bye.x
bye.x: %.x: $$(firstword %.1;
!, '', "#MAKEFILE#:4: *** unterminated call to function 'firstword': missing ')'. Stop.", 512);
# This tells the test driver that the perl test script executed properly.
1;