pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/regress regress: migrate SUBST test to the other SUBST...
details: https://anonhg.NetBSD.org/pkgsrc/rev/ac235751e889
branches: trunk
changeset: 425428:ac235751e889
user: rillig <rillig%pkgsrc.org@localhost>
date: Sat Mar 21 18:43:02 2020 +0000
description:
regress: migrate SUBST test to the other SUBST tests
In the old test code, the input and output data for each test case were
in different files. This was too far apart to relate them. In addition,
all test cases were merged into a single big test, which made it hard to
tell the topics apart.
diffstat:
regress/infra-unittests/subst.sh | 172 +++++++++++++++++++++++++++++++++++++-
regress/infra-unittests/test.subr | 17 +++-
regress/subst/Makefile | 59 -------------
regress/subst/PLIST | 2 -
regress/subst/files/expected | 25 -----
regress/subst/spec | 8 -
6 files changed, 186 insertions(+), 97 deletions(-)
diffs (truncated from 346 to 300 lines):
diff -r 690d00944fc9 -r ac235751e889 regress/infra-unittests/subst.sh
--- a/regress/infra-unittests/subst.sh Sat Mar 21 17:27:24 2020 +0000
+++ b/regress/infra-unittests/subst.sh Sat Mar 21 18:43:02 2020 +0000
@@ -644,7 +644,6 @@
.include "mk/subst.mk"
EOF
- LC_ALL=C \
test_file "testcase.mk" "pre-configure" \
1> "$tmpdir/stdout" \
2> "$tmpdir/stderr" \
@@ -668,3 +667,174 @@
test_case_end
fi
+
+
+if test_case_begin "SUBST_VARS"; then
+
+ create_file_lines "testcase.mk" \
+ 'SUBST_CLASSES+= vars' \
+ 'SUBST_STAGE.vars= pre-configure' \
+ 'SUBST_FILES.vars= vars.txt' \
+ 'SUBST_VARS.vars= PLAIN DQUOT SQUOT DELIM PRINTABLE' \
+ 'SUBST_VARS.vars+= UNDEFINED' \
+ '' \
+ 'PLAIN= plain' \
+ 'DQUOT= "double quoted"' \
+ 'SQUOT= '\''single quoted'\''' \
+ 'DELIM= hello, world' \
+ 'PRINTABLE= !"\#$$%&'\''()*+,-./09:;<=>?@AZ[\]^_`az{|}' \
+ '#UNDEFINED= # undefined' \
+ '' \
+ '.include "prepare-subst.mk"' \
+ '.include "mk/subst.mk"'
+ create_file_lines "vars.txt" \
+ "@PLAIN@" \
+ "@DQUOT@" \
+ "@SQUOT@" \
+ "@DELIM@" \
+ "@PRINTABLE@" \
+ "@UNDEFINED@"
+
+ test_file "testcase.mk" "pre-configure" \
+ 1> "$tmpdir/stdout" \
+ 2> "$tmpdir/stderr" \
+ && exitcode=0 || exitcode=$?
+
+ # The double quotes and single quotes are kept since the variables
+ # are treated as simple string variables, not as lists of shell
+ # words. In these string variables, the quotes are part of the value.
+ assert_that "vars.txt" --file-is-lines \
+ "plain" \
+ "\"double quoted\"" \
+ "'single quoted'" \
+ "hello, world" \
+ '!"#$%&'\''()*+,-./09:;<=>?@AZ[\]^_`az{|}' \
+ ""
+ assert_that "stdout" --file-is-lines \
+ "=> Substituting \"vars\" in vars.txt"
+ assert_that "stderr" --file-is-empty
+ assert_that "$exitcode" --equals 0
+
+ test_case_end
+fi
+
+if test_case_begin "SUBST_VARS with surrounding whitespace"; then
+
+ # Ensure that leading and trailing whitespace is preserved
+ # in the variable values.
+
+ create_file_lines "testcase.mk" \
+ 'SUBST_CLASSES+= vars' \
+ 'SUBST_STAGE.vars= pre-configure' \
+ 'SUBST_FILES.vars= vars.txt' \
+ 'SUBST_VARS.vars= SPACE TAB NEWLINE' \
+ '' \
+ 'SPACE= ${:U }between spaces${:U }' \
+ 'TAB= ${:U }between tabs${:U }' \
+ 'NEWLINE= ${.newline}between newlines${.newline}' \
+ '' \
+ '.include "prepare-subst.mk"' \
+ '.include "mk/subst.mk"'
+ create_file_lines "vars.txt" \
+ "@SPACE@" \
+ "@TAB@" \
+ "@NEWLINE@"
+
+ test_file "testcase.mk" "pre-configure" \
+ 1> "$tmpdir/stdout" \
+ 2> "$tmpdir/stderr" \
+ && exitcode=0 || exitcode=$?
+
+ space=' '
+ tab=' '
+ newline='
+'
+ assert_that "vars.txt" --file-is-lines \
+ "$space""between spaces""$space" \
+ "$tab""between tabs""$tab" \
+ "$newline""between newlines""$newline"
+ assert_that "stdout" --file-is-lines \
+ "=> Substituting \"vars\" in vars.txt"
+ assert_that "stderr" --file-is-empty
+ assert_that "$exitcode" --equals 0
+
+ test_case_end
+fi
+
+
+if test_case_begin "SUBST_VARS with backslashes"; then
+
+ create_file_lines "testcase.mk" \
+ 'SUBST_CLASSES+= bs' \
+ 'SUBST_STAGE.bs= pre-configure' \
+ 'SUBST_FILES.bs= backslash.txt' \
+ 'SUBST_VARS.bs= BACKSLASHES' \
+ '' \
+ 'BACKSLASHES= \" \, \\, \" \'\'' \0\000 \x40 \089 \a \$$' \
+ '' \
+ '.include "prepare-subst.mk"' \
+ '.include "mk/subst.mk"'
+ create_file_lines "backslash.txt" "@BACKSLASHES@"
+
+ test_file "testcase.mk" "pre-configure" \
+ 1> "$tmpdir/stdout" \
+ 2> "$tmpdir/stderr" \
+ && exitcode=0 || exitcode=$?
+
+ assert_that "backslash.txt" --file-is-lines \
+ '\" \, \\, \" \'\'' \0\000 \x40 \089 \a \$'
+ assert_that "stdout" --file-is-lines \
+ "=> Substituting \"bs\" in backslash.txt"
+ assert_that "stderr" --file-is-empty
+ assert_that "$exitcode" --equals 0
+
+ test_case_end
+fi
+
+
+if test_case_begin "SUBST_VARS for variables with regex characters"; then
+
+ # Ensure that special regex characters like dots and parentheses
+ # may appear in variable names and are properly escaped.
+
+ create_file_lines "testcase.mk" \
+ 'SUBST_CLASSES+= vars' \
+ 'SUBST_STAGE.vars= pre-configure' \
+ 'SUBST_FILES.vars= vars.txt' \
+ 'SUBST_VARS.vars= VAR...... VAR.abcde VAR.() VAR.<>' \
+ '' \
+ 'VAR......= dots' \
+ 'VAR.abcde= letters' \
+ 'VAR.()= parentheses' \
+ 'VAR.<>= angle brackets' \
+ 'VAR.[]= square brackets' \
+ '' \
+ '.include "prepare-subst.mk"' \
+ '.include "mk/subst.mk"'
+ create_file_lines "vars.txt" \
+ "@VAR......@" \
+ "@VAR.abcde@" \
+ "@VAR.()@" \
+ "@VAR.<>@" \
+ "@VAR.[]@"
+
+ test_file "testcase.mk" "pre-configure" \
+ 1> "$tmpdir/stdout" \
+ 2> "$tmpdir/stderr" \
+ && exitcode=0 || exitcode=$?
+
+ # TODO: Why are the angle brackets replaced, but not the parentheses
+ # and square brackets?
+ assert_that "vars.txt" --file-is-lines \
+ "dots" \
+ "letters" \
+ "@VAR.()@" \
+ "angle brackets" \
+ "@VAR.[]@"
+ assert_that "stdout" --file-is-lines \
+ "=> Substituting \"vars\" in vars.txt"
+ assert_that "stderr" --file-is-empty
+ assert_that "$exitcode" --equals 0
+
+ test_case_end
+fi
diff -r 690d00944fc9 -r ac235751e889 regress/infra-unittests/test.subr
--- a/regress/infra-unittests/test.subr Sat Mar 21 17:27:24 2020 +0000
+++ b/regress/infra-unittests/test.subr Sat Mar 21 18:43:02 2020 +0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: test.subr,v 1.5 2020/03/21 06:53:18 rillig Exp $
+# $NetBSD: test.subr,v 1.6 2020/03/21 18:43:02 rillig Exp $
set -eu
# This file defines utilities for testing Makefile fragments in a mocked
@@ -70,10 +70,18 @@
exit 1
}
+verbose_printf() {
+ $if_verbose printf "$@"
+}
+
test_case_name="unknown test"
+test_case_begun=0
+test_case_ended=0
test_case_begin() {
test_case_name="$1"
+ test_case_begun="`expr "$test_case_begun" + 1`"
+ verbose_printf 'running test case "%s"\n' "$test_case_name"
test_case_set_up
}
@@ -89,6 +97,11 @@
test_case_end() {
test_case_tear_down
+ test_case_ended="`expr "$test_case_ended" + 1`"
+ test "$test_case_ended" = "$test_case_begun" \
+ || assert_fail 'unbalanced test_case_begin (%d) and test_case_end (%d)\n' \
+ "$test_case_begun" "$test_case_ended"
+
test_case_name="unknown test"
}
@@ -101,7 +114,7 @@
[ "$cleanup" = "yes" ] && rm -rf "$tmpdir"
- $if_verbose printf '%s%d assertions succeeded, %d assertions failed\n' \
+ verbose_printf '%s%d assertions succeeded, %d failed\n' \
"$assert_fail_sep" "$assert_succeeded" "$assert_failed"
if [ "$assert_failed" != 0 ]; then
diff -r 690d00944fc9 -r ac235751e889 regress/subst/Makefile
--- a/regress/subst/Makefile Sat Mar 21 17:27:24 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-# $NetBSD: Makefile,v 1.6 2019/03/17 12:01:14 rillig Exp $
-#
-
-DISTNAME= subst-19.03
-CATEGORIES= regress
-DISTFILES= # none
-
-MAINTAINER= pkgsrc-users%NetBSD.org@localhost
-COMMENT= Test the SUBST framework
-LICENSE= 2-clause-bsd
-
-WRKSRC= ${WRKDIR}
-USE_TOOLS+= diff printf
-
-SUBST_CLASSES+= vars
-SUBST_STAGE.vars= do-build
-SUBST_FILES.vars= vars.after
-SUBST_VARS.vars= PLAIN DQUOT SQUOT DELIM PRINTABLE
-SUBST_VARS.vars+= UNDEFINED
-SUBST_VARS.vars+= BETWEEN_SPACE BETWEEN_TAB BETWEEN_NL
-SUBST_VARS.vars+= BACKSLASHES
-SUBST_VARS.vars+= VAR...... VAR.abcde VAR.<>
-
-PLAIN= hello_world
-DQUOT= "hello world"
-SQUOT= 'hello world'
-DELIM= hello, world
-PRINTABLE= !"\#$$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}
-
-#UNDEFINED= # undefined
-
-# Ensure that leading and trailing whitespace is preserved.
-BETWEEN_SPACE= ${:U }between spaces${:U }
-BETWEEN_TAB= ${:U }between tabs${:U }
-BETWEEN_NL= ${.newline}between newlines${.newline}
-
-BACKSLASHES= \" \, \\, \" \' \0\000 \x40 \089 \a \$$
-
-# Ensure that special regex characters may appear in variable names.
-VAR......= dots
-VAR.abcde= letters
-VAR.<>= angle brackets
-
-do-extract:
- ${RUN} ${SED} -e /^\#/d -e /^$$/d ${FILESDIR}/expected \
- > ${WRKSRC}/expected
-
-pre-build:
- ${RUN} printf '%s: <@%s@>\n' ${SUBST_VARS.vars:@var@ ${var:Q} ${var:Q} @} \
- > ${WRKSRC}/vars.before
- ${RUN} ${CAT} ${WRKSRC}/vars.before > ${WRKSRC}/vars.after
-
-do-build:
- @${DO_NADA}
-
-post-build:
- ${RUN} diff -u ${WRKSRC}/expected ${WRKSRC}/vars.after
-
-.include "../../mk/bsd.pkg.mk"
diff -r 690d00944fc9 -r ac235751e889 regress/subst/PLIST
Home |
Main Index |
Thread Index |
Old Index