Convert all "`'" quotes to "''" per new GNU Coding Standard guidelines.
[make.git] / tests / scripts / functions / foreach
blobf406f7a6bc7f54be89de6287f86b4af39e8d1244
1 #                                                                    -*-perl-*-
2 # $Id: foreach,v 1.6 2012/03/04 00:24:33 psmith Exp $
4 $description = "Test the foreach function.";
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";
14 # TEST 0
16 # Set an environment variable that we can test in the makefile.
17 $extraENV{FOOFOO} = 'foo foo';
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");
34 delete $extraENV{FOOFOO};
36 # TEST 1: Test that foreach variables take precedence over global
37 # variables in a global scope (like inside an eval).  Tests bug #11913
39 run_make_test('
40 .PHONY: all target
41 all: target
43 x := BAD
45 define mktarget
46 target: x := $(x)
47 target: ; @echo "$(x)"
48 endef
50 x := GLOBAL
52 $(foreach x,FOREACH,$(eval $(value mktarget)))',
53               '',
54               'FOREACH');
57 # TEST 2: Check some error conditions.
59 run_make_test('
60 x = $(foreach )
61 y = $x
63 all: ; @echo $y',
64               '',
65               "#MAKEFILE#:2: *** insufficient number of arguments (1) to function 'foreach'.  Stop.",
66               512);
68 run_make_test('
69 x = $(foreach )
70 y := $x
72 all: ; @echo $y',
73               '',
74               "#MAKEFILE#:2: *** insufficient number of arguments (1) to function 'foreach'.  Stop.",
75               512);