pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/regress/infra-unittests



Module Name:    pkgsrc
Committed By:   rillig
Date:           Mon May 11 19:13:10 UTC 2020

Modified Files:
        pkgsrc/regress/infra-unittests: check-portability.sh extract.sh
            subst.sh test.subr

Log Message:
regress/infra-unittests: run tests in a temporary directory

This isolates the tests from the test infrastructure and allows the test
infrastructure to create arbitrary files for its own purpose without
affecting any of the tests.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 pkgsrc/regress/infra-unittests/check-portability.sh \
    pkgsrc/regress/infra-unittests/extract.sh
cvs rdiff -u -r1.33 -r1.34 pkgsrc/regress/infra-unittests/subst.sh
cvs rdiff -u -r1.13 -r1.14 pkgsrc/regress/infra-unittests/test.subr

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/regress/infra-unittests/check-portability.sh
diff -u pkgsrc/regress/infra-unittests/check-portability.sh:1.4 pkgsrc/regress/infra-unittests/check-portability.sh:1.5
--- pkgsrc/regress/infra-unittests/check-portability.sh:1.4     Tue May  5 06:11:29 2020
+++ pkgsrc/regress/infra-unittests/check-portability.sh Mon May 11 19:13:10 2020
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: check-portability.sh,v 1.4 2020/05/05 06:11:29 rillig Exp $
+# $NetBSD: check-portability.sh,v 1.5 2020/05/11 19:13:10 rillig Exp $
 #
 # Test cases for mk/check/check-portability.*.
 #
@@ -29,21 +29,10 @@ check_portability_awk() {
        && exitcode=0 || exitcode=$?
 }
 
-test_case_set_up() {
-       rm -rf "$tmpdir/work"
-       mkdir "$tmpdir/work"
-       cd "$tmpdir/work"
-}
-
-# TODO: remove the "work/" from the tests.
-# The $tmpdir must be a bit structured:
-# $tmpdir/pkgsrc       these files override the actual pkgsrc files
-# $tmpdir/work         current working directory
-
 
 if test_case_begin "test ... = ..."; then
 
-       create_file_lines 'work/file' \
+       create_file_lines 'file' \
                'if [ "$var" = value ]; then' \
                '  ...' \
                'elif test "$var" = value ]; then' \
@@ -52,7 +41,7 @@ if test_case_begin "test ... = ..."; the
 
        check_portability_awk 'file'
 
-       assert_that 'out' --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -61,7 +50,7 @@ fi
 
 if test_case_begin 'test ... == ...'; then
 
-       create_file_lines 'work/file' \
+       create_file_lines 'file' \
                'if [ "$var" == value ]; then' \
                '  ...' \
                'elif test "$var" == value ]; then' \
@@ -93,7 +82,7 @@ package Makefile.
 ===========================================================================
 
 EOF
-       assert_that 'out' --file-equals 'expected'
+       assert_that "$tmpdir/out" --file-equals 'expected'
        assert_that $exitcode --equals 1
 
        test_case_end
@@ -102,18 +91,18 @@ fi
 
 if test_case_begin 'configure patched, configure.in bad'; then
 
-       create_file_lines 'work/patches/patch-aa' \
+       create_file_lines 'patches/patch-aa' \
                '+++ configure 2020-05-04'
-       create_file_lines 'work/configure' \
+       create_file_lines 'configure' \
                '#! /bin/sh' \
                'good'
-       create_file_lines 'work/configure.in' \
+       create_file_lines 'configure.in' \
                'test a == b'
 
        check_portability_sh \
                'CHECK_PORTABILITY_EXPERIMENTAL=yes'
 
-       assert_that "out" --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -125,17 +114,17 @@ if test_case_begin 'Makefile.in patched,
        # As of 2020-05-05, Makefile.am is not checked at all since only
        # very few packages actually use that file during the build.
 
-       create_file_lines 'work/patches/patch-aa' \
+       create_file_lines 'patches/patch-aa' \
                '+++ Makefile.in 2020-05-05'
-       create_file_lines 'work/Makefile.in' \
+       create_file_lines 'Makefile.in' \
                'test a = b'
-       create_file_lines 'work/Makefile.am' \
+       create_file_lines 'Makefile.am' \
                'test a == b'
 
        check_portability_sh \
                'CHECK_PORTABILITY_EXPERIMENTAL=yes'
 
-       assert_that "out" --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -148,15 +137,15 @@ if test_case_begin 'files that are usual
        # developers and are not used during the actual build, except
        # if the package rebuilds everything using the GNU autotools.
 
-       create_file_lines 'work/configure.ac' \
+       create_file_lines 'configure.ac' \
                'test a == b'
