Thu Oct 29 18:38:24 2020 UTC ()
make(1): add test for ignoring assignment to read-only variable


(rillig)
diff -r1.10 -r1.11 src/usr.bin/make/unit-tests/vardebug.exp
diff -r1.4 -r1.5 src/usr.bin/make/unit-tests/vardebug.mk

cvs diff -r1.10 -r1.11 src/usr.bin/make/unit-tests/vardebug.exp (switch to unified diff)

--- src/usr.bin/make/unit-tests/vardebug.exp 2020/10/29 18:19:41 1.10
+++ src/usr.bin/make/unit-tests/vardebug.exp 2020/10/29 18:38:24 1.11
@@ -1,85 +1,88 @@ @@ -1,85 +1,88 @@
1Global:delete FROM_CMDLINE (not found) 1Global:delete FROM_CMDLINE (not found)
2Command:FROM_CMDLINE =  2Command:FROM_CMDLINE =
3Global:.MAKEOVERRIDES = FROM_CMDLINE 3Global:.MAKEOVERRIDES = FROM_CMDLINE
4Global:VAR = added 4Global:VAR = added
5Global:VAR = overwritten 5Global:VAR = overwritten
6Global:delete VAR 6Global:delete VAR
7Global:delete VAR (not found) 7Global:delete VAR (not found)
8Var_Parse: ${:U} with VARE_WANTRES 8Var_Parse: ${:U} with VARE_WANTRES
9Applying ${:U} to "" (VARE_WANTRES, none, VEF_UNDEF) 9Applying ${:U} to "" (VARE_WANTRES, none, VEF_UNDEF)
10Result of ${:U} is "" (VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 10Result of ${:U} is "" (VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
11Var_Set("${:U}", "empty name", ...) name expands to empty string - ignored 11Var_Set("${:U}", "empty name", ...) name expands to empty string - ignored
12Var_Parse: ${:U} with VARE_WANTRES 12Var_Parse: ${:U} with VARE_WANTRES
13Applying ${:U} to "" (VARE_WANTRES, none, VEF_UNDEF) 13Applying ${:U} to "" (VARE_WANTRES, none, VEF_UNDEF)
14Result of ${:U} is "" (VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 14Result of ${:U} is "" (VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
15Var_Append("${:U}", "empty name", ...) name expands to empty string - ignored 15Var_Append("${:U}", "empty name", ...) name expands to empty string - ignored
16Global:FROM_CMDLINE = overwritten ignored! 16Global:FROM_CMDLINE = overwritten ignored!
17Global:VAR = 1 17Global:VAR = 1
18Global:VAR = 1 2 18Global:VAR = 1 2
19Global:VAR = 1 2 3 19Global:VAR = 1 2 3
20Var_Parse: ${VAR:M[2]} with VARE_UNDEFERR|VARE_WANTRES 20Var_Parse: ${VAR:M[2]} with VARE_UNDEFERR|VARE_WANTRES
21Applying ${VAR:M...} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 21Applying ${VAR:M...} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
22Pattern[VAR] for [1 2 3] is [[2]] 22Pattern[VAR] for [1 2 3] is [[2]]
23ModifyWords: split "1 2 3" into 3 words 23ModifyWords: split "1 2 3" into 3 words
24VarMatch [1] [[2]] 24VarMatch [1] [[2]]
25VarMatch [2] [[2]] 25VarMatch [2] [[2]]
26VarMatch [3] [[2]] 26VarMatch [3] [[2]]
27Result of ${VAR:M[2]} is "2" (VARE_UNDEFERR|VARE_WANTRES, none, none) 27Result of ${VAR:M[2]} is "2" (VARE_UNDEFERR|VARE_WANTRES, none, none)
28Var_Parse: ${VAR:N[2]} with VARE_UNDEFERR|VARE_WANTRES 28Var_Parse: ${VAR:N[2]} with VARE_UNDEFERR|VARE_WANTRES
29Applying ${VAR:N...} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 29Applying ${VAR:N...} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
30Pattern[VAR] for [1 2 3] is [[2]] 30Pattern[VAR] for [1 2 3] is [[2]]
31ModifyWords: split "1 2 3" into 3 words 31ModifyWords: split "1 2 3" into 3 words
32Result of ${VAR:N[2]} is "1 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 32Result of ${VAR:N[2]} is "1 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
33Var_Parse: ${VAR:S,2,two,} with VARE_UNDEFERR|VARE_WANTRES 33Var_Parse: ${VAR:S,2,two,} with VARE_UNDEFERR|VARE_WANTRES
34Applying ${VAR:S...} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 34Applying ${VAR:S...} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
35Modifier part: "2" 35Modifier part: "2"
36Modifier part: "two" 36Modifier part: "two"
37ModifyWords: split "1 2 3" into 3 words 37ModifyWords: split "1 2 3" into 3 words
38Result of ${VAR:S,2,two,} is "1 two 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 38Result of ${VAR:S,2,two,} is "1 two 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
39Var_Parse: ${VAR:Q} with VARE_UNDEFERR|VARE_WANTRES 39Var_Parse: ${VAR:Q} with VARE_UNDEFERR|VARE_WANTRES
40Applying ${VAR:Q} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 40Applying ${VAR:Q} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
41QuoteMeta: [1\ 2\ 3] 41QuoteMeta: [1\ 2\ 3]
42Result of ${VAR:Q} is "1\ 2\ 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 42Result of ${VAR:Q} is "1\ 2\ 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
43Var_Parse: ${VAR:tu:tl:Q} with VARE_UNDEFERR|VARE_WANTRES 43Var_Parse: ${VAR:tu:tl:Q} with VARE_UNDEFERR|VARE_WANTRES
44Applying ${VAR:t...} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 44Applying ${VAR:t...} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
45Result of ${VAR:tu} is "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 45Result of ${VAR:tu} is "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
46Applying ${VAR:t...} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 46Applying ${VAR:t...} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
47Result of ${VAR:tl} is "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 47Result of ${VAR:tl} is "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
48Applying ${VAR:Q} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 48Applying ${VAR:Q} to "1 2 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
49QuoteMeta: [1\ 2\ 3] 49QuoteMeta: [1\ 2\ 3]
50Result of ${VAR:Q} is "1\ 2\ 3" (VARE_UNDEFERR|VARE_WANTRES, none, none) 50Result of ${VAR:Q} is "1\ 2\ 3" (VARE_UNDEFERR|VARE_WANTRES, none, none)
51Var_Parse: ${:Uvalue:${:UM*e}:Mvalu[e]} with VARE_UNDEFERR|VARE_WANTRES 51Var_Parse: ${:Uvalue:${:UM*e}:Mvalu[e]} with VARE_UNDEFERR|VARE_WANTRES
52Applying ${:U...} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF) 52Applying ${:U...} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF)
53Result of ${:Uvalue} is "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 53Result of ${:Uvalue} is "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
54Var_Parse: ${:UM*e}:Mvalu[e]} with VARE_UNDEFERR|VARE_WANTRES 54Var_Parse: ${:UM*e}:Mvalu[e]} with VARE_UNDEFERR|VARE_WANTRES
55Applying ${:U...} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF) 55Applying ${:U...} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF)
56Result of ${:UM*e} is "M*e" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 56Result of ${:UM*e} is "M*e" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
57Indirect modifier "M*e" from "${:UM*e}" 57Indirect modifier "M*e" from "${:UM*e}"
58Applying ${:M...} to "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 58Applying ${:M...} to "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
59Pattern[] for [value] is [*e] 59Pattern[] for [value] is [*e]
60ModifyWords: split "value" into 1 words 60ModifyWords: split "value" into 1 words
61VarMatch [value] [*e] 61VarMatch [value] [*e]
62Result of ${:M*e} is "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 62Result of ${:M*e} is "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
63Applying ${:M...} to "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 63Applying ${:M...} to "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
64Pattern[] for [value] is [valu[e]] 64Pattern[] for [value] is [valu[e]]
65ModifyWords: split "value" into 1 words 65ModifyWords: split "value" into 1 words
66VarMatch [value] [valu[e]] 66VarMatch [value] [valu[e]]
67Result of ${:Mvalu[e]} is "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 67Result of ${:Mvalu[e]} is "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
68Var_Parse: ${:UVAR} with VARE_WANTRES 68Var_Parse: ${:UVAR} with VARE_WANTRES
69Applying ${:U...} to "" (VARE_WANTRES, none, VEF_UNDEF) 69Applying ${:U...} to "" (VARE_WANTRES, none, VEF_UNDEF)
70Result of ${:UVAR} is "VAR" (VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 70Result of ${:UVAR} is "VAR" (VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
71Global:delete VAR 71Global:delete VAR
72Var_Parse: ${:Uvariable:unknown} with VARE_UNDEFERR|VARE_WANTRES 72Var_Parse: ${:Uvariable:unknown} with VARE_UNDEFERR|VARE_WANTRES
73Applying ${:U...} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF) 73Applying ${:U...} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF)
74Result of ${:Uvariable} is "variable" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 74Result of ${:Uvariable} is "variable" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
75Applying ${:u...} to "variable" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 75Applying ${:u...} to "variable" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
76make: Unknown modifier 'u' 76make: Unknown modifier 'u'
77Result of ${:unknown} is error (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF) 77Result of ${:unknown} is error (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
78make: "vardebug.mk" line 44: Malformed conditional (${:Uvariable:unknown}) 78make: "vardebug.mk" line 44: Malformed conditional (${:Uvariable:unknown})
79Var_Parse: ${UNDEFINED} with VARE_UNDEFERR|VARE_WANTRES 79Var_Parse: ${UNDEFINED} with VARE_UNDEFERR|VARE_WANTRES
80make: "vardebug.mk" line 53: Malformed conditional (${UNDEFINED}) 80make: "vardebug.mk" line 53: Malformed conditional (${UNDEFINED})
 81Global:delete .SHELL (not found)
 82Command:.SHELL = /bin/sh
 83Command:.SHELL = overwritten ignored (read-only)
81Global:.MAKEFLAGS = -r -k -d v -d 84Global:.MAKEFLAGS = -r -k -d v -d
82Global:.MAKEFLAGS = -r -k -d v -d 0 85Global:.MAKEFLAGS = -r -k -d v -d 0
83make: Fatal errors encountered -- cannot continue 86make: Fatal errors encountered -- cannot continue
84make: stopped in unit-tests 87make: stopped in unit-tests
85exit status 1 88exit status 1

cvs diff -r1.4 -r1.5 src/usr.bin/make/unit-tests/vardebug.mk (switch to unified diff)

--- src/usr.bin/make/unit-tests/vardebug.mk 2020/10/29 18:19:41 1.4
+++ src/usr.bin/make/unit-tests/vardebug.mk 2020/10/29 18:38:24 1.5
@@ -1,59 +1,64 @@ @@ -1,59 +1,64 @@
1# $NetBSD: vardebug.mk,v 1.4 2020/10/29 18:19:41 rillig Exp $ 1# $NetBSD: vardebug.mk,v 1.5 2020/10/29 18:38:24 rillig Exp $
2# 2#
3# Demonstrates the debugging output for var.c. 3# Demonstrates the debugging output for var.c.
4 4
5.MAKEFLAGS: -dv FROM_CMDLINE= 5.MAKEFLAGS: -dv FROM_CMDLINE=
6 6
7VAR= added # VarAdd 7VAR= added # VarAdd
8VAR= overwritten # Var_Set 8VAR= overwritten # Var_Set
9.undef VAR # Var_Delete (found) 9.undef VAR # Var_Delete (found)
10.undef VAR # Var_Delete (not found) 10.undef VAR # Var_Delete (not found)
11 11
12# The variable with the empty name cannot be set at all. 12# The variable with the empty name cannot be set at all.
13${:U}= empty name # Var_Set 13${:U}= empty name # Var_Set
14${:U}+= empty name # Var_Append 14${:U}+= empty name # Var_Append
15 15
16FROM_CMDLINE= overwritten # Var_Set (ignored) 16FROM_CMDLINE= overwritten # Var_Set (ignored)
17 17
18VAR= 1 18VAR= 1
19VAR+= 2 19VAR+= 2
20VAR+= 3 20VAR+= 3
21 21
22.if ${VAR:M[2]} # VarMatch 22.if ${VAR:M[2]} # VarMatch
23.endif 23.endif
24.if ${VAR:N[2]} # VarNoMatch (no debug output) 24.if ${VAR:N[2]} # VarNoMatch (no debug output)
25.endif 25.endif
26 26
27.if ${VAR:S,2,two,} # VarGetPattern 27.if ${VAR:S,2,two,} # VarGetPattern
28.endif 28.endif
29 29
30.if ${VAR:Q} # VarQuote 30.if ${VAR:Q} # VarQuote
31.endif 31.endif
32 32
33.if ${VAR:tu:tl:Q} # ApplyModifiers 33.if ${VAR:tu:tl:Q} # ApplyModifiers
34.endif 34.endif
35 35
36# ApplyModifiers, "Got ..." 36# ApplyModifiers, "Got ..."
37.if ${:Uvalue:${:UM*e}:Mvalu[e]} 37.if ${:Uvalue:${:UM*e}:Mvalu[e]}
38.endif 38.endif
39 39
40.undef ${:UVAR} # Var_Delete 40.undef ${:UVAR} # Var_Delete
41 41
42# When ApplyModifiers results in an error, this appears in the debug log 42# When ApplyModifiers results in an error, this appears in the debug log
43# as "is error", without surrounding quotes. 43# as "is error", without surrounding quotes.
44.if ${:Uvariable:unknown} 44.if ${:Uvariable:unknown}
45.endif 45.endif
46 46
47# XXX: The error message is "Malformed conditional", which is wrong. 47# XXX: The error message is "Malformed conditional", which is wrong.
48# The condition is syntactically fine, it just contains an undefined variable. 48# The condition is syntactically fine, it just contains an undefined variable.
49# 49#
50# There is a specialized error message for "Undefined variable", but as of 50# There is a specialized error message for "Undefined variable", but as of
51# 2020-08-08, that is not covered by any unit tests. It might even be 51# 2020-08-08, that is not covered by any unit tests. It might even be
52# unreachable. 52# unreachable.
53.if ${UNDEFINED} 53.if ${UNDEFINED}
54.endif 54.endif
55 55
 56# By default, .SHELL is not defined and thus can be set. As soon as it is
 57# accessed, it is initialized in the command line context (during VarFind),
 58# where it is set to read-only. Assigning to it is ignored.
 59.MAKEFLAGS: .SHELL=overwritten
 60
56.MAKEFLAGS: -d0 61.MAKEFLAGS: -d0
57 62
58all: 63all:
59 @: 64 @: