Tue Nov 3 18:42:33 2020 UTC ()
make(1): clean up unit tests


(rillig)
diff -r1.7 -r1.8 src/usr.bin/make/unit-tests/dir.mk
diff -r1.7 -r1.8 src/usr.bin/make/unit-tests/modts.mk
diff -r1.49 -r1.50 src/usr.bin/make/unit-tests/modmisc.mk
diff -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-exclam-shell.mk

cvs diff -r1.7 -r1.8 src/usr.bin/make/unit-tests/dir.mk (switch to unified diff)

--- src/usr.bin/make/unit-tests/dir.mk 2020/10/31 21:30:03 1.7
+++ src/usr.bin/make/unit-tests/dir.mk 2020/11/03 18:42:33 1.8
@@ -1,93 +1,94 @@ @@ -1,93 +1,94 @@
1# $NetBSD: dir.mk,v 1.7 2020/10/31 21:30:03 rillig Exp $ 1# $NetBSD: dir.mk,v 1.8 2020/11/03 18:42:33 rillig Exp $
2# 2#
3# Tests for dir.c. 3# Tests for dir.c.
4 4
5.MAKEFLAGS: -m / # hide /usr/share/mk from the debug log 5.MAKEFLAGS: -m / # hide /usr/share/mk from the debug log
6 6
7# Dependency lines may use braces for expansion. 7# Dependency lines may use braces for expansion.
8# See DirExpandCurly for the implementation. 8# See DirExpandCurly for the implementation.
9all: {one,two,three} 9all: {one,two,three}
10 10
11# XXX: The above dependency line is parsed as a single node named 11# XXX: The above dependency line is parsed as a single node named
12# "{one,two,three}". There are no individual targets "one", "two", "three" 12# "{one,two,three}". There are no individual targets "one", "two", "three"
13# yet. The node exists but is not a target since it never appeared 13# yet. The node exists but is not a target since it never appeared
14# on the left-hand side of a dependency operator. However, it is listed 14# on the left-hand side of a dependency operator. However, it is listed
15# in .ALLTARGETS (which lists all nodes, not only targets). 15# in .ALLTARGETS (which lists all nodes, not only targets).
16.if target(one) 16.if target(one)
17. error 17. error
18.endif 18.endif
19.if target({one,two,three}) 19.if target({one,two,three})
20. error 20. error
21.endif 21.endif
22.if ${.ALLTARGETS:M{one,two,three}} != "{one,two,three}" 22.if ${.ALLTARGETS:M{one,two,three}} != "{one,two,three}"
23. error 23. error
24.endif 24.endif
25 25
26one: 26one:
27 : 1 27 : 1
28two: 28two:
29 : 2 29 : 2
30three: 30three:
31 : 3 31 : 3
32 32
33# The braces may start in the middle of a word. 33# The braces may start in the middle of a word.
34all: f{our,ive} 34all: f{our,ive}
35 35
36four: 36four:
37 : 4 37 : 4
38five: 38five:
39 : 5 39 : 5
40six: 40six:
41 : 6 41 : 6
42 42
43# Nested braces work as expected since 2020-07-31 19:06 UTC. 43# Nested braces work as expected since 2020-07-31 19:06 UTC.
44# They had been broken at least since 2003-01-01, probably even longer. 44# They had been broken at least since 2003-01-01, probably even longer.
45all: {{thi,fou}r,fif}teen 45all: {{thi,fou}r,fif}teen
46 46
47thirteen: 47thirteen:
48 : 13 48 : 13
49fourteen: 49fourteen:
50 : 14 50 : 14
51fifteen: 51fifteen:
52 : 15 52 : 15
53 53
54# There may be multiple brace groups side by side. 54# There may be multiple brace groups side by side.
55all: {pre-,}{patch,configure} 55all: {pre-,}{patch,configure}
56 56
57pre-patch patch pre-configure configure: 57pre-patch patch pre-configure configure:
58 : $@ 58 : $@
59 59
60# Empty pieces are allowed in the braces. 60# Empty pieces are allowed in the braces.
61all: {fetch,extract}{,-post} 61all: {fetch,extract}{,-post}
62 62
63fetch fetch-post extract extract-post: 63fetch fetch-post extract extract-post:
64 : $@ 64 : $@
65 65
66# The expansions may have duplicates. 66# The expansions may have duplicates.
67# These are merged together because of the dependency line. 67# When the source of the dependency line is expanded later, each of the
 68# expanded words will be the same.
