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 | $ENV{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 | delete $ENV{FOO};
|
---|
69 |
|
---|
70 | # TEST 2: global export. Explicit unexport takes precedence.
|
---|
71 |
|
---|
72 | &run_make_with_options($makefile,"EXPORT_ALL=1",&get_logfile,0);
|
---|
73 |
|
---|
74 | $answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
|
---|
75 | FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
|
---|
76 |
|
---|
77 | &compare_output($answer,&get_logfile(1));
|
---|
78 |
|
---|
79 | # TEST 3: global unexport. Explicit export takes precedence.
|
---|
80 |
|
---|
81 | &run_make_with_options($makefile,"UNEXPORT_ALL=1",&get_logfile,0);
|
---|
82 |
|
---|
83 | $answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
|
---|
84 | FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
|
---|
85 |
|
---|
86 | &compare_output($answer,&get_logfile(1));
|
---|
87 |
|
---|
88 | # TEST 4: both: in the above makefile the unexport comes last so that rules.
|
---|
89 |
|
---|
90 | &run_make_with_options($makefile,"EXPORT_ALL=1 UNEXPORT_ALL=1",&get_logfile,0);
|
---|
91 |
|
---|
92 | $answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
|
---|
93 | FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
|
---|
94 |
|
---|
95 | &compare_output($answer,&get_logfile(1));
|
---|
96 |
|
---|
97 | # TEST 5: test the pseudo target.
|
---|
98 |
|
---|
99 | &run_make_with_options($makefile,"EXPORT_ALL_PSEUDO=1",&get_logfile,0);
|
---|
100 |
|
---|
101 | $answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
|
---|
102 | FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
|
---|
103 |
|
---|
104 | &compare_output($answer,&get_logfile(1));
|
---|
105 |
|
---|
106 |
|
---|
107 | # TEST 6: Test the expansion of variables inside export
|
---|
108 |
|
---|
109 | $makefile2 = &get_tmpfile;
|
---|
110 |
|
---|
111 | open(MAKEFILE, "> $makefile2");
|
---|
112 |
|
---|
113 | print MAKEFILE <<'EOF';
|
---|
114 |
|
---|
115 | foo = f-ok
|
---|
116 | bar = b-ok
|
---|
117 |
|
---|
118 | FOO = foo
|
---|
119 | F = f
|
---|
120 |
|
---|
121 | BAR = bar
|
---|
122 | B = b
|
---|
123 |
|
---|
124 | export $(FOO)
|
---|
125 | export $(B)ar
|
---|
126 |
|
---|
127 | all:
|
---|
128 | @echo foo=$(foo) bar=$(bar)
|
---|
129 | @echo foo=$$foo bar=$$bar
|
---|
130 |
|
---|
131 | EOF
|
---|
132 |
|
---|
133 | close(MAKEFILE);
|
---|
134 |
|
---|
135 | &run_make_with_options($makefile2,"",&get_logfile,0);
|
---|
136 | $answer = "foo=f-ok bar=b-ok\nfoo=f-ok bar=b-ok\n";
|
---|
137 | &compare_output($answer,&get_logfile(1));
|
---|
138 |
|
---|
139 |
|
---|
140 | # TEST 7: Test the expansion of variables inside unexport
|
---|
141 |
|
---|
142 | $makefile3 = &get_tmpfile;
|
---|
143 |
|
---|
144 | open(MAKEFILE, "> $makefile3");
|
---|
145 |
|
---|
146 | print MAKEFILE <<'EOF';
|
---|
147 |
|
---|
148 | foo = f-ok
|
---|
149 | bar = b-ok
|
---|
150 |
|
---|
151 | FOO = foo
|
---|
152 | F = f
|
---|
153 |
|
---|
154 | BAR = bar
|
---|
155 | B = b
|
---|
156 |
|
---|
157 | export foo bar
|
---|
158 |
|
---|
159 | unexport $(FOO)
|
---|
160 | unexport $(B)ar
|
---|
161 |
|
---|
162 | all:
|
---|
163 | @echo foo=$(foo) bar=$(bar)
|
---|
164 | @echo foo=$$foo bar=$$bar
|
---|
165 |
|
---|
166 | EOF
|
---|
167 |
|
---|
168 | close(MAKEFILE);
|
---|
169 |
|
---|
170 | &run_make_with_options($makefile3,"",&get_logfile,0);
|
---|
171 | $answer = "foo=f-ok bar=b-ok\nfoo= bar=\n";
|
---|
172 | &compare_output($answer,&get_logfile(1));
|
---|
173 |
|
---|
174 |
|
---|
175 | # TEST 7: Test exporting multiple variables on the same line
|
---|
176 |
|
---|
177 | $makefile4 = &get_tmpfile;
|
---|
178 |
|
---|
179 | open(MAKEFILE, "> $makefile4");
|
---|
180 |
|
---|
181 | print MAKEFILE <<'EOF';
|
---|
182 |
|
---|
183 | A = a
|
---|
184 | B = b
|
---|
185 | C = c
|
---|
186 | D = d
|
---|
187 | E = e
|
---|
188 | F = f
|
---|
189 | G = g
|
---|
190 | H = h
|
---|
191 | I = i
|
---|
192 | J = j
|
---|
193 |
|
---|
194 | SOME = A B C
|
---|
195 |
|
---|
196 | export F G H I J
|
---|
197 |
|
---|
198 | export D E $(SOME)
|
---|
199 |
|
---|
200 | all: ; @echo A=$$A B=$$B C=$$C D=$$D E=$$E F=$$F G=$$G H=$$H I=$$I J=$$J
|
---|
201 | EOF
|
---|
202 |
|
---|
203 | close(MAKEFILE);
|
---|
204 |
|
---|
205 | &run_make_with_options($makefile4,"",&get_logfile,0);
|
---|
206 | $answer = "A=a B=b C=c D=d E=e F=f G=g H=h I=i J=j\n";
|
---|
207 | &compare_output($answer,&get_logfile(1));
|
---|
208 |
|
---|
209 |
|
---|
210 | # TEST 8: Test unexporting multiple variables on the same line
|
---|
211 |
|
---|
212 | $makefile5 = &get_tmpfile;
|
---|
213 |
|
---|
214 | open(MAKEFILE, "> $makefile5");
|
---|
215 |
|
---|
216 | print MAKEFILE <<'EOF';
|
---|
217 |
|
---|
218 | A = a
|
---|
219 | B = b
|
---|
220 | C = c
|
---|
221 | D = d
|
---|
222 | E = e
|
---|
223 | F = f
|
---|
224 | G = g
|
---|
225 | H = h
|
---|
226 | I = i
|
---|
227 | J = j
|
---|
228 |
|
---|
229 | SOME = A B C
|
---|
230 |
|
---|
231 | unexport F G H I J
|
---|
232 |
|
---|
233 | unexport D E $(SOME)
|
---|
234 |
|
---|
235 | all: ; @echo A=$$A B=$$B C=$$C D=$$D E=$$E F=$$F G=$$G H=$$H I=$$I J=$$J
|
---|
236 | EOF
|
---|
237 |
|
---|
238 | close(MAKEFILE);
|
---|
239 |
|
---|
240 | @ENV{qw(A B C D E F G H I J)} = qw(1 2 3 4 5 6 7 8 9 10);
|
---|
241 |
|
---|
242 | &run_make_with_options($makefile5,"",&get_logfile,0);
|
---|
243 | $answer = "A= B= C= D= E= F= G= H= I= J=\n";
|
---|
244 | &compare_output($answer,&get_logfile(1));
|
---|
245 |
|
---|
246 | delete @ENV{qw(A B C D E F G H I J)};
|
---|
247 |
|
---|
248 |
|
---|
249 | # This tells the test driver that the perl test script executed properly.
|
---|
250 | 1;
|
---|