1 | # -*-perl-*-
|
---|
2 | $description = "Check GNU make export/unexport commands.";
|
---|
3 |
|
---|
4 | $details = "";
|
---|
5 |
|
---|
6 | # The test driver cleans out our environment for us so we don't have to worry
|
---|
7 | # about that here.
|
---|
8 |
|
---|
9 | open(MAKEFILE,"> $makefile");
|
---|
10 |
|
---|
11 | # The Contents of the MAKEFILE ...
|
---|
12 |
|
---|
13 | print MAKEFILE <<'EOMAKE';
|
---|
14 |
|
---|
15 | FOO = foo
|
---|
16 | BAR = bar
|
---|
17 | BOZ = boz
|
---|
18 |
|
---|
19 | export BAZ = baz
|
---|
20 | export BOZ
|
---|
21 |
|
---|
22 | BITZ = bitz
|
---|
23 | BOTZ = botz
|
---|
24 |
|
---|
25 | export BITZ BOTZ
|
---|
26 | unexport BOTZ
|
---|
27 |
|
---|
28 | ifdef EXPORT_ALL
|
---|
29 | export
|
---|
30 | endif
|
---|
31 |
|
---|
32 | ifdef UNEXPORT_ALL
|
---|
33 | unexport
|
---|
34 | endif
|
---|
35 |
|
---|
36 | ifdef EXPORT_ALL_PSEUDO
|
---|
37 | .EXPORT_ALL_VARIABLES:
|
---|
38 | endif
|
---|
39 |
|
---|
40 | all:
|
---|
41 | @echo "FOO=$(FOO) BAR=$(BAR) BAZ=$(BAZ) BOZ=$(BOZ) BITZ=$(BITZ) BOTZ=$(BOTZ)"
|
---|
42 | @echo "FOO=$$FOO BAR=$$BAR BAZ=$$BAZ BOZ=$$BOZ BITZ=$$BITZ BOTZ=$$BOTZ"
|
---|
43 |
|
---|
44 | EOMAKE
|
---|
45 |
|
---|
46 | close(MAKEFILE);
|
---|
47 |
|
---|
48 | # TEST 0: basics
|
---|
49 |
|
---|
50 | &run_make_with_options($makefile,"",&get_logfile,0);
|
---|
51 |
|
---|
52 | $answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
|
---|
53 | FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
|
---|
54 |
|
---|
55 | &compare_output($answer,&get_logfile(1));
|
---|
56 |
|
---|
57 | # TEST 1: make sure vars inherited from the parent are exported
|
---|
58 |
|
---|
59 | $extraENV{FOO} = 1;
|
---|
60 |
|
---|
61 | &run_make_with_options($makefile,"",&get_logfile,0);
|
---|
62 |
|
---|
63 | $answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
|
---|
64 | FOO=foo BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
|
---|
65 |
|
---|
66 | &compare_output($answer,&get_logfile(1));
|
---|
67 |
|
---|
68 | # TEST 2: global export. Explicit unexport takes precedence.
|
---|
69 |
|
---|
70 | &run_make_with_options($makefile,"EXPORT_ALL=1",&get_logfile,0);
|
---|
71 |
|
---|
72 | $answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
|
---|
73 | FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
|
---|
74 |
|
---|
75 | &compare_output($answer,&get_logfile(1));
|
---|
76 |
|
---|
77 | # TEST 3: global unexport. Explicit export takes precedence.
|
---|
78 |
|
---|
79 | &run_make_with_options($makefile,"UNEXPORT_ALL=1",&get_logfile,0);
|
---|
80 |
|
---|
81 | $answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
|
---|
82 | FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
|
---|
83 |
|
---|
84 | &compare_output($answer,&get_logfile(1));
|
---|
85 |
|
---|
86 | # TEST 4: both: in the above makefile the unexport comes last so that rules.
|
---|
87 |
|
---|
88 | &run_make_with_options($makefile,"EXPORT_ALL=1 UNEXPORT_ALL=1",&get_logfile,0);
|
---|
89 |
|
---|
90 | $answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
|
---|
91 | FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
|
---|
92 |
|
---|
93 | &compare_output($answer,&get_logfile(1));
|
---|
94 |
|
---|
95 | # TEST 5: test the pseudo target.
|
---|
96 |
|
---|
97 | &run_make_with_options($makefile,"EXPORT_ALL_PSEUDO=1",&get_logfile,0);
|
---|
98 |
|
---|
99 | $answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
|
---|
100 | FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
|
---|
101 |
|
---|
102 | &compare_output($answer,&get_logfile(1));
|
---|
103 |
|
---|
104 |
|
---|
105 | # TEST 6: Test the expansion of variables inside export
|
---|
106 |
|
---|
107 | $makefile2 = &get_tmpfile;
|
---|
108 |
|
---|
109 | open(MAKEFILE, "> $makefile2");
|
---|
110 |
|
---|
111 | print MAKEFILE <<'EOF';
|
---|
112 |
|
---|
113 | foo = f-ok
|
---|
114 | bar = b-ok
|
---|
115 |
|
---|
116 | FOO = foo
|
---|
117 | F = f
|
---|
118 |
|
---|
119 | BAR = bar
|
---|
120 | B = b
|
---|
121 |
|
---|
122 | export $(FOO)
|
---|
123 | export $(B)ar
|
---|
124 |
|
---|
125 | all:
|
---|
126 | @echo foo=$(foo) bar=$(bar)
|
---|
127 | @echo foo=$$foo bar=$$bar
|
---|
128 |
|
---|
129 | EOF
|
---|
130 |
|
---|
131 | close(MAKEFILE);
|
---|
132 |
|
---|
133 | &run_make_with_options($makefile2,"",&get_logfile,0);
|
---|
134 | $answer = "foo=f-ok bar=b-ok\nfoo=f-ok bar=b-ok\n";
|
---|
135 | &compare_output($answer,&get_logfile(1));
|
---|
136 |
|
---|
137 |
|
---|
138 | # TEST 7: Test the expansion of variables inside unexport
|
---|
139 |
|
---|
140 | $makefile3 = &get_tmpfile;
|
---|
141 |
|
---|
142 | open(MAKEFILE, "> $makefile3");
|
---|
143 |
|
---|
144 | print MAKEFILE <<'EOF';
|
---|
145 |
|
---|
146 | foo = f-ok
|
---|
147 | bar = b-ok
|
---|
148 |
|
---|
149 | FOO = foo
|
---|
150 | F = f
|
---|
151 |
|
---|
152 | BAR = bar
|
---|
153 | B = b
|
---|
154 |
|
---|
155 | export foo bar
|
---|
156 |
|
---|
157 | unexport $(FOO)
|
---|
158 | unexport $(B)ar
|
---|
159 |
|
---|
160 | all:
|
---|
161 | @echo foo=$(foo) bar=$(bar)
|
---|
162 | @echo foo=$$foo bar=$$bar
|
---|
163 |
|
---|
164 | EOF
|
---|
165 |
|
---|
166 | close(MAKEFILE);
|
---|
167 |
|
---|
168 | &run_make_with_options($makefile3,"",&get_logfile,0);
|
---|
169 | $answer = "foo=f-ok bar=b-ok\nfoo= bar=\n";
|
---|
170 | &compare_output($answer,&get_logfile(1));
|
---|
171 |
|
---|
172 |
|
---|
173 | # TEST 7: Test exporting multiple variables on the same line
|
---|
174 |
|
---|
175 | $makefile4 = &get_tmpfile;
|
---|
176 |
|
---|
177 | open(MAKEFILE, "> $makefile4");
|
---|
178 |
|
---|
179 | print MAKEFILE <<'EOF';
|
---|
180 |
|
---|
181 | A = a
|
---|
182 | B = b
|
---|
183 | C = c
|
---|
184 | D = d
|
---|
185 | E = e
|
---|
186 | F = f
|
---|
187 | G = g
|
---|
188 | H = h
|
---|
189 | I = i
|
---|
190 | J = j
|
---|
191 |
|
---|
192 | SOME = A B C
|
---|
193 |
|
---|
194 | export F G H I J
|
---|
195 |
|
---|
196 | export D E $(SOME)
|
---|
197 |
|
---|
198 | all: ; @echo A=$$A B=$$B C=$$C D=$$D E=$$E F=$$F G=$$G H=$$H I=$$I J=$$J
|
---|
199 | EOF
|
---|
200 |
|
---|
201 | close(MAKEFILE);
|
---|
202 |
|
---|
203 | &run_make_with_options($makefile4,"",&get_logfile,0);
|
---|
204 | $answer = "A=a B=b C=c D=d E=e F=f G=g H=h I=i J=j\n";
|
---|
205 | &compare_output($answer,&get_logfile(1));
|
---|
206 |
|
---|
207 |
|
---|
208 | # TEST 8: Test unexporting multiple variables on the same line
|
---|
209 |
|
---|
210 | $makefile5 = &get_tmpfile;
|
---|
211 |
|
---|
212 | open(MAKEFILE, "> $makefile5");
|
---|
213 |
|
---|
214 | print MAKEFILE <<'EOF';
|
---|
215 |
|
---|
216 | A = a
|
---|
217 | B = b
|
---|
218 | C = c
|
---|
219 | D = d
|
---|
220 | E = e
|
---|
221 | F = f
|
---|
222 | G = g
|
---|
223 | H = h
|
---|
224 | I = i
|
---|
225 | J = j
|
---|
226 |
|
---|
227 | SOME = A B C
|
---|
228 |
|
---|
229 | unexport F G H I J
|
---|
230 |
|
---|
231 | unexport D E $(SOME)
|
---|
232 |
|
---|
233 | all: ; @echo A=$$A B=$$B C=$$C D=$$D E=$$E F=$$F G=$$G H=$$H I=$$I J=$$J
|
---|
234 | EOF
|
---|
235 |
|
---|
236 | close(MAKEFILE);
|
---|
237 |
|
---|
238 | @extraENV{qw(A B C D E F G H I J)} = qw(1 2 3 4 5 6 7 8 9 10);
|
---|
239 |
|
---|
240 | &run_make_with_options($makefile5,"",&get_logfile,0);
|
---|
241 | $answer = "A= B= C= D= E= F= G= H= I= J=\n";
|
---|
242 | &compare_output($answer,&get_logfile(1));
|
---|
243 |
|
---|
244 |
|
---|
245 | # This tells the test driver that the perl test script executed properly.
|
---|
246 | 1;
|
---|