Debian Codegraph @

tests/scripts/features/shell_assignment

raw
1 # -*-perl-*-
2
3 $description = "Test BSD-style shell assignments (VAR != VAL) for variables.";
4
5 $details = "";
6
7 # TEST 0: Basic shell assignment (!=).
8
9 run_make_test('
10 .POSIX:
11
12 demo1!=printf \' 1 2 3\n4\n\n5 \n \n 6\n\n\n\n\'
13 demo2 != printf \'7 8\n \'
14 demo3 != printf \'$$(demo2)\'
15 demo4 != printf \' 2 3 \n\'
16 demo5 != printf \' 2 3 \n\n\'
17 all: ; @echo "<$(demo1)> <$(demo2)> <$(demo3)> <$(demo4)> <${demo5}>"
18 ',
19 '', "< 1 2 3 4 5 6 > <7 8 > <7 8 > < 2 3 > < 2 3 >\n");
20
21 # TEST 1: Handle '#' the same way as BSD make
22 $hashOctal = "\\043";
23 if ($osname eq 'os390') {
24 $hashOctal = "\\173";
25 }
26
27 run_make_test('
28 foo1!=echo bar#baz
29 hash != printf \'' . $hashOctal . '\'
30 foo2!= echo "bar$(hash)baz"
31
32 all: ; @echo "<$(foo1)> <$(hash)> <$(foo2)>"
33 ',
34 '', "<bar> <#> <bar#baz>\n");
35
36 # TEST 2: shell assignment variables (from !=) should be recursive.
37 # Note that variables are re-evaluated later, so the shell can output
38 # a value like $(XYZZY) as part of !=. The $(XYZZY) will be EVALUATED
39 # when the value containing it is evaluated. On the negative side, this
40 # means if you don't want this, you need to escape dollar signs as $$.
41 # On the positive side, it means that shell programs can output macros
42 # that are then evaluated as they are traditionally evaluated.. and that
43 # you can use traditional macro evaluation semantics to implement !=.
44
45 run_make_test('
46 XYZZY = fiddle-dee-dee
47 dollar = $$
48 VAR3 != printf \'%s\' \'$(dollar)(XYZZY)\'
49
50 all: ; @echo "<$(VAR3)>"
51 ',
52 '', "<fiddle-dee-dee>\n");
53
54
55 # TEST 3: Overrides invoke shell anyway; they just don't store the result
56 # in a way that is visible.
57
58 run_make_test('
59
60 override != echo abc > ,abc ; cat ,abc
61
62 all: ; @echo "<$(override)>" ; cat ,abc
63 ',
64 'override=xyz', "<xyz>\nabc\n");
65
66 unlink(',abc');
67
68
69 1;