xref: /freebsd/contrib/bmake/unit-tests/opt-debug-lint.mk (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1# $NetBSD: opt-debug-lint.mk,v 1.12 2020/12/20 19:10:53 rillig Exp $
2#
3# Tests for the -dL command line option, which runs additional checks
4# to catch common mistakes, such as unclosed variable 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.if $X
20.  error
21.endif
22
23# The dynamic variables like .TARGET are treated specially.  It does not make
24# sense to expand them in the global scope since they will never be defined
25# there under normal circumstances.  Therefore they expand to a string that
26# will later be expanded correctly, when the variable is evaluated again in
27# the scope of an actual target.
28#
29# Even though the "@" variable is not defined at this point, this is not an
30# error.  In all practical cases, this is no problem.  This particular test
31# case is made up and unrealistic.
32.if $@ != "\$(.TARGET)"
33.  error
34.endif
35
36# Since 2020-09-13, Var_Parse properly reports errors for undefined variables,
37# but only in lint mode.  Before, it had only silently returned var_Error,
38# hoping for the caller to print an error message.  This resulted in the
39# well-known "Malformed conditional" error message, even though the
40# conditional was well-formed and the only error was an undefined variable.
41.if ${UNDEF}
42.  error
43.endif
44
45# Since 2020-09-14, dependency lines may contain undefined variables.
46# Before, undefined variables were forbidden, but this distinction was not
47# observable from the outside of the function Var_Parse.
48${UNDEF}: ${UNDEF}
49
50# In a condition that has a defined(UNDEF) guard, all guarded conditions
51# may assume that the variable is defined since they will only be evaluated
52# if the variable is indeed defined.  Otherwise they are only parsed, and
53# for parsing it doesn't make a difference whether the variable is defined
54# or not.
55.if defined(UNDEF) && exists(${UNDEF})
56.  error
57.endif
58
59# Since 2020-10-03, in lint mode the variable modifier must be separated
60# by colons.  See varparse-mod.mk.
61.if ${value:LPL} != "value"
62.  error
63.endif
64
65# Between 2020-10-03 and var.c 1.752 from 2020-12-20, in lint mode the
66# variable modifier had to be separated by colons.  This was wrong though
67# since make always fell back trying to parse the indirect modifier as a
68# SysV modifier.
69.if ${value:${:UL}PL} != "LPL}"		# FIXME: "LPL}" is unexpected here.
70.  error ${value:${:UL}PL}
71.endif
72
73# Typically, an indirect modifier is followed by a colon or the closing
74# brace.  This one isn't, therefore make falls back to parsing it as the SysV
75# modifier ":lue=lid".
76.if ${value:L:${:Ulue}=${:Ulid}} != "valid"
77.  error
78.endif
79
80all:
81	@:;
82