pkgsrc-Changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
CVS commit: pkgsrc
Module Name: pkgsrc
Committed By: rillig
Date: Sun Mar 22 12:15:59 UTC 2020
Modified Files:
pkgsrc/mk: subst.mk
pkgsrc/regress/infra-unittests: subst.sh test.subr
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 pkgsrc/mk/subst.mk
cvs rdiff -u -r1.11 -r1.12 pkgsrc/regress/infra-unittests/subst.sh
cvs rdiff -u -r1.6 -r1.7 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/mk/subst.mk
diff -u pkgsrc/mk/subst.mk:1.68 pkgsrc/mk/subst.mk:1.69
--- pkgsrc/mk/subst.mk:1.68 Sat Mar 21 19:26:12 2020
+++ pkgsrc/mk/subst.mk Sun Mar 22 12:15:59 2020
@@ -1,4 +1,4 @@
-# $NetBSD: subst.mk,v 1.68 2020/03/21 19:26:12 rillig Exp $
+# $NetBSD: subst.mk,v 1.69 2020/03/22 12:15:59 rillig Exp $
#
# The subst framework replaces text in one or more files in the WRKSRC
# directory. Packages can define several ``classes'' of replacements.
@@ -126,6 +126,7 @@ _SUBST_KEEP.${_class_}?= LC_ALL=C ${DIFF
_SUBST_KEEP.${_class_}?= ${DO_NADA}
SUBST_SKIP_TEXT_CHECK.${_class_}?= no
SUBST_NOOP_OK.${_class_}?= yes # TODO: change to no after 2020Q1
+_SUBST_WARN.${_class_}= ${${SUBST_NOOP_OK.${_class_}:tl} == yes:?${INFO_MSG}:${WARNING_MSG}} "[subst.mk:${_class_}]"
.if !empty(SUBST_SKIP_TEXT_CHECK.${_class_}:M[Yy][Ee][Ss])
_SUBST_IS_TEXT_FILE_CMD.${_class_}= ${TRUE}
@@ -158,7 +159,7 @@ ${_SUBST_COOKIE.${_class_}}:
case $$file in /*) ;; *) file="./$$file";; esac; \
tmpfile="$$file.subst.sav"; \
if [ ! -f "$$file" ]; then \
- ${WARNING_MSG} "[subst.mk:${_class_}] Ignoring non-existent file \"$$file\"."; \
+ ${_SUBST_WARN.${_class_}} "Ignoring non-existent file \"$$file\"."; \
elif ${_SUBST_IS_TEXT_FILE_CMD.${_class_}}; then \
${SUBST_FILTER_CMD.${_class_}} \
< "$$file" \
@@ -167,7 +168,7 @@ ${_SUBST_COOKIE.${_class_}}:
${CHMOD} +x "$$tmpfile"; \
fi; \
if ${CMP} -s "$$tmpfile" "$$file"; then \
- ${INFO_MSG} "[subst.mk:${_class_}] Nothing changed in $$file."; \
+ ${_SUBST_WARN.${_class_}} "Nothing changed in $$file."; \
${RM} -f "$$tmpfile"; \
else \
changed=yes; \
@@ -176,7 +177,7 @@ ${_SUBST_COOKIE.${_class_}}:
${ECHO} "$$file" >> ${.TARGET}; \
fi; \
else \
- ${WARNING_MSG} "[subst.mk:${_class_}] Ignoring non-text file \"$$file\"."; \
+ ${_SUBST_WARN.${_class_}} "Ignoring non-text file \"$$file\"."; \
fi; \
done; \
\
Index: pkgsrc/regress/infra-unittests/subst.sh
diff -u pkgsrc/regress/infra-unittests/subst.sh:1.11 pkgsrc/regress/infra-unittests/subst.sh:1.12
--- pkgsrc/regress/infra-unittests/subst.sh:1.11 Sat Mar 21 18:43:02 2020
+++ pkgsrc/regress/infra-unittests/subst.sh Sun Mar 22 12:15:59 2020
@@ -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"
Index: pkgsrc/regress/infra-unittests/test.subr
diff -u pkgsrc/regress/infra-unittests/test.subr:1.6 pkgsrc/regress/infra-unittests/test.subr:1.7
--- pkgsrc/regress/infra-unittests/test.subr:1.6 Sat Mar 21 18:43:02 2020
+++ pkgsrc/regress/infra-unittests/test.subr Sun Mar 22 12:15:59 2020
@@ -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"
;;
(*)
Home |
Main Index |
Thread Index |
Old Index