68all: dup-{1,1,1,1,1,1,1} 69all: dup-{1,1,1,1,1,1,1}
69 70
70dup-1: 71dup-1:
71 : $@ 72 : $@
72 73
73# Other than in Bash, the braces are also expanded if there is no comma. 74# Other than in Bash, the braces are also expanded if there is no comma.
74all: {{{{{{{{{{single-word}}}}}}}}}} 75all: {{{{{{{{{{single-word}}}}}}}}}}
75 76
76single-word: 77single-word:
77 : $@ 78 : $@
78 79
79# Demonstrate debug logging for filename expansion, especially curly braces. 80# Demonstrate debug logging for filename expansion, especially curly braces.
80.MAKEFLAGS: -dd 81.MAKEFLAGS: -dd
81# The below line does not call Dir_Expand yet. 82# The below line does not call Dir_Expand yet.
82# It is expanded only when necessary, that is, when the 'debug' target is 83# It is expanded only when necessary, that is, when the 'debug' target is
83# indeed made. 84# indeed made.
84debug: {{thi,fou}r,fif}twen 85debug: {{thi,fou}r,fif}twen
85# Therefore, keep the debug logging active. 86# Therefore, keep the debug logging active.
86 87
87.PHONY: one two three four five six 88.PHONY: one two three four five six
88.PHONY: thirteen fourteen fifteen 89.PHONY: thirteen fourteen fifteen
89.PHONY: single-word 90.PHONY: single-word
90.PHONY: pre-patch patch pre-configure configure 91.PHONY: pre-patch patch pre-configure configure
91.PHONY: fetch fetch-post extract extract-post 92.PHONY: fetch fetch-post extract extract-post
92.PHONY: dup-1 single-word 93.PHONY: dup-1 single-word
93.PHONY: all 94.PHONY: all

cvs diff -r1.7 -r1.8 src/usr.bin/make/unit-tests/Attic/modts.mk (switch to unified diff)

