Add some more unit tests for variable flavors.
[make.git] / tests / scripts / variables / flavors
blob88e9ad59daa0ba39130dcf8a24f7da12ec310b29
1 #                                                                    -*-perl-*-
3 $description = "Test various flavors of make variable setting.";
5 $details = "";
7 open(MAKEFILE, "> $makefile");
9 # The Contents of the MAKEFILE ...
11 print MAKEFILE <<'EOF';
12 foo = $(bar)
13 bar = ${ugh}
14 ugh = Hello
16 all: multi ; @echo $(foo)
18 multi: ; $(multi)
20 x := foo
21 y := $(x) bar
22 x := later
24 nullstring :=
25 space := $(nullstring) $(nullstring)
27 next: ; @echo $x$(space)$y
29 define multi
30 @echo hi
31 echo there
32 endef
34 ifdef BOGUS
35 define
36 @echo error
37 endef
38 endif
40 define outer
41  define inner
42   A = B
43  endef
44 endef
46 $(eval $(outer))
48 outer: ; @echo $(inner)
50 EOF
52 # END of Contents of MAKEFILE
54 close(MAKEFILE);
56 # TEST #1
57 # -------
59 &run_make_with_options($makefile, "", &get_logfile);
60 $answer = "hi\necho there\nthere\nHello\n";
61 &compare_output($answer, &get_logfile(1));
63 # TEST #2
64 # -------
66 &run_make_with_options($makefile, "next", &get_logfile);
67 $answer = "later foo bar\n";
68 &compare_output($answer, &get_logfile(1));
70 # TEST #3
71 # -------
73 &run_make_with_options($makefile, "BOGUS=true", &get_logfile, 512);
74 $answer = "$makefile:24: *** empty variable name.  Stop.\n";
75 &compare_output($answer, &get_logfile(1));
77 # TEST #4
78 # -------
80 &run_make_with_options($makefile, "outer", &get_logfile);
81 $answer = "A = B\n";
82 &compare_output($answer, &get_logfile(1));
84 # Clean up from "old style" testing.  If all the above tests are converted to
85 # run_make_test() syntax than this line can be removed.
86 $makefile = undef;
88 # -------------------------
89 # Make sure that prefix characters apply properly to define/endef values.
91 # There's a bit of oddness here if you try to use a variable to hold the
92 # prefix character for a define.  Even though something like this:
94 #       define foo
95 #       echo bar
96 #       endef
98 #       all: ; $(V)$(foo)
100 # (where V=@) can be seen by the user to be obviously different than this:
102 #       define foo
103 #       $(V)echo bar
104 #       endef
106 #       all: ; $(foo)
108 # and the user thinks it should behave the same as when the "@" is literal
109 # instead of in a variable, that can't happen because by the time make
110 # expands the variables for the command line and sees it begins with a "@" it
111 # can't know anymore whether the prefix character came before the variable
112 # reference or was included in the first line of the variable reference.
114 # TEST #5
115 # -------
117 run_make_test('
118 define FOO
119 $(V1)echo hello
120 $(V2)echo world
121 endef
122 all: ; @$(FOO)
123 ', '', 'hello
124 world');
126 # TEST #6
127 # -------
129 run_make_test(undef, 'V1=@ V2=@', 'hello
130 world');
132 # TEST #7
133 # -------
135 run_make_test('
136 define FOO
137 $(V1)echo hello
138 $(V2)echo world
139 endef
140 all: ; $(FOO)
141 ', 'V1=@', 'hello
142 echo world
143 world');
145 # TEST #8
146 # -------
148 run_make_test(undef, 'V2=@', 'echo hello
149 hello
150 world');
152 # TEST #9
153 # -------
155 run_make_test(undef, 'V1=@ V2=@', 'hello
156 world');