Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add tests for backslash escaping in make(1).



details:   https://anonhg.NetBSD.org/src/rev/de7edfd326da
branches:  trunk
changeset: 331782:de7edfd326da
user:      apb <apb%NetBSD.org@localhost>
date:      Sun Aug 24 11:52:45 2014 +0000

description:
Add tests for backslash escaping in make(1).

Many of these tests fail, and I have populated the escape.exp file with
the results that I expect, not with the results that make(1) actually
produces.

Also update the set lists for these tests.

diffstat:

 distrib/sets/lists/tests/mi        |    4 +-
 usr.bin/make/unit-tests/Makefile   |    3 +-
 usr.bin/make/unit-tests/escape.exp |   72 +++++++++++
 usr.bin/make/unit-tests/escape.mk  |  242 +++++++++++++++++++++++++++++++++++++
 4 files changed, 319 insertions(+), 2 deletions(-)

diffs (truncated from 357 to 300 lines):

diff -r abb91fe14cae -r de7edfd326da distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Aug 24 11:50:00 2014 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Aug 24 11:52:45 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.588 2014/08/24 11:50:00 apb Exp $
+# $NetBSD: mi,v 1.589 2014/08/24 11:52:45 apb Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3508,6 +3508,8 @@
 ./usr/tests/usr.bin/make/unit-tests/dotwait.mk tests-usr.bin-tests     atf
 ./usr/tests/usr.bin/make/unit-tests/error.exp  tests-usr.bin-tests     atf
 ./usr/tests/usr.bin/make/unit-tests/error.mk   tests-usr.bin-tests     atf
+./usr/tests/usr.bin/make/unit-tests/escape.exp tests-usr.bin-tests     atf
+./usr/tests/usr.bin/make/unit-tests/escape.mk  tests-usr.bin-tests     atf
 ./usr/tests/usr.bin/make/unit-tests/export-all.exp     tests-usr.bin-tests     atf
 ./usr/tests/usr.bin/make/unit-tests/export-all.mk      tests-usr.bin-tests     atf
 ./usr/tests/usr.bin/make/unit-tests/export-env.exp     tests-usr.bin-tests     atf
diff -r abb91fe14cae -r de7edfd326da usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sun Aug 24 11:50:00 2014 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sun Aug 24 11:52:45 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.46 2014/08/23 15:21:35 christos Exp $
+# $NetBSD: Makefile,v 1.47 2014/08/24 11:52:45 apb Exp $
 #
 # Unit tests for make(1)
 # The main targets are:
@@ -24,6 +24,7 @@
        comment \
        cond1 \
        error \
+       escape \
        export \
        export-all \
        export-env \