--- src/usr.bin/make/unit-tests/Attic/modts.mk 2020/10/24 08:50:17 1.7
+++ src/usr.bin/make/unit-tests/Attic/modts.mk 2020/11/03 18:42:33 1.8
@@ -1,48 +1,47 @@ @@ -1,48 +1,47 @@
1# $NetBSD: modts.mk,v 1.7 2020/10/24 08:50:17 rillig Exp $ 1# $NetBSD: modts.mk,v 1.8 2020/11/03 18:42:33 rillig Exp $
2 2
3LIST= one two three 3LIST= one two three four five six
4LIST+= four five six 
5 4
6FU_mod-ts= a / b / cool 5FU_mod-ts= a / b / cool
7 6
8AAA= a a a 7AAA= a a a
9B.aaa= Baaa 8B.aaa= Baaa
10 9
11all: mod-ts mod-ts-space 10all: mod-ts mod-ts-space
12 11
13# Use print or printf iff they are builtin. 12# Use print or printf iff they are builtin.
14# XXX note that this causes problems, when make decides 13# XXX note that this causes problems, when make decides
15# there is no need to use a shell, so avoid where possible. 14# there is no need to use a shell, so avoid where possible.
16.if ${type print 2> /dev/null || echo:L:sh:Mbuiltin} != "" 15.if ${type print 2> /dev/null || echo:L:sh:Mbuiltin} != ""
17PRINT= print -r -- 16PRINT= print -r --
18.elif ${type printf 2> /dev/null || echo:L:sh:Mbuiltin} != "" 17.elif ${type printf 2> /dev/null || echo:L:sh:Mbuiltin} != ""
19PRINT= printf '%s\n' 18PRINT= printf '%s\n'
20.else 19.else
21PRINT= echo 20PRINT= echo
22.endif 21.endif
23 22
24mod-ts: 23mod-ts:
25 @${PRINT} 'LIST:tx="${LIST:tx}"' 24 @${PRINT} 'LIST:tx="${LIST:tx}"'
26 @${PRINT} 'LIST:ts/x:tu="${LIST:ts\X:tu}"' 25 @${PRINT} 'LIST:ts/x:tu="${LIST:ts\X:tu}"'
27 @${PRINT} 'FU_$@="${FU_${@:ts}:ts}"' 26 @${PRINT} 'FU_$@="${FU_${@:ts}:ts}"'
28 @${PRINT} 'FU_$@:ts:T="${FU_${@:ts}:ts:T}" == cool?' 27 @${PRINT} 'FU_$@:ts:T="${FU_${@:ts}:ts:T}" == cool?'
29 @${PRINT} 'B.$${AAA:ts}="${B.${AAA:ts}}" == Baaa?' 28 @${PRINT} 'B.$${AAA:ts}="${B.${AAA:ts}}" == Baaa?'
30 29
31mod-ts-space: 30mod-ts-space:
32 # After the :ts modifier, the whole string is interpreted as a single 31 # After the :ts modifier, the whole string is interpreted as a single
33 # word since all spaces have been replaced with x. 32 # word since all spaces have been replaced with x.
34 @${PRINT} ':ts :S => '${aa bb aa bb aa bb:L:tsx:S,b,B,:Q} 33 @${PRINT} ':ts :S => '${aa bb aa bb aa bb:L:tsx:S,b,B,:Q}
35 34
36 # The :ts modifier also applies to word separators that are added 35 # The :ts modifier also applies to word separators that are added
37 # afterwards. 36 # afterwards.
38 @${PRINT} ':ts :S space => '${a ababa c:L:tsx:S,b, ,g:Q} 37 @${PRINT} ':ts :S space => '${a ababa c:L:tsx:S,b, ,g:Q}
39 @${PRINT} ':ts :S space :M => '${a ababa c:L:tsx:S,b, ,g:M*:Q} 38 @${PRINT} ':ts :S space :M => '${a ababa c:L:tsx:S,b, ,g:M*:Q}
40 39
41 # Not all modifiers behave this way though. Some of them always use 40 # Not all modifiers behave this way though. Some of them always use
42 # a space as word separator instead of the :ts separator. 41 # a space as word separator instead of the :ts separator.
43 # This seems like an oversight during implementation. 42 # This seems like an oversight during implementation.
44 @${PRINT} ':ts :S => '${a ababa c:L:tsx:S,b, ,g:Q} 43 @${PRINT} ':ts :S => '${a ababa c:L:tsx:S,b, ,g:Q}
45 @${PRINT} ':ts :S :@ => '${a ababa c:L:tsx:S,b, ,g:@v@${v}@:Q} 44 @${PRINT} ':ts :S :@ => '${a ababa c:L:tsx:S,b, ,g:@v@${v}@:Q}
46 45
47 # A final :M* modifier applies the :ts separator again, though. 46 # A final :M* modifier applies the :ts separator again, though.
48 @${PRINT} ':ts :S :@ :M => '${a ababa c:L:tsx:S,b, ,g:@v@${v}@:M*:Q} 47 @${PRINT} ':ts :S :@ :M => '${a ababa c:L:tsx:S,b, ,g:@v@${v}@:M*:Q}

cvs diff -r1.49 -r1.50 src/usr.bin/make/unit-tests/modmisc.mk (switch to unified diff)

