| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | #! /bin/sh | | 1 | #! /bin/sh |
2 | # $NetBSD: subst.sh,v 1.28 2020/05/01 06:42:32 rillig Exp $ | | 2 | # $NetBSD: subst.sh,v 1.29 2020/05/01 19:53:48 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 | |
| @@ -248,27 +248,27 @@ SUBST_FILES.class= nonexistent | | | @@ -248,27 +248,27 @@ SUBST_FILES.class= nonexistent |
248 | SUBST_SED.class= -e 's,file,example,' | | 248 | SUBST_SED.class= -e 's,file,example,' |
249 | SUBST_NOOP_OK.class= no | | 249 | SUBST_NOOP_OK.class= no |
250 | | | 250 | |
251 | .include "prepare-subst.mk" | | 251 | .include "prepare-subst.mk" |
252 | .include "mk/subst.mk" | | 252 | .include "mk/subst.mk" |
253 | | | 253 | |
254 | all: subst-class | | 254 | all: subst-class |
255 | EOF | | 255 | EOF |
256 | | | 256 | |
257 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? | | 257 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? |
258 | | | 258 | |
259 | create_file_lines "expected-output" \ | | 259 | create_file_lines "expected-output" \ |
260 | '=> Substituting "class" in nonexistent' \ | | 260 | '=> Substituting "class" in nonexistent' \ |
261 | 'warning: [subst.mk:class] Ignoring non-existent file "nonexistent".' \ | | 261 | 'warning: [subst.mk:class] Ignoring nonexistent file "nonexistent".' \ |
262 | 'fail: [subst.mk:class] The filename pattern "nonexistent" has no effect.' \ | | 262 | 'fail: [subst.mk:class] The filename pattern "nonexistent" has no effect.' \ |
263 | '*** Error code 1' \ | | 263 | '*** Error code 1' \ |
264 | '' \ | | 264 | '' \ |
265 | 'Stop.' \ | | 265 | 'Stop.' \ |
266 | "$make: stopped in $PWD" | | 266 | "$make: stopped in $PWD" |
267 | assert_that "actual-output" --file-equals "expected-output" | | 267 | assert_that "actual-output" --file-equals "expected-output" |
268 | assert_that "$exitcode" --equals "1" | | 268 | assert_that "$exitcode" --equals "1" |
269 | | | 269 | |
270 | test_case_end | | 270 | test_case_end |
271 | fi | | 271 | fi |
272 | | | 272 | |
273 | | | 273 | |
274 | if test_case_begin "single file nonexistent ok"; then | | 274 | if test_case_begin "single file nonexistent ok"; then |
| @@ -280,27 +280,27 @@ SUBST_FILES.class= nonexistent | | | @@ -280,27 +280,27 @@ SUBST_FILES.class= nonexistent |
280 | SUBST_SED.class= -e 's,file,example,' | | 280 | SUBST_SED.class= -e 's,file,example,' |
281 | SUBST_NOOP_OK.class= yes | | 281 | SUBST_NOOP_OK.class= yes |
282 | | | 282 | |
283 | .include "prepare-subst.mk" | | 283 | .include "prepare-subst.mk" |
284 | .include "mk/subst.mk" | | 284 | .include "mk/subst.mk" |
285 | | | 285 | |
286 | all: subst-class | | 286 | all: subst-class |
287 | EOF | | 287 | EOF |
288 | | | 288 | |
289 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? | | 289 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? |
290 | | | 290 | |
291 | create_file_lines "expected-output" \ | | 291 | create_file_lines "expected-output" \ |
292 | '=> Substituting "class" in nonexistent' \ | | 292 | '=> Substituting "class" in nonexistent' \ |
293 | 'info: [subst.mk:class] Ignoring non-existent file "nonexistent".' | | 293 | 'info: [subst.mk:class] Ignoring nonexistent file "nonexistent".' |
294 | assert_that "actual-output" --file-equals "expected-output" | | 294 | assert_that "actual-output" --file-equals "expected-output" |
295 | assert_that "$exitcode" --equals "0" | | 295 | assert_that "$exitcode" --equals "0" |
296 | | | 296 | |
297 | test_case_end | | 297 | test_case_end |
298 | fi | | 298 | fi |
299 | | | 299 | |
300 | | | 300 | |
301 | if test_case_begin "several patterns, 1 nonexistent"; then | | 301 | if test_case_begin "several patterns, 1 nonexistent"; then |
302 | | | 302 | |
303 | create_file "testcase.mk" <<EOF | | 303 | create_file "testcase.mk" <<EOF |
304 | SUBST_CLASSES+= class | | 304 | SUBST_CLASSES+= class |
305 | SUBST_STAGE.class= pre-configure | | 305 | SUBST_STAGE.class= pre-configure |
306 | SUBST_FILES.class= *exist* *not-found* | | 306 | SUBST_FILES.class= *exist* *not-found* |
| @@ -308,54 +308,54 @@ SUBST_SED.class= -e 's,file,example,' | | | @@ -308,54 +308,54 @@ SUBST_SED.class= -e 's,file,example,' |
308 | | | 308 | |
309 | .include "prepare-subst.mk" | | 309 | .include "prepare-subst.mk" |
310 | .include "mk/subst.mk" | | 310 | .include "mk/subst.mk" |
311 | | | 311 | |
312 | all: subst-class | | 312 | all: subst-class |
313 | EOF | | 313 | EOF |
314 | | | 314 | |
315 | create_file_lines "exists" "this file exists" | | 315 | create_file_lines "exists" "this file exists" |
316 | | | 316 | |
317 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? | | 317 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? |
318 | | | 318 | |
319 | create_file_lines "expected-output" \ | | 319 | create_file_lines "expected-output" \ |
320 | '=> Substituting "class" in *exist* *not-found*' \ | | 320 | '=> Substituting "class" in *exist* *not-found*' \ |
321 | 'info: [subst.mk:class] Ignoring non-existent file "./*not-found*".' | | 321 | 'info: [subst.mk:class] Ignoring nonexistent file "./*not-found*".' |
322 | assert_that "actual-output" --file-equals "expected-output" | | 322 | assert_that "actual-output" --file-equals "expected-output" |
323 | assert_that "exists" --file-contains-exactly "this example exists" | | 323 | assert_that "exists" --file-contains-exactly "this example exists" |
324 | assert_that "$exitcode" --equals "0" | | 324 | assert_that "$exitcode" --equals "0" |
325 | | | 325 | |
326 | test_case_end | | 326 | test_case_end |
327 | fi | | 327 | fi |
328 | | | 328 | |
329 | | | 329 | |
330 | 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 |
331 | | | 331 | |
332 | create_file "testcase.mk" <<EOF | | 332 | create_file "testcase.mk" <<EOF |
333 | SUBST_CLASSES+= class | | 333 | SUBST_CLASSES+= class |
334 | SUBST_STAGE.class= pre-configure | | 334 | SUBST_STAGE.class= pre-configure |
335 | SUBST_FILES.class= does not exist | | 335 | SUBST_FILES.class= does not exist |
336 | SUBST_SED.class= -e 'sahara' | | 336 | SUBST_SED.class= -e 'sahara' |
337 | | | 337 | |
338 | .include "prepare-subst.mk" | | 338 | .include "prepare-subst.mk" |
339 | .include "mk/subst.mk" | | 339 | .include "mk/subst.mk" |
340 | EOF | | 340 | EOF |
341 | | | 341 | |
342 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? | | 342 | run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? |
343 | | | 343 | |
344 | create_file_lines "expected-output" \ | | 344 | create_file_lines "expected-output" \ |
345 | '=> Substituting "class" in does not exist' \ | | 345 | '=> Substituting "class" in does not exist' \ |
346 | 'info: [subst.mk:class] Ignoring non-existent file "does".' \ | | 346 | 'info: [subst.mk:class] Ignoring nonexistent file "does".' \ |
347 | 'info: [subst.mk:class] Ignoring non-existent file "not".' \ | | 347 | 'info: [subst.mk:class] Ignoring nonexistent file "not".' \ |
348 | 'info: [subst.mk:class] Ignoring non-existent file "exist".' | | 348 | 'info: [subst.mk:class] Ignoring nonexistent file "exist".' |
349 | assert_that "actual-output" --file-equals "expected-output" | | 349 | assert_that "actual-output" --file-equals "expected-output" |
350 | assert_that "$exitcode" --equals "0" | | 350 | assert_that "$exitcode" --equals "0" |
351 | | | 351 | |
352 | test_case_end | | 352 | test_case_end |
353 | fi | | 353 | fi |
354 | | | 354 | |
355 | | | 355 | |
356 | 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 |
357 | | | 357 | |
358 | create_file "testcase.mk" <<EOF | | 358 | create_file "testcase.mk" <<EOF |
359 | SUBST_CLASSES+= class | | 359 | SUBST_CLASSES+= class |
360 | SUBST_STAGE.class= pre-configure | | 360 | SUBST_STAGE.class= pre-configure |
361 | SUBST_FILES.class= first second third | | 361 | SUBST_FILES.class= first second third |
| @@ -1016,27 +1016,27 @@ if test_case_begin "empty SUBST_SED"; th | | | @@ -1016,27 +1016,27 @@ if test_case_begin "empty SUBST_SED"; th |
1016 | 'SUBST_NOOP_OK.id= no' \ | | 1016 | 'SUBST_NOOP_OK.id= no' \ |
1017 | '' \ | | 1017 | '' \ |
1018 | 'all:' \ | | 1018 | 'all:' \ |
1019 | ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ | | 1019 | ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ |
1020 | '' \ | | 1020 | '' \ |
1021 | '.include "prepare-subst.mk"' \ | | 1021 | '.include "prepare-subst.mk"' \ |
1022 | '.include "mk/subst.mk"' | | 1022 | '.include "mk/subst.mk"' |
1023 | | | 1023 | |
1024 | 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 \ |
1025 | && exitcode=0 || exitcode=$? | | 1025 | && exitcode=0 || exitcode=$? |
1026 | | | 1026 | |
1027 | assert_that "out" --file-is-lines \ | | 1027 | assert_that "out" --file-is-lines \ |
1028 | '=> Substituting "id" in file' \ | | 1028 | '=> Substituting "id" in file' \ |
1029 | 'warning: [subst.mk:id] Ignoring non-existent file "file".' \ | | 1029 | 'warning: [subst.mk:id] Ignoring nonexistent file "file".' \ |
1030 | 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ | | 1030 | 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ |
1031 | '*** Error code 1' \ | | 1031 | '*** Error code 1' \ |
1032 | '' \ | | 1032 | '' \ |
1033 | 'Stop.' \ | | 1033 | 'Stop.' \ |
1034 | "$make: stopped in $PWD" | | 1034 | "$make: stopped in $PWD" |
1035 | | | 1035 | |
1036 | test_case_end | | 1036 | test_case_end |
1037 | fi | | 1037 | fi |
1038 | | | 1038 | |
1039 | | | 1039 | |
1040 | if test_case_begin "typo in SUBST_CLASSES"; then | | 1040 | if test_case_begin "typo in SUBST_CLASSES"; then |
1041 | | | 1041 | |
1042 | # Look closely. The SUBST_CLASSES line contains a typo. | | 1042 | # Look closely. The SUBST_CLASSES line contains a typo. |
| @@ -1050,27 +1050,27 @@ if test_case_begin "typo in SUBST_CLASSE | | | @@ -1050,27 +1050,27 @@ if test_case_begin "typo in SUBST_CLASSE |
1050 | 'SUBST_NOOP_OK.id= no' \ | | 1050 | 'SUBST_NOOP_OK.id= no' \ |
1051 | '' \ | | 1051 | '' \ |
1052 | 'all:' \ | | 1052 | 'all:' \ |
1053 | ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ | | 1053 | ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ |
1054 | '' \ | | 1054 | '' \ |
1055 | '.include "prepare-subst.mk"' \ | | 1055 | '.include "prepare-subst.mk"' \ |
1056 | '.include "mk/subst.mk"' | | 1056 | '.include "mk/subst.mk"' |
1057 | | | 1057 | |
1058 | 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 \ |
1059 | && exitcode=0 || exitcode=$? | | 1059 | && exitcode=0 || exitcode=$? |
1060 | | | 1060 | |
1061 | assert_that "out" --file-is-lines \ | | 1061 | assert_that "out" --file-is-lines \ |
1062 | '=> Substituting "id" in file' \ | | 1062 | '=> Substituting "id" in file' \ |
1063 | 'warning: [subst.mk:id] Ignoring non-existent file "file".' \ | | 1063 | 'warning: [subst.mk:id] Ignoring nonexistent file "file".' \ |
1064 | 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ | | 1064 | 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ |
1065 | '*** Error code 1' \ | | 1065 | '*** Error code 1' \ |
1066 | '' \ | | 1066 | '' \ |
1067 | 'Stop.' \ | | 1067 | 'Stop.' \ |
1068 | "$make: stopped in $PWD" | | 1068 | "$make: stopped in $PWD" |
1069 | | | 1069 | |
1070 | test_case_end | | 1070 | test_case_end |
1071 | fi | | 1071 | fi |
1072 | | | 1072 | |
1073 | | | 1073 | |
1074 | if test_case_begin "executable bit is preserved"; then | | 1074 | if test_case_begin "executable bit is preserved"; then |
1075 | | | 1075 | |
1076 | create_file_lines "testcase.mk" \ | | 1076 | create_file_lines "testcase.mk" \ |