mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-22 02:37:15 +00:00
![Simon J. Gerraty](/assets/img/avatar_default.png)
Lots more unit tests and code cleanup Relevant changes from ChangeLog o job.c: Print -de error information when running multiple jobs o var.c: only report error for unmatched regex subexpression when linting (-dL) since we cannot tell when an unmatched subexpression is an expected result. reduce memory allocations in the modifiers ':D' and ':U' reduce memory allocation and strlen calls in modifier ':from=to' in the ':Q' modifier, only allocate memory if necessary improve performance for LazyBuf reduce debug logging and memory allocation for ${:U...} reduce verbosity of the -dv debug logging for standard cases fix double varname expansion in the variable modifier '::=' o var.c: avoid evaluating many modifiers in parse only mode in strict mode (-dL) many variable references are parsed twice, the first time just to report parse errors early, so we want to avoid side effects and wasted effort to the extent possible.
76 lines
2.8 KiB
Makefile
76 lines
2.8 KiB
Makefile
# $NetBSD: directive-for-errors.mk,v 1.3 2021/04/04 10:13:09 rillig Exp $
|
|
#
|
|
# Tests for error handling in .for loops.
|
|
|
|
# A .for directive must be followed by whitespace, everything else results
|
|
# in a parse error.
|
|
.fori in 1 2 3
|
|
. warning ${i}
|
|
.endfor
|
|
|
|
# A slash is not whitespace, therefore this is not parsed as a .for loop.
|
|
#
|
|
# XXX: The error message is misleading though. As of 2020-12-31, it says
|
|
# "Unknown directive "for"", but that directive is actually known. This is
|
|
# because ForEval does not detect the .for loop as such, so parsing
|
|
# continues in ParseLine > ParseDependencyLine > ParseDependency >
|
|
# ParseDependencyTargets > ParseErrorNoDependency, and there the directive
|
|
# name is parsed a bit differently.
|
|
.for/i in 1 2 3
|
|
. warning ${i}
|
|
.endfor
|
|
|
|
# As of 2020-12-31, the variable name can be an arbitrary word, it just needs
|
|
# to be separated by whitespace. Even '$' and '\' are valid variable names,
|
|
# which is not useful in practice.
|
|
#
|
|
# The '$$' is not replaced with the values '1' or '3' from the .for loop,
|
|
# instead it is kept as-is, and when the .info directive expands its argument,
|
|
# each '$$' gets replaced with a single '$'. The "long variable expression"
|
|
# ${$} gets replaced though, even though this would be a parse error everywhere
|
|
# outside a .for loop.
|
|
#
|
|
# The '\' on the other hand is treated as a normal variable name.
|
|
${:U\$}= dollar # see whether the "variable" '$' is local
|
|
${:U\\}= backslash # see whether the "variable" '\' is local
|
|
.for $ \ in 1 2 3 4
|
|
. info Dollar $$ ${$} $($) and backslash $\ ${\} $(\).
|
|
.endfor
|
|
|
|
# If there are no variables, there is no point in expanding the .for loop
|
|
# since this would end up in an endless loop, each time consuming 0 of the
|
|
# 3 values.
|
|
.for in 1 2 3
|
|
# XXX: This should not be reached. It should be skipped, as already done
|
|
# when the number of values is not a multiple of the number of variables,
|
|
# see below.
|
|
. warning Should not be reached.
|
|
.endfor
|
|
|
|
# There are 3 variables and 5 values. These 5 values cannot be split evenly
|
|
# among the variables, therefore the loop is not expanded at all, it is
|
|
# rather skipped.
|
|
.for a b c in 1 2 3 4 5
|
|
. warning Should not be reached.
|
|
.endfor
|
|
|
|
# The list of values after the 'in' may be empty, no matter if this emptiness
|
|
# comes from an empty expansion or even from a syntactically empty line.
|
|
.for i in
|
|
. info Would be reached if there were items to loop over.
|
|
.endfor
|
|
|
|
# A missing 'in' should parse the .for loop but skip the body.
|
|
.for i : k
|
|
# XXX: As of 2020-12-31, this line is reached once.
|
|
. warning Should not be reached.
|
|
.endfor
|
|
|
|
# A malformed modifier should be detected and skip the body of the loop.
|
|
#
|
|
# XXX: As of 2020-12-31, Var_Subst doesn't report any errors, therefore
|
|
# the loop body is expanded as if no error had happened.
|
|
.for i in 1 2 ${:U3:Z} 4
|
|
. warning Should not be reached.
|
|
.endfor
|