diff -r abb91fe14cae -r de7edfd326da usr.bin/make/unit-tests/escape.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/escape.exp        Sun Aug 24 11:52:45 2014 +0000
@@ -0,0 +1,72 @@
+var-1bs
+VAR1BS=:111\111:
+VAR1BSa=:111\aaa:
+VAR1BSA=:111\aaa:
+VAR1BSda=:111\${a}:
+VAR1BSdA=:111\${A}:
+var-2bs
+VAR2BS=:222\\222:
+VAR2BSa=:222\\aaa:
+VAR2BSA=:222\\aaa:
+VAR2BSda=:222\\${a}:
+VAR2BSdA=:222\\${A}:
+var-1bsnl
+VAR1BSNL=:111 111:
+VAR1BSNLa=:111 aaa:
+VAR1BSNLA=:111 aaa:
+VAR1BSNLda=:111 ${a}:
+VAR1BSNLdA=:111 ${A}:
+VAR1BSNLc=:111 # this should not be a comment, it should be part of the value:
+var-2bsnl
+VAR2BSNL=:222\ #222:
+VAR2BSNLa=:222\ #aaa:
+VAR2BSNLA=:222\ #aaa:
+VAR2BSNLda=:222\ #${a}:
+VAR2BSNLdA=:222\ #${A}:
+VAR2BSNLc=:222\ # this should not be a comment, it should be part of the value:
+var-3bsnl
+VAR3BSNL=:333\\ #333:
+VAR3BSNLa=:333\\ #aaa:
+VAR3BSNLA=:333\\ #aaa:
+VAR3BSNLda=:333\\ #${a}:
+VAR3BSNLdA=:333\\ #${A}:
+VAR3BSNLc=:333\ # this should not be a comment, it should be part of the value:
+var-1bsnl-space
+VAR1BSNL00=:first line:
+VAR1BSNL0=:first line no space on second line:
+VAR1BSNLs=:first line one space on second line:
+VAR1BSNLss=:first line two spaces on second line:
+VAR1BSNLt=:first line one tab on second line:
+VAR1BSNLtt=:first line two tabs on second line:
+VAR1BSNLxx=:first line many spaces and tabs [           ] on second line:
+cmd-1bsnl
+:first line\
+#second line without space\
+third line:
+:first line\
+     second line spaces should be retained:
+:first line\
+second line tab should be elided:
+:first line\
+       only one tab should be elided, second tab remains
+cmd-2bsnl
+:first line\\
+#second line without space\\
+third line:
+:first line\\
+     second line spaces should be retained:
+:first line\\
+second line tab should be elided:
+:first line\\
+       only one tab should be elided, second tab remains
+cmd-3bsnl
+:first line\\\
+#second line without space\\\
+third line:
+:first line\\\
+     second line spaces should be retained:
+:first line\\\
+second line tab should be elided:
+:first line\\\
+       only one tab should be elided, second tab remains
+exit status 0
diff -r abb91fe14cae -r de7edfd326da usr.bin/make/unit-tests/escape.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/escape.mk Sun Aug 24 11:52:45 2014 +0000
@@ -0,0 +1,242 @@
+# $Id: escape.mk,v 1.1 2014/08/24 11:52:45 apb Exp $
+#
+# Test backslash escaping.
+
+# Extracts from the POSIX 2008 specification
+# <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html>:
+#
+#     Comments start with a <number-sign> ( '#' ) and continue until an
+#     unescaped <newline> is reached.
+#
+#     When an escaped <newline> (one preceded by a <backslash>) is found
+#     anywhere in the makefile except in a command line, an include
+#     line, or a line immediately preceding an include line, it shall
+#     be replaced, along with any leading white space on the following
+#     line, with a single <space>.
+#
+#     When an escaped <newline> is found in a command line in a
+#     makefile, the command line shall contain the <backslash>, the
+#     <newline>, and the next line, except that the first character of
+#     the next line shall not be included if it is a <tab>.
+#
+#     When an escaped <newline> is found in an include line or in a
+#     line immediately preceding an include line, the behavior is
+#     unspecified.
+#
+# Notice that the behaviour of <backslash><backslash> or
+# <backslash><anything other then newline> is not mentioned.  I think
+# this implies that <backslash> should be taken literally everywhere
+# except before <newline>.
+
+all: .PHONY
+# We will add dependencies like "all: yet-another-test" later.
+
+# Some variables to be expanded in tests
+#
+a = aaa
+A = ${a}
+
+# Backslash at end of line in a comment\
+should continue the comment. \
+# This is also tested in comment.mk.
+
+# Embedded backslash in variable should be taken literally.
+#
+VAR1BS = 111\111
+VAR1BSa = 111\${a}
+VAR1BSA = 111\${A}
+VAR1BSda = 111\$${a}
+VAR1BSdA = 111\$${A}
+
+all: var-1bs
+var-1bs:       .PHONY
+       @echo ${.TARGET}
+       @echo VAR1BS=:${VAR1BS:Q}:
+       @echo VAR1BSa=:${VAR1BSa:Q}:
+       @echo VAR1BSA=:${VAR1BSA:Q}:
+       @echo VAR1BSda=:${VAR1BSa:Q}:
+       @echo VAR1BSdA=:${VAR1BSA:Q}:
+
+# Double backslash in variable should be taken as two literal backslashes.
+#
+VAR2BS = 222\\222
+VAR2BSa = 222\\${a}
+VAR2BSA = 222\\${A}
+VAR2BSda = 222\\$${a}
+VAR2BSdA = 222\\$${A}
+
+all: var-2bs
+var-2bs:       .PHONY
+       @echo ${.TARGET}
+       @echo VAR2BS=:${VAR2BS:Q}:
+       @echo VAR2BSa=:${VAR2BSa:Q}:
+       @echo VAR2BSA=:${VAR2BSA:Q}:
+       @echo VAR2BSda=:${VAR2BSa:Q}:
+       @echo VAR2BSdA=:${VAR2BSA:Q}:
+
+# Backslash-newline in a variable setting is replaced by a single space.
+#
+VAR1BSNL = 111\
+111
+VAR1BSNLa = 111\
+${a}
+VAR1BSNLA = 111\
+${A}
+VAR1BSNLda = 111\
+$${a}
+VAR1BSNLdA = 111\
+$${A}
+VAR1BSNLc = 111\
+# this should not be a comment, it should be part of the value
+
+all: var-1bsnl
+var-1bsnl:     .PHONY
+       @echo ${.TARGET}
+       @echo VAR1BSNL=:${VAR1BSNL:Q}:
+       @echo VAR1BSNLa=:${VAR1BSNLa:Q}:
+       @echo VAR1BSNLA=:${VAR1BSNLA:Q}:
+       @echo VAR1BSNLda=:${VAR1BSNLa:Q}:
+       @echo VAR1BSNLdA=:${VAR1BSNLA:Q}:
+       @echo VAR1BSNLc=:${VAR1BSNLc:Q}:
+
+# Double-backslash-newline in a variable setting.
+# First one should be taken literally, and last should escape the newline.
+# XXX: Is the expected behaviour well defined?
+#
+# The second lines below start with '#' so they should not generate
+# syntax errors regardless of whether or not they are treated as
+# part of the value.
+#
+VAR2BSNL = 222\\
+#222
+VAR2BSNLa = 222\\
+#${a}
+VAR2BSNLA = 222\\
+#${A}
+VAR2BSNLda = 222\\
+#$${a}
+VAR2BSNLdA = 222\\
+#$${A}
+VAR2BSNLc = 222\\
+# this should not be a comment, it should be part of the value
+
+all: var-2bsnl
+var-2bsnl:     .PHONY
+       @echo ${.TARGET}
+       @echo VAR2BSNL=:${VAR2BSNL:Q}:
+       @echo VAR2BSNLa=:${VAR2BSNLa:Q}:
+       @echo VAR2BSNLA=:${VAR2BSNLA:Q}:
+       @echo VAR2BSNLda=:${VAR2BSNLa:Q}:
+       @echo VAR2BSNLdA=:${VAR2BSNLA:Q}:
+       @echo VAR2BSNLc=:${VAR2BSNLc:Q}:
+
+# Triple-backslash-newline in a variable setting.
+# First two should be taken literally, and last should escape the newline.
+# XXX: Is the expected behaviour well defined?
+#
+# The second lines below start with '#' so they should not generate
+# syntax errors regardless of whether or not they ar treated as
+# part of the value.
+#
+VAR3BSNL = 333\\\
+#333
+VAR3BSNLa = 333\\\
+#${a}
+VAR3BSNLA = 333\\\
+#${A}
+VAR3BSNLda = 333\\\
+#$${a}
+VAR3BSNLdA = 333\\\
+#$${A}
+VAR3BSNLc = 333\\\
+# this should not be a comment, it should be part of the value
+
+all: var-3bsnl
+var-3bsnl:     .PHONY
+       @echo ${.TARGET}
+       @echo VAR3BSNL=:${VAR3BSNL:Q}:
+       @echo VAR3BSNLa=:${VAR3BSNLa:Q}:
+       @echo VAR3BSNLA=:${VAR3BSNLA:Q}:
+       @echo VAR3BSNLda=:${VAR3BSNLa:Q}:
+       @echo VAR3BSNLdA=:${VAR3BSNLA:Q}:
+       @echo VAR3BSNLc=:${VAR3BSNLc:Q}:
+
+# Backslash-newline in a variable setting, plus any amount of white space
+# on the next line, is replaced by a single space.
+#
+VAR1BSNL00= first line\
+
+# above line is entirely empty, and this is a comment
+VAR1BSNL0= first line\
+no space on second line
+VAR1BSNLs= first line\
+ one space on second line
+VAR1BSNLss= first line\
+  two spaces on second line
+VAR1BSNLt= first line\
+       one tab on second line
+VAR1BSNLtt= first line\
+               two tabs on second line
+VAR1BSNLxx= first line\
+                        many spaces and tabs [          ] on second line
+
+all: var-1bsnl-space
+var-1bsnl-space:       .PHONY
+       @echo ${.TARGET}



Home | Main Index | Thread Index | Old Index