Add new feature: != shell assignment for portability with BSD make.
[make.git] / tests / scripts / features / shell_assignment
blob686e4bd27cf526dab1b04bb3a92a59fd148a300d
1 #                                                                    -*-perl-*-
3 $description = "Test BSD-style shell assignments (VAR != VAL) for variables.";
5 $details = "";
7 # TEST 0: Basic shell assignment (!=).
9 run_make_test('
10 .POSIX:
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}>"
19               '', "<  1   2 3 4  5     6   > <7 8  > <7 8  > < 2 3 > < 2 3  >\n");
21 # TEST 1: Handle '#' the same way as BSD make
23 run_make_test('
24 foo1!=echo bar#baz
25 hash != printf \'\043\'
26 foo2!= echo "bar$(hash)baz"
28 all: ; @echo "<$(foo1)> <$(hash)> <$(foo2)>"
30               '', "<bar> <#> <bar#baz>\n");
32 # TEST 2: shell assignment variables (from !=) should be recursive.
33 # Note that variables are re-evaluated later, so the shell can output
34 # a value like $(XYZZY) as part of !=.  The $(XYZZY) will be EVALUATED
35 # when the value containing it is evaluated.  On the negative side, this
36 # means if you don't want this, you need to escape dollar signs as $$.
37 # On the positive side, it means that shell programs can output macros
38 # that are then evaluated as they are traditionally evaluated.. and that
39 # you can use traditional macro evaluation semantics to implement !=.
41 run_make_test('
42 XYZZY = fiddle-dee-dee
43 dollar = $$
44 VAR3 != printf \'%s\' \'$(dollar)(XYZZY)\'
46 all: ; @echo "<$(VAR3)>"
48               '', "<fiddle-dee-dee>\n");
51 # TEST 3: Overrides invoke shell anyway; they just don't store the result
52 # in a way that is visible.
54 run_make_test('
56 override != echo abc > ,abc ; cat ,abc
58 all: ; @echo "<$(override)>" ; cat ,abc
60               'override=xyz', "<xyz>\nabc\n");
62 unlink(',abc');