1 | # -*-perl-*-
|
---|
2 | # $Id: foreach,v 1.5 2006/03/10 02:20:46 psmith Exp $
|
---|
3 |
|
---|
4 | $description = "Test the foreach function.";
|
---|
5 |
|
---|
6 | $details = "This is a test of the foreach function in gnu make.
|
---|
7 | This function starts with a space separated list of
|
---|
8 | names and a variable. Each name in the list is subsituted
|
---|
9 | into the variable and the given text evaluated. The general
|
---|
10 | form of the command is $(foreach var,$list,$text). Several
|
---|
11 | types of foreach loops are tested\n";
|
---|
12 |
|
---|
13 |
|
---|
14 | # TEST 0
|
---|
15 |
|
---|
16 | # Set an environment variable that we can test in the makefile.
|
---|
17 | $extraENV{FOOFOO} = 'foo foo';
|
---|
18 |
|
---|
19 | run_make_test("space = ' '".'
|
---|
20 | null :=
|
---|
21 | auto_var = udef space CC null FOOFOO MAKE foo CFLAGS WHITE @ <
|
---|
22 | foo = bletch null @ garf
|
---|
23 | av = $(foreach var, $(auto_var), $(origin $(var)) )
|
---|
24 | override WHITE := BLACK
|
---|
25 | for_var = $(addsuffix .c,foo $(null) $(foo) $(space) $(av) )
|
---|
26 | fe = $(foreach var2, $(for_var),$(subst .c,.o, $(var2) ) )
|
---|
27 | all: auto for2
|
---|
28 | auto : ; @echo $(av)
|
---|
29 | for2: ; @echo $(fe)',
|
---|
30 | '-e WHITE=WHITE CFLAGS=',
|
---|
31 | "undefined file default file environment default file command line override automatic automatic
|
---|
32 | foo.o bletch.o null.o @.o garf.o .o .o undefined.o file.o default.o file.o environment.o default.o file.o command.o line.o override.o automatic.o automatic.o");
|
---|
33 |
|
---|
34 | delete $extraENV{FOOFOO};
|
---|
35 |
|
---|
36 | # TEST 1: Test that foreach variables take precedence over global
|
---|
37 | # variables in a global scope (like inside an eval). Tests bug #11913
|
---|
38 |
|
---|
39 | run_make_test('
|
---|
40 | .PHONY: all target
|
---|
41 | all: target
|
---|
42 |
|
---|
43 | x := BAD
|
---|
44 |
|
---|
45 | define mktarget
|
---|
46 | target: x := $(x)
|
---|
47 | target: ; @echo "$(x)"
|
---|
48 | endef
|
---|
49 |
|
---|
50 | x := GLOBAL
|
---|
51 |
|
---|
52 | $(foreach x,FOREACH,$(eval $(value mktarget)))',
|
---|
53 | '',
|
---|
54 | 'FOREACH');
|
---|
55 |
|
---|
56 |
|
---|
57 | # TEST 2: Check some error conditions.
|
---|
58 |
|
---|
59 | run_make_test('
|
---|
60 | x = $(foreach )
|
---|
61 | y = $x
|
---|
62 |
|
---|
63 | all: ; @echo $y',
|
---|
64 | '',
|
---|
65 | "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.",
|
---|
66 | 512);
|
---|
67 |
|
---|
68 | run_make_test('
|
---|
69 | x = $(foreach )
|
---|
70 | y := $x
|
---|
71 |
|
---|
72 | all: ; @echo $y',
|
---|
73 | '',
|
---|
74 | "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.",
|
---|
75 | 512);
|
---|
76 |
|
---|
77 | 1;
|
---|