Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make/unit-tests usr.bin/make: add tests for surprisi...
details: https://anonhg.NetBSD.org/src/rev/8263f81defd8
branches: trunk
changeset: 971947:8263f81defd8
user: rillig <rillig%NetBSD.org@localhost>
date: Sun May 10 12:34:01 2020 +0000
description:
usr.bin/make: add tests for surprising dollar removal
diffstat:
distrib/sets/lists/tests/mi | 4 +-
usr.bin/make/unit-tests/Makefile | 3 +-
usr.bin/make/unit-tests/dollar.exp | 50 ++++++++++++++++++++++++++
usr.bin/make/unit-tests/dollar.mk | 72 ++++++++++++++++++++++++++++++++++++++
4 files changed, 127 insertions(+), 2 deletions(-)
diffs (165 lines):
diff -r aee543ed8ec8 -r 8263f81defd8 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Sun May 10 11:06:14 2020 +0000
+++ b/distrib/sets/lists/tests/mi Sun May 10 12:34:01 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.839 2020/04/30 11:03:29 ryo Exp $
+# $NetBSD: mi,v 1.840 2020/05/10 12:34:01 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4469,6 +4469,8 @@
./usr/tests/usr.bin/make/unit-tests/cond1.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond2.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond2.mk tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/dollar.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/dollar.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/doterror.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/doterror.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/dotwait.exp tests-usr.bin-tests compattestfile,atf
diff -r aee543ed8ec8 -r 8263f81defd8 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile Sun May 10 11:06:14 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile Sun May 10 12:34:01 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.55 2020/04/29 23:15:21 rillig Exp $
+# $NetBSD: Makefile,v 1.56 2020/05/10 12:34:01 rillig Exp $
#
# Unit tests for make(1)
# The main targets are:
@@ -25,6 +25,7 @@
cond-late \
cond1 \
cond2 \
+ dollar \
error \
export \
export-all \
diff -r aee543ed8ec8 -r 8263f81defd8 usr.bin/make/unit-tests/dollar.exp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/dollar.exp Sun May 10 12:34:01 2020 +0000
@@ -0,0 +1,50 @@
+
+Printing dollar from literals and variables
+
+To survive the parser, a dollar character must be doubled.
+ 1 dollar literal => <\>
+ 2 dollar literal => <$>
+ 4 dollar literal => <$$>
+Some hungry part of make eats all the dollars after a :U modifier.
+ 1 dollar default => <>
+ 2 dollar default => <>
+ 4 dollar default => <>
+This works as expected.
+ 1 dollar variable => <>
+ 2 dollar variable => <$>
+ 4 dollar variable => <$$>
+Some hungry part of make eats all the dollars after a :U modifier.
+ 1 dollar var-default => <>
+ 2 dollar var-default => <>
+ 4 dollar var-default => <>
+
+Dollar in :S pattern
+
+ S,$,word, => <$XYword>
+ S,$X,word, => <$XY>
+ S,$$X,word, => <$XY>
+ S,$$$X,word, => <$XY>
+ S,$X,replaced, => <replaced>
+ S,$$X,replaced, => <replaced>
+ S,$$$X,replaced, => <replaced>
+
+Dollar in :C character class
+
+The A is replaced because the $$ is reduced to a single $,
+which is then resolved to the variable X with the value VAR_X.
+The effective character class becomes [VAR_XY].
+ C,[$XY],<&>,g => <$<A><X><Y>>
+
+Dollar in :C pattern
+
+For some reason, multiple dollars are folded into one.
+ C,$,word, => <>
+ C,$$,word, => <>
+
+Dollar in :S replacement
+
+For some reason, multiple dollars are folded into one.
+ S,word,a$Xo, => <aVAR_Xo>
+ S,word,a$$Xo, => <aVAR_Xo>
+ S,word,a$$$Xo, => <aVAR_Xo>
+exit status 0
diff -r aee543ed8ec8 -r 8263f81defd8 usr.bin/make/unit-tests/dollar.mk
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/dollar.mk Sun May 10 12:34:01 2020 +0000
@@ -0,0 +1,72 @@
+# $NetBSD: dollar.mk,v 1.1 2020/05/10 12:34:01 rillig Exp $
+#
+# Test the various places where a dollar character can appear and
+# see what happens. There are lots of surprises here.
+#
+
+LIST= plain 'single' "double" 'mix'"ed" back\ slashed
+WORD= word
+
+DOLLAR1= $
+DOLLAR2= $$
+DOLLAR4= $$$$
+
+X= VAR_X
+DOLLAR_XY= $$XY
+DOLLAR_AXY= $$AXY
+
+H= @header() { printf '\n%s\n\n' "$$*"; }; header
+T= @testcase() { printf '%23s => <%s>\n' "$$@"; }; testcase
+C= @comment() { printf '%s\n' "$$*"; }; comment
+
+all:
+ $H 'Printing dollar from literals and variables'
+
+ $C 'To survive the parser, a dollar character must be doubled.'
+ $T '1 dollar literal' ''\$
+ $T '2 dollar literal' ''\$$
+ $T '4 dollar literal' ''\$$\$$
+
+ $C 'Some hungry part of make eats all the dollars after a :U modifier.'
+ $T '1 dollar default' ''${:U$:Q}
+ $T '2 dollar default' ''${:U$$:Q}
+ $T '4 dollar default' ''${:U$$$$:Q}
+
+ $C 'This works as expected.'
+ $T '1 dollar variable' ''${DOLLAR1:Q}
+ $T '2 dollar variable' ''${DOLLAR2:Q}
+ $T '4 dollar variable' ''${DOLLAR4:Q}
+
+ $C 'Some hungry part of make eats all the dollars after a :U modifier.'
+ $T '1 dollar var-default' ''${U:${DOLLAR1}:Q}
+ $T '2 dollar var-default' ''${U:${DOLLAR2}:Q}
+ $T '4 dollar var-default' ''${U:${DOLLAR4}:Q}
+
+ $H 'Dollar in :S pattern'
+
+ $T 'S,$$,word,' ''${DOLLAR_XY:S,$,word,:Q}
+ $T 'S,$$X,word,' ''${DOLLAR_XY:S,$X,word,:Q}
+ $T 'S,$$$$X,word,' ''${DOLLAR_XY:S,$$X,word,:Q}
+ $T 'S,$$$$$$X,word,' ''${DOLLAR_XY:S,$$$X,word,:Q}
+
+ $T 'S,$$X,replaced,' ''${X:S,$X,replaced,:Q}
+ $T 'S,$$$$X,replaced,' ''${X:S,$$X,replaced,:Q}
+ $T 'S,$$$$$$X,replaced,' ''${X:S,$$$X,replaced,:Q}
+
+ $H 'Dollar in :C character class'
+
+ $C 'The A is replaced because the $$$$ is reduced to a single $$,'
+ $C 'which is then resolved to the variable X with the value VAR_X.'
+ $C 'The effective character class becomes [VAR_XY].'
+ $T 'C,[$$XY],<&>,g' ''${DOLLAR_AXY:C,[$$XY],<&>,g:Q}
+
+ $H 'Dollar in :C pattern'
+ $C 'For some reason, multiple dollars are folded into one.'
+ $T 'C,$$,word,' ''${DOLLAR:C,$,dollar,g:Q}
+ $T 'C,$$$$,word,' ''${DOLLAR:C,$$,dollar,g:Q}
+
+ $H 'Dollar in :S replacement'
+ $C 'For some reason, multiple dollars are folded into one.'
+ $T 'S,word,a$$Xo,' ''${WORD:S,word,a$Xo,:Q}
+ $T 'S,word,a$$$$Xo,' ''${WORD:S,word,a$$Xo,:Q}
+ $T 'S,word,a$$$$$$Xo,' ''${WORD:S,word,a$$$Xo,:Q}
Home |
Main Index |
Thread Index |
Old Index