1 # $NetBSD: directive-for-errors.mk,v 1.1 2020/12/31 03:05:12 rillig Exp $
3 # Tests for error handling in .for loops.
5 # A .for directive must be followed by whitespace, everything else results
11 # A slash is not whitespace, therefore this is not parsed as a .for loop.
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.
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.
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.
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
37 . info Dollar $$ ${$} $($) and backslash $\ ${\} $(\).
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
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,
47 . warning Should not be reached.
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
53 .for a b c in 1 2 3 4 5
54 . warning Should not be reached.
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.
60 . info Would be reached if there were items to loop over.
63 # A missing 'in' should parse the .for loop but skip the body.
65 # XXX: As of 2020-12-31, this line is reached once.
66 . warning Should not be reached.
69 # A malformed modifier should be detected and skip the body of the loop.
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.