Home | History | Annotate | Line # | Download | only in unit-tests
cond-func.mk revision 1.6
      1 # $NetBSD: cond-func.mk,v 1.6 2020/11/08 21:40:13 rillig Exp $
      2 #
      3 # Tests for those parts of the functions in .if conditions that are common
      4 # among several functions.
      5 #
      6 # The below test uses the function defined(...) since it has no side-effects,
      7 # the other functions (except empty(...)) would work equally well.
      8 
      9 DEF=			defined
     10 ${:UA B}=		variable name with spaces
     11 ${:UVAR(value)}=	variable name with parentheses
     12 ${:UVAR{value}}=	variable name with balanced braces
     13 
     14 # Really strange variable names must be given indirectly via another variable,
     15 # so that no unbalanced braces appear in the top-level expression.
     16 VARNAME_UNBALANCED_BRACES=	VAR{{{value
     17 ${VARNAME_UNBALANCED_BRACES}=	variable name with unbalanced braces
     18 
     19 .if !defined(DEF)
     20 .  error
     21 .endif
     22 
     23 # Horizontal whitespace (space tab) after the opening parenthesis is ignored.
     24 .if !defined( 	DEF)
     25 .  error
     26 .endif
     27 
     28 # Horizontal whitespace (space tab) before the closing parenthesis is ignored.
     29 .if !defined(DEF 	)
     30 .  error
     31 .endif
     32 
     33 # The argument of a function must not directly contain whitespace.
     34 .if !defined(A B)
     35 .  error
     36 .endif
     37 
     38 # If necessary, the whitespace can be generated by a variable expression.
     39 .if !defined(${:UA B})
     40 .  error
     41 .endif
     42 
     43 # Characters that could be mistaken for operators must not appear directly
     44 # in a function argument.  As with whitespace, these can be generated
     45 # indirectly.
     46 #
     47 # It's not entirely clear why these characters are forbidden.
     48 # The most plausible reason seems to be typo detection.
     49 .if !defined(A&B)
     50 .  error
     51 .endif
     52 .if !defined(A|B)
     53 .  error
     54 .endif
     55 
     56 # Even parentheses may appear in variable names.
     57 # They must be balanced though.
     58 .if !defined(VAR(value))
     59 .  error
     60 .endif
     61 
     62 # Braces do not have any special meaning when parsing arguments.
     63 .if !defined(VAR{value})
     64 .  error
     65 .endif
     66 
     67 # Braces do not have any special meaning when parsing arguments.
     68 # They don't need to be balanced.
     69 .if !defined(VAR{{{value)
     70 .  error
     71 .endif
     72 
     73 # There may be spaces around the operators and parentheses, and even
     74 # inside the parentheses.  The spaces inside the parentheses are not
     75 # allowed for the empty() function (see cond-func-empty.mk), therefore
     76 # they are typically omitted for the other functions as well.
     77 .if ! defined ( DEF )
     78 .  error
     79 .endif
     80 
     81 # The following condition is interpreted as defined(A) && defined(B).
     82 # In lack of a function call expression, each kind of .if directive has a
     83 # default function that is called when a bare word is parsed.  For the plain
     84 # .if directive, this function is defined(); see "struct If ifs" in cond.c.
     85 .if A&B
     86 .  error
     87 .endif
     88 
     89 all:
     90 	@:;
     91