| @@ -4,26 +4,27 @@ | | | @@ -4,26 +4,27 @@ |
4 | # | | 4 | # |
5 | set -eu | | 5 | set -eu |
6 | | | 6 | |
7 | . "./test.subr" | | 7 | . "./test.subr" |
8 | | | 8 | |
9 | test_case_set_up() { | | 9 | test_case_set_up() { |
10 | rm -rf "$tmpdir"/.??* "$tmpdir"/* | | 10 | rm -rf "$tmpdir"/.??* "$tmpdir"/* |
11 | | | 11 | |
12 | create_file "prepare-subst.mk" <<EOF | | 12 | create_file "prepare-subst.mk" <<EOF |
13 | | | 13 | |
14 | # The tools that are used by subst.mk | | 14 | # The tools that are used by subst.mk |
15 | CHMOD= chmod-is-not-used | | 15 | CHMOD= chmod-is-not-used |
16 | CMP= cmp | | 16 | CMP= cmp |
| | | 17 | DIFF= diff |
17 | ECHO= echo | | 18 | ECHO= echo |
18 | MKDIR= mkdir -p | | 19 | MKDIR= mkdir -p |
19 | MV= mv | | 20 | MV= mv |
20 | RM= rm | | 21 | RM= rm |
21 | RMDIR= rmdir | | 22 | RMDIR= rmdir |
22 | SED= sed | | 23 | SED= sed |
23 | TEST= test | | 24 | TEST= test |
24 | TOUCH= touch | | 25 | TOUCH= touch |
25 | TOUCH_FLAGS= # none | | 26 | TOUCH_FLAGS= # none |
26 | TR= tr | | 27 | TR= tr |
27 | TRUE= true | | 28 | TRUE= true |
28 | | | 29 | |
29 | # Commands that are specific to pkgsrc | | 30 | # Commands that are specific to pkgsrc |
| @@ -528,13 +529,101 @@ EOF | | | @@ -528,13 +529,101 @@ EOF |
528 | | | 529 | |
529 | test_file "testcase.mk" "all" \ | | 530 | test_file "testcase.mk" "all" \ |
530 | 1> "$tmpdir/stdout" \ | | 531 | 1> "$tmpdir/stdout" \ |
531 | 2> "$tmpdir/stderr" \ | | 532 | 2> "$tmpdir/stderr" \ |
532 | && exitcode=0 || exitcode=$? | | 533 | && exitcode=0 || exitcode=$? |
533 | | | 534 | |
534 | assert_that "stdout" --file-is-empty | | 535 | assert_that "stdout" --file-is-empty |
535 | assert_that "stderr" --file-is-lines \ | | 536 | assert_that "stderr" --file-is-lines \ |
536 | "fail reason: [subst.mk] duplicate SUBST class in: one one two" | | 537 | "fail reason: [subst.mk] duplicate SUBST class in: one one two" |
537 | assert_that "$exitcode" --equals 0 | | 538 | assert_that "$exitcode" --equals 0 |
538 | | | 539 | |
539 | test_case_end | | 540 | test_case_end |
540 | fi | | 541 | fi |
| | | 542 | |
| | | 543 | |
| | | 544 | if test_case_begin "several SUBST classes"; then |
| | | 545 | |
| | | 546 | # It's ok to have several SUBST classes that apply to the same file. |
| | | 547 | # The order of execution is not guaranteed though. |
| | | 548 | |
| | | 549 | create_file_lines "file" "zero one two three four" |
| | | 550 | |
| | | 551 | create_file "testcase.mk" <<EOF |
| | | 552 | SUBST_CLASSES+= one |
| | | 553 | SUBST_STAGE.one= pre-configure |
| | | 554 | SUBST_FILES.one= file |
| | | 555 | SUBST_SED.one= -e 's,one,I,' |
| | | 556 | |
| | | 557 | SUBST_CLASSES+= two |
| | | 558 | SUBST_STAGE.two= pre-configure |
| | | 559 | SUBST_FILES.two= file |
| | | 560 | SUBST_SED.two= -e 's,two,II,' |
| | | 561 | |
| | | 562 | SUBST_CLASSES+= three |
| | | 563 | SUBST_STAGE.three= pre-configure |
| | | 564 | SUBST_FILES.three= file |
| | | 565 | SUBST_SED.three= -e 's,three,III,' |
| | | 566 | |
| | | 567 | .include "prepare-subst.mk" |
| | | 568 | .include "mk/subst.mk" |
| | | 569 | EOF |
| | | 570 | |
| | | 571 | test_file "testcase.mk" "pre-configure" \ |
| | | 572 | 1> "$tmpdir/stdout" \ |
| | | 573 | 2> "$tmpdir/stderr" \ |
| | | 574 | && exitcode=0 || exitcode=$? |
| | | 575 | |
| | | 576 | # The order of the above output is not guaranteed. |
| | | 577 | LC_ALL=C sort < "$tmpdir/stdout" > "$tmpdir/stdout-sorted" |
| | | 578 | |
| | | 579 | assert_that "file" --file-is-lines "zero I II III four" |
| | | 580 | assert_that "stdout-sorted" --file-is-lines \ |
| | | 581 | "=> Substituting \"one\" in file" \ |
| | | 582 | "=> Substituting \"three\" in file" \ |
| | | 583 | "=> Substituting \"two\" in file" |
| | | 584 | assert_that "stderr" --file-is-empty |
| | | 585 | assert_that "$exitcode" --equals 0 |
| | | 586 | |
| | | 587 | test_case_end |
| | | 588 | fi |
| | | 589 | |
| | | 590 | |
| | | 591 | if test_case_begin "show diff"; then |
| | | 592 | |
| | | 593 | create_file_lines "file" "one" "two" "three" |
| | | 594 | |
| | | 595 | create_file "testcase.mk" <<EOF |
| | | 596 | SUBST_CLASSES+= two |
| | | 597 | SUBST_STAGE.two= pre-configure |
| | | 598 | SUBST_FILES.two= file |
| | | 599 | SUBST_SED.two= -e 's,two,II,' |
| | | 600 | SUBST_SHOW_DIFF.two= yes |
| | | 601 | |
| | | 602 | .include "prepare-subst.mk" |
| | | 603 | .include "mk/subst.mk" |
| | | 604 | EOF |
| | | 605 | |
| | | 606 | LC_ALL=C \ |
| | | 607 | test_file "testcase.mk" "pre-configure" \ |
| | | 608 | 1> "$tmpdir/stdout" \ |
| | | 609 | 2> "$tmpdir/stderr" \ |
| | | 610 | && exitcode=0 || exitcode=$? |
| | | 611 | |
| | | 612 | awk '{ if (/^... \.\/.*/) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \ |
| | | 613 | < "$tmpdir/stdout" > "$tmpdir/stdout-filtered" |
| | | 614 | |
| | | 615 | assert_that "file" --file-is-lines "one" "II" "three" |
| | | 616 | assert_that "stdout-filtered" --file-is-lines \ |
| | | 617 | "=> Substituting \"two\" in file" \ |
| | | 618 | "--- ./file (filtered timestamp)" \ |
| | | 619 | "+++ ./file.subst.sav (filtered timestamp)" \ |
| | | 620 | "@@ -1,3 +1,3 @@" \ |
| | | 621 | " one" \ |
| | | 622 | "-two" \ |
| | | 623 | "+II" \ |
| | | 624 | " three" |
| | | 625 | assert_that "stderr" --file-is-empty |
| | | 626 | assert_that "$exitcode" --equals 0 |
| | | 627 | |
| | | 628 | test_case_end |
| | | 629 | fi |