Home | History | Annotate | Line # | Download | only in unit-tests
      1 # $NetBSD: opt-debug-lint.mk,v 1.25 2025/06/28 22:39:29 rillig Exp $
      2 #
      3 # Tests for the -dL command line option, which runs additional checks
      4 # to catch common mistakes, such as unclosed expressions.
      5 
      6 .MAKEFLAGS: -dL
      7 
      8 # Since 2020-09-13, undefined variables that are used on the left-hand side
      9 # of a condition at parse time get a proper error message.  Before, the
     10 # error message was "Malformed conditional" only, which was wrong and
     11 # misleading.  The form of the condition is totally fine, it's the evaluation
     12 # that fails.
     13 #
     14 # Since 2020-09-13, the "Malformed conditional" error message is not printed
     15 # anymore.
     16 #
     17 # See also:
     18 #	cond-undef-lint.mk
     19 # expect+1: Variable "X" is undefined
     20 .if $X
     21 .  error
     22 .endif
     23 
     24 # The dynamic variables like .TARGET are treated specially.  It does not make
     25 # sense to expand them in the global scope since they will never be defined
     26 # there under normal circumstances.  Therefore they expand to a string that
     27 # will later be expanded correctly, when the variable is evaluated again in
     28 # the scope of an actual target.
     29 #
     30 # Even though the "@" variable is not defined at this point, this is not an
     31 # error.  In all practical cases, this is no problem.  This particular test
     32 # case is made up and unrealistic.
     33 .if $@ != "\$(.TARGET)"
     34 .  error
     35 .endif
     36 
     37 # Since 2020-09-13, Var_Parse properly reports errors for undefined variables,
     38 # but only in lint mode.  Before, it had only silently returned var_Error,
     39 # hoping for the caller to print an error message.  This resulted in the
     40 # well-known "Malformed conditional" error message, even though the
     41 # conditional was well-formed and the only error was an undefined variable.
     42 # expect+1: Variable "UNDEF" is undefined
     43 .if ${UNDEF}
     44 .  error
     45 .endif
     46 
     47 # Since 2020-09-14, dependency lines may contain undefined variables.
     48 # Before, undefined variables were forbidden, but this distinction was not
     49 # observable from the outside of the function Var_Parse.
     50 ${UNDEF}: ${UNDEF}
     51 
     52 # In a condition that has a defined(UNDEF) guard, all guarded conditions
     53 # may assume that the variable is defined since they will only be evaluated
     54 # if the variable is indeed defined.  Otherwise they are only parsed, and
     55 # for parsing it doesn't make a difference whether the variable is defined
     56 # or not.
     57 .if defined(UNDEF) && exists(${UNDEF})
     58 .  error
     59 .endif
     60 
     61 # Since 2020-10-03, in lint mode the variable modifier must be separated
     62 # by colons.  See varparse-mod.mk.
     63 # expect+2: Missing delimiter ":" after modifier "L"
     64 # expect+1: Missing delimiter ":" after modifier "P"
     65 .if ${value:LPL} != "value"
     66 .  error
     67 .endif
     68 
     69 # Between 2020-10-03 and var.c 1.752 from 2020-12-20, in lint mode the
     70 # variable modifier had to be separated by colons.  This was wrong though
     71 # since make always fell back trying to parse the indirect modifier as a
     72 # SysV modifier.
     73 # expect+1: Unknown modifier ":${"
     74 .if ${value:${:UL}PL} != ""
     75 .  error ${value:${:UL}PL}
     76 .else
     77 .  error
     78 .endif
     79 
     80 # Typically, an indirect modifier is followed by a colon or the closing
     81 # brace.  This one isn't, therefore make falls back to parsing it as the SysV
     82 # modifier ":lue=lid".
     83 .if ${value:L:${:Ulue}=${:Ulid}} != "valid"
     84 .  error
     85 .endif
     86 
     87 # In lint mode, the whole variable text is evaluated to check for unclosed
     88 # expressions and unknown operators.  During this check, the subexpression
     89 # '${:U2}' is not expanded, instead it is copied verbatim into the regular
     90 # expression, leading to '.*=.{1,${:U2}}$'.
     91 #
     92 # Before var.c 1.856 from 2021-03-14, this regular expression was then
     93 # compiled even though that was not necessary for checking the syntax at the
     94 # level of expressions.  The unexpanded '$' then resulted in a wrong
     95 # error message.
     96 #
     97 # This only happened in lint mode since in default mode the early check for
     98 # unclosed expressions and unknown modifiers is skipped.
     99 #
    100 # See VarCheckSyntax, ApplyModifier_Regex.
    101 #
    102 VARMOD_REGEX=	${:UA=111 B=222 C=33:C/.*=.{1,${:U2}}$//g}
    103