xref: /freebsd/contrib/bmake/unit-tests/directive-for-break.mk (revision 148ee84570001f46b7b667c86573d378101c3801)
1# $NetBSD: directive-for-break.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $
2#
3# Tests for .break in .for loops, which immediately terminates processing of
4# the surrounding .for loop.
5
6
7# .break terminates the loop early.
8# This is usually done within a conditional.
9.for i in 1 2 3 4 5 6 7 8
10.  if $i == 3
11I=	$i
12.    break
13I=	unreached
14.  endif
15.endfor
16.if $I != "3"
17.  error
18.endif
19
20
21# The .break only breaks out of the immediately surrounding .for loop, any
22# other .for loops are continued normally.
23.for outer in o1 o2 o3
24.  for inner in i1 i2 i3
25.    if ${outer} == o2 && ${inner} == i2
26.      break
27.    endif
28COMBINED+=	${outer}-${inner}
29.  endfor
30.endfor
31# Only o2-i2 and o2-i3 are missing.
32.if ${COMBINED} != "o1-i1 o1-i2 o1-i3 o2-i1 o3-i1 o3-i2 o3-i3"
33.  error
34.endif
35
36
37# A .break outside the context of a .for loop is an error.
38.if $I == 0
39# No parse error, even though the .break occurs outside a .for loop, since
40# lines from inactive branches are only parsed as far as necessary to see
41# whether they belong to an .if/.elif/.else/.endif chain.
42.  break
43.else
44# expect+1: break outside of for loop
45.  break
46.endif
47
48
49# Since cond.c 1.335 from 2022-09-02 and before cond.c 1.338 from 2022-09-23,
50# the following paragraph generated the wrong error message '4294967294 open
51# conditionals'.
52.if 1
53.  if 2
54.    for var in value
55.      if 3
56.        break
57.      endif
58.    endfor
59.  endif
60.endif
61
62
63.for i in 1
64# expect+1: The .break directive does not take arguments
65.  break 1
66.endfor
67