-       create_file_lines 'work/Makefile.am' \
+       create_file_lines 'Makefile.am' \
                'test a == b'
 
        check_portability_sh \
                'CHECK_PORTABILITY_EXPERIMENTAL=yes'
 
-       assert_that "out" --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -165,9 +154,9 @@ fi
 
 if test_case_begin 'configure patched and still bad'; then
 
-       create_file_lines 'work/patches/patch-aa' \
+       create_file_lines 'patches/patch-aa' \
                '+++ configure 2020-05-04'
-       create_file_lines 'work/configure' \
+       create_file_lines 'configure' \
                '#! /bin/sh' \
                'test a == b'
 
@@ -196,7 +185,7 @@ package Makefile.
 ===========================================================================
 
 EOF
-       assert_that 'out' --file-equals 'expected'
+       assert_that "$tmpdir/out" --file-equals 'expected'
        assert_that $exitcode --equals 1
 
        test_case_end
@@ -208,16 +197,16 @@ if test_case_begin 'special characters i
        # Ensure that the filename matching for patched files
        # does not treat special characters as shell metacharacters.
 
-       create_file_lines 'work/patches/patch-aa' \
+       create_file_lines 'patches/patch-aa' \
                '+++ [[[[(`" 2020-05-04'
-       create_file_lines 'work/+++ [[[[(`"' \
+       create_file_lines '+++ [[[[(`"' \
                '#! /bin/sh' \
                'test a = b'
 
        check_portability_sh \
                'CHECK_PORTABILITY_EXPERIMENTAL=yes'
 
-       assert_that 'out' --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -233,9 +222,10 @@ if test_case_begin 'no patches'; then
                '#! /bin/sh' \
                'test a = b'
 
-       check_portability_sh
+       check_portability_sh \
+               CHECK_PORTABILITY_EXPERIMENTAL=no
 
-       assert_that 'out' --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -250,7 +240,7 @@ if test_case_begin 'no experimental by d
        check_portability_sh \
                'CHECK_PORTABILITY_EXPERIMENTAL=no'
 
-       assert_that 'out' --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
Index: pkgsrc/regress/infra-unittests/extract.sh
diff -u pkgsrc/regress/infra-unittests/extract.sh:1.4 pkgsrc/regress/infra-unittests/extract.sh:1.5
--- pkgsrc/regress/infra-unittests/extract.sh:1.4       Sun Apr 26 12:46:33 2020
+++ pkgsrc/regress/infra-unittests/extract.sh   Mon May 11 19:13:10 2020
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: extract.sh,v 1.4 2020/04/26 12:46:33 rillig Exp $
+# $NetBSD: extract.sh,v 1.5 2020/05/11 19:13:10 rillig Exp $
 #
 # Test cases for mk/extract/extract.
 #
@@ -9,11 +9,6 @@ set -eu
 . "./test.subr"
 
 test_case_set_up() {
-       # XXX: The mocked pkgsrc directory should be somewhere else.
-       rm -rf "$tmpdir/pkgsrc" "$tmpdir/expected"
-
-       cd "$tmpdir"
-
        LC_ALL=C
        export LC_ALL
 }
@@ -33,17 +28,15 @@ if test_case_begin "exclude directory by
        create_file_lines "other/file"          "content"
        create_file_lines "other/contrib/file"  "content"
 
-       tar cf "archive.tar" "contrib" "other"
+       tar cf "$tmpdir/archive.tar" "contrib" "other"
        rm -r "contrib" "other"
 
-       sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "contrib"
+       sh "$pkgsrcdir/mk/extract/extract" -x "$tmpdir/archive.tar" "contrib"
 
-       find . -print | sort > "extracted"
+       find . -print | sort > "$tmpdir/extracted"
 
-       assert_that "extracted" --file-is-lines \
+       assert_that "$tmpdir/extracted" --file-is-lines \
                "." \
-               "./archive.tar" \
-               "./extracted" \
                "./other" \
                "./other/file"
 
@@ -61,18 +54,16 @@ if test_case_begin "try to exclude direc
        create_file_lines "other/file"          "content"
        create_file_lines "other/contrib/file"  "content"
 
-       tar cf "archive.tar" "contrib" "other"
+       tar cf "$tmpdir/archive.tar" "contrib" "other"
        rm -r "contrib" "other"
 
-       sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "contrib/*"
+       sh "$pkgsrcdir/mk/extract/extract" -x "$tmpdir/archive.tar" "contrib/*"
 
-       find . -print | sort > "extracted"
+       find . -print | sort > "$tmpdir/extracted"
 
-       assert_that "extracted" --file-is-lines \
+       assert_that "$tmpdir/extracted" --file-is-lines \
                "." \
-               "./archive.tar" \
                "./contrib" \
-               "./extracted" \
                "./other" \
                "./other/contrib" \
                "./other/file"
