pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/regress/infra-unittests regress/infra-unittests: add t...
details: https://anonhg.NetBSD.org/pkgsrc/rev/9b092970492e
branches: trunk
changeset: 413569:9b092970492e
user: rillig <rillig%pkgsrc.org@localhost>
date: Fri Mar 20 21:27:04 2020 +0000
description:
regress/infra-unittests: add tests for special characters in subst.mk
diffstat:
regress/infra-unittests/subst.sh | 93 ++++++++++++++++++++++++++++++++++++--
regress/infra-unittests/test.subr | 17 ++++++-
2 files changed, 104 insertions(+), 6 deletions(-)
diffs (146 lines):
diff -r 03e48fac2a3a -r 9b092970492e regress/infra-unittests/subst.sh
--- a/regress/infra-unittests/subst.sh Fri Mar 20 21:19:54 2020 +0000
+++ b/regress/infra-unittests/subst.sh Fri Mar 20 21:27:04 2020 +0000
@@ -7,9 +7,7 @@
. "./test.subr"
test_case_set_up() {
- rm -rf "$tmpdir"/.subst_*_done "$tmpdir"/.subst-empty
- rm -rf "$tmpdir"/*
- ls -A "$tmpdir"
+ rm -rf "$tmpdir"/.??* "$tmpdir"/*
create_file "prepare-subst.mk" <<EOF
@@ -429,5 +427,90 @@
fi
-# TODO: Add tests for files having special characters, like space, dollar,
-# backticks, basically every ASCII character.
+if test_case_begin "special characters in filenames"; then
+
+ create_file "testcase.mk" <<EOF
+SUBST_CLASSES+= class
+SUBST_STAGE.class= pre-configure
+SUBST_FILES.class= *
+SUBST_SED.class= -e s,before,after,
+SUBST_NOOP_OK.class= yes
+
+.include "prepare-subst.mk"
+.include "mk/subst.mk"
+EOF
+
+ create_file_lines " !\"#\$%&'()*+,-." "before"
+ create_file_lines "0123456789:;<=>?" "before"
+ create_file_lines "@ABCDEFGHIJKLMNO" "before"
+ create_file_lines "PQRSTUVWXYZ[\\]^_" "before"
+ create_file_lines "\`abcdefghijklmno" "before"
+ create_file_lines "pqrstuvwxyz{|}~" "before"
+ create_file_lines "--no-option" "before"
+ create_file_lines ".hidden" "before"
+
+ test_file "testcase.mk" "subst-class" \
+ 1> "$tmpdir/stdout" \
+ 2> "$tmpdir/stderr" \
+ && exitcode=0 || exitcode=$?
+
+ assert_that "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
+ assert_that "$exitcode" --equals "0"
+
+ assert_that " !\"#\$%&'()*+,-." --file-is-lines "after"
+ assert_that "0123456789:;<=>?" --file-is-lines "after"
+ assert_that "@ABCDEFGHIJKLMNO" --file-is-lines "after"
+ assert_that "PQRSTUVWXYZ[\\]^_" --file-is-lines "after"
+ assert_that "\`abcdefghijklmno" --file-is-lines "after"
+ assert_that "pqrstuvwxyz{|}~" --file-is-lines "after"
+ assert_that "--no-option" --file-is-lines "after"
+ assert_that ".hidden" --file-is-lines "before"
+
+ test_case_end
+fi
+
+if test_case_begin "brackets in filename patterns"; then
+
+ create_file "testcase.mk" <<EOF
+SUBST_CLASSES+= class
+SUBST_STAGE.class= pre-configure
+SUBST_FILES.class= [*]
+SUBST_SED.class= -e s,before,after,
+SUBST_NOOP_OK.class= yes
+
+.include "prepare-subst.mk"
+.include "mk/subst.mk"
+EOF
+
+ create_file_lines "any" "before"
+ create_file_lines "x" "before"
+ create_file_lines "*" "before"
+ create_file_lines "[*]" "before"
+
+ test_file "testcase.mk" "subst-class" \
+ 1> "$tmpdir/stdout" \
+ 2> "$tmpdir/stderr" \
+ && exitcode=0 || exitcode=$?
+
+ assert_that "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
+ assert_that "$exitcode" --equals "0"
+
+ assert_that "any" --file-is-lines "before"
+ assert_that "x" --file-is-lines "before"
+ assert_that "*" --file-is-lines "after"
+ assert_that "[*]" --file-is-lines "before"
+
+ test_case_end
+fi
diff -r 03e48fac2a3a -r 9b092970492e regress/infra-unittests/test.subr
--- a/regress/infra-unittests/test.subr Fri Mar 20 21:19:54 2020 +0000
+++ b/regress/infra-unittests/test.subr Fri Mar 20 21:27:04 2020 +0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: test.subr,v 1.3 2020/03/20 08:56:42 rillig Exp $
+# $NetBSD: test.subr,v 1.4 2020/03/20 21:27:04 rillig Exp $
set -eu
# This file defines utilities for testing Makefile fragments in a mocked
@@ -148,6 +148,7 @@
}
create_file() {
+ assert_that "$#" --equals 1
cat > "$tmpdir/$1"
}
@@ -230,6 +231,20 @@
diff -u "/dev/null" "$tmpdir/$1" 1>&2 || true
;;
+ (--file-is-lines)
+ _assert_that_tmp_actual="$tmpdir/$1"
+ _assert_that_tmp_expected="$tmpdir/$1"
+ _assert_that_filename="$1"; shift
+
+ printf '%s\n' "$@" > "$_assert_that_tmp_expected"
+ if diff -u "$_assert_that_tmp_expected" "$_assert_that_tmp_actual" > /dev/null; 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
+ ;;
+
(*)
printf 'usage: assert_that <expr> --equals <expr>\n' 1>&2
exit 1
Home |
Main Index |
Thread Index |
Old Index