Home | History | Annotate | Line # | Download | only in unit-tests
directive-for-break.mk revision 1.2
      1 # $NetBSD: directive-for-break.mk,v 1.2 2022/09/03 00:50:07 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
     11 I=	$i
     12 .    break
     13 I=	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
     28 COMBINED+=	${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