summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2020-05-11 19:13:10 +0000
committerrillig <rillig@pkgsrc.org>2020-05-11 19:13:10 +0000
commita880395fa2cd2ba5ddb93efa695963e868592f80 (patch)
tree45d0eaed7844a162b442b57263c7526f3de30690 /regress
parent4a7cf991cb83aafac679005aecac20d200be87b3 (diff)
downloadpkgsrc-a880395fa2cd2ba5ddb93efa695963e868592f80.tar.gz
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.
Diffstat (limited to 'regress')
-rw-r--r--regress/infra-unittests/check-portability.sh62
-rw-r--r--regress/infra-unittests/extract.sh45
-rw-r--r--regress/infra-unittests/subst.sh214
-rw-r--r--regress/infra-unittests/test.subr60
4 files changed, 188 insertions, 193 deletions
diff --git a/regress/infra-unittests/check-portability.sh b/regress/infra-unittests/check-portability.sh
index 37eb301876e..dfbb4a85daa 100644
--- a/regress/infra-unittests/check-portability.sh
+++ b/regress/infra-unittests/check-portability.sh
@@ -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 ... = ..."; then
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, Makefile.am bad'; then
# 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 usually not used for building'; then
# 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 in filenames'; then
# 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 default'; then
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
diff --git a/regress/infra-unittests/extract.sh b/regress/infra-unittests/extract.sh
index 7369975fbf7..b7e4f974c3e 100644
--- a/regress/infra-unittests/extract.sh
+++ b/regress/infra-unittests/extract.sh
@@ -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 basename"; then
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 directory by pattern with slash"; then
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"; then
# 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
diff --git a/regress/infra-unittests/subst.sh b/regress/infra-unittests/subst.sh
index 7eeed2aad23..1d2d24f3dad 100644
--- a/regress/infra-unittests/subst.sh
+++ b/regress/infra-unittests/subst.sh
@@ -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 files"; then
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"; then
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, noop_ok=yes"; then
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, noop_ok=no"; then
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, noop_ok=no"; then
'' \
'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 nonexistent"; then
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 nonexistent"; then
'' \
'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 nonexistent ok"; then
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 nonexistent"; then
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 files, all are reported at once"; then
.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, all are reported at once"; then
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 in filenames"; then
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 patterns"; then
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 classes"; then
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"; 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)" \
@@ -664,7 +670,7 @@ if test_case_begin "global 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
@@ -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 surrounding whitespace"; then
"$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 backslashes"; then
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 variables with regex characters"; then
'@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 directory"; then
'' \
'.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 directory"; then
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 directory"; then
'' \
'.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 directory"; then
&& 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 patterns have no effect"; then
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"; then
'.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"; then
'.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_CLASSES"; then
'.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 preserved"; then
'@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"; then
'.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 substitution, found in file"; then
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 substitution, not found in file"; then
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 substitution"; then
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 substitution"; then
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 + SUBST_SED in NOOP_OK=no mode"; then
'.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 + SUBST_SED in NOOP_OK=no mode"; then
'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_FILTER_CMD in NOOP_OK=no mode"; then
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_CMD in NOOP_OK=no mode"; then
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_SED"; then
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 commands with semicolon"; then
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.' \
diff --git a/regress/infra-unittests/test.subr b/regress/infra-unittests/test.subr
index b4b55f36ad7..da9e8b321de 100644
--- a/regress/infra-unittests/test.subr
+++ b/regress/infra-unittests/test.subr
@@ -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"
;;
(*)