freebsd-src/unit-tests/directive-for-break.mk
Simon J. Gerraty 2e36ab2363 Import bmake-20230126
Relevant/interesting changes (see ChangeLog for more):

	o variables like .newline and .MAKE.{GID,PID,PPID,UID}
	should be read-only.
	o .[NO]READONLY: for control of read-only variables
	o .SYSPATH: for controlling the path searched for makefiles
	o allow for white-space between command specifiers @+-
	o add more details to warning 'Extra targets ignored'
	o make.1: sync list of built-in variables with reality
	sort list of built-in variables
	o cond.c: add more details to error message for numeric comparison
	o job.c: fix handling of null bytes in output
	o Allow .break to terminate a .for loop early
	o var.c: fix out-of-bounds errors when parsing
	o fix exit status for '-q' (since 1994)
2023-01-27 16:23:54 -08:00

61 lines
1.4 KiB
Makefile

# $NetBSD: directive-for-break.mk,v 1.3 2022/09/24 10:52:05 rillig Exp $
#
# Tests for .break in .for loops, which immediately terminates processing of
# the surrounding .for loop.
# .break terminates the loop early.
# This is usually done within a conditional.
.for i in 1 2 3 4 5 6 7 8
. if $i == 3
I= $i
. break
I= unreached
. endif
.endfor
.if $I != "3"
. error
.endif
# The .break only breaks out of the immediately surrounding .for loop, any
# other .for loops are continued normally.
.for outer in o1 o2 o3
. for inner in i1 i2 i3
. if ${outer} == o2 && ${inner} == i2
. break
. endif
COMBINED+= ${outer}-${inner}
. endfor
.endfor
# Only o2-i2 and o2-i3 are missing.
.if ${COMBINED} != "o1-i1 o1-i2 o1-i3 o2-i1 o3-i1 o3-i2 o3-i3"
. error
.endif
# A .break outside the context of a .for loop is an error.
.if $I == 0
# No parse error, even though the .break occurs outside a .for loop, since
# lines from inactive branches are only parsed as far as necessary to see
# whether they belong to an .if/.elif/.else/.endif chain.
. break
.else
# expect+1: break outside of for loop
. break
.endif
# Since cond.c 1.335 from 2022-09-02 and before cond.c 1.338 from 2022-09-23,
# the following paragraph generated the wrong error message '4294967294 open
# conditionals'.
.if 1
. if 2
. for var in value
. if 3
. break
. endif
. endfor
. endif
.endif