aboutsummaryrefslogtreecommitdiffstats
path: root/test/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'test/Makefile')
-rw-r--r--test/Makefile173
1 files changed, 131 insertions, 42 deletions
diff --git a/test/Makefile b/test/Makefile
index 59063e6..ba612fa 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,72 +1,161 @@
+# Copyright (c) 2015, Loïc Hoguin <[email protected]>
# Copyright (c) 2014, Viktor Söderqvist <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
-# Tests for erlang.mk targets. If any test fails or if you run a target other
-# than 'all', you must probably do 'make clean' before you can test again.
+# Temporary application name, taken from rule name.
+
+APP = $(subst -,_,$@)
+APP_TO_CLEAN = $(subst -,_,$(patsubst clean-%,%,$@))
+
+# Erlang, quickly!
+
+ERL = erl +A0 -noinput -boot start_clean
+
+# Platform, condensed version.
+
+ifeq ($(shell uname -o),Msys)
+ PLATFORM = msys2
+else
+ PLATFORM = unix
+endif
+
+# OTP master, for downloading files for testing.
+
+OTP_MASTER = https://raw.githubusercontent.com/erlang/otp/master
# Verbosity.
+#
+# V=0: Show info messages only.
+# V=1: Show test commands.
+# V=2: Also show normal Erlang.mk output.
+# V=3: Also show verbose Erlang.mk output.
V ?= 0
-# Temporary files directory.
+# t: Verbosity control for tests.
+# v: Verbosity control for erlang.mk.
+# i: Command to display (or suppress) info messages.
-ERLANG_MK_TMP=$(CURDIR)/tmp
-export ERLANG_MK_TMP
-
-# t = Verbosity control for tests
-# v = Verbosity control for erlang.mk
-# i = Command to display (or suppress) info messages
ifeq ($V,0)
- # Show info messages only
t = @
v = V=0 >/dev/null 2>&1
- i = @echo
+ i = @echo $@:
else ifeq ($V,1)
- # Show test commands
t =
v = V=0 >/dev/null 2>&1
- i = @echo ==
+ i = @echo == $@:
else ifeq ($V,2)
- # Show briefly what erlang.mk is doing
t = @echo " TEST " $@;
v = V=0
- i = @echo ==
+ i = @echo == $@:
else
- # Show all commands with maximum verbosity
t =
v = V=1
- i = @echo ==
+ i = @echo == $@:
endif
-.PHONY: all clean app ct eunit tests-cover docs
+# Main targets.
-.NOTPARALLEL:
+.PHONY: all clean build
-all: clean app ct eunit tests-cover docs pkgs
- $i '+---------------------+'
- $i '| All tests passed. |'
- $i '+---------------------+'
+all:: core
-clean:
- $t rm -rf app1 pkgs.log $(ERLANG_MK_TMP)
+clean:: clean-core
+ $t rm -f erl_crash.dump
-app: app1
- $i "app: Testing the 'app' target."
- $t $(MAKE) -C app1 app $v
- $i "Checking the modules line in the generated .app file."
- $t [ `grep -E "{modules, *\['m'\]}" app1/ebin/app1.app | wc -l` -eq 1 ]
- $t [ -e app1/ebin/m.beam ]
- $i "Checking that '$(MAKE) clean-app' deletes ebin."
- $t $(MAKE) -C app1 clean-app $v
- $t [ ! -e app1/ebin ]
- $i "Checking that '$(MAKE) app' returns non-zero on compile errors."
- $t printf "%s\n" \
- "-module(syntax_error)." \
- "foo lorem_ipsum dolor sit amet." \
- > app1/src/syntax_error.erl
- $t if $(MAKE) -C app1 app $v ; then false ; fi
- $t rm app1/src/syntax_error.erl
- $i "Test 'app' passed."
+build:
+ $i "Generate a bleeding edge Erlang.mk"
+ $t cd .. && $(MAKE) $v
+
+# Core.
+
+.PHONY: core clean-core
+
+define include_core
+core:: core-$1
+clean-core:: clean-core-$1
+
+include core_$1.mk
+
+endef
+
+$(eval $(foreach t,$(patsubst %.mk,%,$(patsubst core_%,%,$(wildcard core_*.mk))),$(call include_core,$t)))
+
+# Plugins.
+
+define include_plugin
+all:: $1
+clean:: clean-$1
+
+include plugin_$1.mk
+
+endef
+
+$(eval $(foreach t,$(patsubst %.mk,%,$(patsubst plugin_%,%,$(wildcard plugin_*.mk))),$(call include_plugin,$t)))
+
+# Tests that don't easily fit into other categories.
+
+core:: core-clean-crash-dump core-distclean-tmp core-help
+clean-core:: clean-core-clean-crash-dump clean-core-distclean-tmp clean-core-help
+
+.PHONY: core-clean-crash-dump core-distclean-tmp core-help clean-core-clean-crash-dump clean-core-distclean-tmp clean-core-help
+
+clean-core-clean-crash-dump clean-core-distclean-tmp clean-core-help:
+ $t rm -rf $(APP_TO_CLEAN)/
+
+core-clean-crash-dump: build clean-core-clean-crash-dump
+
+ $i "Bootstrap a new OTP library named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+
+ $i "Create a fake erl_crash.dump file"
+ $t touch $(APP)/erl_crash.dump
+
+ $i "Clean the application"
+ $t $(MAKE) -C $(APP) clean $v
+
+ $i "Check that the crash dump is removed"
+ $t test ! -e $(APP)/erl_crash.dump
+
+core-distclean-tmp: build clean-core-distclean-tmp
+
+ $i "Bootstrap a new OTP application named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap all $v
+
+ $i "Check that a .erlang.mk directory exists"
+ $t test -d $(APP)/.erlang.mk
+
+ $i "Distclean the application"
+ $t $(MAKE) -C $(APP) distclean $v
+
+ $i "Check if .erlang.mk directory got removed"
+ $t test ! -e $(APP)/.erlang.mk
+
+core-help: build clean-core-help
+
+ $i "Bootstrap a new OTP library named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+
+ $i "Run 'make help' and check that it prints help"
+ $t test -n "`$(MAKE) -C $(APP) help` | grep Usage"
+
+# Legacy tests.
+#
+# The following tests are slowly being converted.
+# Do NOT use -j with legacy tests.
+
+.PHONY: legacy clean-legacy ct eunit tests-cover docs
+
+legacy: clean-legacy ct eunit tests-cover docs pkgs
+
+clean-legacy:
+ $t rm -rf app1 pkgs.log
ct: app1
$i "ct: Testing ct and related targets."