summaryrefslogtreecommitdiff
path: root/tests/scripts/functions/eval
blob: cfb27b22b55b37cefb4f22f3a1c9903ba1feb6bb (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
#                                                                    -*-perl-*-

$description = "Test the eval function.";

$details = "This is a test of the eval function in GNU make.
This function will evaluate inline makefile syntax and incorporate the
results into its internal database.\n";

open(MAKEFILE,"> $makefile");

print MAKEFILE <<'EOF';
define Y
  all:: ; @echo $AA
  A = B
endef

X = $(eval $(value Y))

$(eval $(shell echo A = A))
$(eval $(Y))
$(eval A = C)
$(eval $(X))
EOF

close(MAKEFILE);

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

# Create the answer to what should be produced by this Makefile
$answer = "AA\nBA\n";

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

# Test to make sure defining variables when we have extra scope pushed works
# as expected.

$makefile2 = &get_tmpfile;

open(MAKEFILE,"> $makefile2");

print MAKEFILE <<'EOF';
VARS = A B

VARSET = $(1) = $(2)

$(foreach v,$(VARS),$(eval $(call VARSET,$v,$v)))

all: ; @echo A = $(A) B = $(B)
EOF

close(MAKEFILE);

&run_make_with_options($makefile2, "", &get_logfile);

# Create the answer to what should be produced by this Makefile
$answer = "A = A B = B\n";

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

# Test to make sure eval'ing inside conditionals works properly

$makefile3 = &get_tmpfile;

open(MAKEFILE,"> $makefile3");

print MAKEFILE <<'EOF';
FOO = foo

all:: ; @echo it

define Y
  all:: ; @echo worked
endef

ifdef BAR
$(eval $(Y))
endif

EOF

close(MAKEFILE);

&run_make_with_options($makefile3, "", &get_logfile);
$answer = "it\n";
&compare_output($answer,&get_logfile(1));

&run_make_with_options($makefile3, "BAR=1", &get_logfile);
$answer = "it\nworked\n";
&compare_output($answer,&get_logfile(1));


# TEST very recursive invocation of eval

$makefile3 = &get_tmpfile;

open(MAKEFILE,"> $makefile3");

print MAKEFILE <<'EOF';
..9 := 0 1 2 3 4 5 6 7 8 9
rev=$(eval res:=)$(foreach word,$1,$(eval res:=${word} ${res}))${res}
a:=$(call rev,${..9})
all: ; @echo '[$(a)]'

EOF

close(MAKEFILE);

&run_make_with_options($makefile3, "", &get_logfile);
$answer = "[         9 8 7 6 5 4 3 2 1 0 ]\n";
&compare_output($answer,&get_logfile(1));

1;