@@ -84,22 +75,26 @@ if test_case_begin "exclude asterisk"; t
 
        # Ensure that the exclusion pattern "*" is not expanded by the
        # shell but passed as-is to the extractor.
+       #
+       # If the pattern were expanded, it would expand to 'expanded'
+       # and would thus not exclude anything from the actual archive,
+       # which means that all files in the archive would be extracted.
 
        create_file_lines "contrib/file"        "content"
        create_file_lines "other/file"          "content"
        create_file_lines "other/contrib/file"  "content"
 
-       tar cf "archive.tar" "contrib" "other"
+       tar cf "$tmpdir/archive.tar" "contrib" "other"
        rm -r "contrib" "other"
 
-       sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "*"
+       > 'expanded'
+       sh "$pkgsrcdir/mk/extract/extract" -x "$tmpdir/archive.tar" "*"
+       rm 'expanded'
 
-       find . -print | sort > "extracted"
+       find . -print | sort > "$tmpdir/extracted"
 
-       assert_that "extracted" --file-is-lines \
-               "." \
-               "./archive.tar" \
-               "./extracted"
+       assert_that "$tmpdir/extracted" --file-is-lines \
+               "."
 
        test_case_end
 fi

Index: pkgsrc/regress/infra-unittests/subst.sh
diff -u pkgsrc/regress/infra-unittests/subst.sh:1.33 pkgsrc/regress/infra-unittests/subst.sh:1.34
--- pkgsrc/regress/infra-unittests/subst.sh:1.33        Sat May  9 17:10:38 2020
+++ pkgsrc/regress/infra-unittests/subst.sh     Mon May 11 19:13:10 2020
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: subst.sh,v 1.33 2020/05/09 17:10:38 rillig Exp $
+# $NetBSD: subst.sh,v 1.34 2020/05/11 19:13:10 rillig Exp $
 #
 # Tests for mk/subst.mk.
 #
