summaryrefslogtreecommitdiffstats
path: root/config/makefiles/test
diff options
context:
space:
mode:
Diffstat (limited to 'config/makefiles/test')
-rw-r--r--config/makefiles/test/Makefile.in98
-rw-r--r--config/makefiles/test/check-arglist.mk100
-rw-r--r--config/makefiles/test/check-autotargets.mk84
-rw-r--r--config/makefiles/test/check_XinY.mk70
-rw-r--r--config/makefiles/test/moz.build6
5 files changed, 358 insertions, 0 deletions
diff --git a/config/makefiles/test/Makefile.in b/config/makefiles/test/Makefile.in
new file mode 100644
index 000000000..6c66d820e
--- /dev/null
+++ b/config/makefiles/test/Makefile.in
@@ -0,0 +1,98 @@
+# -*- makefile -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+STANDALONE_MAKEFILE := 1
+USE_AUTOTARGETS_MK = 1
+MAKEUTILS_UNIT_TEST = 1
+include $(topsrcdir)/config/makefiles/makeutils.mk
+
+dir-ts = .deps/test
+check-arglist = $(dir-ts)/arglist.ts
+check-autotargets = $(dir-ts)/autotargets_mk.ts
+check-XinY = $(dir-ts)/check_XinY_mk.ts
+check-tests =\
+ $(check-arglist) \
+ $(check-autotargets) \
+ $(check-XinY) \
+ $(NULL)
+
+
+##------------------_##
+##---] TARGETS [---##
+##------------------_##
+all::
+
+clean:
+ $(RM) $(check-tests)
+
+###########################################################################
+## Logic processed at compile time so be selective about when to test
+## $(MAKE) check VERBOSE=1
+ifneq ($(NULL),$(findstring check,$(MAKECMDGOALS))) #
+
+check-preqs =\
+ $(call mkdir_deps,$(dir-ts)) \
+ $(check-tests) \
+ $(NULL)
+
+check:: $(check-preqs)
+ @true
+
+
+ifdef VERBOSE #{ gmake check VERBOSE=1
+ $(info ===========================================================================)
+ $(info Running test: $(MAKECMDGOALS): pwd=$(CURDIR))
+ $(info ===========================================================================)
+endif #}
+
+ifndef requiredfunction
+ $(error requiredfunction is not defined)
+endif
+
+
+##################
+check-XinY-preqs=\
+ $(call mkdir_deps,$(dir-ts)) \
+ $(topsrcdir)/config/makefiles/makeutils.mk \
+ $(srcdir)/check_XinY.mk \
+ $(eval include $(srcdir)/check_XinY.mk) \
+ $(NULL)
+
+$(check-XinY): $(check-XinY-preqs)
+ @$(TOUCH) $@
+# </check-XinY.mk>
+
+
+###########################################################################
+## check-arglist.mk always invoked as a compile time test
+## maintain real file dependencies for use later on.
+check-arglist-preqs=\
+ $(call mkdir_deps,$(dir-ts)) \
+ $(topsrcdir)/config/makefiles/makeutils.mk \
+ $(srcdir)/check-arglist.mk \
+ $(eval include $(srcdir)/check-arglist.mk) \
+ $(NULL)
+
+$(check-arglist): $(check-arglist-preqs)
+ @$(TOUCH) $@
+# </check-arglist.mk>
+
+
+###########################################################################
+# <CHECK: autotargets.mk>
+check-autotargets-preqs=\
+ $(call mkdir_deps,$(dir-ts)) \
+ $(topsrcdir)/config/makefiles/makeutils.mk \
+ $(topsrcdir)/config/makefiles/autotargets.mk \
+ $(srcdir)/check-autotargets.mk \
+ $(eval include $(srcdir)/check-autotargets.mk) \
+ $(NULL)
+
+$(check-autotargets): $(check-autotargets-preqs)
+ @$(TOUCH) $@
+# </CHECK: autotargets.mk>
+
+endif #} findstring MAKECMDGOAL
diff --git a/config/makefiles/test/check-arglist.mk b/config/makefiles/test/check-arglist.mk
new file mode 100644
index 000000000..fb720ee42
--- /dev/null
+++ b/config/makefiles/test/check-arglist.mk
@@ -0,0 +1,100 @@
+# -*- makefile -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+ifdef VERBOSE
+ $(warning loading test)
+endif
+
+
+$(call requiredfunction,getargv)
+$(call requiredfunction,subargv)
+$(call requiredfunction,istype isval isvar)
+
+# arg_scalar = [scalar|literal]
+arg_list = foo bar
+arg_ref = arg_list
+
+## Identify type of function argument(s)
+########################################
+ifneq (scalar,$(call istype,arg_scalar))
+ $(error istype(arg_scalar)=scalar, found [$(call istype,arg_scalar)])
+endif
+ifneq (list,$(call istype,arg_list))
+ $(error istype(arg_list)=list, found [$(call istype,arg_list)])
+endif
+ifneq (list,$(call istype,arg_ref))
+ $(error istype(arg_ref)=list, found [$(call istype,arg_ref)])
+endif
+
+## Type == scalar or a list of values
+#####################################
+ifneq (true,$(call isval,scalar))
+ $(error isval(scalar)=true, found [$(call isval,scalar)])
+endif
+ifneq ($(NULL),$(call isval,arg_list))
+ $(error isval(arg_list)=null, found [$(call isval,arg_list)])
+endif
+
+## type == reference: macro=>macro => $($(1))
+#############################################
+ifneq ($(NULL),$(call isvar,scalar))
+ $(error isvar(scalar)=$(NULL), found [$(call isvar,scalar)])
+endif
+ifneq (true,$(call isvar,arg_list))
+ $(error isvar(arg_list)=true, found [$(call isvar,arg_list)])
+endif
+ifneq (true,$(call isvar,arg_ref))
+ $(error isvar(arg_ref)=true, found [$(call isvar,arg_ref)])
+endif
+
+# Verify getargv expansion
+##########################
+ifneq (scalar,$(call getargv,scalar))
+ $(error getargv(scalar)=scalar, found [$(call getargv,scalar)])
+endif
+ifneq ($(arg_list),$(call getargv,arg_list))
+ $(error getargv(arg_list)=list, found [$(call getargv,arg_list)])
+endif
+ifneq (arg_list,$(call getargv,arg_ref))
+ $(error getargv(arg_ref)=list, found [$(call getargv,arg_ref)])
+endif
+
+###########################################################################
+##
+###########################################################################
+ifdef MANUAL_TEST #{
+ # For automated testing a callback is needed that can set an external status
+ # variable that can be tested. Syntax is tricky to get correct functionality.
+ ifdef VERBOSE
+ $(info )
+ $(info ===========================================================================)
+ $(info Running test: checkIfEmpty)
+ $(info ===========================================================================)
+ endif
+
+ #status =
+ #setTRUE =status=true
+ #setFALSE =status=$(NULL)
+ #$(call checkIfEmpty,setFALSE NULL)
+ #$(if $(status),$(error checkIfEmpty(xyz) failed))
+ #$(call checkIfEmpty,setTRUE xyz)
+ #$(if $(status),$(error checkIfEmpty(xyz) failed))
+ xyz=abc
+ $(info STATUS: warnIfEmpty - two vars)
+ $(call warnIfEmpty,foo xyz bar)
+ $(info STATUS: errorIfEmpty - on first var)
+ $(call errorIfEmpty,foo xyz bar)
+ $(error TEST FAILED: processing should not reach this point)
+endif #}
+
+# Verify subargv expansion
+##########################
+subargs=foo bar tans fans
+subargs_exp=tans fans
+subargs_found=$(call subargv,4,$(subargs))
+ifneq ($(subargs_exp),$(subargs_found))
+ $(error subargv(4,$(subargs)): expected [$(subargs_exp)] found [$(subargs_found)])
+endif
diff --git a/config/makefiles/test/check-autotargets.mk b/config/makefiles/test/check-autotargets.mk
new file mode 100644
index 000000000..c103f1d02
--- /dev/null
+++ b/config/makefiles/test/check-autotargets.mk
@@ -0,0 +1,84 @@
+# -*- makefile -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+ifdef VERBOSE
+ $(warning loading test)
+endif
+
+space=$(null) $(null)
+GENERATED_DIRS = bogus # test data
+
+undefine USE_AUTOTARGETS_MK
+undefine INCLUDED_AUTOTARGETS_MK
+include $(topsrcdir)/config/makefiles/autotargets.mk
+
+ifndef INCLUDED_AUTOTARGETS_MK
+ $(error autotargets.mk was not included
+endif
+
+$(call requiredfunction,mkdir_deps)
+
+
+# Verify test data populated makefile vars correctly
+vars = AUTO_DEPS GARBAGE_DIRS GENERATED_DIRS_DEPS
+$(foreach var,$(vars),$(call errorIfEmpty,$(var)))
+
+# Data should also be valid
+ifneq (bogus,$(findstring bogus,$(AUTO_DEPS)))
+ $(error AUTO_DEPS=[$(AUTO_DEPS)] is not set correctly)
+endif
+
+
+# relpath
+path := foo/bar.c
+exp := foo/.mkdir.done
+found := $(call mkdir_deps,$(dir $(path)))
+ifneq ($(exp),$(found))
+ $(error mkdir_deps($(path))=$(exp) not set correctly [$(found)])
+endif
+
+# abspath
+path := /foo//bar/
+exp := /foo/bar/.mkdir.done
+found := $(call mkdir_deps,$(path))
+ifneq ($(exp),$(found))
+ $(error mkdir_deps($(path))=$(exp) not set correctly [$(found)])
+endif
+
+
+## verify strip_slash
+#####################
+
+path := a/b//c///d////e/////
+exp := a/b/c/d/e/.mkdir.done
+found := $(call mkdir_deps,$(path))
+ifneq ($(exp),$(found))
+ $(error mkdir_deps($(path))=$(exp) not set correctly [$(found)])
+endif
+
+
+## verify mkdir_stem()
+######################
+path := verify/mkdir_stem
+pathD = $(call mkdir_deps,$(path))
+pathS = $(call mkdir_stem,$(pathD))
+exp := $(path)
+
+ifeq ($(pathD),$(pathS))
+ $(error mkdir_deps and mkdir_stem should not match [$(pathD)])
+endif
+ifneq ($(pathS),$(exp))
+ $(error mkdir_stem=[$(pathS)] != exp=[$(exp)])
+endif
+
+
+## Verify embedded whitespace has been protected
+path := a/b$(space)c//d
+exp := a/b$(space)c/d
+found := $(call slash_strip,$(path))
+ifneq ($(exp),$(found))
+ $(error slash_strip($(path))=$(exp) not set correctly [$(found)])
+endif
diff --git a/config/makefiles/test/check_XinY.mk b/config/makefiles/test/check_XinY.mk
new file mode 100644
index 000000000..1e7a19f0e
--- /dev/null
+++ b/config/makefiles/test/check_XinY.mk
@@ -0,0 +1,70 @@
+# -*- makefile -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Verify dependencies are available
+$(call requiredfunction,getargv subargv is_XinY errorifneq)
+
+ifdef VERBOSE
+ $(warning loading test)
+endif
+
+zero := 0
+one := 1
+
+# Verify 'invalid' is not matched
+val := invalid
+$(call errorifneq,$(zero),$(words $(call is_XinY,foo,$(val))))
+$(call errorifneq,$(zero),$(words $(call is_XinY,clean,$(val))))
+$(call errorifneq,$(zero),$(words $(call is_XinY,clean%,$(val))))
+
+# verify strcmp('clean')
+val := clean
+$(call errorifneq,$(zero),$(words $(call is_XinY,foo,$(val))))
+$(call errorifneq,$(one),$(words $(call is_XinY,clean,$(val))))
+$(call errorifneq,$(one),$(words $(call is_XinY,clean%,$(val))))
+$(call errorifneq,$(one),$(words $(call is_XinY,%clean,$(val))))
+
+# List match for 'clean'
+val := blah clean distclean FcleanG clean-level-1
+wanted := clean distclean clean-level-1
+$(call errorifneq,$(zero),$(words $(call is_XinY_debug,foo,$(val))))
+$(call errorifneq,$(one),$(words $(call is_XinY,clean,$(val))))
+$(call errorifneq,$(one),$(words $(call is_XinY,distclean,$(val))))
+
+# pattern match 'clean'
+# match: clean, distclean, clean-level-1
+# exclude: FcleanG
+TEST_MAKECMDGOALS := $(val)
+$(call errorifneq,3,$(words $(call isTargetStemClean)))
+
+TEST_MAKECMDGOALS := invalid
+$(call errorifneq,$(zero),$(words $(call isTargetStemClean)))
+
+
+#############################
+ifdef VERBOSE
+ $(call banner,Unit test: isTargetStem)
+endif
+
+# Verify list argument processing
+TEST_MAKECMDGOALS := echo
+$(call errorifneq,$(one),$(words $(call isTargetStem,echo,show)))
+
+TEST_MAKECMDGOALS := echo-123
+$(call errorifneq,$(one),$(words $(call isTargetStem,echo,show)))
+
+TEST_MAKECMDGOALS := show
+$(call errorifneq,$(one),$(words $(call isTargetStem,echo,show)))
+
+TEST_MAKECMDGOALS := show-123
+$(call errorifneq,$(one),$(words $(call isTargetStem,echo,show)))
+
+TEST_MAKECMDGOALS := show-123-echo
+$(call errorifneq,$(one),$(words $(call isTargetStem,echo,show)))
+
+TEST_MAKECMDGOALS := invalid
+$(call errorifneq,$(zero),$(words $(call isTargetStem,echo,show)))
+
diff --git a/config/makefiles/test/moz.build b/config/makefiles/test/moz.build
new file mode 100644
index 000000000..28919c271
--- /dev/null
+++ b/config/makefiles/test/moz.build
@@ -0,0 +1,6 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+