VirtualBox

source: kBuild/trunk/src/gmake/tests/scripts/functions/eval@ 285

Last change on this file since 285 was 285, checked in by bird, 20 years ago

This commit was generated by cvs2svn to compensate for changes in r284,
which included commits to RCS files with non-trunk default branches.

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1# -*-perl-*-
2
3$description = "Test the eval function.";
4
5$details = "This is a test of the eval function in GNU make.
6This function will evaluate inline makefile syntax and incorporate the
7results into its internal database.\n";
8
9open(MAKEFILE,"> $makefile");
10
11print MAKEFILE <<'EOF';
12define Y
13 all:: ; @echo $AA
14 A = B
15endef
16
17X = $(eval $(value Y))
18
19$(eval $(shell echo A = A))
20$(eval $(Y))
21$(eval A = C)
22$(eval $(X))
23EOF
24
25close(MAKEFILE);
26
27&run_make_with_options($makefile, "", &get_logfile);
28
29# Create the answer to what should be produced by this Makefile
30$answer = "AA\nBA\n";
31
32&compare_output($answer,&get_logfile(1));
33
34# Test to make sure defining variables when we have extra scope pushed works
35# as expected.
36
37$makefile2 = &get_tmpfile;
38
39open(MAKEFILE,"> $makefile2");
40
41print MAKEFILE <<'EOF';
42VARS = A B
43
44VARSET = $(1) = $(2)
45
46$(foreach v,$(VARS),$(eval $(call VARSET,$v,$v)))
47
48all: ; @echo A = $(A) B = $(B)
49EOF
50
51close(MAKEFILE);
52
53&run_make_with_options($makefile2, "", &get_logfile);
54
55# Create the answer to what should be produced by this Makefile
56$answer = "A = A B = B\n";
57
58&compare_output($answer,&get_logfile(1));
59
60# Test to make sure eval'ing inside conditionals works properly
61
62$makefile3 = &get_tmpfile;
63
64open(MAKEFILE,"> $makefile3");
65
66print MAKEFILE <<'EOF';
67FOO = foo
68
69all:: ; @echo it
70
71define Y
72 all:: ; @echo worked
73endef
74
75ifdef BAR
76$(eval $(Y))
77endif
78
79EOF
80
81close(MAKEFILE);
82
83&run_make_with_options($makefile3, "", &get_logfile);
84$answer = "it\n";
85&compare_output($answer,&get_logfile(1));
86
87&run_make_with_options($makefile3, "BAR=1", &get_logfile);
88$answer = "it\nworked\n";
89&compare_output($answer,&get_logfile(1));
90
91
92# TEST very recursive invocation of eval
93
94$makefile3 = &get_tmpfile;
95
96open(MAKEFILE,"> $makefile3");
97
98print MAKEFILE <<'EOF';
99..9 := 0 1 2 3 4 5 6 7 8 9
100rev=$(eval res:=)$(foreach word,$1,$(eval res:=${word} ${res}))${res}
101a:=$(call rev,${..9})
102all: ; @echo '[$(a)]'
103
104EOF
105
106close(MAKEFILE);
107
108&run_make_with_options($makefile3, "", &get_logfile);
109$answer = "[ 9 8 7 6 5 4 3 2 1 0 ]\n";
110&compare_output($answer,&get_logfile(1));
111
112
113# TEST eval with no filename context.
114# The trick here is that because EVAR is taken from the environment, it must
115# be evaluated before every command is invoked. Make sure that works, when
116# we have no file context for reading_file (bug # 6195)
117
118$makefile4 = &get_tmpfile;
119
120open(MAKEFILE,"> $makefile4");
121
122print MAKEFILE <<'EOF';
123EVAR = $(eval FOBAR = 1)
124all: ; @echo "OK"
125
126EOF
127
128close(MAKEFILE);
129
130$ENV{EVAR} = '1';
131&run_make_with_options($makefile4, "", &get_logfile);
132$answer = "OK\n";
133&compare_output($answer,&get_logfile(1));
134
135delete $ENV{EVAR};
136
137
138# Clean out previous information to allow new run_make_test() interface.
139# If we ever convert all the above to run_make_test() we can remove this line.
140$makefile = undef;
141
142# Test handling of backslashes in strings to be evaled.
143
144run_make_test('
145define FOO
146all: ; @echo hello \
147world
148endef
149$(eval $(FOO))
150', '', 'hello world');
151
152run_make_test('
153define FOO
154all: ; @echo he\llo
155 @echo world
156endef
157$(eval $(FOO))
158', '', 'hello
159world');
160
161
162# We don't allow new target/prerequisite relationships to be defined within a
163# command script, because these are evaluated after snap_deps() and that
164# causes lots of problems (like core dumps!)
165# See Savannah bug # 12124.
166
167run_make_test('deps: ; $(eval deps: foo)', '',
168 '#MAKEFILE#:1: *** prerequisites cannot be defined in command scripts. Stop.',
169 512);
170
1711;
Note: See TracBrowser for help on using the repository browser.

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