@@ -9,7 +9,8 @@ set -eu
 . "./test.subr"
 
 test_case_set_up() {
-       rm -rf "$tmpdir"/.??* "$tmpdir"/*
+       wrkdir="$tmpdir/wrkdir"
+       mkdir "$wrkdir"
 
        create_file "prepare-subst.mk" <<-EOF
                # The tools that are used by subst.mk
@@ -37,11 +38,16 @@ test_case_set_up() {
                WARNING_MSG=    echo "warning:"
                FAIL_MSG=       sh $pkgsrcdir/mk/scripts/fail echo "fail:"
 
-               WRKDIR=         $tmpdir
-               WRKSRC=         $tmpdir
+               WRKDIR=         $tmpdir/wrkdir
+               WRKSRC=         .
        EOF
 }
 
+test_case_tear_down() {
+       # Clean up the .subst_*_done cookie files.
+       rm -r "$wrkdir"
+}
+
 
 if test_case_begin "single file"; then
 
@@ -64,8 +70,10 @@ if test_case_begin "single file"; then
 
        run_bmake "subst-single.mk" > "$tmpdir/output"
 
-       assert_that "output" --file-contains-exactly "=> Substituting \"class\" in subst-single.txt"
-       assert_that "subst-single.txt" --file-contains-exactly "after"
+       assert_that "$tmpdir/output" --file-contains-exactly \
+               "=> Substituting \"class\" in subst-single.txt"
+       assert_that "subst-single.txt" --file-contains-exactly \
+               "after"
 
        test_case_end
 fi
@@ -91,9 +99,10 @@ if test_case_begin "several individual f
        create_file_lines "second"      "the second file"
        create_file_lines "third"       "the third file"
 
-       output=$(run_bmake "testcase.mk")
+       run_bmake "testcase.mk" > "$tmpdir/output"
 
-       assert_that "$output" --equals "=> Substituting \"class\" in first second third"
+       assert_that "$tmpdir/output" --file-is-lines \
+               "=> Substituting \"class\" in first second third"
        assert_that "first" --file-contains-exactly "the first example"
        assert_that "second" --file-contains-exactly "the second example"
        assert_that "third" --file-contains-exactly "the third example"
@@ -159,12 +168,12 @@ if test_case_begin "pattern with 1 noop"
        create_file_lines "pattern-second"      "the second is already an example"
        create_file_lines "pattern-third"       "the third file"
 
-       run_bmake "testcase.mk" > "$tmpdir/actual-output"
+       run_bmake "testcase.mk" > "$tmpdir/output"
        create_file_lines "expected-output" \
                '=> Substituting "class" in pattern-*' \
                'info: [subst.mk:class] Nothing changed in "pattern-second".'
 
-       assert_that "actual-output" --file-equals "expected-output"
+       assert_that "$tmpdir/output" --file-equals "expected-output"
        assert_that "pattern-first" --file-contains-exactly "the first example"
        assert_that "pattern-second" --file-contains-exactly "the second is already an example"
        assert_that "pattern-third" --file-contains-exactly "the third example"
@@ -190,12 +199,12 @@ if test_case_begin "single file noop, no
 
        create_file_lines "single"      "already an example"
 
-       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/output" \
+       && exitcode=0 || exitcode=$?
 
-       create_file_lines "expected-output" \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in single' \
                'info: [subst.mk:class] Nothing changed in "single".'
-       assert_that "actual-output" --file-equals "expected-output"
        assert_that "single" --file-contains-exactly "already an example"
        assert_that "$exitcode" --equals "0"
 
@@ -220,7 +229,8 @@ if test_case_begin "single file noop, no
 
        create_file_lines "single"      "already an example"
 
-       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/output" \
+       && exitcode=0 || exitcode=$?
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in single' \
@@ -230,7 +240,7 @@ if test_case_begin "single file noop, no
                '' \
                'Stop.' \
                "$make: stopped in $PWD"
-       assert_that "actual-output" --file-equals "expected-output"
+       assert_that "$tmpdir/output" --file-equals "expected-output"
        assert_that "single" --file-contains-exactly "already an example"
        assert_that "$exitcode" --equals "1"
 
@@ -253,9 +263,10 @@ if test_case_begin "single file nonexist
                all: subst-class
        EOF
 
-       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/output" \
+       && exitcode=0 || exitcode=$?
 
-       create_file_lines "expected-output" \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in nonexistent' \
                'warning: [subst.mk:class] Ignoring nonexistent file "nonexistent".' \
                'fail: [subst.mk:class] The filename pattern "nonexistent" has no effect.' \
@@ -263,7 +274,6 @@ if test_case_begin "single file nonexist
                '' \
                'Stop.' \
                "$make: stopped in $PWD"
-       assert_that "actual-output" --file-equals "expected-output"
        assert_that "$exitcode" --equals "1"
 
        test_case_end
@@ -285,12 +295,12 @@ if test_case_begin "single file nonexist
                all: subst-class
        EOF
 
-       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/output" \
+       && exitcode=0 || exitcode=$?
 
-       create_file_lines "expected-output" \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in nonexistent' \
                'info: [subst.mk:class] Ignoring nonexistent file "nonexistent".'
-       assert_that "actual-output" --file-equals "expected-output"
        assert_that "$exitcode" --equals "0"
 
        test_case_end
@@ -313,12 +323,12 @@ if test_case_begin "several patterns, 1 
 
        create_file_lines "exists"      "this file exists"
 
-       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/output" \
+       && exitcode=0 || exitcode=$?
 
-       create_file_lines "expected-output" \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in *exist* *not-found*' \
                'info: [subst.mk:class] Ignoring nonexistent file "./*not-found*".'
-       assert_that "actual-output" --file-equals "expected-output"
        assert_that "exists" --file-contains-exactly "this example exists"
        assert_that "$exitcode" --equals "0"
 
@@ -338,14 +348,14 @@ if test_case_begin "multiple missing fil
                .include "mk/subst.mk"
        EOF
 
-       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/output" \
+       && exitcode=0 || exitcode=$?
 
-       create_file_lines "expected-output" \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in does not exist' \
                'info: [subst.mk:class] Ignoring nonexistent file "does".' \
                'info: [subst.mk:class] Ignoring nonexistent file "not".' \
                'info: [subst.mk:class] Ignoring nonexistent file "exist".'
-       assert_that "actual-output" --file-equals "expected-output"
        assert_that "$exitcode" --equals "0"
 
        test_case_end
@@ -367,14 +377,14 @@ if test_case_begin "multiple no-op files
        create_file_lines "second"      "second"
        create_file_lines "third"       "third"
 
-       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/output" \
+       && exitcode=0 || exitcode=$?
 
-       create_file_lines "expected-output" \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in first second third' \
                'info: [subst.mk:class] Nothing changed in "first".' \
                'info: [subst.mk:class] Nothing changed in "second".' \
                'info: [subst.mk:class] Nothing changed in "third".'
-       assert_that "actual-output" --file-equals "expected-output"
        assert_that "$exitcode" --equals "0"
 
        test_case_end
@@ -413,17 +423,16 @@ prepare-subst-class:
 EOF
 
        run_bmake "testcase.mk" "subst-class" \
-               1> "$tmpdir/actual-output" \
-               2> "$tmpdir/actual-stderr" \
+               1> "$tmpdir/stdout" \
+               2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
 
-       create_file_lines "expected-output" \
+       assert_that "$tmpdir/stdout" --file-is-lines \
                '=> Substituting "class" in first third'
-       assert_that "actual-output" --file-equals "expected-output"
-       assert_that "actual-stderr" --file-is-empty
-       assert_that "package-1.0/first" --file-contains-exactly "to"
-       assert_that "package-1.0/second" --file-contains-exactly "from"
-       assert_that "package-1.0/third" --file-contains-exactly "to"
+       assert_that "$tmpdir/stderr" --file-is-empty
+       assert_that "$wrkdir/package-1.0/first" --file-contains-exactly "to"
+       assert_that "$wrkdir/package-1.0/second" --file-contains-exactly "from"
+       assert_that "$wrkdir/package-1.0/third" --file-contains-exactly "to"
        assert_that "$exitcode" --equals "0"
 
        test_case_end
@@ -457,13 +466,10 @@ if test_case_begin "special characters i
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
 
-       assert_that "stdout" --file-is-lines \
+       assert_that "$tmpdir/stdout" --file-is-lines \
                '=> Substituting "class" in *' \
-               'info: [subst.mk:class] Nothing changed in "prepare-subst.mk".' \
-               'info: [subst.mk:class] Nothing changed in "stderr".' \
-               'info: [subst.mk:class] Nothing changed in "stdout".' \
-               'info: [subst.mk:class] Nothing changed in "test.subr.main.mk".'
-       assert_that "stderr" --file-is-empty
+               'info: [subst.mk:class] Nothing changed in "prepare-subst.mk".'
+       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals "0"
 
        assert_that " !\"#\$%&'()*+,-." --file-is-lines "after"
@@ -501,9 +507,9 @@ if test_case_begin "brackets in filename
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
 
-       assert_that "stdout" --file-is-lines \
+       assert_that "$tmpdir/stdout" --file-is-lines \
                '=> Substituting "class" in [*]'
-       assert_that "stderr" --file-is-empty
+       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals "0"
 
        assert_that "any"       --file-is-lines "before"
@@ -534,8 +540,8 @@ EOF
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
 
-       assert_that "stdout" --file-is-empty
-       assert_that "stderr" --file-is-lines \
+       assert_that "$tmpdir/stdout" --file-is-empty
+       assert_that "$tmpdir/stderr" --file-is-lines \
                "fail reason: [subst.mk] duplicate SUBST class in: one one two"
        assert_that "$exitcode" --equals 0
 
@@ -579,11 +585,11 @@ if test_case_begin "several SUBST classe
        LC_ALL=C sort < "$tmpdir/stdout" > "$tmpdir/stdout-sorted"
 
        assert_that "file" --file-is-lines "zero I II III four"
-       assert_that "stdout-sorted" --file-is-lines \
+       assert_that "$tmpdir/stdout-sorted" --file-is-lines \
                "=> Substituting \"one\" in file" \
                "=> Substituting \"three\" in file" \
                "=> Substituting \"two\" in file"
-       assert_that "stderr" --file-is-empty
+       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals 0
 
        test_case_end
@@ -615,7 +621,7 @@ if test_case_begin "show diff"; then
        < "$tmpdir/stdout" > "$tmpdir/stdout-filtered"
 
        assert_that "file" --file-is-lines "one" "II" "three"
-       assert_that "stdout-filtered" --file-is-lines \
+       assert_that "$tmpdir/stdout-filtered" --file-is-lines \
                "=> Substituting \"two\" in file" \
                "--- file (filtered timestamp)" \
                "+++ file.subst.sav (filtered timestamp)" \
@@ -624,7 +630,7 @@ if test_case_begin "show diff"; then
                "-two" \
                "+II" \
                " three"
-       assert_that "stderr" --file-is-empty
+       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals 0
 
        test_case_end
@@ -655,7 +661,7 @@ if test_case_begin "global show diff"; t
        < "$tmpdir/stdout" > "$tmpdir/stdout-filtered"
 
        assert_that "file" --file-is-lines "one" "II" "three"
-       assert_that "stdout-filtered" --file-is-lines \
+       assert_that "$tmpdir/stdout-filtered" --file-is-lines \
                "=> Substituting \"two\" in file" \
                "--- file (filtered timestamp)" \
                "+++ file.subst.sav (filtered timestamp)" \
@@ -664,7 +670,7 @@ if test_case_begin "global show diff"; t
                "-two" \
                "+II" \
                " three"
-       assert_that "stderr" --file-is-empty
+       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals 0
 
        test_case_end
@@ -712,9 +718,9 @@ if test_case_begin "SUBST_VARS"; then
                "hello,   world" \
                '!"#$%&'\''()*+,-./09:;<=>?@AZ[\]^_`az{|}' \
                ""
-       assert_that "stdout" --file-is-lines \
+       assert_that "$tmpdir/stdout" --file-is-lines \
                "=> Substituting \"vars\" in vars.txt"
-       assert_that "stderr" --file-is-empty
+       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals 0
 
        test_case_end
@@ -755,9 +761,9 @@ if test_case_begin "SUBST_VARS with surr
                "$space""between spaces""$space" \
                "$tab""between tabs""$tab" \
                "$newline""between newlines""$newline"
-       assert_that "stdout" --file-is-lines \
+       assert_that "$tmpdir/stdout" --file-is-lines \
                "=> Substituting \"vars\" in vars.txt"
-       assert_that "stderr" --file-is-empty
+       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals 0
 
        test_case_end
@@ -785,9 +791,9 @@ if test_case_begin "SUBST_VARS with back
 
        assert_that "backslash.txt" --file-is-lines \
                '\" \, \\, \" \'\'' \0\000 \x40 \089 \a \$'
-       assert_that "stdout" --file-is-lines \
+       assert_that "$tmpdir/stdout" --file-is-lines \
                "=> Substituting \"bs\" in backslash.txt"
-       assert_that "stderr" --file-is-empty
+       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals 0
 
        test_case_end
@@ -850,9 +856,9 @@ if test_case_begin "SUBST_VARS for varia
                '@VAR.$x@' \
                'circumflex' \
                'backslash'
-       assert_that "stdout" --file-is-lines \
+       assert_that "$tmpdir/stdout" --file-is-lines \
                "=> Substituting \"vars\" in vars.txt"
-       assert_that "stderr" --file-is-empty
+       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals 0
 
        test_case_end
@@ -878,7 +884,6 @@ if test_case_begin "pattern matches dire
                '' \
                '.include "prepare-subst.mk"' \
                '.include "mk/subst.mk"'
-       mkdir "$tmpdir/subdir"
        create_file_lines "subdir/subfile" \
                "@VAR@"
        create_file_lines "subst-file" \
@@ -891,9 +896,9 @@ if test_case_begin "pattern matches dire
 
        assert_that "subst-file" --file-is-lines "value"
        assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged
-       assert_that "stdout" --file-is-lines \
+       assert_that "$tmpdir/stdout" --file-is-lines \
                "=> Substituting \"dir\" in sub*"
-       assert_that "stderr" --file-is-empty
+       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals 0
 
        test_case_end
@@ -916,7 +921,6 @@ if test_case_begin "pattern matches only
                '' \
                '.include "prepare-subst.mk"' \
                '.include "mk/subst.mk"'
-       mkdir "$tmpdir/subdir"
        create_file_lines "subdir/subfile" \
                "@VAR@"
 
@@ -926,14 +930,14 @@ if test_case_begin "pattern matches only
        && exitcode=0 || exitcode=$?
 
        assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged
-       assert_that "stdout" --file-is-lines \
+       assert_that "$tmpdir/stdout" --file-is-lines \
                "=> Substituting \"dir\" in sub*" \
                'fail: [subst.mk:dir] The filename pattern "sub*" has no effect.' \
                "*** Error code 1" \
                "" \
                "Stop." \
                "$make: stopped in $PWD"
-       assert_that "stderr" --file-is-empty
+       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals 1
 
        test_case_end
@@ -959,10 +963,10 @@ if test_case_begin "two filename pattern
        create_file_lines "file1"       "nothing to replace"
        create_file_lines "file2"       "nothing to replace"
 
-       run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file1 file2' \
                'warning: [subst.mk:id] Nothing changed in "file1".' \
                'warning: [subst.mk:id] Nothing changed in "file2".' \
@@ -994,10 +998,10 @@ if test_case_begin "empty SUBST_FILES"; 
                '.include "prepare-subst.mk"' \
                '.include "mk/subst.mk"'
 
-       run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in ' \
                'ok'
 
@@ -1020,10 +1024,10 @@ if test_case_begin "empty SUBST_SED"; th
                '.include "prepare-subst.mk"' \
                '.include "mk/subst.mk"'
 
-       run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file' \
                'warning: [subst.mk:id] Ignoring nonexistent file "file".' \
                'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
@@ -1054,10 +1058,10 @@ if test_case_begin "typo in SUBST_CLASSE
                '.include "prepare-subst.mk"' \
                '.include "mk/subst.mk"'
 
-       run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file' \
                'warning: [subst.mk:id] Ignoring nonexistent file "file".' \
                'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
@@ -1085,19 +1089,19 @@ if test_case_begin "executable bit is pr
                '@VAR@'
        create_file_lines "data" \
                '@VAR@'
-       chmod +x "$tmpdir/cmd"
+       chmod +x 'cmd'
 
-       run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in cmd data'
        assert_that "cmd" --file-is-lines "replaced"
        assert_that "data" --file-is-lines "replaced"
-       [ -x "$tmpdir/cmd" ] \
-       || assert_fail "cmd must still be executable"
-       [ -x "$tmpdir/data" ] \
-       && assert_fail "data must not be executable"
+       [ -x 'cmd' ] \
+       || assert_fail 'cmd must still be executable\n'
+       [ -x 'data' ] \
+       && assert_fail 'data must not be executable\n'
 
        test_case_end
 fi
@@ -1115,12 +1119,12 @@ if test_case_begin "unreadable file"; th
                '.include "mk/subst.mk"'
        create_file_lines "unreadable-file" \
                'before'
-       chmod 0000 "$tmpdir/unreadable-file"
+       chmod 0000 'unreadable-file'
 
-       run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in unreadable-file' \
                'sh: cannot open unreadable-file: permission denied' \
                'sh: cannot open unreadable-file: permission denied' \
@@ -1253,10 +1257,10 @@ if test_case_begin "identity substitutio
        create_file_lines "file" \
                'before'
 
-       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file'
 
        test_case_end
@@ -1276,10 +1280,10 @@ if test_case_begin "identity substitutio
        create_file_lines "file" \
                'other'
 
-       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file' \
                'warning: [subst.mk:id] Nothing changed in "file".' \
                'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
@@ -1306,10 +1310,10 @@ if test_case_begin "identity + effective
        create_file_lines "file" \
                'from'
 
-       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file'
        assert_that "file" --file-is-lines \
                'to'
@@ -1337,10 +1341,10 @@ if test_case_begin "identity + no-op sub
        create_file_lines "file" \
                'other'
 
-       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file' \
                'warning: [subst.mk:id] Nothing changed in "file".' \
                'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
@@ -1372,7 +1376,7 @@ if test_case_begin "SUBST_FILTER_CMD + S
                '.include "mk/subst.mk"'
        create_file_lines "file" \
                'letters 123 letters'
-       create_file_lines "main.mk" \
+       create_file_lines "$tmpdir/main.mk" \
                "PKGSRCDIR=     $pkgsrcdir" \
                ".PATH:         $mocked_pkgsrcdir" \
                ".PATH:         $pkgsrcdir" \
@@ -1381,10 +1385,10 @@ if test_case_begin "SUBST_FILTER_CMD + S
                'all: subst-id' \
                '       @printf '\''fail reason: %s\n'\'' ${PKG_FAIL_REASON} 1>&2'
 
-       "$make" -f "$tmpdir/main.mk" "all" 1> "$tmpdir/out" 2>&1 \
+       "$make" -f "$tmpdir/main.mk" "all" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file' \
                'fail reason: [subst.mk:id] SUBST_FILTER_CMD and SUBST_SED/SUBST_VARS cannot be combined.'
        assert_that "file" --file-is-lines \
@@ -1407,10 +1411,10 @@ if test_case_begin "effective SUBST_FILT
        create_file_lines "file" \
                'letters 123 letters'
 
-       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file'
        assert_that "file" --file-is-lines \
                'letters  letters'
@@ -1432,10 +1436,10 @@ if test_case_begin "no-op SUBST_FILTER_C
        create_file_lines "file" \
                'only letters'
 
-       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file' \
                'warning: [subst.mk:id] Nothing changed in "file".' \
                'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
@@ -1463,10 +1467,10 @@ if test_case_begin "backtick in SUBST_SE
        create_file_lines "file" \
                'from`'
 
-       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file' \
                'info: [subst.mk:id] Nothing changed in "file".'
 
@@ -1491,10 +1495,10 @@ if test_case_begin "multiple sed command
        create_file_lines "file" \
                '$mode = 755;'
 
-       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \
+       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "out" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "id" in file' \
                'warning: [subst.mk:id] Nothing changed in "file".' \
                'fail: [subst.mk:id] The filename pattern "file" has no effect.' \

Index: pkgsrc/regress/infra-unittests/test.subr
diff -u pkgsrc/regress/infra-unittests/test.subr:1.13 pkgsrc/regress/infra-unittests/test.subr:1.14
--- pkgsrc/regress/infra-unittests/test.subr:1.13       Sat May  9 17:41:08 2020
+++ pkgsrc/regress/infra-unittests/test.subr    Mon May 11 19:13:10 2020
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: test.subr,v 1.13 2020/05/09 17:41:08 rillig Exp $
+# $NetBSD: test.subr,v 1.14 2020/05/11 19:13:10 rillig Exp $
 #
 # This file defines utilities for testing Makefile fragments and shell
 # programs from the pkgsrc infrastructure. While testing one part of the
@@ -17,7 +17,7 @@
 #
 #      if test_case_begin "description of the test"; then
 #              ...
-#              test_end
+#              test_case_end
 #      fi
 #
 # The functions test_case_set_up and test_case_tear_down can be defined in the
@@ -26,12 +26,15 @@
 #
 # During a test case, the following variables are defined:
 #
-#      tmpdir          a directory for creating intermediate files
-#      pkgsrcdir       the real pkgsrc directory
-#      mocked_pkgsrcdir
-#                      the directory where the mock files are installed,
-#                      which override the Makefile fragments from the real
-#                      pkgsrc infrastructure
+# tmpdir
+#      a directory for creating intermediate files
+#
+# pkgsrcdir
+#      the real pkgsrc directory
+#
+# mocked_pkgsrcdir
+#      the directory where the mock files are installed, which override
+#      the Makefile fragments from the real pkgsrc infrastructure
 #
 #
 # Setting up a test
@@ -160,6 +163,11 @@ test_case_begin() {
        test_case_begun="`expr "$test_case_begun" + 1`"
        verbose_printf 'running test case "%s"\n' "$test_case_name"
 
+       cd "$tmpdir" || exit 1
+       rm -rf 'work'
+       mkdir 'work' || exit 1
+       cd 'work' || exit 1
+
        test_case_set_up
 }
 
@@ -243,18 +251,18 @@ EOF
 
 create_file() {
        assert_that "$#" --equals 1
-       mkdir -p "$(dirname "$tmpdir/$1")"
-       cat > "$tmpdir/$1"
+       mkdir -p "$(dirname -- "$1")"
+       cat > "$1"
 }
 
 create_file_lines() {
-       mkdir -p "$(dirname "$tmpdir/$1")"
        _cfl_filename="$1"; shift
-       printf '%s\n' "$@" > "$tmpdir/$_cfl_filename"
+       mkdir -p "$(dirname -- "$_cfl_filename")"
+       printf '%s\n' "$@" > "$_cfl_filename"
 }
 
 create_pkgsrc_file() {
-       mkdir -p "$(dirname "$mocked_pkgsrcdir/$1")"
+       mkdir -p "$(dirname -- "$mocked_pkgsrcdir/$1")"
        cat > "$mocked_pkgsrcdir/$1"
 }
 
@@ -289,14 +297,12 @@ assert_fail() {
        assert_failed=`expr "$assert_failed" + 1`
 }
 
-tmpdir_equal() {
-       (cd "$tmpdir" && diff -u -- "$@" >/dev/null) || return 1
+files_equal() {
+       (diff -u -- "$@" >/dev/null) || return 1
 }
 
-tmpdir_diff() {
-       # removes the timestamps from the diff files since these are not
-       # useful in tests.
-       (cd "$tmpdir" && diff -u -- "$@" || true) \
+diff_without_timestamps() {
+       (diff -u -- "$@" || true) \
        | awk '/^(---|[+][+][+]) / { print($1, $2); next } { print }' 1>&2
 }
 
@@ -312,30 +318,30 @@ assert_that() {
 
        (--file-contains-exactly)
                printf '%s\n' "$3" > "$tmpdir/expected"
-               if tmpdir_equal "expected" "$1"; then
+               if files_equal "$tmpdir/expected" "$1"; then
                        assert_succeed
                        return 0
                fi
                assert_fail 'file "%s" has unexpected content:\n' "$1"
-               tmpdir_diff "expected" "$1"
+               diff_without_timestamps "$tmpdir/expected" "$1"
                ;;
 
        (--file-equals)
-               if tmpdir_equal "$3" "$1"; then
+               if files_equal "$3" "$1"; then
                        assert_succeed
                        return 0
                fi
                assert_fail 'files "%s" and "%s" differ:\n' "$1" "$3"
-               tmpdir_diff "$3" "$1"
+               diff_without_timestamps "$3" "$1"
                ;;
 
        (--file-is-empty)
-               if tmpdir_equal "/dev/null" "$1"; then
+               if files_equal "/dev/null" "$1"; then
                        assert_succeed
                        return 0
                fi
                assert_fail 'file "%s" is not empty:\n' "$1"
-               tmpdir_diff "/dev/null" "$1"
+               diff_without_timestamps "/dev/null" "$1"
                ;;
 
        (--file-is-lines)
@@ -343,12 +349,12 @@ assert_that() {
                _assert_that_filename="$1"; shift 2
 
                printf '%s\n' "$@" > "$tmpdir/expected"
-               if tmpdir_equal "expected" "$_assert_that_tmp_actual"; then
+               if files_equal "$tmpdir/expected" "$_assert_that_tmp_actual"; then
                        assert_succeed
                        return 0
                fi
                assert_fail 'file "%s" has unexpected content:\n' "$_assert_that_filename"
-               tmpdir_diff "expected" "$_assert_that_tmp_actual"
+               diff_without_timestamps "$tmpdir/expected" "$_assert_that_tmp_actual"
                ;;
 
        (*)



Home | Main Index | Thread Index | Old Index