Home | History | Annotate | Line # | Download | only in unit-tests
cond-func.mk revision 1.8
      1 # $NetBSD: cond-func.mk,v 1.8 2020/11/10 20:44:18 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 .if defined()
     90 .  error
     91 .else
     92 .  info The empty variable is never defined.
     93 .endif
     94 
     95 # The plain word 'defined' is interpreted as '!empty(defined)'.
     96 # That variable is not defined (yet).
     97 .if defined
     98 .  error
     99 .else
    100 .  info A plain function name is parsed as !empty(...).
    101 .endif
    102 
    103 # If a variable named 'defined' is actually defined and not empty, the plain
    104 # symbol 'defined' evaluates to true.
    105 defined=	non-empty
    106 .if defined
    107 .  info A plain function name is parsed as !empty(...).
    108 .else
    109 .  error
    110 .endif
    111 
    112 # A plain symbol name may start with one of the function names, in this case
    113 # 'defined'.
    114 .if defined-var
    115 .  error
    116 .else
    117 .  info Symbols may start with a function name.
    118 .endif
    119 
    120 defined-var=	non-empty
    121 .if defined-var
    122 .  info Symbols may start with a function name.
    123 .else
    124 .  error
    125 .endif
    126 
    127 # Missing closing parenthesis when parsing the function argument.
    128 .if defined(
    129 .  error
    130 .else
    131 .  error
    132 .endif
    133 
    134 all:
    135 	@:;
    136