]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/directive-for-errors.mk
less: upgrade to v581.
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / directive-for-errors.mk
1 # $NetBSD: directive-for-errors.mk,v 1.1 2020/12/31 03:05:12 rillig Exp $
2 #
3 # Tests for error handling in .for loops.
4
5 # A .for directive must be followed by whitespace, everything else results
6 # in a parse error.
7 .fori in 1 2 3
8 .  warning ${i}
9 .endfor
10
11 # A slash is not whitespace, therefore this is not parsed as a .for loop.
12 #
13 # XXX: The error message is misleading though.  As of 2020-12-31, it says
14 # "Unknown directive "for"", but that directive is actually known.  This is
15 # because ForEval does not detect the .for loop as such, so parsing
16 # continues in ParseLine > ParseDependency > ParseDoDependency >
17 # ParseDoDependencyTargets > ParseErrorNoDependency, and there the directive
18 # name is parsed a bit differently.
19 .for/i in 1 2 3
20 .  warning ${i}
21 .endfor
22
23 # As of 2020-12-31, the variable name can be an arbitrary word, it just needs
24 # to be separated by whitespace.  Even '$' and '\' are valid variable names,
25 # which is not useful in practice.
26 #
27 # The '$$' is not replaced with the values '1' or '3' from the .for loop,
28 # instead it is kept as-is, and when the .info directive expands its argument,
29 # each '$$' gets replaced with a single '$'.  The "long variable expression"
30 # ${$} gets replaced though, even though this would be a parse error everywhere
31 # outside a .for loop.
32 #
33 # The '\' on the other hand is treated as a normal variable name.
34 ${:U\$}=        dollar          # see whether the "variable" '$' is local
35 ${:U\\}=        backslash       # see whether the "variable" '\' is local
36 .for $ \ in 1 2 3 4
37 .  info Dollar $$ ${$} $($) and backslash $\ ${\} $(\).
38 .endfor
39
40 # If there are no variables, there is no point in expanding the .for loop
41 # since this would end up in an endless loop, each time consuming 0 of the
42 # 3 values.
43 .for in 1 2 3
44 # XXX: This should not be reached.  It should be skipped, as already done
45 # when the number of values is not a multiple of the number of variables,
46 # see below.
47 .  warning Should not be reached.
48 .endfor
49
50 # There are 3 variables and 5 values.  These 5 values cannot be split evenly
51 # among the variables, therefore the loop is not expanded at all, it is
52 # rather skipped.
53 .for a b c in 1 2 3 4 5
54 .  warning Should not be reached.
55 .endfor
56
57 # The list of values after the 'in' may be empty, no matter if this emptiness
58 # comes from an empty expansion or even from a syntactically empty line.
59 .for i in
60 .  info Would be reached if there were items to loop over.
61 .endfor
62
63 # A missing 'in' should parse the .for loop but skip the body.
64 .for i : k
65 # XXX: As of 2020-12-31, this line is reached once.
66 .  warning Should not be reached.
67 .endfor
68
69 # A malformed modifier should be detected and skip the body of the loop.
70 #
71 # XXX: As of 2020-12-31, Var_Subst doesn't report any errors, therefore
72 # the loop body is expanded as if no error had happened.
73 .for i in 1 2 ${:U3:Z} 4
74 .  warning Should not be reached.
75 .endfor