VirtualBox

source: kBuild/trunk/src/kmk/tests/scripts/functions/foreach@ 2175

Last change on this file since 2175 was 2175, checked in by bird, 16 years ago

another test which doesn't work right without -j1.

  • Property svn:eol-style set to LF
File size: 2.2 KB
Line 
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.
7This function starts with a space separated list of
8names and a variable. Each name in the list is subsituted
9into the variable and the given text evaluated. The general
10form of the command is $(foreach var,$list,$text). Several
11types 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# kmk: CC isn't a default.
18$extraENV{FOOFOO} = 'foo foo';
19$CC_origin = $is_kmk ? "undefined" : "default";
20
21run_make_test("space = ' '".'
22null :=
23auto_var = udef space CC null FOOFOO MAKE foo CFLAGS WHITE @ <
24foo = bletch null @ garf
25av = $(foreach var, $(auto_var), $(origin $(var)) )
26override WHITE := BLACK
27for_var = $(addsuffix .c,foo $(null) $(foo) $(space) $(av) )
28fe = $(foreach var2, $(for_var),$(subst .c,.o, $(var2) ) )
29all: auto for2
30auto : ; @echo $(av)
31for2: ; @echo $(fe)',
32 '-j1 -e WHITE=WHITE CFLAGS=',
33 "undefined file ". $CC_origin ." file environment default file command line override automatic automatic
34foo.o bletch.o null.o @.o garf.o .o .o undefined.o file.o ". $CC_origin .".o file.o environment.o default.o file.o command.o line.o override.o automatic.o automatic.o");
35
36delete $extraENV{FOOFOO};
37
38# TEST 1: Test that foreach variables take precedence over global
39# variables in a global scope (like inside an eval). Tests bug #11913
40
41run_make_test('
42.PHONY: all target
43all: target
44
45x := BAD
46
47define mktarget
48target: x := $(x)
49target: ; @echo "$(x)"
50endef
51
52x := GLOBAL
53
54$(foreach x,FOREACH,$(eval $(value mktarget)))',
55 '',
56 'FOREACH');
57
58
59# TEST 2: Check some error conditions.
60
61run_make_test('
62x = $(foreach )
63y = $x
64
65all: ; @echo $y',
66 '',
67 "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.",
68 512);
69
70run_make_test('
71x = $(foreach )
72y := $x
73
74all: ; @echo $y',
75 '',
76 "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.",
77 512);
78
791;
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette