Home | History | Annotate | Line # | Download | only in unit-tests
cond-func.mk revision 1.12
      1  1.12  rillig # $NetBSD: cond-func.mk,v 1.12 2023/05/10 15:53:32 rillig Exp $
      2   1.1  rillig #
      3   1.1  rillig # Tests for those parts of the functions in .if conditions that are common
      4   1.1  rillig # among several functions.
      5   1.1  rillig #
      6  1.12  rillig # The below test uses the 'defined' function since it has no side-effects.
      7  1.12  rillig # The other functions would work equally well, except for 'empty', which
      8  1.12  rillig # parses its argument differently from the other functions.
      9  1.12  rillig #
     10   1.1  rillig 
     11   1.1  rillig DEF=			defined
     12   1.1  rillig ${:UA B}=		variable name with spaces
     13   1.1  rillig ${:UVAR(value)}=	variable name with parentheses
     14   1.6  rillig ${:UVAR{value}}=	variable name with balanced braces
     15   1.6  rillig 
     16   1.6  rillig # Really strange variable names must be given indirectly via another variable,
     17   1.6  rillig # so that no unbalanced braces appear in the top-level expression.
     18   1.6  rillig VARNAME_UNBALANCED_BRACES=	VAR{{{value
     19   1.6  rillig ${VARNAME_UNBALANCED_BRACES}=	variable name with unbalanced braces
     20   1.1  rillig 
     21   1.1  rillig .if !defined(DEF)
     22   1.4  rillig .  error
     23   1.1  rillig .endif
     24   1.1  rillig 
     25   1.3  rillig # Horizontal whitespace (space tab) after the opening parenthesis is ignored.
     26   1.1  rillig .if !defined( 	DEF)
     27   1.4  rillig .  error
     28   1.1  rillig .endif
     29   1.1  rillig 
     30   1.3  rillig # Horizontal whitespace (space tab) before the closing parenthesis is ignored.
     31   1.1  rillig .if !defined(DEF 	)
     32   1.4  rillig .  error
     33   1.1  rillig .endif
     34   1.1  rillig 
     35   1.1  rillig # The argument of a function must not directly contain whitespace.
     36   1.1  rillig .if !defined(A B)
     37   1.4  rillig .  error
     38   1.1  rillig .endif
     39   1.1  rillig 
     40   1.1  rillig # If necessary, the whitespace can be generated by a variable expression.
     41   1.1  rillig .if !defined(${:UA B})
     42   1.4  rillig .  error
     43   1.1  rillig .endif
     44   1.1  rillig 
     45   1.1  rillig # Characters that could be mistaken for operators must not appear directly
     46   1.1  rillig # in a function argument.  As with whitespace, these can be generated
     47   1.1  rillig # indirectly.
     48   1.1  rillig #
     49   1.1  rillig # It's not entirely clear why these characters are forbidden.
     50   1.1  rillig # The most plausible reason seems to be typo detection.
     51   1.1  rillig .if !defined(A&B)
     52   1.4  rillig .  error
     53   1.1  rillig .endif
     54   1.1  rillig .if !defined(A|B)
     55   1.4  rillig .  error
     56   1.1  rillig .endif
     57   1.1  rillig 
     58   1.1  rillig # Even parentheses may appear in variable names.
     59   1.1  rillig # They must be balanced though.
     60   1.1  rillig .if !defined(VAR(value))
     61   1.4  rillig .  error
     62   1.1  rillig .endif
     63   1.1  rillig 
     64   1.1  rillig # Braces do not have any special meaning when parsing arguments.
     65   1.1  rillig .if !defined(VAR{value})
     66   1.4  rillig .  error
     67   1.1  rillig .endif
     68   1.1  rillig 
     69   1.6  rillig # Braces do not have any special meaning when parsing arguments.
     70   1.6  rillig # They don't need to be balanced.
     71   1.6  rillig .if !defined(VAR{{{value)
     72   1.6  rillig .  error
     73   1.6  rillig .endif
     74   1.6  rillig 
     75   1.2  rillig # There may be spaces around the operators and parentheses, and even
     76   1.2  rillig # inside the parentheses.  The spaces inside the parentheses are not
     77  1.12  rillig # allowed for the 'empty' function (see cond-func-empty.mk), therefore
     78   1.2  rillig # they are typically omitted for the other functions as well.
     79   1.2  rillig .if ! defined ( DEF )
     80   1.2  rillig .  error
     81   1.2  rillig .endif
     82   1.2  rillig 
     83   1.5  rillig # The following condition is interpreted as defined(A) && defined(B).
     84   1.5  rillig # In lack of a function call expression, each kind of .if directive has a
     85   1.5  rillig # default function that is called when a bare word is parsed.  For the plain
     86   1.5  rillig # .if directive, this function is defined(); see "struct If ifs" in cond.c.
     87   1.5  rillig .if A&B
     88   1.5  rillig .  error
     89   1.5  rillig .endif
     90   1.5  rillig 
     91   1.7  rillig .if defined()
     92   1.7  rillig .  error
     93   1.7  rillig .else
     94   1.7  rillig .  info The empty variable is never defined.
     95   1.7  rillig .endif
     96   1.7  rillig 
     97  1.11  rillig # The plain word 'defined' is interpreted as 'defined(defined)', see
     98  1.11  rillig # CondParser_ComparisonOrLeaf.
     99   1.7  rillig # That variable is not defined (yet).
    100   1.7  rillig .if defined
    101   1.7  rillig .  error
    102   1.7  rillig .else
    103  1.11  rillig .  info A plain function name is parsed as defined(...).
    104   1.7  rillig .endif
    105   1.7  rillig 
    106  1.10  rillig # If a variable named 'defined' is actually defined, the bare word 'defined'
    107  1.10  rillig # is interpreted as 'defined(defined)', and the condition evaluates to true.
    108  1.10  rillig defined=	# defined but empty
    109   1.7  rillig .if defined
    110  1.11  rillig .  info A plain function name is parsed as defined(...).
    111   1.7  rillig .else
    112   1.7  rillig .  error
    113   1.7  rillig .endif
    114   1.7  rillig 
    115   1.7  rillig # A plain symbol name may start with one of the function names, in this case
    116   1.7  rillig # 'defined'.
    117   1.7  rillig .if defined-var
    118   1.7  rillig .  error
    119   1.7  rillig .else
    120   1.7  rillig .  info Symbols may start with a function name.
    121   1.7  rillig .endif
    122   1.7  rillig 
    123  1.10  rillig defined-var=	# defined but empty
    124   1.7  rillig .if defined-var
    125   1.7  rillig .  info Symbols may start with a function name.
    126   1.7  rillig .else
    127   1.7  rillig .  error
    128   1.7  rillig .endif
    129   1.7  rillig 
    130   1.8  rillig # Missing closing parenthesis when parsing the function argument.
    131   1.8  rillig .if defined(
    132   1.8  rillig .  error
    133   1.8  rillig .else
    134   1.8  rillig .  error
    135   1.8  rillig .endif
    136