Sat Mar 21 12:47:13 2020 UTC ()
regress/infra-unittests: add more tests for subst.mk


(rillig)
diff -r1.8 -r1.9 pkgsrc/regress/infra-unittests/subst.sh

cvs diff -r1.8 -r1.9 pkgsrc/regress/infra-unittests/subst.sh (expand / switch to unified diff)

--- pkgsrc/regress/infra-unittests/subst.sh 2020/03/21 12:22:31 1.8
+++ pkgsrc/regress/infra-unittests/subst.sh 2020/03/21 12:47:13 1.9
@@ -4,26 +4,27 @@ @@ -4,26 +4,27 @@
4# 4#
5set -eu 5set -eu
6 6
7. "./test.subr" 7. "./test.subr"
8 8
9test_case_set_up() { 9test_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
15CHMOD= chmod-is-not-used 15CHMOD= chmod-is-not-used
16CMP= cmp 16CMP= cmp
 17DIFF= diff
17ECHO= echo 18ECHO= echo
18MKDIR= mkdir -p 19MKDIR= mkdir -p
19MV= mv 20MV= mv
20RM= rm 21RM= rm
21RMDIR= rmdir 22RMDIR= rmdir
22SED= sed 23SED= sed
23TEST= test 24TEST= test
24TOUCH= touch 25TOUCH= touch
25TOUCH_FLAGS= # none 26TOUCH_FLAGS= # none
26TR= tr 27TR= tr
27TRUE= true 28TRUE= 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
540fi 541fi
 542
 543
 544if 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
 552SUBST_CLASSES+= one
 553SUBST_STAGE.one= pre-configure
 554SUBST_FILES.one= file
 555SUBST_SED.one= -e 's,one,I,'
 556
 557SUBST_CLASSES+= two
 558SUBST_STAGE.two= pre-configure
 559SUBST_FILES.two= file
 560SUBST_SED.two= -e 's,two,II,'
 561
 562SUBST_CLASSES+= three
 563SUBST_STAGE.three= pre-configure
 564SUBST_FILES.three= file
 565SUBST_SED.three= -e 's,three,III,'
 566
 567.include "prepare-subst.mk"
 568.include "mk/subst.mk"
 569EOF
 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
 588fi
 589
 590
 591if test_case_begin "show diff"; then
 592
 593 create_file_lines "file" "one" "two" "three"
 594
 595 create_file "testcase.mk" <<EOF
 596SUBST_CLASSES+= two
 597SUBST_STAGE.two= pre-configure
 598SUBST_FILES.two= file
 599SUBST_SED.two= -e 's,two,II,'
 600SUBST_SHOW_DIFF.two= yes
 601
 602.include "prepare-subst.mk"
 603.include "mk/subst.mk"
 604EOF
 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
 629fi