| 1 |
# -*-perl-*- |
| 2 |
# $Id$ |
| 3 |
|
| 4 |
$description = "Test the let function."; |
| 5 |
|
| 6 |
$details = "This is a test of the let function in gnu make. |
| 7 |
This function destructures a list of values and binds each |
| 8 |
value to a variable name in a list of variable names. |
| 9 |
Superfluous variable names are assigned the empty string and |
| 10 |
the remaining values are assigned to the last variable name. |
| 11 |
The binding holds for the duration of the evaluation of the |
| 12 |
given text and no longer. The general form of the command |
| 13 |
is $(let \$vars,\$list,\$text). Several types of let |
| 14 |
assignments are tested\n"; |
| 15 |
|
| 16 |
# check for mismatched var and list word counts |
| 17 |
run_make_test(q! |
| 18 |
a = bad |
| 19 |
b = news |
| 20 |
x = $(let a b,1 2,$a $b) |
| 21 |
y = $(let a,1 2,$a) |
| 22 |
z = $(let a b,1,$a $b) |
| 23 |
all:;@echo 'a=,$a,' 'b=,$b,' 'x=,$x,' 'y=,$y,' 'z=,$z,' |
| 24 |
!, |
| 25 |
'', "a=,bad, b=,news, x=,1 2, y=,1 2, z=,1 ,\n"); |
| 26 |
|
| 27 |
# check for whitespace |
| 28 |
run_make_test(q! |
| 29 |
a = bad |
| 30 |
b = news |
| 31 |
x = $(let a b, 1 2 ,+$a+$b+) |
| 32 |
y = $(let a, 1 2 ,+$a+) |
| 33 |
z = $(let a b, 1 ,+$a+$b+) |
| 34 |
all:;@echo 'a=,$a,' 'b=,$b,' 'x=,$x,' 'y=,$y,' 'z=,$z,' |
| 35 |
!, |
| 36 |
'', "a=,bad, b=,news, x=,+1+2 +, y=,+1 2 +, z=,+1++,\n"); |
| 37 |
|
| 38 |
# Allow empty variable names and empty value list. |
| 39 |
# We still expand the list and body. |
| 40 |
run_make_test(' |
| 41 |
null = |
| 42 |
v = $(let ,$(info blankvar),abc) |
| 43 |
x = $(let $(null),$(info side-effect),abc) |
| 44 |
y = $(let y,,$ydef) |
| 45 |
|
| 46 |
all: ; @echo $v/$x/$y', |
| 47 |
'', "blankvar\nside-effect\nabc/abc/def\n"); |
| 48 |
|
| 49 |
# The example macro from the manual. |
| 50 |
run_make_test(' |
| 51 |
reverse = $(let first rest,$1,$(if $(rest),$(call reverse,$(rest)) )$(first)) |
| 52 |
|
| 53 |
all: ; @echo $(call reverse, \ |
| 54 |
moe miny meeny eeny \ |
| 55 |
)', |
| 56 |
'', "eeny meeny miny moe\n"); |
| 57 |
|
| 58 |
|
| 59 |
# Set an environment variable that we can test in the makefile. |
| 60 |
$ENV{FOOFOO} = 'foo foo'; |
| 61 |
|
| 62 |
# Verify masking: expansion outside the scope of let is unaffected. |
| 63 |
run_make_test(' |
| 64 |
auto_var = \ |
| 65 |
udef \ |
| 66 |
CC \ |
| 67 |
FOOFOO \ |
| 68 |
MAKE \ |
| 69 |
foo \ |
| 70 |
CFLAGS \ |
| 71 |
WHITE \ |
| 72 |
@ \ |
| 73 |
< |
| 74 |
av = $(foreach var, $(auto_var), $(origin $(var)) ) |
| 75 |
foo = bletch null @ garf |
| 76 |
override WHITE := BLACK |
| 77 |
|
| 78 |
define mktarget |
| 79 |
target: foo := $(foo) |
| 80 |
target: ; @echo $(AR)_$(foo)_ |
| 81 |
endef |
| 82 |
|
| 83 |
all: auto target |
| 84 |
auto: ; @echo $(let $(auto_var),,$(av)) $(av) |
| 85 |
$(let AR foo,bar foo ,$(eval $(value mktarget)))', |
| 86 |
'-e WHITE=WHITE CFLAGS=', |
| 87 |
"automatic automatic automatic automatic automatic automatic automatic automatic automatic undefined default environment default file command line override automatic automatic |
| 88 |
ar_foo _ |
| 89 |
"); |
| 90 |
|
| 91 |
|
| 92 |
# Check some error conditions. |
| 93 |
run_make_test(' |
| 94 |
x = $(let ) |
| 95 |
y = $x |
| 96 |
|
| 97 |
all: ; @echo $y', |
| 98 |
'', |
| 99 |
"#MAKEFILE#:2: *** insufficient number of arguments (1) to function 'let'. Stop.", |
| 100 |
512); |
| 101 |
|
| 102 |
run_make_test(' |
| 103 |
x = $(let x,y) |
| 104 |
y := $x |
| 105 |
|
| 106 |
all: ; @echo $y', |
| 107 |
'', |
| 108 |
"#MAKEFILE#:2: *** insufficient number of arguments (2) to function 'let'. Stop.", |
| 109 |
512); |
| 110 |
|
| 111 |
1; |