1*22619282SSimon J. Gerraty# $NetBSD: vardebug.mk,v 1.11 2024/07/05 19:47:22 rillig Exp $ 22c3632d1SSimon J. Gerraty# 32c3632d1SSimon J. Gerraty# Demonstrates the debugging output for var.c. 42c3632d1SSimon J. Gerraty 5956e45f6SSimon J. Gerraty.MAKEFLAGS: -dv FROM_CMDLINE= 62c3632d1SSimon J. Gerraty 7d5e0a182SSimon J. Gerraty# expect: Global: VAR = added 82c3632d1SSimon J. GerratyVAR= added # VarAdd 9d5e0a182SSimon J. Gerraty# expect: Global: VAR = overwritten 102c3632d1SSimon J. GerratyVAR= overwritten # Var_Set 11d5e0a182SSimon J. Gerraty# expect: Global: delete VAR 12d5e0a182SSimon J. Gerraty.undef VAR 13d5e0a182SSimon J. Gerraty# expect: Global: ignoring delete 'VAR' as it is not found 14d5e0a182SSimon J. Gerraty.undef VAR 152c3632d1SSimon J. Gerraty 162c3632d1SSimon J. Gerraty# The variable with the empty name cannot be set at all. 17d5e0a182SSimon J. Gerraty# expect: Global: ignoring ' = empty name' as the variable name '${:U}' expands to empty 182c3632d1SSimon J. Gerraty${:U}= empty name # Var_Set 19d5e0a182SSimon J. Gerraty# expect: Global: ignoring ' += empty name' as the variable name '${:U}' expands to empty 202c3632d1SSimon J. Gerraty${:U}+= empty name # Var_Append 212c3632d1SSimon J. Gerraty 222c3632d1SSimon J. GerratyFROM_CMDLINE= overwritten # Var_Set (ignored) 232c3632d1SSimon J. Gerraty 24d5e0a182SSimon J. Gerraty# expect: Global: VAR = 1 252c3632d1SSimon J. GerratyVAR= 1 26d5e0a182SSimon J. Gerraty# expect: Global: VAR = 1 2 272c3632d1SSimon J. GerratyVAR+= 2 28d5e0a182SSimon J. Gerraty# expect: Global: VAR = 1 2 3 292c3632d1SSimon J. GerratyVAR+= 3 302c3632d1SSimon J. Gerraty 31d5e0a182SSimon J. Gerraty# expect: Pattern for ':M' is "[2]" 32d5e0a182SSimon J. Gerraty# expect: Result of ${VAR:M[2]} is "2" 33956e45f6SSimon J. Gerraty.if ${VAR:M[2]} # ModifyWord_Match 342c3632d1SSimon J. Gerraty.endif 35d5e0a182SSimon J. Gerraty# expect: Pattern for ':N' is "[2]" 36d5e0a182SSimon J. Gerraty# expect: Result of ${VAR:N[2]} is "1 3" 37d5e0a182SSimon J. Gerraty.if ${VAR:N[2]} # ModifyWord_NoMatch 382c3632d1SSimon J. Gerraty.endif 392c3632d1SSimon J. Gerraty 40956e45f6SSimon J. Gerraty.if ${VAR:S,2,two,} # ParseModifierPart 412c3632d1SSimon J. Gerraty.endif 422c3632d1SSimon J. Gerraty 43d5e0a182SSimon J. Gerraty# expect: Result of ${VAR:Q} is "1\ 2\ 3" 442c3632d1SSimon J. Gerraty.if ${VAR:Q} # VarQuote 452c3632d1SSimon J. Gerraty.endif 462c3632d1SSimon J. Gerraty 472c3632d1SSimon J. Gerraty.if ${VAR:tu:tl:Q} # ApplyModifiers 482c3632d1SSimon J. Gerraty.endif 492c3632d1SSimon J. Gerraty 502c3632d1SSimon J. Gerraty# ApplyModifiers, "Got ..." 51d5e0a182SSimon J. Gerraty# expect: Result of ${:Mvalu[e]} is "value" (eval-defined, defined) 522c3632d1SSimon J. Gerraty.if ${:Uvalue:${:UM*e}:Mvalu[e]} 532c3632d1SSimon J. Gerraty.endif 542c3632d1SSimon J. Gerraty 55d5e0a182SSimon J. Gerraty# expect: Global: delete VAR 562c3632d1SSimon J. Gerraty.undef ${:UVAR} # Var_Delete 572c3632d1SSimon J. Gerraty 582c3632d1SSimon J. Gerraty# When ApplyModifiers results in an error, this appears in the debug log 592c3632d1SSimon J. Gerraty# as "is error", without surrounding quotes. 60d5e0a182SSimon J. Gerraty# expect: Result of ${:unknown} is error (eval-defined, defined) 61148ee845SSimon J. Gerraty# expect+2: Malformed conditional (${:Uvariable:unknown}) 62*22619282SSimon J. Gerraty# expect+1: while evaluating "${:Uvariable:unknown}" with value "variable": Unknown modifier "unknown" 632c3632d1SSimon J. Gerraty.if ${:Uvariable:unknown} 642c3632d1SSimon J. Gerraty.endif 652c3632d1SSimon J. Gerraty 662c3632d1SSimon J. Gerraty# XXX: The error message is "Malformed conditional", which is wrong. 672c3632d1SSimon J. Gerraty# The condition is syntactically fine, it just contains an undefined variable. 682c3632d1SSimon J. Gerraty# 692c3632d1SSimon J. Gerraty# There is a specialized error message for "Undefined variable", but as of 702c3632d1SSimon J. Gerraty# 2020-08-08, that is not covered by any unit tests. It might even be 712c3632d1SSimon J. Gerraty# unreachable. 72148ee845SSimon J. Gerraty# expect+1: Malformed conditional (${UNDEFINED}) 732c3632d1SSimon J. Gerraty.if ${UNDEFINED} 742c3632d1SSimon J. Gerraty.endif 752c3632d1SSimon J. Gerraty 76956e45f6SSimon J. Gerraty# By default, .SHELL is not defined and thus can be set. As soon as it is 77dba7b0efSSimon J. Gerraty# accessed, it is initialized in the command line scope (during VarFind), 78956e45f6SSimon J. Gerraty# where it is set to read-only. Assigning to it is ignored. 79d5e0a182SSimon J. Gerraty# expect: Command: ignoring '.SHELL = overwritten' as it is read-only 80956e45f6SSimon J. Gerraty.MAKEFLAGS: .SHELL=overwritten 81956e45f6SSimon J. Gerraty 82956e45f6SSimon J. Gerraty.MAKEFLAGS: -d0 83