Home | History | Annotate | Line # | Download | only in unit-tests
cond-token-string.mk revision 1.6
      1  1.6  rillig # $NetBSD: cond-token-string.mk,v 1.6 2022/05/08 06:57:00 rillig Exp $
      2  1.1  rillig #
      3  1.4  rillig # Tests for quoted string literals in .if conditions.
      4  1.4  rillig #
      5  1.4  rillig # See also:
      6  1.4  rillig #	cond-token-plain.mk
      7  1.4  rillig #		Covers string literals without quotes (called "bare words").
      8  1.1  rillig 
      9  1.1  rillig # TODO: Implementation
     10  1.1  rillig 
     11  1.3  rillig # Cover the code in CondParser_String that frees the memory after parsing
     12  1.3  rillig # a variable expression based on an undefined variable.
     13  1.3  rillig .if "" != "${:Uvalue:Z}"
     14  1.3  rillig .  error
     15  1.3  rillig .else
     16  1.3  rillig .  error
     17  1.3  rillig .endif
     18  1.3  rillig 
     19  1.3  rillig .if x${:Uvalue}
     20  1.3  rillig .  error
     21  1.3  rillig .else
     22  1.3  rillig .  info xvalue is not defined.
     23  1.3  rillig .endif
     24  1.3  rillig 
     25  1.3  rillig # The 'x' produces a "Malformed conditional" since the left-hand side of a
     26  1.3  rillig # comparison in an .if directive must be either a variable expression, a
     27  1.3  rillig # quoted string literal or a number that starts with a digit.
     28  1.3  rillig .if x${:Uvalue} == ""
     29  1.3  rillig .  error
     30  1.3  rillig .else
     31  1.3  rillig .  error
     32  1.3  rillig .endif
     33  1.3  rillig 
     34  1.3  rillig # In plain words, a '\' can be used to escape any character, just as in
     35  1.3  rillig # double-quoted string literals.  See CondParser_String.
     36  1.3  rillig .if \x${:Uvalue} == "xvalue"
     37  1.3  rillig .  info Expected.
     38  1.3  rillig .else
     39  1.3  rillig .  error
     40  1.3  rillig .endif
     41  1.3  rillig 
     42  1.4  rillig .MAKEFLAGS: -dc
     43  1.4  rillig 
     44  1.4  rillig # A string in quotes is checked whether it is not empty.
     45  1.4  rillig .if "UNDEF"
     46  1.4  rillig .  info The string literal "UNDEF" is not empty.
     47  1.4  rillig .else
     48  1.4  rillig .  error
     49  1.4  rillig .endif
     50  1.4  rillig 
     51  1.4  rillig # A space is not empty as well.
     52  1.4  rillig # This differs from many other places where whitespace is trimmed.
     53  1.4  rillig .if " "
     54  1.4  rillig .  info The string literal " " is not empty, even though it consists of $\
     55  1.4  rillig 	whitespace only.
     56  1.4  rillig .else
     57  1.4  rillig .  error
     58  1.4  rillig .endif
     59  1.4  rillig 
     60  1.4  rillig .if "${UNDEF}"
     61  1.4  rillig .  error
     62  1.4  rillig .else
     63  1.4  rillig .  info An undefined variable in quotes expands to an empty string, which $\
     64  1.4  rillig 	then evaluates to false.
     65  1.4  rillig .endif
     66  1.4  rillig 
     67  1.4  rillig .if "${:Uvalue}"
     68  1.4  rillig .  info A nonempty variable expression evaluates to true.
     69  1.4  rillig .else
     70  1.4  rillig .  error
     71  1.4  rillig .endif
     72  1.4  rillig 
     73  1.4  rillig .if "${:U}"
     74  1.4  rillig .  error
     75  1.4  rillig .else
     76  1.4  rillig .  info An empty variable evaluates to false.
     77  1.4  rillig .endif
     78  1.4  rillig 
     79  1.5  rillig # A non-empty string evaluates to true, no matter if it's a literal string or
     80  1.6  rillig # if it contains variable expressions.  The parentheses are not necessary for
     81  1.6  rillig # the parser, in this case their only purpose is to make the code harder to
     82  1.6  rillig # read for humans.
     83  1.5  rillig VAR=	value
     84  1.6  rillig .if ("${VAR}")
     85  1.5  rillig .else
     86  1.5  rillig .  error
     87  1.5  rillig .endif
     88  1.5  rillig 
     89  1.5  rillig # In the conditions in .if directives, the left-hand side of a comparison must
     90  1.5  rillig # be enclosed in quotes.  The right-hand side does not need to be enclosed in
     91  1.5  rillig # quotes.
     92  1.5  rillig .if "quoted" == quoted
     93  1.5  rillig .else
     94  1.5  rillig .  error
     95  1.5  rillig .endif
     96  1.5  rillig 
     97  1.4  rillig .MAKEFLAGS: -d0
     98  1.4  rillig 
     99  1.5  rillig all: .PHONY
    100