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: Fri Mar 20 21:27:04 UTC 2020
Modified Files:
pkgsrc/regress/infra-unittests: subst.sh test.subr
Log Message:
regress/infra-unittests: add tests for special characters in subst.mk
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 pkgsrc/regress/infra-unittests/subst.sh
cvs rdiff -u -r1.3 -r1.4 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/subst.sh
diff -u pkgsrc/regress/infra-unittests/subst.sh:1.5 pkgsrc/regress/infra-unittests/subst.sh:1.6
--- pkgsrc/regress/infra-unittests/subst.sh:1.5 Fri Mar 20 09:00:45 2020
+++ pkgsrc/regress/infra-unittests/subst.sh Fri Mar 20 21:27:04 2020
@@ -7,9 +7,7 @@ set -eu
. "./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 @@ EOF
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
Index: pkgsrc/regress/infra-unittests/test.subr
diff -u pkgsrc/regress/infra-unittests/test.subr:1.3 pkgsrc/regress/infra-unittests/test.subr:1.4
--- pkgsrc/regress/infra-unittests/test.subr:1.3 Fri Mar 20 08:56:42 2020
+++ pkgsrc/regress/infra-unittests/test.subr Fri Mar 20 21:27:04 2020
@@ -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 @@ EOF
}
create_file() {
+ assert_that "$#" --equals 1
cat > "$tmpdir/$1"
}
@@ -230,6 +231,20 @@ assert_that() {
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