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