xref: /freebsd/contrib/bmake/unit-tests/varmod-head.mk (revision 8d5c8e21c690b35d0a9a604d6b886fba222cd2fe)
1*8d5c8e21SSimon J. Gerraty# $NetBSD: varmod-head.mk,v 1.6 2024/06/01 18:44:05 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for the :H variable modifier, which returns the dirname of
42c3632d1SSimon J. Gerraty# each of the words in the variable value.
52c3632d1SSimon J. Gerraty
6954401e6SSimon J. Gerraty.if ${:U a/b/c :H} != "a/b"
7954401e6SSimon J. Gerraty.  error
8954401e6SSimon J. Gerraty.endif
9954401e6SSimon J. Gerraty
10954401e6SSimon J. Gerraty.if ${:U def :H} != "."
11954401e6SSimon J. Gerraty.  error
12954401e6SSimon J. Gerraty.endif
13954401e6SSimon J. Gerraty
14954401e6SSimon J. Gerraty.if ${:U a.b.c :H} != "."
15954401e6SSimon J. Gerraty.  error
16954401e6SSimon J. Gerraty.endif
17954401e6SSimon J. Gerraty
18954401e6SSimon J. Gerraty.if ${:U a.b/c :H} != "a.b"
19954401e6SSimon J. Gerraty.  error
20954401e6SSimon J. Gerraty.endif
21954401e6SSimon J. Gerraty
22954401e6SSimon J. Gerraty.if ${:U a :H} != "."
23954401e6SSimon J. Gerraty.  error
24954401e6SSimon J. Gerraty.endif
25954401e6SSimon J. Gerraty
26954401e6SSimon J. Gerraty.if ${:U a.a :H} != "."
27954401e6SSimon J. Gerraty.  error
28954401e6SSimon J. Gerraty.endif
29954401e6SSimon J. Gerraty
30954401e6SSimon J. Gerraty.if ${:U .gitignore :H} != "."
31954401e6SSimon J. Gerraty.  error
32954401e6SSimon J. Gerraty.endif
33954401e6SSimon J. Gerraty
34954401e6SSimon J. Gerraty.if ${:U trailing/ :H} != "trailing"
35954401e6SSimon J. Gerraty.  error
36954401e6SSimon J. Gerraty.endif
37954401e6SSimon J. Gerraty
38954401e6SSimon J. Gerraty.if ${:U /abs/dir/file :H} != "/abs/dir"
39954401e6SSimon J. Gerraty.  error
40954401e6SSimon J. Gerraty.endif
41954401e6SSimon J. Gerraty
42954401e6SSimon J. Gerraty.if ${:U rel/dir/file :H} != "rel/dir"
43954401e6SSimon J. Gerraty.  error
44954401e6SSimon J. Gerraty.endif
45954401e6SSimon J. Gerraty
46954401e6SSimon J. Gerraty# The head of "/" was an empty string before 2020.07.20.14.50.41, leading to
47954401e6SSimon J. Gerraty# the output "before  after", with two spaces.  Since 2020.07.20.14.50.41, the
48954401e6SSimon J. Gerraty# output is "before after", discarding the empty word.
49954401e6SSimon J. Gerraty.if ${:U before/ / after/ :H} == "before after"
50954401e6SSimon J. Gerraty# OK
51954401e6SSimon J. Gerraty.elif ${:U before/ / after/ :H} == "before  after"
52954401e6SSimon J. Gerraty# No '.info' to keep the file compatible with old make versions.
53954401e6SSimon J. Gerraty_!=	echo "The modifier ':H' generates an empty word." 1>&2; echo
54954401e6SSimon J. Gerraty.else
55954401e6SSimon J. Gerraty.  error
56954401e6SSimon J. Gerraty.endif
57954401e6SSimon J. Gerraty
58954401e6SSimon J. Gerraty# An empty list is split into a single empty word.
59954401e6SSimon J. Gerraty# The dirname of this empty word is ".".
60954401e6SSimon J. Gerraty.if ${:U :H} != "."
61954401e6SSimon J. Gerraty.  error
62954401e6SSimon J. Gerraty.endif
63954401e6SSimon J. Gerraty
64*8d5c8e21SSimon J. Gerraty# If the ':H' is not directly followed by a delimiting ':' or '}', the
65*8d5c8e21SSimon J. Gerraty# ':from=to' modifier is tried as a fallback.
66*8d5c8e21SSimon J. Gerraty.if ${:U Head :Head=replaced} != "replaced"
67*8d5c8e21SSimon J. Gerraty.  error
68*8d5c8e21SSimon J. Gerraty.endif
69*8d5c8e21SSimon J. Gerraty
70954401e6SSimon J. Gerratyall: .PHONY
71