Sun Jul 26 13:09:53 2020 UTC ()
make(1): add basic tests for the :S modifier


(rillig)
diff -r1.25 -r1.26 src/usr.bin/make/unit-tests/modmisc.mk

cvs diff -r1.25 -r1.26 src/usr.bin/make/unit-tests/modmisc.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/modmisc.mk 2020/07/26 12:19:37 1.25
+++ src/usr.bin/make/unit-tests/modmisc.mk 2020/07/26 13:09:53 1.26
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $Id: modmisc.mk,v 1.25 2020/07/26 12:19:37 rillig Exp $ 1# $Id: modmisc.mk,v 1.26 2020/07/26 13:09:53 rillig Exp $
2# 2#
3# miscellaneous modifier tests 3# miscellaneous modifier tests
4 4
5# do not put any dirs in this list which exist on some 5# do not put any dirs in this list which exist on some
6# but not all target systems - an exists() check is below. 6# but not all target systems - an exists() check is below.
7path=:/bin:/tmp::/:.:/no/such/dir:. 7path=:/bin:/tmp::/:.:/no/such/dir:.
8# strip cwd from path. 8# strip cwd from path.
9MOD_NODOT=S/:/ /g:N.:ts: 9MOD_NODOT=S/:/ /g:N.:ts:
10# and decorate, note that $'s need to be doubled. Also note that  10# and decorate, note that $'s need to be doubled. Also note that
11# the modifier_variable can be used with other modifiers. 11# the modifier_variable can be used with other modifiers.
12MOD_NODOTX=S/:/ /g:N.:@d@'$$d'@ 12MOD_NODOTX=S/:/ /g:N.:@d@'$$d'@
13# another mod - pretend it is more interesting 13# another mod - pretend it is more interesting
14MOD_HOMES=S,/home/,/homes/, 14MOD_HOMES=S,/home/,/homes/,
@@ -63,43 +63,73 @@ emptyvar: @@ -63,43 +63,73 @@ emptyvar:
63 @echo C:${:C,^$,empty,} 63 @echo C:${:C,^$,empty,}
64 @echo @:${:@var@${var}@} 64 @echo @:${:@var@${var}@}
65 65
66# The :U modifier turns even the "" variable into something that has a value. 66# The :U modifier turns even the "" variable into something that has a value.
67# The resulting variable is empty, but is still considered to contain a 67# The resulting variable is empty, but is still considered to contain a
68# single empty word. This word can be accessed by the :S and :C modifiers, 68# single empty word. This word can be accessed by the :S and :C modifiers,
69# but not by the :@ modifier since it explicitly skips empty words. 69# but not by the :@ modifier since it explicitly skips empty words.
70undefvar: 70undefvar:
71 @echo S:${:U:S,^$,empty,} 71 @echo S:${:U:S,^$,empty,}
72 @echo C:${:U:C,^$,empty,} 72 @echo C:${:U:C,^$,empty,}
73 @echo @:${:U:@var@empty@} 73 @echo @:${:U:@var@empty@}
74 74
75WORDS= sequences of letters 75WORDS= sequences of letters
 76.if ${WORDS:S,,,} != ${WORDS}
 77.warning The empty pattern matches something.
 78.endif
76.if ${WORDS:S,e,*,1} != "s*quences of letters" 79.if ${WORDS:S,e,*,1} != "s*quences of letters"
77.warning ${WORDS:S,e,*,1} 80.warning The :S modifier flag '1' is not applied exactly once.
78.endif 81.endif
79.if ${WORDS:S,e,*,} != "s*quences of l*tters" 82.if ${WORDS:S,e,*,} != "s*quences of l*tters"
80.error oops 83.warning The :S modifier does not replace every first match per word.
81.endif 84.endif
82.if ${WORDS:S,e,*,g} != "s*qu*nc*s of l*tt*rs" 85.if ${WORDS:S,e,*,g} != "s*qu*nc*s of l*tt*rs"
83.error oops 86.warning The :S modifier flag 'g' does not replace every occurrence.
84.endif 87.endif
85.if ${WORDS:S,^sequ,occurr,} != "occurrences of letters" 88.if ${WORDS:S,^sequ,occurr,} != "occurrences of letters"
86.error oops 89.warning The :S modifier fails for a short match anchored at the start.
87.endif 90.endif
88.if ${WORDS:S,^of,with,} != "sequences with letters" 91.if ${WORDS:S,^of,with,} != "sequences with letters"
89.error oops 92.warning The :S modifier fails for an exact match anchored at the start.
90.endif 93.endif
91.if ${WORDS:S,^office,does not match,} != ${WORDS} 94.if ${WORDS:S,^office,does not match,} != ${WORDS}
92.error oops 95.warning The :S modifier matches a too long pattern anchored at the start.
 96.endif
 97.if ${WORDS:S,f$,r,} != "sequences or letters"
 98.warning The :S modifier fails for a short match anchored at the end.
 99.endif
 100.if ${WORDS:S,s$,,} != "sequence of letter"
 101.warning The :S modifier fails to replace one occurrence per word.
 102.endif
 103.if ${WORDS:S,of$,,} != "sequences letters"
 104.warning The :S modifier fails for an exact match anchored at the end.
 105.endif
 106.if ${WORDS:S,eof$,,} != ${WORDS}
 107.warning The :S modifier matches a too long pattern anchored at the end.
 108.endif
 109.if ${WORDS:S,^of$,,} != "sequences letters"
 110.warning The :S modifier does not match a word anchored at both ends.
 111.endif
 112.if ${WORDS:S,^o$,,} != ${WORDS}
 113.warning The :S modifier matches a prefix anchored at both ends.
 114.endif
 115.if ${WORDS:S,^f$,,} != ${WORDS}
 116.warning The :S modifier matches a suffix anchored at both ends.
 117.endif
 118.if ${WORDS:S,^eof$,,} != ${WORDS}
 119.warning The :S modifier matches a too long prefix anchored at both ends.
 120.endif
 121.if ${WORDS:S,^office$,,} != ${WORDS}
 122.warning The :S modifier matches a too long suffix anchored at both ends.
93.endif 123.endif
94 124
95mod-subst: 125mod-subst:
96 @echo $@: 126 @echo $@:
97 @echo :${:Ua b b c:S,a b,,:Q}: 127 @echo :${:Ua b b c:S,a b,,:Q}:
98 @echo :${:Ua b b c:S,a b,,1:Q}: 128 @echo :${:Ua b b c:S,a b,,1:Q}:
99 @echo :${:Ua b b c:S,a b,,W:Q}: 129 @echo :${:Ua b b c:S,a b,,W:Q}:
100 @echo :${:Ua b b c:S,b,,g:Q}: 130 @echo :${:Ua b b c:S,b,,g:Q}:
101 @echo :${:U1 2 3 1 2 3:S,1 2,___,Wg:S,_,x,:Q}: 131 @echo :${:U1 2 3 1 2 3:S,1 2,___,Wg:S,_,x,:Q}:
102 @echo ${:U12345:S,,sep,g:Q} 132 @echo ${:U12345:S,,sep,g:Q}
103 133
104mod-regex: 134mod-regex:
105 @echo $@: 135 @echo $@: