summaryrefslogtreecommitdiff
path: root/tests/scripts/features/export
blob: 09aeac2fe12de745a9370b81a718f81d168e662e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#                                                                    -*-perl-*-
$description = "Check GNU make export/unexport commands.";

$details = "";

# The test driver cleans out our environment for us so we don't have to worry
# about that here.

open(MAKEFILE,"> $makefile");

# The Contents of the MAKEFILE ...

print MAKEFILE <<'EOMAKE';

FOO = foo
BAR = bar
BOZ = boz

export BAZ = baz
export BOZ

BITZ = bitz
BOTZ = botz

export BITZ BOTZ
unexport BOTZ


ifdef EXPORT_ALL
export
endif

ifdef UNEXPORT_ALL
unexport
endif

ifdef EXPORT_ALL_PSEUDO
.EXPORT_ALL_VARIABLES:
endif

all:
	@echo "FOO=$(FOO) BAR=$(BAR) BAZ=$(BAZ) BOZ=$(BOZ) BITZ=$(BITZ) BOTZ=$(BOTZ)"
	@echo "FOO=$$FOO BAR=$$BAR BAZ=$$BAZ BOZ=$$BOZ BITZ=$$BITZ BOTZ=$$BOTZ"

EOMAKE

close(MAKEFILE);

# TEST 0: basics

&run_make_with_options($makefile,"",&get_logfile,0);

$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";

&compare_output($answer,&get_logfile(1));

# TEST 1: make sure vars inherited from the parent are exported

$ENV{FOO} = 1;

&run_make_with_options($makefile,"",&get_logfile,0);

$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
FOO=foo BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";

&compare_output($answer,&get_logfile(1));

delete $ENV{FOO};

# TEST 2: global export.  Explicit unexport takes precedence.

&run_make_with_options($makefile,"EXPORT_ALL=1",&get_logfile,0);

$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";

&compare_output($answer,&get_logfile(1));

# TEST 3: global unexport.  Explicit export takes precedence.

&run_make_with_options($makefile,"UNEXPORT_ALL=1",&get_logfile,0);

$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";

&compare_output($answer,&get_logfile(1));

# TEST 4: both: in the above makefile the unexport comes last so that rules.

&run_make_with_options($makefile,"EXPORT_ALL=1 UNEXPORT_ALL=1",&get_logfile,0);

$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";

&compare_output($answer,&get_logfile(1));

# TEST 5: test the pseudo target.

&run_make_with_options($makefile,"EXPORT_ALL_PSEUDO=1",&get_logfile,0);

$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";

&compare_output($answer,&get_logfile(1));


# TEST 6: Test the expansion of variables inside export

$makefile2 = &get_tmpfile;

open(MAKEFILE, "> $makefile2");

print MAKEFILE <<'EOF';

foo = f-ok
bar = b-ok

FOO = foo
F = f

BAR = bar
B = b

export $(FOO)
export $(B)ar

all:
	@echo foo=$(foo) bar=$(bar)
	@echo foo=$$foo bar=$$bar

EOF

&run_make_with_options($makefile2,"",&get_logfile,0);
$answer = "foo=f-ok bar=b-ok\nfoo=f-ok bar=b-ok\n";
&compare_output($answer,&get_logfile(1));


# TEST 7: Test the expansion of variables inside unexport

$makefile3 = &get_tmpfile;

open(MAKEFILE, "> $makefile3");

print MAKEFILE <<'EOF';

foo = f-ok
bar = b-ok

FOO = foo
F = f

BAR = bar
B = b

export foo bar

unexport $(FOO)
unexport $(B)ar

all:
	@echo foo=$(foo) bar=$(bar)
	@echo foo=$$foo bar=$$bar

EOF

&run_make_with_options($makefile3,"",&get_logfile,0);
$answer = "foo=f-ok bar=b-ok\nfoo= bar=\n";
&compare_output($answer,&get_logfile(1));


# This tells the test driver that the perl test script executed properly.
1;