--- src/usr.bin/make/unit-tests/modmisc.mk 2020/10/24 08:50:17 1.49
+++ src/usr.bin/make/unit-tests/modmisc.mk 2020/11/03 18:42:33 1.50
@@ -1,92 +1,92 @@ @@ -1,92 +1,92 @@
1# $NetBSD: modmisc.mk,v 1.49 2020/10/24 08:50:17 rillig Exp $ 1# $NetBSD: modmisc.mk,v 1.50 2020/11/03 18:42:33 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/,
15MOD_OPT= @d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@ 15MOD_OPT= @d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
16MOD_SEP= S,:, ,g 16MOD_SEP= S,:, ,g
17 17
18all: modvar modvarloop modsysv emptyvar undefvar 18all: modvar modvarloop modsysv emptyvar undefvar
19all: mod-quote 19all: mod-quote
20all: mod-break-many-words 20all: mod-break-many-words
21 21
22# See also sysv.mk. 22# See also sysv.mk.
23modsysv: 23modsysv:
24 @echo "The answer is ${libfoo.a:L:libfoo.a=42}" 24 @echo "The answer is ${libfoo.a:L:libfoo.a=42}"
25 25
26# Demonstrates modifiers that are given indirectly from a variable. 26# Demonstrates modifiers that are given indirectly from a variable.
27modvar: 27modvar:
28 @echo "path='${path}'" 28 @echo "path='${path}'"
29 @echo "path='${path:${MOD_NODOT}}'" 29 @echo "path='${path:${MOD_NODOT}}'"
30 @echo "path='${path:S,home,homes,:${MOD_NODOT}}'" 30 @echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
31 @echo "path=${path:${MOD_NODOTX}:ts:}" 31 @echo "path=${path:${MOD_NODOTX}:ts:}"
32 @echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}" 32 @echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
33 33
34.for d in ${path:${MOD_SEP}:N.} /usr/xbin 34.for d in ${path:${MOD_SEP}:N.} /usr/xbin
35path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/ 35path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/
36paths+= ${d:${MOD_OPT}:${MOD_HOMES}} 36paths+= ${d:${MOD_OPT}:${MOD_HOMES}}
37.endfor 37.endfor
38 38
39modvarloop: 39modvarloop:
40 @echo "path_/usr/xbin=${path_/usr/xbin}" 40 @echo "path_/usr/xbin=${path_/usr/xbin}"
41 @echo "paths=${paths}" 41 @echo "paths=${paths}"
42 @echo "PATHS=${paths:tu}" 42 @echo "PATHS=${paths:tu}"
43 43
44# When a modifier is applied to the "" variable, the result is discarded. 44# When a modifier is applied to the "" variable, the result is discarded.
45emptyvar: 45emptyvar:
46 @echo S:${:S,^$,empty,} 46 @echo S:${:S,^$,empty,}
47 @echo C:${:C,^$,empty,} 47 @echo C:${:C,^$,empty,}
48 @echo @:${:@var@${var}@} 48 @echo @:${:@var@${var}@}
49 49
50# The :U modifier turns even the "" variable into something that has a value. 50# The :U modifier turns even the "" variable into something that has a value.
51# The resulting variable is empty, but is still considered to contain a 51# The value of the resulting expression is empty, but is still considered to
52# single empty word. This word can be accessed by the :S and :C modifiers, 52# contain a single empty word. This word can be accessed by the :S and :C
53# but not by the :@ modifier since it explicitly skips empty words. 53# modifiers, but not by the :@ modifier since it explicitly skips empty words.
54undefvar: 54undefvar:
55 @echo S:${:U:S,^$,empty,} 55 @echo S:${:U:S,^$,empty,}
56 @echo C:${:U:C,^$,empty,} 56 @echo C:${:U:C,^$,empty,}
57 @echo @:${:U:@var@empty@} 57 @echo @:${:U:@var@empty@}
58 58
59 59
60mod-quote: 60mod-quote:
61 @echo $@: new${.newline:Q}${.newline:Q}line 61 @echo $@: new${.newline:Q}${.newline:Q}line
62 62
63# Cover the bmake_realloc in brk_string. 63# Cover the bmake_realloc in brk_string.
64mod-break-many-words: 64mod-break-many-words:
65 @echo $@: ${UNDEF:U:range=500:[#]} 65 @echo $@: ${UNDEF:U:range=500:[#]}
66 66
67# To apply a modifier indirectly via another variable, the whole 67# To apply a modifier indirectly via another variable, the whole
68# modifier must be put into a single variable. 68# modifier must be put into a single variable expression.
69.if ${value:L:${:US}${:U,value,replacement,}} != "S,value,replacement,}" 69.if ${value:L:${:US}${:U,value,replacement,}} != "S,value,replacement,}"
70. warning unexpected 70. warning unexpected
71.endif 71.endif
72 72
73# Adding another level of indirection (the 2 nested :U expressions) helps. 73# Adding another level of indirection (the 2 nested :U expressions) helps.
74.if ${value:L:${:U${:US}${:U,value,replacement,}}} != "replacement" 74.if ${value:L:${:U${:US}${:U,value,replacement,}}} != "replacement"
75. warning unexpected 75. warning unexpected
76.endif 76.endif
77 77
78# Multiple indirect modifiers can be applied one after another as long as 78# Multiple indirect modifiers can be applied one after another as long as
79# they are separated with colons. 79# they are separated with colons.
80.if ${value:L:${:US,a,A,}:${:US,e,E,}} != "vAluE" 80.if ${value:L:${:US,a,A,}:${:US,e,E,}} != "vAluE"
81. warning unexpected 81. warning unexpected
82.endif 82.endif
83 83
84# An indirect variable that evaluates to the empty string is allowed though. 84# An indirect variable that evaluates to the empty string is allowed though.
85# This makes it possible to define conditional modifiers, like this: 85# This makes it possible to define conditional modifiers, like this:
86# 86#
87# M.little-endian= S,1234,4321, 87# M.little-endian= S,1234,4321,
88# M.big-endian= # none 88# M.big-endian= # none
89.if ${value:L:${:Dempty}S,a,A,} != "vAlue" 89.if ${value:L:${:Dempty}S,a,A,} != "vAlue"
90. warning unexpected 90. warning unexpected
91.endif 91.endif
92 92

cvs diff -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-exclam-shell.mk (switch to unified diff)

--- src/usr.bin/make/unit-tests/varmod-exclam-shell.mk 2020/10/24 08:46:08 1.3
+++ src/usr.bin/make/unit-tests/varmod-exclam-shell.mk 2020/11/03 18:42:33 1.4
@@ -1,28 +1,37 @@ @@ -1,28 +1,37 @@
1# $NetBSD: varmod-exclam-shell.mk,v 1.3 2020/10/24 08:46:08 rillig Exp $ 1# $NetBSD: varmod-exclam-shell.mk,v 1.4 2020/11/03 18:42:33 rillig Exp $
2# 2#
3# Tests for the :!cmd! variable modifier. 3# Tests for the :!cmd! variable modifier, which evaluates the modifier
 4# argument, independent of the value or the name of the original variable.
4 5
5.if ${:!echo hello | tr 'l' 'l'!} != "hello" 6.if ${:!echo hello | tr 'l' 'l'!} != "hello"
6. warning unexpected 7. error
7.endif 8.endif
8 9
9# The output is truncated at the first null byte. 10# The output is truncated at the first null byte.
10# Cmd_Exec returns only a string pointer without length information. 11# Cmd_Exec returns only a string pointer without length information.
 12# Truncating the output is not necessarily intended but may also be a side
 13# effect from the implementation. Having null bytes in the output of a
 14# shell command is so unusual that it doesn't matter in practice.
11.if ${:!echo hello | tr 'l' '\0'!} != "he" 15.if ${:!echo hello | tr 'l' '\0'!} != "he"
12. warning unexpected 16. error
13.endif 17.endif
14 18
 19# The newline at the end of the output is stripped.
15.if ${:!echo!} != "" 20.if ${:!echo!} != ""
16. warning A newline at the end of the output must be stripped. 21. error
17.endif 22.endif
18 23
 24# Only the final newline of the output is stripped. All other newlines are
 25# converted to spaces.
19.if ${:!echo;echo!} != " " 26.if ${:!echo;echo!} != " "
20. warning Only a single newline at the end of the output is stripped. 27. error
21.endif 28.endif
22 29
 30# Each newline in the output is converted to a space, except for the newline
 31# at the end of the output, which is stripped.
23.if ${:!echo;echo;echo;echo!} != " " 32.if ${:!echo;echo;echo;echo!} != " "
24. warning Other newlines in the output are converted to spaces. 33. error
25.endif 34.endif
26 35
27all: 36all:
28 @:; 37 @:;