Home | History | Annotate | Line # | Download | only in unit-tests
varmisc.mk revision 1.9
      1 # $Id: varmisc.mk,v 1.9 2020/07/01 18:02:26 sjg Exp $
      2 #
      3 # Miscellaneous variable tests.
      4 
      5 all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \
      6 	strftime cmpv manok
      7 
      8 unmatched_var_paren:
      9 	@echo ${foo::=foo-text}
     10 
     11 True = ${echo true >&2:L:sh}TRUE
     12 False= ${echo false >&2:L:sh}FALSE
     13 
     14 VSET= is set
     15 .undef UNDEF
     16 
     17 U_false:
     18 	@echo :U skipped when var set
     19 	@echo ${VSET:U${False}}
     20 
     21 D_false:
     22 	@echo :D skipped if var undef
     23 	@echo ${UNDEF:D${False}}
     24 
     25 U_true:
     26 	@echo :U expanded when var undef
     27 	@echo ${UNDEF:U${True}}
     28 
     29 D_true:
     30 	@echo :D expanded when var set
     31 	@echo ${VSET:D${True}}
     32 
     33 Q_lhs:
     34 	@echo :? only lhs when value true
     35 	@echo ${1:L:?${True}:${False}}
     36 
     37 Q_rhs:
     38 	@echo :? only rhs when value false
     39 	@echo ${0:L:?${True}:${False}}
     40 
     41 NQ_none:
     42 	@echo do not evaluate or expand :? if discarding
     43 	@echo ${VSET:U${1:L:?${True}:${False}}}
     44 
     45 April1= 1459494000
     46 
     47 # slightly contorted syntax to use utc via variable
     48 strftime:
     49 	@echo ${year=%Y month=%m day=%d:L:gmtime=1459494000}
     50 	@echo date=${%Y%m%d:L:${gmtime=${April1}:L}}
     51 
     52 # big jumps to handle 3 digits per step
     53 M_cmpv.units = 1 1000 1000000
     54 M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
     55 
     56 Version = 123.456.789
     57 cmpv.only = target specific vars
     58 
     59 cmpv:
     60 	@echo Version=${Version} == ${Version:${M_cmpv}}
     61 	@echo Literal=3.4.5 == ${3.4.5:L:${M_cmpv}}
     62 	@echo We have ${${.TARGET:T}.only}
     63 
     64 # catch misshandling of nested vars in .for loop
     65 MAN=
     66 MAN1= make.1
     67 .for s in 1 2
     68 .if defined(MAN$s) && !empty(MAN$s)
     69 MAN+= ${MAN$s}
     70 .endif
     71 .endfor
     72 
     73 manok:
     74 	@echo MAN=${MAN}
     75