xref: /freebsd/contrib/bmake/unit-tests/dir.mk (revision d5e0a182cf153f8993a633b93d9220c99a89e760)
1*d5e0a182SSimon J. Gerraty# $NetBSD: dir.mk,v 1.11 2023/12/19 19:33:40 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for dir.c.
42c3632d1SSimon J. Gerraty
54fde40d9SSimon J. Gerraty# hide /usr/share/mk from the debug log
64fde40d9SSimon J. Gerraty.SYSPATH:
74fde40d9SSimon J. Gerraty.SYSPATH: /
8956e45f6SSimon J. Gerraty
92c3632d1SSimon J. Gerraty# Dependency lines may use braces for expansion.
10956e45f6SSimon J. Gerraty# See DirExpandCurly for the implementation.
112c3632d1SSimon J. Gerratyall: {one,two,three}
122c3632d1SSimon J. Gerraty
13956e45f6SSimon J. Gerraty# XXX: The above dependency line is parsed as a single node named
14956e45f6SSimon J. Gerraty# "{one,two,three}".  There are no individual targets "one", "two", "three"
15956e45f6SSimon J. Gerraty# yet.  The node exists but is not a target since it never appeared
16956e45f6SSimon J. Gerraty# on the left-hand side of a dependency operator.  However, it is listed
17956e45f6SSimon J. Gerraty# in .ALLTARGETS (which lists all nodes, not only targets).
18956e45f6SSimon J. Gerraty.if target(one)
19956e45f6SSimon J. Gerraty.  error
20956e45f6SSimon J. Gerraty.endif
21956e45f6SSimon J. Gerraty.if target({one,two,three})
22956e45f6SSimon J. Gerraty.  error
23956e45f6SSimon J. Gerraty.endif
24956e45f6SSimon J. Gerraty.if ${.ALLTARGETS:M{one,two,three}} != "{one,two,three}"
25956e45f6SSimon J. Gerraty.  error
26956e45f6SSimon J. Gerraty.endif
27956e45f6SSimon J. Gerraty
282c3632d1SSimon J. Gerratyone:
29956e45f6SSimon J. Gerraty	: 1
302c3632d1SSimon J. Gerratytwo:
31956e45f6SSimon J. Gerraty	: 2
322c3632d1SSimon J. Gerratythree:
33956e45f6SSimon J. Gerraty	: 3
342c3632d1SSimon J. Gerraty
352c3632d1SSimon J. Gerraty# The braces may start in the middle of a word.
362c3632d1SSimon J. Gerratyall: f{our,ive}
372c3632d1SSimon J. Gerraty
382c3632d1SSimon J. Gerratyfour:
39956e45f6SSimon J. Gerraty	: 4
402c3632d1SSimon J. Gerratyfive:
41956e45f6SSimon J. Gerraty	: 5
422c3632d1SSimon J. Gerratysix:
43956e45f6SSimon J. Gerraty	: 6
442c3632d1SSimon J. Gerraty
45956e45f6SSimon J. Gerraty# Nested braces work as expected since 2020-07-31 19:06 UTC.
46956e45f6SSimon J. Gerraty# They had been broken at least since 2003-01-01, probably even longer.
472c3632d1SSimon J. Gerratyall: {{thi,fou}r,fif}teen
482c3632d1SSimon J. Gerraty
492c3632d1SSimon J. Gerratythirteen:
50956e45f6SSimon J. Gerraty	: 13
512c3632d1SSimon J. Gerratyfourteen:
52956e45f6SSimon J. Gerraty	: 14
532c3632d1SSimon J. Gerratyfifteen:
54956e45f6SSimon J. Gerraty	: 15
552c3632d1SSimon J. Gerraty
562c3632d1SSimon J. Gerraty# There may be multiple brace groups side by side.
572c3632d1SSimon J. Gerratyall: {pre-,}{patch,configure}
582c3632d1SSimon J. Gerraty
592c3632d1SSimon J. Gerratypre-patch patch pre-configure configure:
60956e45f6SSimon J. Gerraty	: $@
612c3632d1SSimon J. Gerraty
622c3632d1SSimon J. Gerraty# Empty pieces are allowed in the braces.
632c3632d1SSimon J. Gerratyall: {fetch,extract}{,-post}
642c3632d1SSimon J. Gerraty
652c3632d1SSimon J. Gerratyfetch fetch-post extract extract-post:
66956e45f6SSimon J. Gerraty	: $@
672c3632d1SSimon J. Gerraty
682c3632d1SSimon J. Gerraty# The expansions may have duplicates.
69e2eeea75SSimon J. Gerraty# When the source of the dependency line is expanded later, each of the
70*d5e0a182SSimon J. Gerraty# expanded words resolves to the same node.
712c3632d1SSimon J. Gerratyall: dup-{1,1,1,1,1,1,1}
722c3632d1SSimon J. Gerraty
732c3632d1SSimon J. Gerratydup-1:
74956e45f6SSimon J. Gerraty	: $@
752c3632d1SSimon J. Gerraty
762c3632d1SSimon J. Gerraty# Other than in Bash, the braces are also expanded if there is no comma.
772c3632d1SSimon J. Gerratyall: {{{{{{{{{{single-word}}}}}}}}}}
782c3632d1SSimon J. Gerraty
792c3632d1SSimon J. Gerratysingle-word:
80956e45f6SSimon J. Gerraty	: $@
81956e45f6SSimon J. Gerraty
82956e45f6SSimon J. Gerraty# Demonstrate debug logging for filename expansion, especially curly braces.
83956e45f6SSimon J. Gerraty.MAKEFLAGS: -dd
84dba7b0efSSimon J. Gerraty# The below line does not call SearchPath_Expand yet.
85956e45f6SSimon J. Gerraty# It is expanded only when necessary, that is, when the 'debug' target is
86956e45f6SSimon J. Gerraty# indeed made.
87956e45f6SSimon J. Gerratydebug: {{thi,fou}r,fif}twen
88956e45f6SSimon J. Gerraty# Therefore, keep the debug logging active.
89956e45f6SSimon J. Gerraty
90956e45f6SSimon J. Gerraty.PHONY: one two three four five six
91956e45f6SSimon J. Gerraty.PHONY: thirteen fourteen fifteen
92956e45f6SSimon J. Gerraty.PHONY: single-word
93956e45f6SSimon J. Gerraty.PHONY: pre-patch patch pre-configure configure
94956e45f6SSimon J. Gerraty.PHONY: fetch fetch-post extract extract-post
95956e45f6SSimon J. Gerraty.PHONY: dup-1 single-word
96956e45f6SSimon J. Gerraty.PHONY: all
97