head	1.2;
access;
symbols;
locks; strict;
comment	@# @;


1.2
date	2026.08.23.08.48.56;	author rillig;	state Exp;
branches;
next	1.1;
commitid	lSuFZ0D2dktbVJSG;

1.1
date	2026.08.23.08.23.56;	author rillig;	state Exp;
branches;
next	;
commitid	ZNxfItOETiAGNJSG;


desc
@@


1.2
log
@make: fix newline in word splitting

The newline character behaved differently depending on whether it
occurred at the beginning of a word or in the middle of it.  In the
middle, it didn't act as a word separator but instead stopped splitting,
thereby ignoring any following words.  This behavior was neither
documented nor to be expected.  It probably came from a time before 1993
where the makefiles were read as a single block of text instead of
splitting them into lines first.
@
text
@# $NetBSD: char-000a-new-line.mk,v 1.1 2026/08/23 08:23:56 rillig Exp $
#
# Tests for the character U+000A "LINE FEED" or "NEW LINE".

# begin word splitting
#
# When splitting a string into words, the newline character separates words,
# unless it occurs in "double" or 'single' quotes.

# expect+4: used
# expect+3: +
# expect+2: word
.for var in used +${.newline} word
.  info ${var}
.endfor

.export used +${.newline} word
.unexport used +${.newline} word
.undef used +${.newline} word

# Same for the MAKEFLAGS environment variable.
.MAKEFLAGS: used=yes-from-cmdline +${.newline} word=yes-from-cmdline
.if ${used} != "yes-from-cmdline" || ${word:Uundefined} != "yes-from-cmdline"
.  error
.endif

# expect+1: used + word
.info ${:U used +${.newline} word :%=%}
# expect+1: used + word
.info ${:U used +${.newline} word :@@v@@$v@@}
# expect+1: used + word
.info ${:U used +${.newline} word :C,x,x,}
# expect+1: used + word
.info ${:U a.used a.+${.newline} a.word :E}
# expect+1: used + word
.info ${:U used/x +/${.newline} word/x :H}
# expect+1: used + word
.info ${:U used +${.newline} word :M*}
# expect+1: used + word
.info ${:U used +${.newline} word :N}
# expect+1: + used word
.info ${:U used +${.newline} word :O}
# expect+1: used + word
.info ${:U used +${.newline} word :R}
# expect+1: used + word
.info ${:U used +${.newline} word :S,x,x,}
# expect+1: used + word
.info ${:U used +${.newline} word :T}
# expect+1: 3
.info ${:U used +${.newline} word :[#]}
# expect+1: used + word
.info ${:U used +${.newline} word :[1..-1]}
# expect+1: 1234567 1234567 1234567
.info ${:U used +${.newline} word :mtime=1234567}
# expect+1: 1 2 3
.info ${:U used +${.newline} word :range}
# expect+1: used + word
.info ${:U used +${.newline} word :tA}
# expect+1: used + word
.info ${:U used +${.newline} word :ts }
# expect+1: used + word
.info ${:U used +${.newline} word :u}

# end word splitting
@


1.1
log
@tests/make: demonstrate newline in word splitting
@
text
@d1 1
a1 1
# $NetBSD$
d7 7
a13 9
# When splitting a string into words, the newline character has different
# functions depending on where exactly it occurs:
#	* At the beginning of the string, or after a space, it separates words.
#	* Inside "double" or 'single' quotes, it represents itself.
#	* After an unquoted word character, it stops splitting.

# expect+3: used
# expect+2: +
.for var in used +${.newline} ignored
d17 3
a19 3
.export used +${.newline} ignored
.unexport used +${.newline} ignored
.undef used +${.newline} ignored
d22 2
a23 2
.MAKEFLAGS: used=yes-from-cmdline +${.newline} ignored=yes-from-cmdline
.if ${used} != "yes-from-cmdline" || ${ignored:Uundefined} != "undefined"
d27 36
a62 36
# expect+1: used +
.info ${:U used +${.newline} ignored :%=%}
# expect+1: used +
.info ${:U used +${.newline} ignored :@@v@@$v@@}
# expect+1: used +
.info ${:U used +${.newline} ignored :C,x,x,}
# expect+1: used +
.info ${:U a.used a.+${.newline} a.ignored :E}
# expect+1: used +
.info ${:U used/x +/${.newline} ignored/x :H}
# expect+1: used +
.info ${:U used +${.newline} ignored :M*}
# expect+1: used +
.info ${:U used +${.newline} ignored :N}
# expect+1: + used
.info ${:U used +${.newline} ignored :O}
# expect+1: used +
.info ${:U used +${.newline} ignored :R}
# expect+1: used +
.info ${:U used +${.newline} ignored :S,x,x,}
# expect+1: used +
.info ${:U used +${.newline} ignored :T}
# expect+1: 2
.info ${:U used +${.newline} ignored :[#]}
# expect+1: used +
.info ${:U used +${.newline} ignored :[1..-1]}
# expect+1: 1234567 1234567
.info ${:U used +${.newline} ignored :mtime=1234567}
# expect+1: 1 2
.info ${:U used +${.newline} ignored :range}
# expect+1: used +
.info ${:U used +${.newline} ignored :tA}
# expect+1: used +
.info ${:U used +${.newline} ignored :ts }
# expect+1: used +
.info ${:U used +${.newline} ignored :u}
@

