directive-for-errors.mk revision 1.5 1 1.5 rillig # $NetBSD: directive-for-errors.mk,v 1.5 2023/05/09 19:43:12 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # Tests for error handling in .for loops.
4 1.1 rillig
5 1.5 rillig # expect-all
6 1.5 rillig
7 1.5 rillig
8 1.1 rillig # A .for directive must be followed by whitespace, everything else results
9 1.1 rillig # in a parse error.
10 1.5 rillig # expect+1: Unknown directive "fori"
11 1.1 rillig .fori in 1 2 3
12 1.5 rillig . warning <${i}>
13 1.1 rillig .endfor
14 1.5 rillig # expect-2: <>
15 1.5 rillig # expect-2: for-less endfor
16 1.5 rillig
17 1.1 rillig
18 1.1 rillig # A slash is not whitespace, therefore this is not parsed as a .for loop.
19 1.1 rillig #
20 1.1 rillig # XXX: The error message is misleading though. As of 2020-12-31, it says
21 1.5 rillig # 'Unknown directive "for"', but that directive is actually known. This is
22 1.1 rillig # because ForEval does not detect the .for loop as such, so parsing
23 1.3 rillig # continues in ParseLine > ParseDependencyLine > ParseDependency >
24 1.3 rillig # ParseDependencyTargets > ParseErrorNoDependency, and there the directive
25 1.1 rillig # name is parsed a bit differently.
26 1.5 rillig # expect+1: Unknown directive "for"
27 1.1 rillig .for/i in 1 2 3
28 1.5 rillig . warning <${i}>
29 1.1 rillig .endfor
30 1.5 rillig # expect-2: warning: <>
31 1.5 rillig # expect-2: for-less endfor
32 1.5 rillig
33 1.1 rillig
34 1.4 rillig # Before for.c 1.173 from 2023-05-08, the variable name could be an arbitrary
35 1.4 rillig # word, it only needed to be separated by whitespace. Even '$' and '\' were
36 1.4 rillig # valid variable names, which was not useful in practice.
37 1.1 rillig #
38 1.4 rillig # The '$$' was not replaced with the values '1' or '3' from the .for loop,
39 1.4 rillig # instead it was kept as-is, and when the .info directive expanded its
40 1.4 rillig # argument, each '$$' got replaced with a single '$'. The "long variable
41 1.4 rillig # expression" ${$} got replaced though, even though this would be a parse
42 1.4 rillig # error everywhere outside a .for loop.
43 1.1 rillig ${:U\$}= dollar # see whether the "variable" '$' is local
44 1.1 rillig ${:U\\}= backslash # see whether the "variable" '\' is local
45 1.5 rillig # expect+1: invalid character '$' in .for loop variable name
46 1.1 rillig .for $ \ in 1 2 3 4
47 1.1 rillig . info Dollar $$ ${$} $($) and backslash $\ ${\} $(\).
48 1.1 rillig .endfor
49 1.1 rillig
50 1.1 rillig # If there are no variables, there is no point in expanding the .for loop
51 1.4 rillig # since this would end up in an endless loop, consuming 0 of the 3 values in
52 1.4 rillig # each iteration.
53 1.5 rillig # expect+1: no iteration variables in for
54 1.1 rillig .for in 1 2 3
55 1.1 rillig # XXX: This should not be reached. It should be skipped, as already done
56 1.1 rillig # when the number of values is not a multiple of the number of variables,
57 1.1 rillig # see below.
58 1.1 rillig . warning Should not be reached.
59 1.1 rillig .endfor
60 1.1 rillig
61 1.5 rillig
62 1.1 rillig # There are 3 variables and 5 values. These 5 values cannot be split evenly
63 1.1 rillig # among the variables, therefore the loop is not expanded at all, it is
64 1.4 rillig # skipped instead.
65 1.5 rillig # expect+1: Wrong number of words (5) in .for substitution list with 3 variables
66 1.1 rillig .for a b c in 1 2 3 4 5
67 1.1 rillig . warning Should not be reached.
68 1.1 rillig .endfor
69 1.1 rillig
70 1.5 rillig
71 1.1 rillig # The list of values after the 'in' may be empty, no matter if this emptiness
72 1.1 rillig # comes from an empty expansion or even from a syntactically empty line.
73 1.1 rillig .for i in
74 1.1 rillig . info Would be reached if there were items to loop over.
75 1.1 rillig .endfor
76 1.1 rillig
77 1.5 rillig
78 1.1 rillig # A missing 'in' should parse the .for loop but skip the body.
79 1.4 rillig # expect+1: missing `in' in for
80 1.4 rillig .for i over k
81 1.1 rillig # XXX: As of 2020-12-31, this line is reached once.
82 1.1 rillig . warning Should not be reached.
83 1.1 rillig .endfor
84 1.1 rillig
85 1.5 rillig
86 1.1 rillig # A malformed modifier should be detected and skip the body of the loop.
87 1.1 rillig #
88 1.1 rillig # XXX: As of 2020-12-31, Var_Subst doesn't report any errors, therefore
89 1.1 rillig # the loop body is expanded as if no error had happened.
90 1.5 rillig # expect+1: Unknown modifier "Z"
91 1.1 rillig .for i in 1 2 ${:U3:Z} 4
92 1.1 rillig . warning Should not be reached.
93 1.1 rillig .endfor
94 1.5 rillig # expect-2: Should not be reached.
95 1.5 rillig # expect-3: Should not be reached.
96 1.5 rillig # expect-4: Should not be reached.
97