regress/subst: demonstrate that SUBST_VARS doesn't pass newlines

Sure, it's an edge case and has not been necessary until now.
Nevertheless it's good to see how this can be done.

Variables having dots in their names are also not handled completely
correct. This also didn't occur in practice since the variable names
passed to SUBST_VARS are usually A-Za-z0-9_ only.
This commit is contained in:
rillig 2019-03-17 11:28:13 +00:00
parent 73a66af002
commit ecd80128b4
4 changed files with 61 additions and 13 deletions

View file

@ -1,30 +1,58 @@
# $NetBSD: Makefile,v 1.4 2019/03/17 10:19:36 rillig Exp $
# $NetBSD: Makefile,v 1.5 2019/03/17 11:28:13 rillig Exp $
#
DISTNAME= subst-1.0
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
USE_TOOLS+= diff printf
SUBST_CLASSES+= vars
SUBST_STAGE.vars= do-build
SUBST_FILES.vars= vars
SUBST_VARS.vars= PLAIN DQUOT SQUOT DELIM EVIL1
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 VAR...... VAR.abcde
.include "vars.mk"
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 }
# TODO: currently fails; needs to be fixed in subst.mk
#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
do-extract:
${RUN} ${SED} -e /^\#/d -e /^$$/d ${FILESDIR}/expected \
> ${WRKSRC}/expected
pre-build:
for v in ${SUBST_VARS.vars}; do echo "$$v=@$$v@"; done > ${WRKSRC}/vars
${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:
diff -u vars.mk ${WRKSRC}/vars
${RUN} diff -u ${WRKSRC}/expected ${WRKSRC}/vars.after
.include "../../mk/bsd.pkg.mk"

View file

@ -0,0 +1,2 @@
@comment $NetBSD: PLIST,v 1.2 2019/03/17 11:28:13 rillig Exp $
@comment unused

View file

@ -0,0 +1,23 @@
# $NetBSD: expected,v 1.1 2019/03/17 11:28:13 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: <>
BACKSLASHES: <\" \, \\, \" \' \0\000 \x40 \089 \a \$>
VAR......: <dots>
# FIXME: must be <letters> instead of <dots>
VAR.abcde: <dots>

View file

@ -1,5 +0,0 @@
PLAIN=hello_world
DQUOT="hello world"
SQUOT='hello world'
DELIM=hello, world
EVIL1=h\ello \0\0\0 \\\"\' foo && bar