varmod-edge.mk revision 1.1 1 1.1 rillig # $NetBSD: varmod-edge.mk,v 1.1 2019/11/30 00:38:51 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # Tests for edge cases in variable modifiers.
4 1.1 rillig #
5 1.1 rillig # These tests demonstrate the current implementation in small examples.
6 1.1 rillig # They may contain surprising behavior.
7 1.1 rillig #
8 1.1 rillig # Each test consists of:
9 1.1 rillig # - INP, the input to the test
10 1.1 rillig # - MOD, the expression for testing the modifier
11 1.1 rillig # - EXP, the expected output
12 1.1 rillig
13 1.1 rillig TESTS+= M-paren
14 1.1 rillig INP.M-paren= (parentheses) {braces} (opening closing) ()
15 1.1 rillig MOD.M-paren= ${INP.M-paren:M(*)}
16 1.1 rillig EXP.M-paren= (parentheses) ()
17 1.1 rillig
18 1.1 rillig # The first closing brace matches the opening parenthesis.
19 1.1 rillig # The second closing brace actually ends the variable expression.
20 1.1 rillig #
21 1.1 rillig # XXX: This is unexpected but rarely occurs in practice.
22 1.1 rillig TESTS+= M-mixed
23 1.1 rillig INP.M-mixed= (paren-brace} (
24 1.1 rillig MOD.M-mixed= ${INP.M-mixed:M(*}}
25 1.1 rillig EXP.M-mixed= (paren-brace}
26 1.1 rillig
27 1.1 rillig # When the :M and :N modifiers are parsed, the pattern finishes as soon
28 1.1 rillig # as open_parens + open_braces == closing_parens + closing_braces. This
29 1.1 rillig # means that ( and } form a matching pair.
30 1.1 rillig #
31 1.1 rillig # Nested variable expressions are not parsed as such. Instead, only the
32 1.1 rillig # parentheses and braces are counted. This leads to a parse error since
33 1.1 rillig # the nested expression is not "${:U*)}" but only "${:U*)", which is
34 1.1 rillig # missing the closing brace. The expression is evaluated anyway.
35 1.1 rillig # The final brace in the output comes from the end of M.nest-mix.
36 1.1 rillig #
37 1.1 rillig # XXX: This is unexpected but rarely occurs in practice.
38 1.1 rillig TESTS+= M-nest-mix
39 1.1 rillig INP.M-nest-mix= (parentheses)
40 1.1 rillig MOD.M-nest-mix= ${INP.M-nest-mix:M${:U*)}}
41 1.1 rillig EXP.M-nest-mix= (parentheses)}
42 1.1 rillig
43 1.1 rillig # In contrast to parentheses and braces, the brackets are not counted
44 1.1 rillig # when the :M modifier is parsed since Makefile variables only take the
45 1.1 rillig # ${VAR} or $(VAR) forms, but not $[VAR].
46 1.1 rillig #
47 1.1 rillig # The final ] in the pattern is needed to close the character class.
48 1.1 rillig TESTS+= M-nest-brk
49 1.1 rillig INP.M-nest-brk= [ [[ [[[
50 1.1 rillig MOD.M-nest-brk= ${INP.M-nest-brk:M${:U[[[[[]}}
51 1.1 rillig EXP.M-nest-brk= [
52 1.1 rillig
53 1.1 rillig # The pattern in the nested variable has an unclosed character class.
54 1.1 rillig # No error is reported though, and the pattern is closed implicitly.
55 1.1 rillig #
56 1.1 rillig # XXX: It is unexpected that no error is reported.
57 1.1 rillig TESTS+= M-pat-err
58 1.1 rillig INP.M-pat-err= [ [[ [[[
59 1.1 rillig MOD.M-pat-err= ${INP.M-pat-err:M${:U[[}}
60 1.1 rillig EXP.M-pat-err= [
61 1.1 rillig
62 1.1 rillig all:
63 1.1 rillig .for test in ${TESTS}
64 1.1 rillig . if ${MOD.${test}} == ${EXP.${test}}
65 1.1 rillig @printf 'ok %s\n' ${test:Q}''
66 1.1 rillig . else
67 1.1 rillig @printf 'error in %s: expected %s, got %s\n' \
68 1.1 rillig ${test:Q}'' ${EXP.${test}:Q}'' ${MOD.${test}:Q}''
69 1.1 rillig . endif
70 1.1 rillig .endfor
71