config/makefiles/test/check-arglist.mk

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/config/makefiles/test/check-arglist.mk	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +# -*- makefile -*-
     1.5 +#
     1.6 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 +# You can obtain one at http://mozilla.org/MPL/2.0/.
     1.9 +
    1.10 +ifdef VERBOSE
    1.11 +  $(warning loading test)
    1.12 +endif
    1.13 +
    1.14 +
    1.15 +$(call requiredfunction,getargv)
    1.16 +$(call requiredfunction,subargv)
    1.17 +$(call requiredfunction,istype isval isvar)
    1.18 +
    1.19 +# arg_scalar = [scalar|literal]
    1.20 +arg_list = foo bar
    1.21 +arg_ref  = arg_list
    1.22 +
    1.23 +## Identify type of function argument(s)
    1.24 +########################################
    1.25 +ifneq (scalar,$(call istype,arg_scalar))
    1.26 +  $(error istype(arg_scalar)=scalar, found [$(call istype,arg_scalar)])
    1.27 +endif
    1.28 +ifneq (list,$(call istype,arg_list))
    1.29 +  $(error istype(arg_list)=list, found [$(call istype,arg_list)])
    1.30 +endif
    1.31 +ifneq (list,$(call istype,arg_ref))
    1.32 +  $(error istype(arg_ref)=list, found [$(call istype,arg_ref)])
    1.33 +endif
    1.34 +
    1.35 +## Type == scalar or a list of values
    1.36 +#####################################
    1.37 +ifneq (true,$(call isval,scalar))
    1.38 +  $(error isval(scalar)=true, found [$(call isval,scalar)])
    1.39 +endif
    1.40 +ifneq ($(NULL),$(call isval,arg_list))
    1.41 +  $(error isval(arg_list)=null, found [$(call isval,arg_list)])
    1.42 +endif
    1.43 +
    1.44 +## type == reference: macro=>macro => $($(1))
    1.45 +#############################################
    1.46 +ifneq ($(NULL),$(call isvar,scalar))
    1.47 +  $(error isvar(scalar)=$(NULL), found [$(call isvar,scalar)])
    1.48 +endif
    1.49 +ifneq (true,$(call isvar,arg_list))
    1.50 +  $(error isvar(arg_list)=true, found [$(call isvar,arg_list)])
    1.51 +endif
    1.52 +ifneq (true,$(call isvar,arg_ref))
    1.53 +  $(error isvar(arg_ref)=true, found [$(call isvar,arg_ref)])
    1.54 +endif
    1.55 +
    1.56 +# Verify getargv expansion
    1.57 +##########################
    1.58 +ifneq (scalar,$(call getargv,scalar))
    1.59 +  $(error getargv(scalar)=scalar, found [$(call getargv,scalar)])
    1.60 +endif
    1.61 +ifneq ($(arg_list),$(call getargv,arg_list))
    1.62 +  $(error getargv(arg_list)=list, found [$(call getargv,arg_list)])
    1.63 +endif
    1.64 +ifneq (arg_list,$(call getargv,arg_ref))
    1.65 +  $(error getargv(arg_ref)=list, found [$(call getargv,arg_ref)])
    1.66 +endif
    1.67 +
    1.68 +###########################################################################
    1.69 +##
    1.70 +###########################################################################
    1.71 +ifdef MANUAL_TEST #{
    1.72 +  # For automated testing a callback is needed that can set an external status
    1.73 +  # variable that can be tested.  Syntax is tricky to get correct functionality.
    1.74 +  ifdef VERBOSE
    1.75 +    $(info )
    1.76 +    $(info ===========================================================================)
    1.77 +    $(info Running test: checkIfEmpty)
    1.78 +    $(info ===========================================================================)
    1.79 +  endif
    1.80 +
    1.81 +  #status =
    1.82 +  #setTRUE =status=true
    1.83 +  #setFALSE =status=$(NULL)
    1.84 +  #$(call checkIfEmpty,setFALSE NULL)
    1.85 +  #$(if $(status),$(error checkIfEmpty(xyz) failed))
    1.86 +  #$(call checkIfEmpty,setTRUE xyz)
    1.87 +  #$(if $(status),$(error checkIfEmpty(xyz) failed))
    1.88 +  xyz=abc
    1.89 +  $(info STATUS: warnIfEmpty - two vars)
    1.90 +  $(call warnIfEmpty,foo xyz bar)
    1.91 +  $(info STATUS: errorIfEmpty - on first var)
    1.92 +  $(call errorIfEmpty,foo xyz bar)
    1.93 +  $(error TEST FAILED: processing should not reach this point)
    1.94 +endif #}
    1.95 +
    1.96 +# Verify subargv expansion
    1.97 +##########################
    1.98 +subargs=foo bar tans fans
    1.99 +subargs_exp=tans fans
   1.100 +subargs_found=$(call subargv,4,$(subargs))
   1.101 +ifneq ($(subargs_exp),$(subargs_found))
   1.102 +  $(error subargv(4,$(subargs)): expected [$(subargs_exp)] found [$(subargs_found)])
   1.103 +endif

mercurial