summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2020-03-21 18:43:02 +0000
committerrillig <rillig@pkgsrc.org>2020-03-21 18:43:02 +0000
commit4415ae4c599a6e0e8cb21d14c199871863ddf65a (patch)
treee04aadd41a18d6ffb6422792105fc5f9665fab47 /regress
parent5ae47ecb234df88c3ff39a2eb72dc7e328ce7ba6 (diff)
downloadpkgsrc-4415ae4c599a6e0e8cb21d14c199871863ddf65a.tar.gz
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 (limited to 'regress')
-rw-r--r--regress/infra-unittests/subst.sh172
-rw-r--r--regress/infra-unittests/test.subr17
-rw-r--r--regress/subst/Makefile59
-rw-r--r--regress/subst/PLIST2
-rw-r--r--regress/subst/files/expected25
-rw-r--r--regress/subst/spec8
6 files changed, 186 insertions, 97 deletions
diff --git a/regress/infra-unittests/subst.sh b/regress/infra-unittests/subst.sh
index 053d3835d8b..4e5f4310837 100644
--- a/regress/infra-unittests/subst.sh
+++ b/regress/infra-unittests/subst.sh
@@ -644,7 +644,6 @@ SUBST_SHOW_DIFF= yes
.include "mk/subst.mk"
EOF
- LC_ALL=C \
test_file "testcase.mk" "pre-configure" \
1> "$tmpdir/stdout" \
2> "$tmpdir/stderr" \
@@ -668,3 +667,174 @@ EOF
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 --git a/regress/infra-unittests/test.subr b/regress/infra-unittests/test.subr
index 3f7f7da2cf8..2b1a0163a82 100644
--- a/regress/infra-unittests/test.subr
+++ b/regress/infra-unittests/test.subr
@@ -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 @@ done
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_tear_down() {
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 @@ test_subr_cleanup() {
[ "$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 --git a/regress/subst/Makefile b/regress/subst/Makefile
deleted file mode 100644
index 812e07f7d4f..00000000000
--- a/regress/subst/Makefile
+++ /dev/null
@@ -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
-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 --git a/regress/subst/PLIST b/regress/subst/PLIST
deleted file mode 100644
index 42c6c1d819c..00000000000
--- a/regress/subst/PLIST
+++ /dev/null
@@ -1,2 +0,0 @@
-@comment $NetBSD: PLIST,v 1.2 2019/03/17 11:28:13 rillig Exp $
-@comment unused
diff --git a/regress/subst/files/expected b/regress/subst/files/expected
deleted file mode 100644
index 6e11bde3895..00000000000
--- a/regress/subst/files/expected
+++ /dev/null
@@ -1,25 +0,0 @@
-# $NetBSD: expected,v 1.2 2019/03/17 12:01:14 rillig Exp $
-#
-# The expected output from the SUBST_VARS test.
-# Each substituted value is enclosed in <angle brackets> to clearly
-# show where it begins and ends.
-
-PLAIN: <hello_world>
-DQUOT: <"hello world">
-SQUOT: <'hello world'>
-DELIM: <hello, world>
-PRINTABLE: <!"#$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}>
-
-UNDEFINED: <>
-
-BETWEEN_SPACE: < between spaces >
-BETWEEN_TAB: < between tabs >
-BETWEEN_NL: <
-between newlines
->
-
-BACKSLASHES: <\" \, \\, \" \' \0\000 \x40 \089 \a \$>
-
-VAR......: <dots>
-VAR.abcde: <letters>
-VAR.<>: <angle brackets>
diff --git a/regress/subst/spec b/regress/subst/spec
deleted file mode 100644
index 85e1b88596c..00000000000
--- a/regress/subst/spec
+++ /dev/null
@@ -1,8 +0,0 @@
-# $NetBSD: spec,v 1.1 2019/03/17 10:19:36 rillig Exp $
-#
-
-MAKEARGS_CLEAN="clean"
-
-check_result() {
- exit_status 0
-}