freebsd-src/unit-tests/dollar.mk
Simon J. Gerraty b897d72a5a Import bmake-20200517
Changes since 20181221 are mostly portability related
hence the large gap in versions imported.

There are however some bug fixes, and a rework of filemon handling.
In NetBSD make/filemon/filemon_ktrace.c allows use of fktrace
and elimination of filemon(4) which has not had the TLC it needs.

FreeBSD filemon(4) is in much better shape, so bmake/filemon/filemon_dev.c
allows use of that, with a bit less overhead than the ktrace model.

Summary of changes from ChangeLog

	o str.c: empty string does not match % pattern
	  plus unit-test changes
	o var.c: import handling of old sysV style modifier using '%'
	o str.c: refactor brk_string
	o meta.c: meta_oodate, CHECK_VALID_META is too aggressive for CMD
	  a blank command is perfectly valid.
	o meta.c: meta_oodate, check for corrupted meta file
	  earlier and more often.
	* meta.c: meta_compat_parent check for USE_FILEMON
	  patch from Soeren Tempel
	o meta.c: fix compat mode, need to call meta_job_output()
	o job.c: extra fds for meta mode not needed if using filemon_dev
	o meta.c: avoid passing NULL to filemon_*() when meta_needed()
	  returns FALSE.
	o filemon/filemon_{dev,ktrace}.c: allow selection of
	  filemon implementation.  filemon_dev.c uses the kernel module
	  while filemon_ktrace.c leverages the fktrace api available in
	  NetBSD.  filemon_ktrace.c can hopefully form the basis for
	  adding support for other tracing mechanisms such as strace on
	  Linux.
	o meta.c: when target is out-of-date per normal make rules
	  record value of .OODATE in meta file.
	o parse.c: don't pass NULL to realpath(3)
	  some versions cannot handle it.
	o parse.c: ParseDoDependency: free paths rather than assert

plus more unit-tests
2020-05-20 19:34:48 +00:00

82 lines
2.6 KiB
Makefile

# $NetBSD: dollar.mk,v 1.3 2020/05/17 09:37:48 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
# These variable values are not accessed.
# The trailing dollar in the '1 dollar literal eol' test case accesses
# the empty variable instead, which is always guaranteed to be empty.
${:U }= space-var-value
${:U${.newline}}= newline-var-value
# But this one is accessed.
${:U'}= single-quote-var-value'
all:
$H 'Printing dollar from literals and variables'
$C 'To survive the parser, a dollar character must be doubled.'
$T '1 dollar literal' '$'
$T '1 dollar literal eol' ''$
$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,$$,dollar,g' ''${DOLLAR:C,$,dollar,g:Q}
$T 'C,$$$$,dollar,g' ''${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}