summaryrefslogtreecommitdiff
path: root/regress/infra-unittests
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2020-03-22 12:15:59 +0000
committerrillig <rillig@pkgsrc.org>2020-03-22 12:15:59 +0000
commit365a3632ac2177e317321b12bb03850ffc09d2ab (patch)
tree846167e463bd6fa95e25654624664abd9992d13a /regress/infra-unittests
parentf529608d9b99d4894125f216fcc9e2b9a5e14dc1 (diff)
downloadpkgsrc-365a3632ac2177e317321b12bb03850ffc09d2ab.tar.gz
mk/subst.mk: use the same severity for all messages
The severity now depends only on the setting of SUBST_NOOP_OK. Right now this means that some former warnings will be reported as info only, but that will change after switching the default of SUBST_NOOP_OK after 2020Q1. Then they will all be reported as warnings, followed by the final error saying that the pattern has no effect. This change makes it easier to detect inconsistencies and outdated definitions, for example by setting the global SUBST_NOOP_OK=no and redefining WARNING_MSG to actuall fail.
Diffstat (limited to 'regress/infra-unittests')
-rw-r--r--regress/infra-unittests/subst.sh12
-rw-r--r--regress/infra-unittests/test.subr34
2 files changed, 28 insertions, 18 deletions
diff --git a/regress/infra-unittests/subst.sh b/regress/infra-unittests/subst.sh
index 4e5f4310837..2a7c174294b 100644
--- a/regress/infra-unittests/subst.sh
+++ b/regress/infra-unittests/subst.sh
@@ -222,7 +222,7 @@ EOF
create_file_lines "expected-output" \
'=> Substituting "class" in single' \
- 'info: [subst.mk:class] Nothing changed in ./single.' \
+ 'warning: [subst.mk:class] Nothing changed in ./single.' \
'fail: [subst.mk:class] The pattern single has no effect.' \
'*** Error code 1' \
'' \
@@ -287,7 +287,7 @@ EOF
create_file_lines "expected-output" \
'=> Substituting "class" in nonexistent' \
- 'warning: [subst.mk:class] Ignoring non-existent file "./nonexistent".'
+ 'info: [subst.mk:class] Ignoring non-existent file "./nonexistent".'
assert_that "actual-output" --file-equals "expected-output"
assert_that "$exitcode" --equals "0"
@@ -315,7 +315,7 @@ EOF
create_file_lines "expected-output" \
'=> Substituting "class" in *exist* *not-found*' \
- 'warning: [subst.mk:class] Ignoring non-existent file "./*not-found*".'
+ 'info: [subst.mk:class] Ignoring non-existent 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"
@@ -340,9 +340,9 @@ EOF
create_file_lines "expected-output" \
'=> Substituting "class" in does not exist' \
- 'warning: [subst.mk:class] Ignoring non-existent file "./does".' \
- 'warning: [subst.mk:class] Ignoring non-existent file "./not".' \
- 'warning: [subst.mk:class] Ignoring non-existent file "./exist".'
+ 'info: [subst.mk:class] Ignoring non-existent file "./does".' \
+ 'info: [subst.mk:class] Ignoring non-existent file "./not".' \
+ 'info: [subst.mk:class] Ignoring non-existent file "./exist".'
assert_that "actual-output" --file-equals "expected-output"
assert_that "$exitcode" --equals "0"
diff --git a/regress/infra-unittests/test.subr b/regress/infra-unittests/test.subr
index 2b1a0163a82..da11c430e2b 100644
--- a/regress/infra-unittests/test.subr
+++ b/regress/infra-unittests/test.subr
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: test.subr,v 1.6 2020/03/21 18:43:02 rillig Exp $
+# $NetBSD: test.subr,v 1.7 2020/03/22 12:15:59 rillig Exp $
set -eu
# This file defines utilities for testing Makefile fragments in a mocked
@@ -206,6 +206,17 @@ assert_fail() {
assert_failed=`expr "$assert_failed" + 1`
}
+tmpdir_equal() {
+ (cd "$tmpdir" && 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) \
+ | awk '/^(---|[+][+][+]) / { print($1, $2); next } { print }' 1>&2
+}
+
assert_that() {
case "$2" in
(--equals)
@@ -218,44 +229,43 @@ assert_that() {
(--file-contains-exactly)
printf '%s\n' "$3" > "$tmpdir/expected"
- if diff -u "$tmpdir/expected" "$tmpdir/$1" > /dev/null; then
+ if tmpdir_equal "expected" "$1"; then
assert_succeed
return 0
fi
assert_fail 'file "%s" has unexpected content:\n' "$1"
- diff -u "$tmpdir/expected" "$tmpdir/$1" 1>&2 || true
+ tmpdir_diff "expected" "$1"
;;
(--file-equals)
- if diff -u "$tmpdir/$3" "$tmpdir/$1" > /dev/null; then
+ if tmpdir_equal "$3" "$1"; then
assert_succeed
return 0
fi
assert_fail 'files "%s" and "%s" differ:\n' "$1" "$3"
- diff -u "$tmpdir/$3" "$tmpdir/$1" 1>&2 || true
+ tmpdir_diff "$3" "$1"
;;
(--file-is-empty)
- if diff -u "/dev/null" "$tmpdir/$1" > /dev/null; then
+ if tmpdir_equal "/dev/null" "$1"; then
assert_succeed
return 0
fi
assert_fail 'file "%s" is not empty:\n' "$1"
- diff -u "/dev/null" "$tmpdir/$1" 1>&2 || true
+ tmpdir_diff "/dev/null" "$1"
;;
(--file-is-lines)
- _assert_that_tmp_actual="$tmpdir/$1"
- _assert_that_tmp_expected="$tmpdir/expected"
+ _assert_that_tmp_actual="$1"
_assert_that_filename="$1"; shift 2
- printf '%s\n' "$@" > "$_assert_that_tmp_expected"
- if diff -u "$_assert_that_tmp_expected" "$_assert_that_tmp_actual" > /dev/null; then
+ printf '%s\n' "$@" > "$tmpdir/expected"
+ if tmpdir_equal "expected" "$_assert_that_tmp_actual"; then
assert_succeed
return 0
fi
assert_fail 'file "%s" has unexpected content:\n' "$_assert_that_filename"
- diff -u "$_assert_that_tmp_expected" "$_assert_that_tmp_actual" 1>&2 || true
+ tmpdir_diff "expected" "$_assert_that_tmp_actual"
;;
(*)