| @@ -1,1133 +1,1331 @@ | | | @@ -1,1133 +1,1331 @@ |
1 | #! /bin/sh | | 1 | #! /bin/sh |
2 | # $NetBSD: subst.sh,v 1.25 2020/04/26 12:46:33 rillig Exp $ | | 2 | # $NetBSD: subst.sh,v 1.26 2020/04/29 18:33:56 rillig Exp $ |
3 | # | | 3 | # |
4 | # Tests for mk/subst.mk. | | 4 | # Tests for mk/subst.mk. |
5 | # | | 5 | # |
6 | | | 6 | |
7 | set -eu | | 7 | set -eu |
8 | | | 8 | |
9 | . "./test.subr" | | 9 | . "./test.subr" |
10 | | | 10 | |
11 | test_case_set_up() { | | 11 | test_case_set_up() { |
12 | rm -rf "$tmpdir"/.??* "$tmpdir"/* | | 12 | rm -rf "$tmpdir"/.??* "$tmpdir"/* |
13 | | | 13 | |
14 | create_file "prepare-subst.mk" <<EOF | | 14 | create_file "prepare-subst.mk" <<EOF |
15 | | | 15 | |
16 | # The tools that are used by subst.mk | | 16 | # The tools that are used by subst.mk |
| | | 17 | AWK= awk |
17 | CHMOD= chmod | | 18 | CHMOD= chmod |
18 | CMP= cmp | | 19 | CMP= cmp |
19 | DIFF= diff | | 20 | DIFF= diff |
20 | ECHO= echo | | 21 | ECHO= echo |
21 | MKDIR= mkdir -p | | 22 | MKDIR= mkdir -p |
22 | MV= mv | | 23 | MV= mv |
23 | RM= rm | | 24 | RM= rm |
24 | RMDIR= rmdir | | 25 | RMDIR= rmdir |
25 | SED= sed | | 26 | SED= sed |
26 | TEST= test | | 27 | TEST= test |
27 | TOUCH= touch | | 28 | TOUCH= touch |
28 | TOUCH_FLAGS= # none | | 29 | TOUCH_FLAGS= # none |
29 | TR= tr | | 30 | TR= tr |
30 | TRUE= true | | 31 | TRUE= true |
31 | | | 32 | |
32 | # Commands that are specific to pkgsrc | | 33 | # Commands that are specific to pkgsrc |
33 | RUN= @set -e; | | 34 | RUN= @set -e; |
34 | STEP_MSG= echo "=>" | | 35 | STEP_MSG= echo "=>" |
35 | DO_NADA= : do-nada | | 36 | DO_NADA= : do-nada |
36 | INFO_MSG= echo "info:" | | 37 | INFO_MSG= echo "info:" |
37 | WARNING_MSG= echo "warning:" | | 38 | WARNING_MSG= echo "warning:" |
38 | FAIL_MSG= sh $pkgsrcdir/mk/scripts/fail echo "fail:" | | 39 | FAIL_MSG= sh $pkgsrcdir/mk/scripts/fail echo "fail:" |
39 | | | 40 | |
40 | WRKDIR= $tmpdir | | 41 | WRKDIR= $tmpdir |
41 | WRKSRC= $tmpdir | | 42 | WRKSRC= $tmpdir |
42 | EOF | | 43 | EOF |
43 | } | | 44 | } |
44 | | | 45 | |
45 | | | 46 | |
46 | if test_case_begin "single file"; then | | 47 | if test_case_begin "single file"; then |
47 | | | 48 | |
48 | # A single file is patched successfully. | | 49 | # A single file is patched successfully. |
49 | | | 50 | |
50 | create_file "subst-single.mk" <<EOF | | 51 | create_file "subst-single.mk" <<EOF |
51 | SUBST_CLASSES+= class | | 52 | SUBST_CLASSES+= class |
52 | SUBST_STAGE.class= pre-configure | | 53 | SUBST_STAGE.class= pre-configure |
53 | SUBST_FILES.class= subst-single.txt | | 54 | SUBST_FILES.class= subst-single.txt |
54 | SUBST_SED.class= -e 's,before,after,' | | 55 | SUBST_SED.class= -e 's,before,after,' |
55 | | | 56 | |
56 | .include "prepare-subst.mk" | | 57 | .include "prepare-subst.mk" |
57 | .include "mk/subst.mk" | | 58 | .include "mk/subst.mk" |
58 | | | 59 | |
59 | all: subst-class | | 60 | all: subst-class |
60 | EOF | | 61 | EOF |
61 | | | 62 | |
62 | create_file_lines "subst-single.txt" \ | | 63 | create_file_lines "subst-single.txt" \ |
63 | "before" | | 64 | "before" |
64 | | | 65 | |
65 | run_bmake "subst-single.mk" > "$tmpdir/output" | | 66 | run_bmake "subst-single.mk" > "$tmpdir/output" |
66 | | | 67 | |
67 | assert_that "output" --file-contains-exactly "=> Substituting \"class\" in subst-single.txt" | | 68 | assert_that "output" --file-contains-exactly "=> Substituting \"class\" in subst-single.txt" |
68 | assert_that "subst-single.txt" --file-contains-exactly "after" | | 69 | assert_that "subst-single.txt" --file-contains-exactly "after" |
69 | | | 70 | |
70 | test_case_end | | 71 | test_case_end |
71 | fi | | 72 | fi |
72 | | | 73 | |
73 | | | 74 | |
74 | if test_case_begin "several individual files"; then | | 75 | if test_case_begin "several individual files"; then |
75 | | | 76 | |
76 | # Several individual files are patched successfully. | | 77 | # Several individual files are patched successfully. |
77 | | | 78 | |
78 | create_file "testcase.mk" <<EOF | | 79 | create_file "testcase.mk" <<EOF |
79 | SUBST_CLASSES+= class | | 80 | SUBST_CLASSES+= class |
80 | SUBST_STAGE.class= pre-configure | | 81 | SUBST_STAGE.class= pre-configure |
81 | SUBST_FILES.class= first second third | | 82 | SUBST_FILES.class= first second third |
82 | SUBST_SED.class= -e 's,file,example,' | | 83 | SUBST_SED.class= -e 's,file,example,' |
83 | | | 84 | |
84 | .include "prepare-subst.mk" | | 85 | .include "prepare-subst.mk" |
85 | .include "mk/subst.mk" | | 86 | .include "mk/subst.mk" |
86 | | | 87 | |
87 | all: subst-class | | 88 | all: subst-class |
88 | EOF | | 89 | EOF |
89 | | | 90 | |
90 | create_file_lines "first" "the first file" | | 91 | create_file_lines "first" "the first file" |
91 | create_file_lines "second" "the second file" | | 92 | create_file_lines "second" "the second file" |
92 | create_file_lines "third" "the third file" | | 93 | create_file_lines "third" "the third file" |
93 | | | 94 | |
94 | output=$(run_bmake "testcase.mk") | | 95 | output=$(run_bmake "testcase.mk") |
95 | | | 96 | |
96 | assert_that "$output" --equals "=> Substituting \"class\" in first second third" | | 97 | assert_that "$output" --equals "=> Substituting \"class\" in first second third" |
97 | assert_that "first" --file-contains-exactly "the first example" | | 98 | assert_that "first" --file-contains-exactly "the first example" |
98 | assert_that "second" --file-contains-exactly "the second example" | | 99 | assert_that "second" --file-contains-exactly "the second example" |
99 | assert_that "third" --file-contains-exactly "the third example" | | 100 | assert_that "third" --file-contains-exactly "the third example" |
100 | | | 101 | |
101 | test_case_end | | 102 | test_case_end |
102 | fi | | 103 | fi |
103 | | | 104 | |
104 | | | 105 | |
105 | if test_case_begin "several files by pattern"; then | | 106 | if test_case_begin "several files by pattern"; then |
106 | | | 107 | |
107 | # Several files are patched successfully. | | 108 | # Several files are patched successfully. |
108 | # The filenames are given by a pattern. | | 109 | # The filenames are given by a pattern. |
109 | | | 110 | |
110 | create_file "testcase.mk" <<EOF | | 111 | create_file "testcase.mk" <<EOF |
111 | SUBST_CLASSES+= class | | 112 | SUBST_CLASSES+= class |
112 | SUBST_STAGE.class= pre-configure | | 113 | SUBST_STAGE.class= pre-configure |
113 | SUBST_FILES.class= pattern-* | | 114 | SUBST_FILES.class= pattern-* |
114 | SUBST_SED.class= -e 's,file,example,' | | 115 | SUBST_SED.class= -e 's,file,example,' |
115 | | | 116 | |
116 | .include "prepare-subst.mk" | | 117 | .include "prepare-subst.mk" |
117 | .include "mk/subst.mk" | | 118 | .include "mk/subst.mk" |
118 | | | 119 | |
119 | all: subst-class | | 120 | all: subst-class |
120 | EOF | | 121 | EOF |
121 | | | 122 | |
122 | create_file_lines "pattern-first" "the first file" | | 123 | create_file_lines "pattern-first" "the first file" |
123 | create_file_lines "pattern-second" "the second file" | | 124 | create_file_lines "pattern-second" "the second file" |
124 | create_file_lines "pattern-third" "the third file" | | 125 | create_file_lines "pattern-third" "the third file" |
125 | | | 126 | |
126 | output=$(run_bmake "testcase.mk") | | 127 | output=$(run_bmake "testcase.mk") |
127 | | | 128 | |
128 | assert_that "$output" --equals "=> Substituting \"class\" in pattern-*" | | 129 | assert_that "$output" --equals "=> Substituting \"class\" in pattern-*" |
129 | assert_that "pattern-first" --file-contains-exactly "the first example" | | 130 | assert_that "pattern-first" --file-contains-exactly "the first example" |
130 | assert_that "pattern-second" --file-contains-exactly "the second example" | | 131 | assert_that "pattern-second" --file-contains-exactly "the second example" |
131 | assert_that "pattern-third" --file-contains-exactly "the third example" | | 132 | assert_that "pattern-third" --file-contains-exactly "the third example" |
132 | | | 133 | |
133 | test_case_end | | 134 | test_case_end |
134 | fi | | 135 | fi |
135 | | | 136 | |
136 | | | 137 | |
137 | if test_case_begin "pattern with 1 noop"; then | | 138 | if test_case_begin "pattern with 1 noop"; then |
138 | | | 139 | |
139 | # Several files are given via a pattern. | | 140 | # Several files are given via a pattern. |
140 | # Most of the files are patched, but one stays the same. | | 141 | # Most of the files are patched, but one stays the same. |
141 | # Since it is easier to give a too broad pattern like *.py | | 142 | # Since it is easier to give a too broad pattern like *.py |
142 | # than to exclude a few files from such a pattern, | | 143 | # than to exclude a few files from such a pattern, |
143 | # only an info is logged. | | 144 | # only an info is logged. |
144 | # This is not an error. | | 145 | # This is not an error. |
145 | | | 146 | |
146 | create_file "testcase.mk" <<EOF | | 147 | create_file "testcase.mk" <<EOF |
147 | SUBST_CLASSES+= class | | 148 | SUBST_CLASSES+= class |
148 | SUBST_STAGE.class= pre-configure | | 149 | SUBST_STAGE.class= pre-configure |
149 | SUBST_FILES.class= pattern-* | | 150 | SUBST_FILES.class= pattern-* |
150 | SUBST_SED.class= -e 's,file,example,' | | 151 | SUBST_SED.class= -e 's,file,example,' |
151 | | | 152 | |
152 | .include "prepare-subst.mk" | | 153 | .include "prepare-subst.mk" |
153 | .include "mk/subst.mk" | | 154 | .include "mk/subst.mk" |
154 | | | 155 | |
155 | all: subst-class | | 156 | all: subst-class |
156 | EOF | | 157 | EOF |
157 | | | 158 | |
158 | create_file_lines "pattern-first" "the first file" | | 159 | create_file_lines "pattern-first" "the first file" |
159 | create_file_lines "pattern-second" "the second is already an example" | | 160 | create_file_lines "pattern-second" "the second is already an example" |
160 | create_file_lines "pattern-third" "the third file" | | 161 | create_file_lines "pattern-third" "the third file" |
161 | | | 162 | |
162 | run_bmake "testcase.mk" > "$tmpdir/actual-output" | | 163 | run_bmake "testcase.mk" > "$tmpdir/actual-output" |
163 | create_file_lines "expected-output" \ | | 164 | create_file_lines "expected-output" \ |
164 | '=> Substituting "class" in pattern-*' \ | | 165 | '=> Substituting "class" in pattern-*' \ |
165 | 'info: [subst.mk:class] Nothing changed in "pattern-second".' | | 166 | 'info: [subst.mk:class] Nothing changed in "pattern-second".' |
166 | | | 167 | |
167 | assert_that "actual-output" --file-equals "expected-output" | | 168 | assert_that "actual-output" --file-equals "expected-output" |
168 | assert_that "pattern-first" --file-contains-exactly "the first example" | | 169 | assert_that "pattern-first" --file-contains-exactly "the first example" |
169 | assert_that "pattern-second" --file-contains-exactly "the second is already an example" | | 170 | assert_that "pattern-second" --file-contains-exactly "the second is already an example" |
170 | assert_that "pattern-third" --file-contains-exactly "the third example" | | 171 | assert_that "pattern-third" --file-contains-exactly "the third example" |
171 | | | 172 | |
172 | test_case_end | | 173 | test_case_end |
173 | fi | | 174 | fi |
174 | | | 175 | |
175 | | | 176 | |
176 | if test_case_begin "single file noop, noop_ok=yes"; then | | 177 | if test_case_begin "single file noop, noop_ok=yes"; then |
177 | | | 178 | |
178 | create_file "testcase.mk" <<EOF | | 179 | create_file "testcase.mk" <<EOF |
179 | SUBST_CLASSES+= class | | 180 | SUBST_CLASSES+= class |
180 | SUBST_STAGE.class= pre-configure | | 181 | SUBST_STAGE.class= pre-configure |
181 | SUBST_FILES.class= single | | 182 | SUBST_FILES.class= single |
182 | SUBST_SED.class= -e 's,file,example,' | | 183 | SUBST_SED.class= -e 's,file,example,' |
183 | SUBST_NOOP_OK.class= yes | | 184 | SUBST_NOOP_OK.class= yes |
184 | | | 185 | |
185 | .include "prepare-subst.mk" | | 186 | .include "prepare-subst.mk" |
186 | .include "mk/subst.mk" | | 187 | .include "mk/subst.mk" |
187 | | | 188 | |
188 | all: subst-class | | 189 | all: subst-class |
189 | EOF | | 190 | EOF |
190 | | | 191 | |
191 | create_file_lines "single" "already an example" | | 192 | create_file_lines "single" "already an example" |
192 | | | 193 | |
193 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? | | 194 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? |
194 | | | 195 | |
195 | create_file_lines "expected-output" \ | | 196 | create_file_lines "expected-output" \ |
196 | '=> Substituting "class" in single' \ | | 197 | '=> Substituting "class" in single' \ |
197 | 'info: [subst.mk:class] Nothing changed in "single".' | | 198 | 'info: [subst.mk:class] Nothing changed in "single".' |
198 | assert_that "actual-output" --file-equals "expected-output" | | 199 | assert_that "actual-output" --file-equals "expected-output" |
199 | assert_that "single" --file-contains-exactly "already an example" | | 200 | assert_that "single" --file-contains-exactly "already an example" |
200 | assert_that "$exitcode" --equals "0" | | 201 | assert_that "$exitcode" --equals "0" |
201 | | | 202 | |
202 | test_case_end | | 203 | test_case_end |
203 | fi | | 204 | fi |
204 | | | 205 | |
205 | | | 206 | |
206 | if test_case_begin "single file noop, noop_ok=no"; then | | 207 | if test_case_begin "single file noop, noop_ok=no"; then |
207 | | | 208 | |
208 | create_file "testcase.mk" <<EOF | | 209 | create_file "testcase.mk" <<EOF |
209 | SUBST_CLASSES+= class | | 210 | SUBST_CLASSES+= class |
210 | SUBST_STAGE.class= pre-configure | | 211 | SUBST_STAGE.class= pre-configure |
211 | SUBST_FILES.class= single | | 212 | SUBST_FILES.class= single |
212 | SUBST_SED.class= -e 's,file,example,' | | 213 | SUBST_SED.class= -e 's,file,example,' |
213 | SUBST_NOOP_OK.class= no | | 214 | SUBST_NOOP_OK.class= no |
214 | | | 215 | |
215 | .include "prepare-subst.mk" | | 216 | .include "prepare-subst.mk" |
216 | .include "mk/subst.mk" | | 217 | .include "mk/subst.mk" |
217 | | | 218 | |
218 | all: subst-class | | 219 | all: subst-class |
219 | EOF | | 220 | EOF |
220 | | | 221 | |
221 | create_file_lines "single" "already an example" | | 222 | create_file_lines "single" "already an example" |
222 | | | 223 | |
223 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? | | 224 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? |
224 | | | 225 | |
225 | create_file_lines "expected-output" \ | | 226 | create_file_lines "expected-output" \ |
226 | '=> Substituting "class" in single' \ | | 227 | '=> Substituting "class" in single' \ |
227 | 'warning: [subst.mk:class] Nothing changed in "single".' \ | | 228 | 'warning: [subst.mk:class] Nothing changed in "single".' \ |
228 | 'fail: [subst.mk:class] The filename pattern "single" has no effect.' \ | | 229 | 'fail: [subst.mk:class] The filename pattern "single" has no effect.' \ |
229 | '*** Error code 1' \ | | 230 | '*** Error code 1' \ |
230 | '' \ | | 231 | '' \ |
231 | 'Stop.' \ | | 232 | 'Stop.' \ |
232 | "$make: stopped in $PWD" | | 233 | "$make: stopped in $PWD" |
233 | assert_that "actual-output" --file-equals "expected-output" | | 234 | assert_that "actual-output" --file-equals "expected-output" |
234 | assert_that "single" --file-contains-exactly "already an example" | | 235 | assert_that "single" --file-contains-exactly "already an example" |
235 | assert_that "$exitcode" --equals "1" | | 236 | assert_that "$exitcode" --equals "1" |
236 | | | 237 | |
237 | test_case_end | | 238 | test_case_end |
238 | fi | | 239 | fi |
239 | | | 240 | |
240 | | | 241 | |
241 | if test_case_begin "single file nonexistent"; then | | 242 | if test_case_begin "single file nonexistent"; then |
242 | | | 243 | |
243 | create_file "testcase.mk" <<EOF | | 244 | create_file "testcase.mk" <<EOF |
244 | SUBST_CLASSES+= class | | 245 | SUBST_CLASSES+= class |
245 | SUBST_STAGE.class= pre-configure | | 246 | SUBST_STAGE.class= pre-configure |
246 | SUBST_FILES.class= nonexistent | | 247 | SUBST_FILES.class= nonexistent |
247 | SUBST_SED.class= -e 's,file,example,' | | 248 | SUBST_SED.class= -e 's,file,example,' |
248 | SUBST_NOOP_OK.class= no | | 249 | SUBST_NOOP_OK.class= no |
249 | | | 250 | |
250 | .include "prepare-subst.mk" | | 251 | .include "prepare-subst.mk" |
251 | .include "mk/subst.mk" | | 252 | .include "mk/subst.mk" |
252 | | | 253 | |
253 | all: subst-class | | 254 | all: subst-class |
254 | EOF | | 255 | EOF |
255 | | | 256 | |
256 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? | | 257 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? |
257 | | | 258 | |
258 | create_file_lines "expected-output" \ | | 259 | create_file_lines "expected-output" \ |
259 | '=> Substituting "class" in nonexistent' \ | | 260 | '=> Substituting "class" in nonexistent' \ |
260 | 'warning: [subst.mk:class] Ignoring non-existent file "nonexistent".' \ | | 261 | 'warning: [subst.mk:class] Ignoring non-existent file "nonexistent".' \ |
261 | 'fail: [subst.mk:class] The filename pattern "nonexistent" has no effect.' \ | | 262 | 'fail: [subst.mk:class] The filename pattern "nonexistent" has no effect.' \ |
262 | '*** Error code 1' \ | | 263 | '*** Error code 1' \ |
263 | '' \ | | 264 | '' \ |
264 | 'Stop.' \ | | 265 | 'Stop.' \ |
265 | "$make: stopped in $PWD" | | 266 | "$make: stopped in $PWD" |
266 | assert_that "actual-output" --file-equals "expected-output" | | 267 | assert_that "actual-output" --file-equals "expected-output" |
267 | assert_that "$exitcode" --equals "1" | | 268 | assert_that "$exitcode" --equals "1" |
268 | | | 269 | |
269 | test_case_end | | 270 | test_case_end |
270 | fi | | 271 | fi |
271 | | | 272 | |
272 | | | 273 | |
273 | if test_case_begin "single file nonexistent ok"; then | | 274 | if test_case_begin "single file nonexistent ok"; then |
274 | | | 275 | |
275 | create_file "testcase.mk" <<EOF | | 276 | create_file "testcase.mk" <<EOF |
276 | SUBST_CLASSES+= class | | 277 | SUBST_CLASSES+= class |
277 | SUBST_STAGE.class= pre-configure | | 278 | SUBST_STAGE.class= pre-configure |
278 | SUBST_FILES.class= nonexistent | | 279 | SUBST_FILES.class= nonexistent |
279 | SUBST_SED.class= -e 's,file,example,' | | 280 | SUBST_SED.class= -e 's,file,example,' |
280 | SUBST_NOOP_OK.class= yes | | 281 | SUBST_NOOP_OK.class= yes |
281 | | | 282 | |
282 | .include "prepare-subst.mk" | | 283 | .include "prepare-subst.mk" |
283 | .include "mk/subst.mk" | | 284 | .include "mk/subst.mk" |
284 | | | 285 | |
285 | all: subst-class | | 286 | all: subst-class |
286 | EOF | | 287 | EOF |
287 | | | 288 | |
288 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? | | 289 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? |
289 | | | 290 | |
290 | create_file_lines "expected-output" \ | | 291 | create_file_lines "expected-output" \ |
291 | '=> Substituting "class" in nonexistent' \ | | 292 | '=> Substituting "class" in nonexistent' \ |
292 | 'info: [subst.mk:class] Ignoring non-existent file "nonexistent".' | | 293 | 'info: [subst.mk:class] Ignoring non-existent file "nonexistent".' |
293 | assert_that "actual-output" --file-equals "expected-output" | | 294 | assert_that "actual-output" --file-equals "expected-output" |
294 | assert_that "$exitcode" --equals "0" | | 295 | assert_that "$exitcode" --equals "0" |
295 | | | 296 | |
296 | test_case_end | | 297 | test_case_end |
297 | fi | | 298 | fi |
298 | | | 299 | |
299 | | | 300 | |
300 | if test_case_begin "several patterns, 1 nonexistent"; then | | 301 | if test_case_begin "several patterns, 1 nonexistent"; then |
301 | | | 302 | |
302 | create_file "testcase.mk" <<EOF | | 303 | create_file "testcase.mk" <<EOF |
303 | SUBST_CLASSES+= class | | 304 | SUBST_CLASSES+= class |
304 | SUBST_STAGE.class= pre-configure | | 305 | SUBST_STAGE.class= pre-configure |
305 | SUBST_FILES.class= *exist* *not-found* | | 306 | SUBST_FILES.class= *exist* *not-found* |
306 | SUBST_SED.class= -e 's,file,example,' | | 307 | SUBST_SED.class= -e 's,file,example,' |
307 | | | 308 | |
308 | .include "prepare-subst.mk" | | 309 | .include "prepare-subst.mk" |
309 | .include "mk/subst.mk" | | 310 | .include "mk/subst.mk" |
310 | | | 311 | |
311 | all: subst-class | | 312 | all: subst-class |
312 | EOF | | 313 | EOF |
313 | | | 314 | |
314 | create_file_lines "exists" "this file exists" | | 315 | create_file_lines "exists" "this file exists" |
315 | | | 316 | |
316 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? | | 317 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? |
317 | | | 318 | |
318 | create_file_lines "expected-output" \ | | 319 | create_file_lines "expected-output" \ |
319 | '=> Substituting "class" in *exist* *not-found*' \ | | 320 | '=> Substituting "class" in *exist* *not-found*' \ |
320 | 'info: [subst.mk:class] Ignoring non-existent file "./*not-found*".' | | 321 | 'info: [subst.mk:class] Ignoring non-existent file "./*not-found*".' |
321 | assert_that "actual-output" --file-equals "expected-output" | | 322 | assert_that "actual-output" --file-equals "expected-output" |
322 | assert_that "exists" --file-contains-exactly "this example exists" | | 323 | assert_that "exists" --file-contains-exactly "this example exists" |
323 | assert_that "$exitcode" --equals "0" | | 324 | assert_that "$exitcode" --equals "0" |
324 | | | 325 | |
325 | test_case_end | | 326 | test_case_end |
326 | fi | | 327 | fi |
327 | | | 328 | |
328 | | | 329 | |
329 | if test_case_begin "multiple missing files, all are reported at once"; then | | 330 | if test_case_begin "multiple missing files, all are reported at once"; then |
330 | | | 331 | |
331 | create_file "testcase.mk" <<EOF | | 332 | create_file "testcase.mk" <<EOF |
332 | SUBST_CLASSES+= class | | 333 | SUBST_CLASSES+= class |
333 | SUBST_STAGE.class= pre-configure | | 334 | SUBST_STAGE.class= pre-configure |
334 | SUBST_FILES.class= does not exist | | 335 | SUBST_FILES.class= does not exist |
335 | SUBST_SED.class= -e 'sahara' | | 336 | SUBST_SED.class= -e 'sahara' |
336 | | | 337 | |
337 | .include "prepare-subst.mk" | | 338 | .include "prepare-subst.mk" |
338 | .include "mk/subst.mk" | | 339 | .include "mk/subst.mk" |
339 | EOF | | 340 | EOF |
340 | | | 341 | |
341 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? | | 342 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? |
342 | | | 343 | |
343 | create_file_lines "expected-output" \ | | 344 | create_file_lines "expected-output" \ |
344 | '=> Substituting "class" in does not exist' \ | | 345 | '=> Substituting "class" in does not exist' \ |
345 | 'info: [subst.mk:class] Ignoring non-existent file "does".' \ | | 346 | 'info: [subst.mk:class] Ignoring non-existent file "does".' \ |
346 | 'info: [subst.mk:class] Ignoring non-existent file "not".' \ | | 347 | 'info: [subst.mk:class] Ignoring non-existent file "not".' \ |
347 | 'info: [subst.mk:class] Ignoring non-existent file "exist".' | | 348 | 'info: [subst.mk:class] Ignoring non-existent file "exist".' |
348 | assert_that "actual-output" --file-equals "expected-output" | | 349 | assert_that "actual-output" --file-equals "expected-output" |
349 | assert_that "$exitcode" --equals "0" | | 350 | assert_that "$exitcode" --equals "0" |
350 | | | 351 | |
351 | test_case_end | | 352 | test_case_end |
352 | fi | | 353 | fi |
353 | | | 354 | |
354 | | | 355 | |
355 | if test_case_begin "multiple no-op files, all are reported at once"; then | | 356 | if test_case_begin "multiple no-op files, all are reported at once"; then |
356 | | | 357 | |
357 | create_file "testcase.mk" <<EOF | | 358 | create_file "testcase.mk" <<EOF |
358 | SUBST_CLASSES+= class | | 359 | SUBST_CLASSES+= class |
359 | SUBST_STAGE.class= pre-configure | | 360 | SUBST_STAGE.class= pre-configure |
360 | SUBST_FILES.class= first second third | | 361 | SUBST_FILES.class= first second third |
361 | SUBST_SED.class= -e 's,from,to,' | | 362 | SUBST_SED.class= -e 's,from,to,' |
362 | | | 363 | |
363 | .include "prepare-subst.mk" | | 364 | .include "prepare-subst.mk" |
364 | .include "mk/subst.mk" | | 365 | .include "mk/subst.mk" |
365 | EOF | | 366 | EOF |
366 | create_file_lines "first" "text" | | 367 | create_file_lines "first" "text" |
367 | create_file_lines "second" "second" | | 368 | create_file_lines "second" "second" |
368 | create_file_lines "third" "third" | | 369 | create_file_lines "third" "third" |
369 | | | 370 | |
370 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? | | 371 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? |
371 | | | 372 | |
372 | create_file_lines "expected-output" \ | | 373 | create_file_lines "expected-output" \ |
373 | '=> Substituting "class" in first second third' \ | | 374 | '=> Substituting "class" in first second third' \ |
374 | 'info: [subst.mk:class] Nothing changed in "first".' \ | | 375 | 'info: [subst.mk:class] Nothing changed in "first".' \ |
375 | 'info: [subst.mk:class] Nothing changed in "second".' \ | | 376 | 'info: [subst.mk:class] Nothing changed in "second".' \ |
376 | 'info: [subst.mk:class] Nothing changed in "third".' | | 377 | 'info: [subst.mk:class] Nothing changed in "third".' |
377 | assert_that "actual-output" --file-equals "expected-output" | | 378 | assert_that "actual-output" --file-equals "expected-output" |
378 | assert_that "$exitcode" --equals "0" | | 379 | assert_that "$exitcode" --equals "0" |
379 | | | 380 | |
380 | test_case_end | | 381 | test_case_end |
381 | fi | | 382 | fi |
382 | | | 383 | |
383 | | | 384 | |
384 | if test_case_begin "late evaluation of SUBST_FILES"; then | | 385 | if test_case_begin "late evaluation of SUBST_FILES"; then |
385 | | | 386 | |
386 | # Ensure that SUBST_FILES is evaluated as late as possible. | | 387 | # Ensure that SUBST_FILES is evaluated as late as possible. |
387 | # Evaluating it early breaks cases like pkglocaledir where the | | 388 | # Evaluating it early breaks cases like pkglocaledir where the |
388 | # list of files is generated by a shell command. | | 389 | # list of files is generated by a shell command. |
389 | # See mk/configure/replace-localedir.mk. | | 390 | # See mk/configure/replace-localedir.mk. |
390 | | | 391 | |
391 | create_file "testcase.mk" <<EOF | | 392 | create_file "testcase.mk" <<EOF |
392 | REPLACE_FILES_CMD.class= \ | | 393 | REPLACE_FILES_CMD.class= \ |
393 | cd \${WRKSRC} && echo *r* | | 394 | cd \${WRKSRC} && echo *r* |
394 | | | 395 | |
395 | SUBST_CLASSES+= class | | 396 | SUBST_CLASSES+= class |
396 | SUBST_STAGE.class= pre-configure | | 397 | SUBST_STAGE.class= pre-configure |
397 | SUBST_FILES.class= first third # \${REPLACE_FILES_CMD.class:sh} | | 398 | SUBST_FILES.class= first third # \${REPLACE_FILES_CMD.class:sh} |
398 | SUBST_SED.class= -e 's,from,to,' | | 399 | SUBST_SED.class= -e 's,from,to,' |
399 | | | 400 | |
400 | .include "prepare-subst.mk" | | 401 | .include "prepare-subst.mk" |
401 | RUN= @set -e; | | 402 | RUN= @set -e; |
402 | WRKSRC= \${WRKDIR}/package-1.0 | | 403 | WRKSRC= \${WRKDIR}/package-1.0 |
403 | .include "mk/subst.mk" | | 404 | .include "mk/subst.mk" |
404 | | | 405 | |
405 | # It is tricky that the dependency must use an internal implementation | | 406 | # It is tricky that the dependency must use an internal implementation |
406 | # detail, but that's the only way to guarantee the correct ordering. | | 407 | # detail, but that's the only way to guarantee the correct ordering. |
407 | \${_SUBST_COOKIE.class}: prepare-subst-class | | 408 | \${_SUBST_COOKIE.class}: prepare-subst-class |
408 | prepare-subst-class: | | 409 | prepare-subst-class: |
409 | \${RUN} \${MKDIR} \${WRKSRC} | | 410 | \${RUN} \${MKDIR} \${WRKSRC} |
410 | \${RUN} \${ECHO} "from" > "\${WRKSRC}/first" | | 411 | \${RUN} \${ECHO} "from" > "\${WRKSRC}/first" |
411 | \${RUN} \${ECHO} "from" > "\${WRKSRC}/second" | | 412 | \${RUN} \${ECHO} "from" > "\${WRKSRC}/second" |
412 | \${RUN} \${ECHO} "from" > "\${WRKSRC}/third" | | 413 | \${RUN} \${ECHO} "from" > "\${WRKSRC}/third" |
413 | EOF | | 414 | EOF |
414 | | | 415 | |
415 | run_bmake "testcase.mk" "subst-class" \ | | 416 | run_bmake "testcase.mk" "subst-class" \ |
416 | 1> "$tmpdir/actual-output" \ | | 417 | 1> "$tmpdir/actual-output" \ |
417 | 2> "$tmpdir/actual-stderr" \ | | 418 | 2> "$tmpdir/actual-stderr" \ |
418 | && exitcode=0 || exitcode=$? | | 419 | && exitcode=0 || exitcode=$? |
419 | | | 420 | |
420 | create_file_lines "expected-output" \ | | 421 | create_file_lines "expected-output" \ |
421 | '=> Substituting "class" in first third' | | 422 | '=> Substituting "class" in first third' |
422 | assert_that "actual-output" --file-equals "expected-output" | | 423 | assert_that "actual-output" --file-equals "expected-output" |
423 | assert_that "actual-stderr" --file-is-empty | | 424 | assert_that "actual-stderr" --file-is-empty |
424 | assert_that "package-1.0/first" --file-contains-exactly "to" | | 425 | assert_that "package-1.0/first" --file-contains-exactly "to" |
425 | assert_that "package-1.0/second" --file-contains-exactly "from" | | 426 | assert_that "package-1.0/second" --file-contains-exactly "from" |
426 | assert_that "package-1.0/third" --file-contains-exactly "to" | | 427 | assert_that "package-1.0/third" --file-contains-exactly "to" |
427 | assert_that "$exitcode" --equals "0" | | 428 | assert_that "$exitcode" --equals "0" |
428 | | | 429 | |
429 | test_case_end | | 430 | test_case_end |
430 | fi | | 431 | fi |
431 | | | 432 | |
432 | | | 433 | |
433 | if test_case_begin "special characters in filenames"; then | | 434 | if test_case_begin "special characters in filenames"; then |
434 | | | 435 | |
435 | create_file "testcase.mk" <<EOF | | 436 | create_file "testcase.mk" <<EOF |
436 | SUBST_CLASSES+= class | | 437 | SUBST_CLASSES+= class |
437 | SUBST_STAGE.class= pre-configure | | 438 | SUBST_STAGE.class= pre-configure |
438 | SUBST_FILES.class= * | | 439 | SUBST_FILES.class= * |
439 | SUBST_SED.class= -e s,before,after, | | 440 | SUBST_SED.class= -e s,before,after, |
440 | SUBST_NOOP_OK.class= yes | | 441 | SUBST_NOOP_OK.class= yes |
441 | | | 442 | |
442 | .include "prepare-subst.mk" | | 443 | .include "prepare-subst.mk" |
443 | .include "mk/subst.mk" | | 444 | .include "mk/subst.mk" |
444 | EOF | | 445 | EOF |
445 | | | 446 | |
446 | create_file_lines " !\"#\$%&'()*+,-." "before" | | 447 | create_file_lines " !\"#\$%&'()*+,-." "before" |
447 | create_file_lines "0123456789:;<=>?" "before" | | 448 | create_file_lines "0123456789:;<=>?" "before" |
448 | create_file_lines "@ABCDEFGHIJKLMNO" "before" | | 449 | create_file_lines "@ABCDEFGHIJKLMNO" "before" |
449 | create_file_lines "PQRSTUVWXYZ[\\]^_" "before" | | 450 | create_file_lines "PQRSTUVWXYZ[\\]^_" "before" |
450 | create_file_lines "\`abcdefghijklmno" "before" | | 451 | create_file_lines "\`abcdefghijklmno" "before" |
451 | create_file_lines "pqrstuvwxyz{|}~" "before" | | 452 | create_file_lines "pqrstuvwxyz{|}~" "before" |
452 | create_file_lines "--no-option" "before" | | 453 | create_file_lines "--no-option" "before" |
453 | create_file_lines ".hidden" "before" | | 454 | create_file_lines ".hidden" "before" |
454 | | | 455 | |
455 | run_bmake "testcase.mk" "subst-class" \ | | 456 | run_bmake "testcase.mk" "subst-class" \ |
456 | 1> "$tmpdir/stdout" \ | | 457 | 1> "$tmpdir/stdout" \ |
457 | 2> "$tmpdir/stderr" \ | | 458 | 2> "$tmpdir/stderr" \ |
458 | && exitcode=0 || exitcode=$? | | 459 | && exitcode=0 || exitcode=$? |
459 | | | 460 | |
460 | assert_that "stdout" --file-is-lines \ | | 461 | assert_that "stdout" --file-is-lines \ |
461 | '=> Substituting "class" in *' \ | | 462 | '=> Substituting "class" in *' \ |
462 | 'info: [subst.mk:class] Nothing changed in "prepare-subst.mk".' \ | | 463 | 'info: [subst.mk:class] Nothing changed in "prepare-subst.mk".' \ |
463 | 'info: [subst.mk:class] Nothing changed in "stderr".' \ | | 464 | 'info: [subst.mk:class] Nothing changed in "stderr".' \ |
464 | 'info: [subst.mk:class] Nothing changed in "stdout".' \ | | 465 | 'info: [subst.mk:class] Nothing changed in "stdout".' \ |
465 | 'info: [subst.mk:class] Nothing changed in "test.subr.main.mk".' | | 466 | 'info: [subst.mk:class] Nothing changed in "test.subr.main.mk".' |
466 | assert_that "stderr" --file-is-empty | | 467 | assert_that "stderr" --file-is-empty |
467 | assert_that "$exitcode" --equals "0" | | 468 | assert_that "$exitcode" --equals "0" |
468 | | | 469 | |
469 | assert_that " !\"#\$%&'()*+,-." --file-is-lines "after" | | 470 | assert_that " !\"#\$%&'()*+,-." --file-is-lines "after" |
470 | assert_that "0123456789:;<=>?" --file-is-lines "after" | | 471 | assert_that "0123456789:;<=>?" --file-is-lines "after" |
471 | assert_that "@ABCDEFGHIJKLMNO" --file-is-lines "after" | | 472 | assert_that "@ABCDEFGHIJKLMNO" --file-is-lines "after" |
472 | assert_that "PQRSTUVWXYZ[\\]^_" --file-is-lines "after" | | 473 | assert_that "PQRSTUVWXYZ[\\]^_" --file-is-lines "after" |
473 | assert_that "\`abcdefghijklmno" --file-is-lines "after" | | 474 | assert_that "\`abcdefghijklmno" --file-is-lines "after" |
474 | assert_that "pqrstuvwxyz{|}~" --file-is-lines "after" | | 475 | assert_that "pqrstuvwxyz{|}~" --file-is-lines "after" |
475 | assert_that "--no-option" --file-is-lines "after" | | 476 | assert_that "--no-option" --file-is-lines "after" |
476 | assert_that ".hidden" --file-is-lines "before" | | 477 | assert_that ".hidden" --file-is-lines "before" |
477 | | | 478 | |
478 | test_case_end | | 479 | test_case_end |
479 | fi | | 480 | fi |
480 | | | 481 | |
481 | if test_case_begin "brackets in filename patterns"; then | | 482 | if test_case_begin "brackets in filename patterns"; then |
482 | | | 483 | |
483 | create_file "testcase.mk" <<EOF | | 484 | create_file "testcase.mk" <<EOF |
484 | SUBST_CLASSES+= class | | 485 | SUBST_CLASSES+= class |
485 | SUBST_STAGE.class= pre-configure | | 486 | SUBST_STAGE.class= pre-configure |
486 | SUBST_FILES.class= [*] | | 487 | SUBST_FILES.class= [*] |
487 | SUBST_SED.class= -e s,before,after, | | 488 | SUBST_SED.class= -e s,before,after, |
488 | SUBST_NOOP_OK.class= yes | | 489 | SUBST_NOOP_OK.class= yes |
489 | | | 490 | |
490 | .include "prepare-subst.mk" | | 491 | .include "prepare-subst.mk" |
491 | .include "mk/subst.mk" | | 492 | .include "mk/subst.mk" |
492 | EOF | | 493 | EOF |
493 | | | 494 | |
494 | create_file_lines "any" "before" | | 495 | create_file_lines "any" "before" |
495 | create_file_lines "x" "before" | | 496 | create_file_lines "x" "before" |
496 | create_file_lines "*" "before" | | 497 | create_file_lines "*" "before" |
497 | create_file_lines "[*]" "before" | | 498 | create_file_lines "[*]" "before" |
498 | | | 499 | |
499 | run_bmake "testcase.mk" "subst-class" \ | | 500 | run_bmake "testcase.mk" "subst-class" \ |
500 | 1> "$tmpdir/stdout" \ | | 501 | 1> "$tmpdir/stdout" \ |
501 | 2> "$tmpdir/stderr" \ | | 502 | 2> "$tmpdir/stderr" \ |
502 | && exitcode=0 || exitcode=$? | | 503 | && exitcode=0 || exitcode=$? |
503 | | | 504 | |
504 | assert_that "stdout" --file-is-lines \ | | 505 | assert_that "stdout" --file-is-lines \ |
505 | '=> Substituting "class" in [*]' | | 506 | '=> Substituting "class" in [*]' |
506 | assert_that "stderr" --file-is-empty | | 507 | assert_that "stderr" --file-is-empty |
507 | assert_that "$exitcode" --equals "0" | | 508 | assert_that "$exitcode" --equals "0" |
508 | | | 509 | |
509 | assert_that "any" --file-is-lines "before" | | 510 | assert_that "any" --file-is-lines "before" |
510 | assert_that "x" --file-is-lines "before" | | 511 | assert_that "x" --file-is-lines "before" |
511 | assert_that "*" --file-is-lines "after" | | 512 | assert_that "*" --file-is-lines "after" |
512 | assert_that "[*]" --file-is-lines "before" | | 513 | assert_that "[*]" --file-is-lines "before" |
513 | | | 514 | |
514 | test_case_end | | 515 | test_case_end |
515 | fi | | 516 | fi |
516 | | | 517 | |
517 | | | 518 | |
518 | if test_case_begin "duplicate SUBST class"; then | | 519 | if test_case_begin "duplicate SUBST class"; then |
519 | | | 520 | |
520 | create_file "testcase.mk" <<EOF | | 521 | create_file "testcase.mk" <<EOF |
521 | SUBST_CLASSES+= one | | 522 | SUBST_CLASSES+= one |
522 | SUBST_CLASSES+= two | | 523 | SUBST_CLASSES+= two |
523 | SUBST_CLASSES+= one | | 524 | SUBST_CLASSES+= one |
524 | | | 525 | |
525 | all: | | 526 | all: |
526 | @printf 'fail reason: %s\n' \${PKG_FAIL_REASON} 1>&2 | | 527 | @printf 'fail reason: %s\n' \${PKG_FAIL_REASON} 1>&2 |
527 | | | 528 | |
528 | .include "prepare-subst.mk" | | 529 | .include "prepare-subst.mk" |
529 | .include "mk/subst.mk" | | 530 | .include "mk/subst.mk" |
530 | EOF | | 531 | EOF |
531 | | | 532 | |
532 | run_bmake "testcase.mk" "all" \ | | 533 | run_bmake "testcase.mk" "all" \ |
533 | 1> "$tmpdir/stdout" \ | | 534 | 1> "$tmpdir/stdout" \ |
534 | 2> "$tmpdir/stderr" \ | | 535 | 2> "$tmpdir/stderr" \ |
535 | && exitcode=0 || exitcode=$? | | 536 | && exitcode=0 || exitcode=$? |
536 | | | 537 | |
537 | assert_that "stdout" --file-is-empty | | 538 | assert_that "stdout" --file-is-empty |
538 | assert_that "stderr" --file-is-lines \ | | 539 | assert_that "stderr" --file-is-lines \ |
539 | "fail reason: [subst.mk] duplicate SUBST class in: one one two" | | 540 | "fail reason: [subst.mk] duplicate SUBST class in: one one two" |
540 | assert_that "$exitcode" --equals 0 | | 541 | assert_that "$exitcode" --equals 0 |
541 | | | 542 | |
542 | test_case_end | | 543 | test_case_end |
543 | fi | | 544 | fi |
544 | | | 545 | |
545 | | | 546 | |
546 | if test_case_begin "several SUBST classes"; then | | 547 | if test_case_begin "several SUBST classes"; then |
547 | | | 548 | |
548 | # It's ok to have several SUBST classes that apply to the same file. | | 549 | # It's ok to have several SUBST classes that apply to the same file. |
549 | # The order of execution is not guaranteed though. | | 550 | # The order of execution is not guaranteed though. |
550 | | | 551 | |
551 | create_file_lines "file" "zero one two three four" | | 552 | create_file_lines "file" "zero one two three four" |
552 | | | 553 | |
553 | create_file "testcase.mk" <<EOF | | 554 | create_file "testcase.mk" <<EOF |
554 | SUBST_CLASSES+= one | | 555 | SUBST_CLASSES+= one |
555 | SUBST_STAGE.one= pre-configure | | 556 | SUBST_STAGE.one= pre-configure |
556 | SUBST_FILES.one= file | | 557 | SUBST_FILES.one= file |
557 | SUBST_SED.one= -e 's,one,I,' | | 558 | SUBST_SED.one= -e 's,one,I,' |
558 | | | 559 | |
559 | SUBST_CLASSES+= two | | 560 | SUBST_CLASSES+= two |
560 | SUBST_STAGE.two= pre-configure | | 561 | SUBST_STAGE.two= pre-configure |
561 | SUBST_FILES.two= file | | 562 | SUBST_FILES.two= file |
562 | SUBST_SED.two= -e 's,two,II,' | | 563 | SUBST_SED.two= -e 's,two,II,' |
563 | | | 564 | |
564 | SUBST_CLASSES+= three | | 565 | SUBST_CLASSES+= three |
565 | SUBST_STAGE.three= pre-configure | | 566 | SUBST_STAGE.three= pre-configure |
566 | SUBST_FILES.three= file | | 567 | SUBST_FILES.three= file |
567 | SUBST_SED.three= -e 's,three,III,' | | 568 | SUBST_SED.three= -e 's,three,III,' |
568 | | | 569 | |
569 | .include "prepare-subst.mk" | | 570 | .include "prepare-subst.mk" |
570 | .include "mk/subst.mk" | | 571 | .include "mk/subst.mk" |
571 | EOF | | 572 | EOF |
572 | | | 573 | |
573 | run_bmake "testcase.mk" "pre-configure" \ | | 574 | run_bmake "testcase.mk" "pre-configure" \ |
574 | 1> "$tmpdir/stdout" \ | | 575 | 1> "$tmpdir/stdout" \ |
575 | 2> "$tmpdir/stderr" \ | | 576 | 2> "$tmpdir/stderr" \ |
576 | && exitcode=0 || exitcode=$? | | 577 | && exitcode=0 || exitcode=$? |
577 | | | 578 | |
578 | # The order of the above output is not guaranteed. | | 579 | # The order of the above output is not guaranteed. |
579 | LC_ALL=C sort < "$tmpdir/stdout" > "$tmpdir/stdout-sorted" | | 580 | LC_ALL=C sort < "$tmpdir/stdout" > "$tmpdir/stdout-sorted" |
580 | | | 581 | |
581 | assert_that "file" --file-is-lines "zero I II III four" | | 582 | assert_that "file" --file-is-lines "zero I II III four" |
582 | assert_that "stdout-sorted" --file-is-lines \ | | 583 | assert_that "stdout-sorted" --file-is-lines \ |
583 | "=> Substituting \"one\" in file" \ | | 584 | "=> Substituting \"one\" in file" \ |
584 | "=> Substituting \"three\" in file" \ | | 585 | "=> Substituting \"three\" in file" \ |
585 | "=> Substituting \"two\" in file" | | 586 | "=> Substituting \"two\" in file" |
586 | assert_that "stderr" --file-is-empty | | 587 | assert_that "stderr" --file-is-empty |
587 | assert_that "$exitcode" --equals 0 | | 588 | assert_that "$exitcode" --equals 0 |
588 | | | 589 | |
589 | test_case_end | | 590 | test_case_end |
590 | fi | | 591 | fi |
591 | | | 592 | |
592 | | | 593 | |
593 | if test_case_begin "show diff"; then | | 594 | if test_case_begin "show diff"; then |
594 | | | 595 | |
595 | create_file_lines "file" "one" "two" "three" | | 596 | create_file_lines "file" "one" "two" "three" |
596 | | | 597 | |
597 | create_file "testcase.mk" <<EOF | | 598 | create_file "testcase.mk" <<EOF |
598 | SUBST_CLASSES+= two | | 599 | SUBST_CLASSES+= two |
599 | SUBST_STAGE.two= pre-configure | | 600 | SUBST_STAGE.two= pre-configure |
600 | SUBST_FILES.two= file | | 601 | SUBST_FILES.two= file |
601 | SUBST_SED.two= -e 's,two,II,' | | 602 | SUBST_SED.two= -e 's,two,II,' |
602 | SUBST_SHOW_DIFF.two= yes | | 603 | SUBST_SHOW_DIFF.two= yes |
603 | | | 604 | |
604 | .include "prepare-subst.mk" | | 605 | .include "prepare-subst.mk" |
605 | .include "mk/subst.mk" | | 606 | .include "mk/subst.mk" |
606 | EOF | | 607 | EOF |
607 | | | 608 | |
608 | LC_ALL=C \ | | 609 | LC_ALL=C \ |
609 | run_bmake "testcase.mk" "pre-configure" \ | | 610 | run_bmake "testcase.mk" "pre-configure" \ |
610 | 1> "$tmpdir/stdout" \ | | 611 | 1> "$tmpdir/stdout" \ |
611 | 2> "$tmpdir/stderr" \ | | 612 | 2> "$tmpdir/stderr" \ |
612 | && exitcode=0 || exitcode=$? | | 613 | && exitcode=0 || exitcode=$? |
613 | | | 614 | |
614 | awk '{ if (/^(---|\+\+\+) /) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \ | | 615 | awk '{ if (/^(---|\+\+\+) /) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \ |
615 | < "$tmpdir/stdout" > "$tmpdir/stdout-filtered" | | 616 | < "$tmpdir/stdout" > "$tmpdir/stdout-filtered" |
616 | | | 617 | |
617 | assert_that "file" --file-is-lines "one" "II" "three" | | 618 | assert_that "file" --file-is-lines "one" "II" "three" |
618 | assert_that "stdout-filtered" --file-is-lines \ | | 619 | assert_that "stdout-filtered" --file-is-lines \ |
619 | "=> Substituting \"two\" in file" \ | | 620 | "=> Substituting \"two\" in file" \ |
620 | "--- file (filtered timestamp)" \ | | 621 | "--- file (filtered timestamp)" \ |
621 | "+++ file.subst.sav (filtered timestamp)" \ | | 622 | "+++ file.subst.sav (filtered timestamp)" \ |
622 | "@@ -1,3 +1,3 @@" \ | | 623 | "@@ -1,3 +1,3 @@" \ |
623 | " one" \ | | 624 | " one" \ |
624 | "-two" \ | | 625 | "-two" \ |
625 | "+II" \ | | 626 | "+II" \ |
626 | " three" | | 627 | " three" |
627 | assert_that "stderr" --file-is-empty | | 628 | assert_that "stderr" --file-is-empty |
628 | assert_that "$exitcode" --equals 0 | | 629 | assert_that "$exitcode" --equals 0 |
629 | | | 630 | |
630 | test_case_end | | 631 | test_case_end |
631 | fi | | 632 | fi |
632 | | | 633 | |
633 | | | 634 | |
634 | if test_case_begin "global show diff"; then | | 635 | if test_case_begin "global show diff"; then |
635 | | | 636 | |
636 | create_file_lines "file" "one" "two" "three" | | 637 | create_file_lines "file" "one" "two" "three" |
637 | | | 638 | |
638 | create_file "testcase.mk" <<EOF | | 639 | create_file "testcase.mk" <<EOF |
639 | SUBST_CLASSES+= two | | 640 | SUBST_CLASSES+= two |
640 | SUBST_STAGE.two= pre-configure | | 641 | SUBST_STAGE.two= pre-configure |
641 | SUBST_FILES.two= file | | 642 | SUBST_FILES.two= file |
642 | SUBST_SED.two= -e 's,two,II,' | | 643 | SUBST_SED.two= -e 's,two,II,' |
643 | SUBST_SHOW_DIFF= yes | | 644 | SUBST_SHOW_DIFF= yes |
644 | | | 645 | |
645 | .include "prepare-subst.mk" | | 646 | .include "prepare-subst.mk" |
646 | .include "mk/subst.mk" | | 647 | .include "mk/subst.mk" |
647 | EOF | | 648 | EOF |
648 | | | 649 | |
649 | run_bmake "testcase.mk" "pre-configure" \ | | 650 | run_bmake "testcase.mk" "pre-configure" \ |
650 | 1> "$tmpdir/stdout" \ | | 651 | 1> "$tmpdir/stdout" \ |
651 | 2> "$tmpdir/stderr" \ | | 652 | 2> "$tmpdir/stderr" \ |
652 | && exitcode=0 || exitcode=$? | | 653 | && exitcode=0 || exitcode=$? |
653 | | | 654 | |
654 | awk '{ if (/^(---|\+\+\+) /) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \ | | 655 | awk '{ if (/^(---|\+\+\+) /) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \ |
655 | < "$tmpdir/stdout" > "$tmpdir/stdout-filtered" | | 656 | < "$tmpdir/stdout" > "$tmpdir/stdout-filtered" |
656 | | | 657 | |
657 | assert_that "file" --file-is-lines "one" "II" "three" | | 658 | assert_that "file" --file-is-lines "one" "II" "three" |
658 | assert_that "stdout-filtered" --file-is-lines \ | | 659 | assert_that "stdout-filtered" --file-is-lines \ |
659 | "=> Substituting \"two\" in file" \ | | 660 | "=> Substituting \"two\" in file" \ |
660 | "--- file (filtered timestamp)" \ | | 661 | "--- file (filtered timestamp)" \ |
661 | "+++ file.subst.sav (filtered timestamp)" \ | | 662 | "+++ file.subst.sav (filtered timestamp)" \ |
662 | "@@ -1,3 +1,3 @@" \ | | 663 | "@@ -1,3 +1,3 @@" \ |
663 | " one" \ | | 664 | " one" \ |
664 | "-two" \ | | 665 | "-two" \ |
665 | "+II" \ | | 666 | "+II" \ |
666 | " three" | | 667 | " three" |
667 | assert_that "stderr" --file-is-empty | | 668 | assert_that "stderr" --file-is-empty |
668 | assert_that "$exitcode" --equals 0 | | 669 | assert_that "$exitcode" --equals 0 |
669 | | | 670 | |
670 | test_case_end | | 671 | test_case_end |
671 | fi | | 672 | fi |
672 | | | 673 | |
673 | | | 674 | |
674 | if test_case_begin "SUBST_VARS"; then | | 675 | if test_case_begin "SUBST_VARS"; then |
675 | | | 676 | |
676 | create_file_lines "testcase.mk" \ | | 677 | create_file_lines "testcase.mk" \ |
677 | 'SUBST_CLASSES+= vars' \ | | 678 | 'SUBST_CLASSES+= vars' \ |
678 | 'SUBST_STAGE.vars= pre-configure' \ | | 679 | 'SUBST_STAGE.vars= pre-configure' \ |
679 | 'SUBST_FILES.vars= vars.txt' \ | | 680 | 'SUBST_FILES.vars= vars.txt' \ |
680 | 'SUBST_VARS.vars= PLAIN DQUOT SQUOT DELIM PRINTABLE' \ | | 681 | 'SUBST_VARS.vars= PLAIN DQUOT SQUOT DELIM PRINTABLE' \ |
681 | 'SUBST_VARS.vars+= UNDEFINED' \ | | 682 | 'SUBST_VARS.vars+= UNDEFINED' \ |
682 | '' \ | | 683 | '' \ |
683 | 'PLAIN= plain' \ | | 684 | 'PLAIN= plain' \ |
684 | 'DQUOT= "double quoted"' \ | | 685 | 'DQUOT= "double quoted"' \ |
685 | 'SQUOT= '\''single quoted'\''' \ | | 686 | 'SQUOT= '\''single quoted'\''' \ |
686 | 'DELIM= hello, world' \ | | 687 | 'DELIM= hello, world' \ |
687 | 'PRINTABLE= !"\#$$%&'\''()*+,-./09:;<=>?@AZ[\]^_`az{|}' \ | | 688 | 'PRINTABLE= !"\#$$%&'\''()*+,-./09:;<=>?@AZ[\]^_`az{|}' \ |
688 | '#UNDEFINED= # undefined' \ | | 689 | '#UNDEFINED= # undefined' \ |
689 | '' \ | | 690 | '' \ |
690 | '.include "prepare-subst.mk"' \ | | 691 | '.include "prepare-subst.mk"' \ |
691 | '.include "mk/subst.mk"' | | 692 | '.include "mk/subst.mk"' |
692 | create_file_lines "vars.txt" \ | | 693 | create_file_lines "vars.txt" \ |
693 | "@PLAIN@" \ | | 694 | "@PLAIN@" \ |
694 | "@DQUOT@" \ | | 695 | "@DQUOT@" \ |
695 | "@SQUOT@" \ | | 696 | "@SQUOT@" \ |
696 | "@DELIM@" \ | | 697 | "@DELIM@" \ |
697 | "@PRINTABLE@" \ | | 698 | "@PRINTABLE@" \ |
698 | "@UNDEFINED@" | | 699 | "@UNDEFINED@" |
699 | | | 700 | |
700 | run_bmake "testcase.mk" "pre-configure" \ | | 701 | run_bmake "testcase.mk" "pre-configure" \ |
701 | 1> "$tmpdir/stdout" \ | | 702 | 1> "$tmpdir/stdout" \ |
702 | 2> "$tmpdir/stderr" \ | | 703 | 2> "$tmpdir/stderr" \ |
703 | && exitcode=0 || exitcode=$? | | 704 | && exitcode=0 || exitcode=$? |
704 | | | 705 | |
705 | # The double quotes and single quotes are kept since the variables | | 706 | # The double quotes and single quotes are kept since the variables |
706 | # are treated as simple string variables, not as lists of shell | | 707 | # are treated as simple string variables, not as lists of shell |
707 | # words. In these string variables, the quotes are part of the value. | | 708 | # words. In these string variables, the quotes are part of the value. |
708 | assert_that "vars.txt" --file-is-lines \ | | 709 | assert_that "vars.txt" --file-is-lines \ |
709 | "plain" \ | | 710 | "plain" \ |
710 | "\"double quoted\"" \ | | 711 | "\"double quoted\"" \ |
711 | "'single quoted'" \ | | 712 | "'single quoted'" \ |
712 | "hello, world" \ | | 713 | "hello, world" \ |
713 | '!"#$%&'\''()*+,-./09:;<=>?@AZ[\]^_`az{|}' \ | | 714 | '!"#$%&'\''()*+,-./09:;<=>?@AZ[\]^_`az{|}' \ |
714 | "" | | 715 | "" |
715 | assert_that "stdout" --file-is-lines \ | | 716 | assert_that "stdout" --file-is-lines \ |
716 | "=> Substituting \"vars\" in vars.txt" | | 717 | "=> Substituting \"vars\" in vars.txt" |
717 | assert_that "stderr" --file-is-empty | | 718 | assert_that "stderr" --file-is-empty |
718 | assert_that "$exitcode" --equals 0 | | 719 | assert_that "$exitcode" --equals 0 |
719 | | | 720 | |
720 | test_case_end | | 721 | test_case_end |
721 | fi | | 722 | fi |
722 | | | 723 | |
723 | if test_case_begin "SUBST_VARS with surrounding whitespace"; then | | 724 | if test_case_begin "SUBST_VARS with surrounding whitespace"; then |
724 | | | 725 | |
725 | # Ensure that leading and trailing whitespace is preserved | | 726 | # Ensure that leading and trailing whitespace is preserved |
726 | # in the variable values. | | 727 | # in the variable values. |
727 | | | 728 | |
728 | create_file_lines "testcase.mk" \ | | 729 | create_file_lines "testcase.mk" \ |
729 | 'SUBST_CLASSES+= vars' \ | | 730 | 'SUBST_CLASSES+= vars' \ |
730 | 'SUBST_STAGE.vars= pre-configure' \ | | 731 | 'SUBST_STAGE.vars= pre-configure' \ |
731 | 'SUBST_FILES.vars= vars.txt' \ | | 732 | 'SUBST_FILES.vars= vars.txt' \ |
732 | 'SUBST_VARS.vars= SPACE TAB NEWLINE' \ | | 733 | 'SUBST_VARS.vars= SPACE TAB NEWLINE' \ |
733 | '' \ | | 734 | '' \ |
734 | 'SPACE= ${:U }between spaces${:U }' \ | | 735 | 'SPACE= ${:U }between spaces${:U }' \ |
735 | 'TAB= ${:U }between tabs${:U }' \ | | 736 | 'TAB= ${:U }between tabs${:U }' \ |
736 | 'NEWLINE= ${.newline}between newlines${.newline}' \ | | 737 | 'NEWLINE= ${.newline}between newlines${.newline}' \ |
737 | '' \ | | 738 | '' \ |
738 | '.include "prepare-subst.mk"' \ | | 739 | '.include "prepare-subst.mk"' \ |
739 | '.include "mk/subst.mk"' | | 740 | '.include "mk/subst.mk"' |
740 | create_file_lines "vars.txt" \ | | 741 | create_file_lines "vars.txt" \ |
741 | "@SPACE@" \ | | 742 | "@SPACE@" \ |
742 | "@TAB@" \ | | 743 | "@TAB@" \ |
743 | "@NEWLINE@" | | 744 | "@NEWLINE@" |
744 | | | 745 | |
745 | run_bmake "testcase.mk" "pre-configure" \ | | 746 | run_bmake "testcase.mk" "pre-configure" \ |
746 | 1> "$tmpdir/stdout" \ | | 747 | 1> "$tmpdir/stdout" \ |
747 | 2> "$tmpdir/stderr" \ | | 748 | 2> "$tmpdir/stderr" \ |
748 | && exitcode=0 || exitcode=$? | | 749 | && exitcode=0 || exitcode=$? |
749 | | | 750 | |
750 | space=' ' | | 751 | space=' ' |
751 | tab=' ' | | 752 | tab=' ' |
752 | newline=' | | 753 | newline=' |
753 | ' | | 754 | ' |
754 | assert_that "vars.txt" --file-is-lines \ | | 755 | assert_that "vars.txt" --file-is-lines \ |
755 | "$space""between spaces""$space" \ | | 756 | "$space""between spaces""$space" \ |
756 | "$tab""between tabs""$tab" \ | | 757 | "$tab""between tabs""$tab" \ |
757 | "$newline""between newlines""$newline" | | 758 | "$newline""between newlines""$newline" |
758 | assert_that "stdout" --file-is-lines \ | | 759 | assert_that "stdout" --file-is-lines \ |
759 | "=> Substituting \"vars\" in vars.txt" | | 760 | "=> Substituting \"vars\" in vars.txt" |
760 | assert_that "stderr" --file-is-empty | | 761 | assert_that "stderr" --file-is-empty |
761 | assert_that "$exitcode" --equals 0 | | 762 | assert_that "$exitcode" --equals 0 |
762 | | | 763 | |
763 | test_case_end | | 764 | test_case_end |
764 | fi | | 765 | fi |
765 | | | 766 | |
766 | | | 767 | |
767 | if test_case_begin "SUBST_VARS with backslashes"; then | | 768 | if test_case_begin "SUBST_VARS with backslashes"; then |
768 | | | 769 | |
769 | create_file_lines "testcase.mk" \ | | 770 | create_file_lines "testcase.mk" \ |
770 | 'SUBST_CLASSES+= bs' \ | | 771 | 'SUBST_CLASSES+= bs' \ |
771 | 'SUBST_STAGE.bs= pre-configure' \ | | 772 | 'SUBST_STAGE.bs= pre-configure' \ |
772 | 'SUBST_FILES.bs= backslash.txt' \ | | 773 | 'SUBST_FILES.bs= backslash.txt' \ |
773 | 'SUBST_VARS.bs= BACKSLASHES' \ | | 774 | 'SUBST_VARS.bs= BACKSLASHES' \ |
774 | '' \ | | 775 | '' \ |
775 | 'BACKSLASHES= \" \, \\, \" \'\'' \0\000 \x40 \089 \a \$$' \ | | 776 | 'BACKSLASHES= \" \, \\, \" \'\'' \0\000 \x40 \089 \a \$$' \ |
776 | '' \ | | 777 | '' \ |
777 | '.include "prepare-subst.mk"' \ | | 778 | '.include "prepare-subst.mk"' \ |
778 | '.include "mk/subst.mk"' | | 779 | '.include "mk/subst.mk"' |
779 | create_file_lines "backslash.txt" "@BACKSLASHES@" | | 780 | create_file_lines "backslash.txt" "@BACKSLASHES@" |
780 | | | 781 | |
781 | run_bmake "testcase.mk" "pre-configure" \ | | 782 | run_bmake "testcase.mk" "pre-configure" \ |
782 | 1> "$tmpdir/stdout" \ | | 783 | 1> "$tmpdir/stdout" \ |
783 | 2> "$tmpdir/stderr" \ | | 784 | 2> "$tmpdir/stderr" \ |
784 | && exitcode=0 || exitcode=$? | | 785 | && exitcode=0 || exitcode=$? |
785 | | | 786 | |
786 | assert_that "backslash.txt" --file-is-lines \ | | 787 | assert_that "backslash.txt" --file-is-lines \ |
787 | '\" \, \\, \" \'\'' \0\000 \x40 \089 \a \$' | | 788 | '\" \, \\, \" \'\'' \0\000 \x40 \089 \a \$' |
788 | assert_that "stdout" --file-is-lines \ | | 789 | assert_that "stdout" --file-is-lines \ |
789 | "=> Substituting \"bs\" in backslash.txt" | | 790 | "=> Substituting \"bs\" in backslash.txt" |
790 | assert_that "stderr" --file-is-empty | | 791 | assert_that "stderr" --file-is-empty |
791 | assert_that "$exitcode" --equals 0 | | 792 | assert_that "$exitcode" --equals 0 |
792 | | | 793 | |
793 | test_case_end | | 794 | test_case_end |
794 | fi | | 795 | fi |
795 | | | 796 | |
796 | | | 797 | |
797 | if test_case_begin "SUBST_VARS for variables with regex characters"; then | | 798 | if test_case_begin "SUBST_VARS for variables with regex characters"; then |
798 | | | 799 | |
799 | # Ensure that special regex characters like dots and parentheses | | 800 | # Ensure that special regex characters like dots and parentheses |
800 | # may appear in variable names and are properly escaped. | | 801 | # may appear in variable names and are properly escaped. |
801 | | | 802 | |
802 | # Variable names containing a dollar are not supported. | | 803 | # Variable names containing a dollar are not supported. |
803 | # Bmake behaves very surprisingly when a $ is expanded inside a :C | | 804 | # Bmake behaves very surprisingly when a $ is expanded inside a :C |
804 | # modifier. Nobody needs this feature anyway, it was just an | | 805 | # modifier. Nobody needs this feature anyway, it was just an |
805 | # experiment to see whether this would be theoretically possible. | | 806 | # experiment to see whether this would be theoretically possible. |
806 | | | 807 | |
807 | # Variable names ending with a backslash are not supported. | | 808 | # Variable names ending with a backslash are not supported. |
808 | # The backslash may only occur in the middle of the variable name. | | 809 | # The backslash may only occur in the middle of the variable name. |
809 | | | 810 | |
810 | create_file_lines "testcase.mk" \ | | 811 | create_file_lines "testcase.mk" \ |
811 | 'SUBST_CLASSES+= vars' \ | | 812 | 'SUBST_CLASSES+= vars' \ |
812 | 'SUBST_STAGE.vars= pre-configure' \ | | 813 | 'SUBST_STAGE.vars= pre-configure' \ |
813 | 'SUBST_FILES.vars= vars.txt' \ | | 814 | 'SUBST_FILES.vars= vars.txt' \ |
814 | 'SUBST_VARS.vars= VAR...... VAR.abcde' \ | | 815 | 'SUBST_VARS.vars= VAR...... VAR.abcde' \ |
815 | 'SUBST_VARS.vars+= VAR.() VAR.<> VAR.[]' \ | | 816 | 'SUBST_VARS.vars+= VAR.() VAR.<> VAR.[]' \ |
816 | 'SUBST_VARS.vars+= VAR.$$x VAR.^ VAR.\x' \ | | 817 | 'SUBST_VARS.vars+= VAR.$$x VAR.^ VAR.\x' \ |
817 | '' \ | | 818 | '' \ |
818 | 'VAR......= dots' \ | | 819 | 'VAR......= dots' \ |
819 | 'VAR.abcde= letters' \ | | 820 | 'VAR.abcde= letters' \ |
820 | 'VAR.()= parentheses' \ | | 821 | 'VAR.()= parentheses' \ |
821 | 'VAR.<>= angle brackets' \ | | 822 | 'VAR.<>= angle brackets' \ |
822 | 'VAR.[]= square brackets' \ | | 823 | 'VAR.[]= square brackets' \ |
823 | 'VAR.$$x= dollar' \ | | 824 | 'VAR.$$x= dollar' \ |
824 | 'VAR.^= circumflex' \ | | 825 | 'VAR.^= circumflex' \ |
825 | 'VAR.\x= backslash' \ | | 826 | 'VAR.\x= backslash' \ |
826 | '' \ | | 827 | '' \ |
827 | '.include "prepare-subst.mk"' \ | | 828 | '.include "prepare-subst.mk"' \ |
828 | '.include "mk/subst.mk"' | | 829 | '.include "mk/subst.mk"' |
829 | create_file_lines "vars.txt" \ | | 830 | create_file_lines "vars.txt" \ |
830 | "@VAR......@" \ | | 831 | "@VAR......@" \ |
831 | "@VAR.abcde@" \ | | 832 | "@VAR.abcde@" \ |
832 | "@VAR.()@" \ | | 833 | "@VAR.()@" \ |
833 | "@VAR.<>@" \ | | 834 | "@VAR.<>@" \ |
834 | "@VAR.[]@" \ | | 835 | "@VAR.[]@" \ |
835 | '@VAR.$x@' \ | | 836 | '@VAR.$x@' \ |
836 | '@VAR.^@' \ | | 837 | '@VAR.^@' \ |
837 | '@VAR.\x@' | | 838 | '@VAR.\x@' |
838 | | | 839 | |
839 | run_bmake "testcase.mk" "pre-configure" \ | | 840 | run_bmake "testcase.mk" "pre-configure" \ |
840 | 1> "$tmpdir/stdout" \ | | 841 | 1> "$tmpdir/stdout" \ |
841 | 2> "$tmpdir/stderr" \ | | 842 | 2> "$tmpdir/stderr" \ |
842 | && exitcode=0 || exitcode=$? | | 843 | && exitcode=0 || exitcode=$? |
843 | | | 844 | |
844 | assert_that "vars.txt" --file-is-lines \ | | 845 | assert_that "vars.txt" --file-is-lines \ |
845 | "dots" \ | | 846 | "dots" \ |
846 | "letters" \ | | 847 | "letters" \ |
847 | "parentheses" \ | | 848 | "parentheses" \ |
848 | "angle brackets" \ | | 849 | "angle brackets" \ |
849 | "square brackets" \ | | 850 | "square brackets" \ |
850 | '@VAR.$x@' \ | | 851 | '@VAR.$x@' \ |
851 | 'circumflex' \ | | 852 | 'circumflex' \ |
852 | 'backslash' | | 853 | 'backslash' |
853 | assert_that "stdout" --file-is-lines \ | | 854 | assert_that "stdout" --file-is-lines \ |
854 | "=> Substituting \"vars\" in vars.txt" | | 855 | "=> Substituting \"vars\" in vars.txt" |
855 | assert_that "stderr" --file-is-empty | | 856 | assert_that "stderr" --file-is-empty |
856 | assert_that "$exitcode" --equals 0 | | 857 | assert_that "$exitcode" --equals 0 |
857 | | | 858 | |
858 | test_case_end | | 859 | test_case_end |
859 | fi | | 860 | fi |
860 | | | 861 | |
861 | if test_case_begin "pattern matches directory"; then | | 862 | if test_case_begin "pattern matches directory"; then |
862 | | | 863 | |
863 | # When a pattern matches a directory, that directory is silently | | 864 | # When a pattern matches a directory, that directory is silently |
864 | # skipped. | | 865 | # skipped. |
865 | # | | 866 | # |
866 | # In this test case, the pattern also matches a regular file that | | 867 | # In this test case, the pattern also matches a regular file that |
867 | # is actually modified. Therefore the pattern has an effect, and | | 868 | # is actually modified. Therefore the pattern has an effect, and |
868 | # there is no error message. | | 869 | # there is no error message. |
869 | | | 870 | |
870 | create_file_lines "testcase.mk" \ | | 871 | create_file_lines "testcase.mk" \ |
871 | 'SUBST_CLASSES+= dir' \ | | 872 | 'SUBST_CLASSES+= dir' \ |
872 | 'SUBST_STAGE.dir= pre-configure' \ | | 873 | 'SUBST_STAGE.dir= pre-configure' \ |
873 | 'SUBST_FILES.dir= sub*' \ | | 874 | 'SUBST_FILES.dir= sub*' \ |
874 | 'SUBST_VARS.dir= VAR' \ | | 875 | 'SUBST_VARS.dir= VAR' \ |
875 | 'SUBST_NOOP_OK.dir= no' \ | | 876 | 'SUBST_NOOP_OK.dir= no' \ |
876 | '' \ | | 877 | '' \ |
877 | 'VAR= value' \ | | 878 | 'VAR= value' \ |
878 | '' \ | | 879 | '' \ |
879 | '.include "prepare-subst.mk"' \ | | 880 | '.include "prepare-subst.mk"' \ |
880 | '.include "mk/subst.mk"' | | 881 | '.include "mk/subst.mk"' |
881 | mkdir "$tmpdir/subdir" | | 882 | mkdir "$tmpdir/subdir" |
882 | create_file_lines "subdir/subfile" \ | | 883 | create_file_lines "subdir/subfile" \ |
883 | "@VAR@" | | 884 | "@VAR@" |
884 | create_file_lines "subst-file" \ | | 885 | create_file_lines "subst-file" \ |
885 | "@VAR@" | | 886 | "@VAR@" |
886 | | | 887 | |
887 | run_bmake "testcase.mk" "pre-configure" \ | | 888 | run_bmake "testcase.mk" "pre-configure" \ |
888 | 1> "$tmpdir/stdout" \ | | 889 | 1> "$tmpdir/stdout" \ |
889 | 2> "$tmpdir/stderr" \ | | 890 | 2> "$tmpdir/stderr" \ |
890 | && exitcode=0 || exitcode=$? | | 891 | && exitcode=0 || exitcode=$? |
891 | | | 892 | |
892 | assert_that "subst-file" --file-is-lines "value" | | 893 | assert_that "subst-file" --file-is-lines "value" |
893 | assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged | | 894 | assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged |
894 | assert_that "stdout" --file-is-lines \ | | 895 | assert_that "stdout" --file-is-lines \ |
895 | "=> Substituting \"dir\" in sub*" | | 896 | "=> Substituting \"dir\" in sub*" |
896 | assert_that "stderr" --file-is-empty | | 897 | assert_that "stderr" --file-is-empty |
897 | assert_that "$exitcode" --equals 0 | | 898 | assert_that "$exitcode" --equals 0 |
898 | | | 899 | |
899 | test_case_end | | 900 | test_case_end |
900 | fi | | 901 | fi |
901 | | | 902 | |
902 | | | 903 | |
903 | if test_case_begin "pattern matches only directory"; then | | 904 | if test_case_begin "pattern matches only directory"; then |
904 | | | 905 | |
905 | # When a pattern matches a directory, that directory is silently | | 906 | # When a pattern matches a directory, that directory is silently |
906 | # skipped. | | 907 | # skipped. |
907 | | | 908 | |
908 | create_file_lines "testcase.mk" \ | | 909 | create_file_lines "testcase.mk" \ |
909 | 'SUBST_CLASSES+= dir' \ | | 910 | 'SUBST_CLASSES+= dir' \ |
910 | 'SUBST_STAGE.dir= pre-configure' \ | | 911 | 'SUBST_STAGE.dir= pre-configure' \ |
911 | 'SUBST_FILES.dir= sub*' \ | | 912 | 'SUBST_FILES.dir= sub*' \ |
912 | 'SUBST_VARS.dir= VAR' \ | | 913 | 'SUBST_VARS.dir= VAR' \ |
913 | 'SUBST_NOOP_OK.dir= no' \ | | 914 | 'SUBST_NOOP_OK.dir= no' \ |
914 | '' \ | | 915 | '' \ |
915 | 'VAR= value' \ | | 916 | 'VAR= value' \ |
916 | '' \ | | 917 | '' \ |
917 | '.include "prepare-subst.mk"' \ | | 918 | '.include "prepare-subst.mk"' \ |
918 | '.include "mk/subst.mk"' | | 919 | '.include "mk/subst.mk"' |
919 | mkdir "$tmpdir/subdir" | | 920 | mkdir "$tmpdir/subdir" |
920 | create_file_lines "subdir/subfile" \ | | 921 | create_file_lines "subdir/subfile" \ |
921 | "@VAR@" | | 922 | "@VAR@" |
922 | | | 923 | |
923 | run_bmake "testcase.mk" "pre-configure" \ | | 924 | run_bmake "testcase.mk" "pre-configure" \ |
924 | 1> "$tmpdir/stdout" \ | | 925 | 1> "$tmpdir/stdout" \ |
925 | 2> "$tmpdir/stderr" \ | | 926 | 2> "$tmpdir/stderr" \ |
926 | && exitcode=0 || exitcode=$? | | 927 | && exitcode=0 || exitcode=$? |
927 | | | 928 | |
928 | assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged | | 929 | assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged |
929 | assert_that "stdout" --file-is-lines \ | | 930 | assert_that "stdout" --file-is-lines \ |
930 | "=> Substituting \"dir\" in sub*" \ | | 931 | "=> Substituting \"dir\" in sub*" \ |
931 | 'fail: [subst.mk:dir] The filename pattern "sub*" has no effect.' \ | | 932 | 'fail: [subst.mk:dir] The filename pattern "sub*" has no effect.' \ |
932 | "*** Error code 1" \ | | 933 | "*** Error code 1" \ |
933 | "" \ | | 934 | "" \ |
934 | "Stop." \ | | 935 | "Stop." \ |
935 | "$make: stopped in $PWD" | | 936 | "$make: stopped in $PWD" |
936 | assert_that "stderr" --file-is-empty | | 937 | assert_that "stderr" --file-is-empty |
937 | assert_that "$exitcode" --equals 1 | | 938 | assert_that "$exitcode" --equals 1 |
938 | | | 939 | |
939 | test_case_end | | 940 | test_case_end |
940 | fi | | 941 | fi |
941 | | | 942 | |
942 | | | 943 | |
943 | if test_case_begin "two filename patterns have no effect"; then | | 944 | if test_case_begin "two filename patterns have no effect"; then |
944 | | | 945 | |
945 | # All patterns of SUBST_FILES should be applied before erroring out, | | 946 | # All patterns of SUBST_FILES should be applied before erroring out, |
946 | # to give a complete picture of the situation. | | 947 | # to give a complete picture of the situation. |
947 | | | 948 | |
948 | create_file_lines "testcase.mk" \ | | 949 | create_file_lines "testcase.mk" \ |
949 | 'SUBST_CLASSES+= id' \ | | 950 | 'SUBST_CLASSES+= id' \ |
950 | 'SUBST_STAGE.id= pre-configure' \ | | 951 | 'SUBST_STAGE.id= pre-configure' \ |
951 | 'SUBST_FILES.id= file1 file2' \ | | 952 | 'SUBST_FILES.id= file1 file2' \ |
952 | 'SUBST_VARS.id= A B' \ | | 953 | 'SUBST_VARS.id= A B' \ |
953 | 'SUBST_NOOP_OK.id= no' \ | | 954 | 'SUBST_NOOP_OK.id= no' \ |
954 | 'A= a-value' \ | | 955 | 'A= a-value' \ |
955 | 'B= b-value' \ | | 956 | 'B= b-value' \ |
956 | '' \ | | 957 | '' \ |
957 | '.include "prepare-subst.mk"' \ | | 958 | '.include "prepare-subst.mk"' \ |
958 | '.include "mk/subst.mk"' | | 959 | '.include "mk/subst.mk"' |
959 | create_file_lines "file1" "nothing to replace" | | 960 | create_file_lines "file1" "nothing to replace" |
960 | create_file_lines "file2" "nothing to replace" | | 961 | create_file_lines "file2" "nothing to replace" |
961 | | | 962 | |
962 | run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \ | | 963 | run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \ |
963 | && exitcode=0 || exitcode=$? | | 964 | && exitcode=0 || exitcode=$? |
964 | | | 965 | |
965 | assert_that "out" --file-is-lines \ | | 966 | assert_that "out" --file-is-lines \ |
966 | '=> Substituting "id" in file1 file2' \ | | 967 | '=> Substituting "id" in file1 file2' \ |
967 | 'warning: [subst.mk:id] Nothing changed in "file1".' \ | | 968 | 'warning: [subst.mk:id] Nothing changed in "file1".' \ |
968 | 'warning: [subst.mk:id] Nothing changed in "file2".' \ | | 969 | 'warning: [subst.mk:id] Nothing changed in "file2".' \ |
969 | 'fail: [subst.mk:id] The filename patterns "file1 file2" have no effect.' \ | | 970 | 'fail: [subst.mk:id] The filename patterns "file1 file2" have no effect.' \ |
970 | '*** Error code 1' \ | | 971 | '*** Error code 1' \ |
971 | '' \ | | 972 | '' \ |
972 | 'Stop.' \ | | 973 | 'Stop.' \ |
973 | "$make: stopped in $PWD" | | 974 | "$make: stopped in $PWD" |
974 | | | 975 | |
975 | test_case_end | | 976 | test_case_end |
976 | fi | | 977 | fi |
977 | | | 978 | |
978 | | | 979 | |
979 | if test_case_begin "empty SUBST_FILES"; then | | 980 | if test_case_begin "empty SUBST_FILES"; then |
980 | | | 981 | |
981 | # An empty SUBST_FILES section is ok. | | 982 | # An empty SUBST_FILES section is ok. |
982 | # It may have been produced by a shell command like find(1). | | 983 | # It may have been produced by a shell command like find(1). |
983 | | | 984 | |
984 | create_file_lines "testcase.mk" \ | | 985 | create_file_lines "testcase.mk" \ |
985 | 'SUBST_CLASSES+= id' \ | | 986 | 'SUBST_CLASSES+= id' \ |
986 | 'SUBST_STAGE.id= pre-configure' \ | | 987 | 'SUBST_STAGE.id= pre-configure' \ |
987 | 'SUBST_FILES.id= # none' \ | | 988 | 'SUBST_FILES.id= # none' \ |
988 | 'SUBST_SED.id= -e s,from,to,' \ | | 989 | 'SUBST_SED.id= -e s,from,to,' \ |
989 | 'SUBST_NOOP_OK.id= no' \ | | 990 | 'SUBST_NOOP_OK.id= no' \ |
990 | '' \ | | 991 | '' \ |
991 | 'all:' \ | | 992 | 'all:' \ |
992 | ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ | | 993 | ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ |
993 | '' \ | | 994 | '' \ |
994 | '.include "prepare-subst.mk"' \ | | 995 | '.include "prepare-subst.mk"' \ |
995 | '.include "mk/subst.mk"' | | 996 | '.include "mk/subst.mk"' |
996 | | | 997 | |
997 | run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \ | | 998 | run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \ |
998 | && exitcode=0 || exitcode=$? | | 999 | && exitcode=0 || exitcode=$? |
999 | | | 1000 | |
1000 | assert_that "out" --file-is-lines \ | | 1001 | assert_that "out" --file-is-lines \ |
1001 | '=> Substituting "id" in ' \ | | 1002 | '=> Substituting "id" in ' \ |
1002 | 'ok' | | 1003 | 'ok' |
1003 | | | 1004 | |
1004 | test_case_end | | 1005 | test_case_end |
1005 | fi | | 1006 | fi |
1006 | | | 1007 | |
1007 | | | 1008 | |
1008 | if test_case_begin "empty SUBST_SED"; then | | 1009 | if test_case_begin "empty SUBST_SED"; then |
1009 | | | 1010 | |
1010 | create_file_lines "testcase.mk" \ | | 1011 | create_file_lines "testcase.mk" \ |
1011 | 'SUBST_CLASSES+= id' \ | | 1012 | 'SUBST_CLASSES+= id' \ |
1012 | 'SUBST_STAGE.id= pre-configure' \ | | 1013 | 'SUBST_STAGE.id= pre-configure' \ |
1013 | 'SUBST_FILES.id= file' \ | | 1014 | 'SUBST_FILES.id= file' \ |
1014 | 'SUBST_SED.id= # none' \ | | 1015 | 'SUBST_SED.id= # none' \ |
1015 | 'SUBST_NOOP_OK.id= no' \ | | 1016 | 'SUBST_NOOP_OK.id= no' \ |
1016 | '' \ | | 1017 | '' \ |
1017 | 'all:' \ | | 1018 | 'all:' \ |
1018 | ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ | | 1019 | ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ |
1019 | '' \ | | 1020 | '' \ |
1020 | '.include "prepare-subst.mk"' \ | | 1021 | '.include "prepare-subst.mk"' \ |
1021 | '.include "mk/subst.mk"' | | 1022 | '.include "mk/subst.mk"' |
1022 | | | 1023 | |
1023 | run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \ | | 1024 | run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \ |
1024 | && exitcode=0 || exitcode=$? | | 1025 | && exitcode=0 || exitcode=$? |
1025 | | | 1026 | |
1026 | assert_that "out" --file-is-lines \ | | 1027 | assert_that "out" --file-is-lines \ |
1027 | '=> Substituting "id" in file' \ | | 1028 | '=> Substituting "id" in file' \ |
1028 | 'warning: [subst.mk:id] Ignoring non-existent file "file".' \ | | 1029 | 'warning: [subst.mk:id] Ignoring non-existent file "file".' \ |
1029 | 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ | | 1030 | 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ |
1030 | '*** Error code 1' \ | | 1031 | '*** Error code 1' \ |
1031 | '' \ | | 1032 | '' \ |
1032 | 'Stop.' \ | | 1033 | 'Stop.' \ |
1033 | "$make: stopped in $PWD" | | 1034 | "$make: stopped in $PWD" |
1034 | | | 1035 | |
1035 | test_case_end | | 1036 | test_case_end |
1036 | fi | | 1037 | fi |
1037 | | | 1038 | |
1038 | | | 1039 | |
1039 | if test_case_begin "typo in SUBST_CLASSES"; then | | 1040 | if test_case_begin "typo in SUBST_CLASSES"; then |
1040 | | | 1041 | |
1041 | # Look closely. The SUBST_CLASSES line contains a typo. | | 1042 | # Look closely. The SUBST_CLASSES line contains a typo. |
1042 | # subst.mk does not catch this, but pkglint does. | | 1043 | # subst.mk does not catch this, but pkglint does. |
1043 | | | 1044 | |
1044 | create_file_lines "testcase.mk" \ | | 1045 | create_file_lines "testcase.mk" \ |
1045 | 'SUBST_CLASSES=+ id' \ | | 1046 | 'SUBST_CLASSES=+ id' \ |
1046 | 'SUBST_STAGE.id= pre-configure' \ | | 1047 | 'SUBST_STAGE.id= pre-configure' \ |
1047 | 'SUBST_FILES.id= file' \ | | 1048 | 'SUBST_FILES.id= file' \ |
1048 | 'SUBST_SED.id= # none' \ | | 1049 | 'SUBST_SED.id= # none' \ |
1049 | 'SUBST_NOOP_OK.id= no' \ | | 1050 | 'SUBST_NOOP_OK.id= no' \ |
1050 | '' \ | | 1051 | '' \ |
1051 | 'all:' \ | | 1052 | 'all:' \ |
1052 | ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ | | 1053 | ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ |
1053 | '' \ | | 1054 | '' \ |
1054 | '.include "prepare-subst.mk"' \ | | 1055 | '.include "prepare-subst.mk"' \ |
1055 | '.include "mk/subst.mk"' | | 1056 | '.include "mk/subst.mk"' |
1056 | | | 1057 | |
1057 | run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \ | | 1058 | run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \ |
1058 | && exitcode=0 || exitcode=$? | | 1059 | && exitcode=0 || exitcode=$? |
1059 | | | 1060 | |
1060 | assert_that "out" --file-is-lines \ | | 1061 | assert_that "out" --file-is-lines \ |
1061 | '=> Substituting "id" in file' \ | | 1062 | '=> Substituting "id" in file' \ |
1062 | 'warning: [subst.mk:id] Ignoring non-existent file "file".' \ | | 1063 | 'warning: [subst.mk:id] Ignoring non-existent file "file".' \ |
1063 | 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ | | 1064 | 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ |
1064 | '*** Error code 1' \ | | 1065 | '*** Error code 1' \ |
1065 | '' \ | | 1066 | '' \ |
1066 | 'Stop.' \ | | 1067 | 'Stop.' \ |
1067 | "$make: stopped in $PWD" | | 1068 | "$make: stopped in $PWD" |
1068 | | | 1069 | |
1069 | test_case_end | | 1070 | test_case_end |
1070 | fi | | 1071 | fi |
1071 | | | 1072 | |
1072 | | | 1073 | |
1073 | if test_case_begin "executable bit is preserved"; then | | 1074 | if test_case_begin "executable bit is preserved"; then |
1074 | | | 1075 | |
1075 | create_file_lines "testcase.mk" \ | | 1076 | create_file_lines "testcase.mk" \ |
1076 | 'SUBST_CLASSES+= id' \ | | 1077 | 'SUBST_CLASSES+= id' \ |
1077 | 'SUBST_STAGE.id= pre-configure' \ | | 1078 | 'SUBST_STAGE.id= pre-configure' \ |
1078 | 'SUBST_FILES.id= cmd data' \ | | 1079 | 'SUBST_FILES.id= cmd data' \ |
1079 | 'SUBST_VARS.id= VAR' \ | | 1080 | 'SUBST_VARS.id= VAR' \ |
1080 | 'VAR= replaced' \ | | 1081 | 'VAR= replaced' \ |
1081 | '' \ | | 1082 | '' \ |
1082 | '.include "prepare-subst.mk"' \ | | 1083 | '.include "prepare-subst.mk"' \ |
1083 | '.include "mk/subst.mk"' | | 1084 | '.include "mk/subst.mk"' |
1084 | create_file_lines "cmd" \ | | 1085 | create_file_lines "cmd" \ |
1085 | '@VAR@' | | 1086 | '@VAR@' |
1086 | create_file_lines "data" \ | | 1087 | create_file_lines "data" \ |
1087 | '@VAR@' | | 1088 | '@VAR@' |
1088 | chmod +x "$tmpdir/cmd" | | 1089 | chmod +x "$tmpdir/cmd" |
1089 | | | 1090 | |
1090 | run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \ | | 1091 | run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \ |
1091 | && exitcode=0 || exitcode=$? | | 1092 | && exitcode=0 || exitcode=$? |
1092 | | | 1093 | |
1093 | assert_that "out" --file-is-lines \ | | 1094 | assert_that "out" --file-is-lines \ |
1094 | '=> Substituting "id" in cmd data' | | 1095 | '=> Substituting "id" in cmd data' |
1095 | assert_that "cmd" --file-is-lines "replaced" | | 1096 | assert_that "cmd" --file-is-lines "replaced" |
1096 | assert_that "data" --file-is-lines "replaced" | | 1097 | assert_that "data" --file-is-lines "replaced" |
1097 | [ -x "$tmpdir/cmd" ] \ | | 1098 | [ -x "$tmpdir/cmd" ] \ |
1098 | || assert_fail "cmd must still be executable" | | 1099 | || assert_fail "cmd must still be executable" |
1099 | [ -x "$tmpdir/data" ] \ | | 1100 | [ -x "$tmpdir/data" ] \ |
1100 | && assert_fail "data must not be executable" | | 1101 | && assert_fail "data must not be executable" |
1101 | | | 1102 | |
1102 | test_case_end | | 1103 | test_case_end |
1103 | fi | | 1104 | fi |
1104 | | | 1105 | |
1105 | | | 1106 | |
1106 | if test_case_begin "unreadable file"; then | | 1107 | if test_case_begin "unreadable file"; then |
1107 | | | 1108 | |
1108 | create_file_lines "testcase.mk" \ | | 1109 | create_file_lines "testcase.mk" \ |
1109 | 'SUBST_CLASSES+= id' \ | | 1110 | 'SUBST_CLASSES+= id' \ |
1110 | 'SUBST_STAGE.id= pre-configure' \ | | 1111 | 'SUBST_STAGE.id= pre-configure' \ |
1111 | 'SUBST_FILES.id= unreadable-file' \ | | 1112 | 'SUBST_FILES.id= unreadable-file' \ |
1112 | 'SUBST_SED.id= -e s,before,after,' \ | | 1113 | 'SUBST_SED.id= -e s,before,after,' \ |
1113 | '' \ | | 1114 | '' \ |
1114 | '.include "prepare-subst.mk"' \ | | 1115 | '.include "prepare-subst.mk"' \ |
1115 | '.include "mk/subst.mk"' | | 1116 | '.include "mk/subst.mk"' |
1116 | create_file_lines "unreadable-file" \ | | 1117 | create_file_lines "unreadable-file" \ |
1117 | 'before' | | 1118 | 'before' |
1118 | chmod 0000 "$tmpdir/unreadable-file" | | 1119 | chmod 0000 "$tmpdir/unreadable-file" |
1119 | | | 1120 | |
1120 | run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \ | | 1121 | run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \ |
1121 | && exitcode=0 || exitcode=$? | | 1122 | && exitcode=0 || exitcode=$? |
1122 | | | 1123 | |
1123 | assert_that "out" --file-is-lines \ | | 1124 | assert_that "out" --file-is-lines \ |
1124 | '=> Substituting "id" in unreadable-file' \ | | 1125 | '=> Substituting "id" in unreadable-file' \ |
1125 | 'sh: cannot open unreadable-file: permission denied' \ | | 1126 | 'sh: cannot open unreadable-file: permission denied' \ |
1126 | 'sh: cannot open unreadable-file: permission denied' \ | | 1127 | 'sh: cannot open unreadable-file: permission denied' \ |
1127 | '*** Error code 1' \ | | 1128 | '*** Error code 1' \ |
1128 | '' \ | | 1129 | '' \ |
1129 | 'Stop.' \ | | 1130 | 'Stop.' \ |
1130 | "$make: stopped in $PWD" | | 1131 | "$make: stopped in $PWD" |
1131 | | | 1132 | |
1132 | test_case_end | | 1133 | test_case_end |
1133 | fi | | 1134 | fi |
| | | 1135 | |
| | | 1136 | |
| | | 1137 | if test_case_begin "identity substitution implementation"; then |
| | | 1138 | |
| | | 1139 | assert_identity() { |
| | | 1140 | ai_expected="$1"; shift |
| | | 1141 | awk -f "$pkgsrcdir/mk/scripts/subst-identity.awk" -- "$@" \ |
| | | 1142 | && ai_actual="yes" || ai_actual="no" |
| | | 1143 | |
| | | 1144 | [ "$ai_actual" = "$ai_expected" ] \ |
| | | 1145 | || assert_fail "expected '%s', got '%s' for %s\n" "$ai_expected" "$ai_actual" "$*" |
| | | 1146 | } |
| | | 1147 | |
| | | 1148 | # If there is no SUBST_SED at all, this is not the situation |
| | | 1149 | # that is targeted by this test for identity substitution. |
| | | 1150 | assert_identity "no" # no substitutions at all |
| | | 1151 | |
| | | 1152 | # Even though this is an identity substitution, it is missing |
| | | 1153 | # the -e option and thus does not follow the usual format. |
| | | 1154 | # Therefore it is considered just a normal substitution. |
| | | 1155 | assert_identity "no" 's,from,from,' |
| | | 1156 | |
| | | 1157 | # The following are typical identity substitutions. |
| | | 1158 | # It does not matter whether the g modifier is there or not. |
| | | 1159 | # Unknown modifiers are not allowed though. |
| | | 1160 | assert_identity "yes" -e 's,from,from,' |
| | | 1161 | assert_identity "yes" -e 's;from;from;' |
| | | 1162 | assert_identity "yes" -e 's,from,from,g' |
| | | 1163 | assert_identity "no" -e 's,from,from,gunknown' |
| | | 1164 | |
| | | 1165 | # The identity substitution may include characters other than |
| | | 1166 | # A-Za-z0-9, but no characters that have a special meaning in |
| | | 1167 | # basic regular expressions. |
| | | 1168 | assert_identity "yes" -e 's,/dev/audio,/dev/audio,' |
| | | 1169 | assert_identity "yes" -e 's!/dev/audio!/dev/audio!' |
| | | 1170 | |
| | | 1171 | # There may be several identity substitutions in the same |
| | | 1172 | # SUBST_SED. As long as all these substitutions are identity |
| | | 1173 | # substitutions, they may be skipped. As soon as there is one |
| | | 1174 | # other substitution, the whole SUBST_SED is treated as usual. |
| | | 1175 | assert_identity "yes" -e 's;from;from;' -e 's!second!second!' |
| | | 1176 | assert_identity "no" -e 's,changing,x,' -e 's,id,id,' |
| | | 1177 | assert_identity "no" -e 's,id,id,' -e 's,changing,x,' |
| | | 1178 | |
| | | 1179 | # A demonstration of all ASCII characters that may appear in an |
| | | 1180 | # identity substitution. |
| | | 1181 | # |
| | | 1182 | # The # and $ are excluded since they are interpreted specially |
| | | 1183 | # in Makefiles and would thus be confusing to the human reader. |
| | | 1184 | # |
| | | 1185 | # The characters *.?[\]^ have a special meaning in the pattern of the |
| | | 1186 | # substitution. |
| | | 1187 | # The & has a special meaning in the replacement of the |
| | | 1188 | # substitution. |
| | | 1189 | specials='!"%'\''()+,-/:;<=>@_`{|}~' |
| | | 1190 | assert_identity "yes" -e "sX${specials}X${specials}X" |
| | | 1191 | |
| | | 1192 | test_case_end |
| | | 1193 | fi |
| | | 1194 | |
| | | 1195 | |
| | | 1196 | if test_case_begin "identity substitution, found in file"; then |
| | | 1197 | |
| | | 1198 | # There are many situations in which a fixed text is replaced |
| | | 1199 | # with a dynamic value that may or may not be equal to the |
| | | 1200 | # original text. |
| | | 1201 | # |
| | | 1202 | # Typical examples are s|man|${PKGMANDIR}|, s|/usr/pkg|${PREFIX}|, |
| | | 1203 | # s|/dev/audio|${DEVOSSAUDIO}|. |
| | | 1204 | # |
| | | 1205 | # It is not an error if these substitutions result in a no-op, |
| | | 1206 | # provided that the text is actually found in the file. |
| | | 1207 | # |
| | | 1208 | # Alternatives for this special exception would be: |
| | | 1209 | # |
| | | 1210 | # 1. Mark these blocks as SUBST_NOOP_OK. This would not detect |
| | | 1211 | # outdated definitions. Since this detection is the main goal |
| | | 1212 | # of SUBST_NOOP_OK, this is out of the question. |
| | | 1213 | # |
| | | 1214 | # 2. Surround these blocks with a condition like ".if ${VAR} != |
| | | 1215 | # fixed-value ... .endif". This pattern only works if VAR is |
| | | 1216 | # definitely assigned, which often requires a corresponding |
| | | 1217 | # .include line, leading to code bloat. It would also mean that |
| | | 1218 | # variables defined in bsd.pkg.mk could not be used in SUBST |
| | | 1219 | # blocks like these. |
| | | 1220 | |
| | | 1221 | create_file_lines "testcase.mk" \ |
| | | 1222 | 'SUBST_CLASSES+= id' \ |
| | | 1223 | 'SUBST_FILES.id= file' \ |
| | | 1224 | 'SUBST_SED.id= -e s,before,before,' \ |
| | | 1225 | 'SUBST_NOOP_OK.id= no' \ |
| | | 1226 | '' \ |
| | | 1227 | '.include "prepare-subst.mk"' \ |
| | | 1228 | '.include "mk/subst.mk"' |
| | | 1229 | create_file_lines "file" \ |
| | | 1230 | 'before' |
| | | 1231 | |
| | | 1232 | run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ |
| | | 1233 | && exitcode=0 || exitcode=$? |
| | | 1234 | |
| | | 1235 | assert_that "out" --file-is-lines \ |
| | | 1236 | '=> Substituting "id" in file' |
| | | 1237 | |
| | | 1238 | test_case_end |
| | | 1239 | fi |
| | | 1240 | |
| | | 1241 | |
| | | 1242 | if test_case_begin "identity substitution, not found in file"; then |
| | | 1243 | |
| | | 1244 | create_file_lines "testcase.mk" \ |
| | | 1245 | 'SUBST_CLASSES+= id' \ |
| | | 1246 | 'SUBST_FILES.id= file' \ |
| | | 1247 | 'SUBST_SED.id= s,before,before,' \ |
| | | 1248 | 'SUBST_NOOP_OK.id= no' \ |
| | | 1249 | '' \ |
| | | 1250 | '.include "prepare-subst.mk"' \ |
| | | 1251 | '.include "mk/subst.mk"' |
| | | 1252 | create_file_lines "file" \ |
| | | 1253 | 'other' |
| | | 1254 | |
| | | 1255 | run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ |
| | | 1256 | && exitcode=0 || exitcode=$? |
| | | 1257 | |
| | | 1258 | assert_that "out" --file-is-lines \ |
| | | 1259 | '=> Substituting "id" in file' \ |
| | | 1260 | 'warning: [subst.mk:id] Nothing changed in "file".' \ |
| | | 1261 | 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ |
| | | 1262 | '*** Error code 1' \ |
| | | 1263 | '' \ |
| | | 1264 | 'Stop.' \ |
| | | 1265 | "$make: stopped in $PWD" |
| | | 1266 | |
| | | 1267 | test_case_end |
| | | 1268 | fi |
| | | 1269 | |
| | | 1270 | |
| | | 1271 | if test_case_begin "identity + effective substitution"; then |
| | | 1272 | |
| | | 1273 | create_file_lines "testcase.mk" \ |
| | | 1274 | 'SUBST_CLASSES+= id' \ |
| | | 1275 | 'SUBST_FILES.id= file' \ |
| | | 1276 | 'SUBST_SED.id= -e s,no-op,no-op,g' \ |
| | | 1277 | 'SUBST_SED.id+= -e s,from,to,' \ |
| | | 1278 | 'SUBST_NOOP_OK.id= no' \ |
| | | 1279 | '' \ |
| | | 1280 | '.include "prepare-subst.mk"' \ |
| | | 1281 | '.include "mk/subst.mk"' |
| | | 1282 | create_file_lines "file" \ |
| | | 1283 | 'from' |
| | | 1284 | |
| | | 1285 | run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ |
| | | 1286 | && exitcode=0 || exitcode=$? |
| | | 1287 | |
| | | 1288 | assert_that "out" --file-is-lines \ |
| | | 1289 | '=> Substituting "id" in file' |
| | | 1290 | assert_that "file" --file-is-lines \ |
| | | 1291 | 'to' |
| | | 1292 | |
| | | 1293 | test_case_end |
| | | 1294 | fi |
| | | 1295 | |
| | | 1296 | |
| | | 1297 | if test_case_begin "identity + no-op substitution"; then |
| | | 1298 | |
| | | 1299 | # If there were only an identity substitution, it wouldn't be an |
| | | 1300 | # error. But since there is a regular substitution as well, |
| | | 1301 | # that substitution is an unexpected no-op and is therefore |
| | | 1302 | # flagged as an error. |
| | | 1303 | |
| | | 1304 | create_file_lines "testcase.mk" \ |
| | | 1305 | 'SUBST_CLASSES+= id' \ |
| | | 1306 | 'SUBST_FILES.id= file' \ |
| | | 1307 | 'SUBST_SED.id= -e s,no-op,no-op,g' \ |
| | | 1308 | 'SUBST_SED.id+= -e s,from,to,' \ |
| | | 1309 | 'SUBST_NOOP_OK.id= no' \ |
| | | 1310 | '' \ |
| | | 1311 | '.include "prepare-subst.mk"' \ |
| | | 1312 | '.include "mk/subst.mk"' |
| | | 1313 | create_file_lines "file" \ |
| | | 1314 | 'other' |
| | | 1315 | |
| | | 1316 | run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ |
| | | 1317 | && exitcode=0 || exitcode=$? |
| | | 1318 | |
| | | 1319 | assert_that "out" --file-is-lines \ |
| | | 1320 | '=> Substituting "id" in file' \ |
| | | 1321 | 'warning: [subst.mk:id] Nothing changed in "file".' \ |
| | | 1322 | 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ |
| | | 1323 | '*** Error code 1' \ |
| | | 1324 | '' \ |
| | | 1325 | 'Stop.' \ |
| | | 1326 | "$make: stopped in $PWD" |
| | | 1327 | assert_that "file" --file-is-lines \ |
| | | 1328 | 'other' |
| | | 1329 | |
| | | 1330 | test_case_end |
| | | 1331 | fi |