VirtualBox

source: kBuild/vendor/gnumake/current/tests/scripts/functions/foreach@ 3208

最後變更 在這個檔案從3208是 3138,由 bird 提交於 7 年 前

Imported make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6) from https://git.savannah.gnu.org/git/make.git.

  • 屬性 svn:eol-style 設為 LF
檔案大小: 2.3 KB
 
1# -*-perl-*-
2# $Id$
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$extraENV{FOOFOO} = 'foo foo';
18
19run_make_test("space = ' '".'
20null :=
21auto_var = udef space CC null FOOFOO MAKE foo CFLAGS WHITE @ <
22foo = bletch null @ garf
23av = $(foreach var, $(auto_var), $(origin $(var)) )
24override WHITE := BLACK
25for_var = $(addsuffix .c,foo $(null) $(foo) $(space) $(av) )
26fe = $(foreach var2, $(for_var),$(subst .c,.o, $(var2) ) )
27all: auto for2
28auto : ; @echo $(av)
29for2: ; @echo $(fe)',
30 '-e WHITE=WHITE CFLAGS=',
31 "undefined file default file environment default file command line override automatic automatic
32foo.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
34delete $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
39run_make_test('
40.PHONY: all target
41all: target
42
43x := BAD
44
45define mktarget
46target: x := $(x)
47target: ; @echo "$(x)"
48endef
49
50x := GLOBAL
51
52$(foreach x,FOREACH,$(eval $(value mktarget)))',
53 '',
54 'FOREACH');
55
56# Allow variable names with trailing space
57run_make_test(q!
58$(foreach \
59 a \
60, b c d \
61, $(info $a))
62all:;@:
63!,
64 "", "b\nc\nd\n");
65
66# Allow empty variable names. We still expand the body.
67
68run_make_test('
69x = $(foreach ,1 2 3,a)
70y := $x
71
72all: ; @echo $y',
73 '', "a a a\n");
74
75# Check some error conditions.
76
77run_make_test('
78x = $(foreach )
79y = $x
80
81all: ; @echo $y',
82 '',
83 "#MAKEFILE#:2: *** insufficient number of arguments (1) to function 'foreach'. Stop.",
84 512);
85
86run_make_test('
87x = $(foreach x,y)
88y := $x
89
90all: ; @echo $y',
91 '',
92 "#MAKEFILE#:2: *** insufficient number of arguments (2) to function 'foreach'. Stop.",
93 512);
94
951;
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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