aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-09-26 14:41:56 +0200
committerLoïc Hoguin <[email protected]>2015-09-26 14:41:56 +0200
commit0f78319fd528236a0fd7d152870e77248cfc5891 (patch)
tree05452461c84f7acd477525ea759570b1a7a6ed08
parentc1131f4f7420d009c8a05e5de9dd0888127aa0aa (diff)
downloaderlang.mk-0f78319fd528236a0fd7d152870e77248cfc5891.tar.gz
erlang.mk-0f78319fd528236a0fd7d152870e77248cfc5891.tar.bz2
erlang.mk-0f78319fd528236a0fd7d152870e77248cfc5891.zip
Make tests work on more systems
Some systems do not have subsecond file modification detection capabilities. This is the case in OSX because the HFS+ file system has 1 second resolution. This is also the case in other OSes with particular file systems or even shells. For example, the "test" command in Bash does not support subsecond file times, while the ZSH one and the /usr/bin/test on my machine does. On those systems, with Bash, find -newer will work, but not test -nt. Tests were updated to reflect this. The test Makefile runs a series of commands to determine if subsecond resolution is available. When it is not, a sleep command will be executed before relevant operations in the tests. Because the Bash shell is often the default shell for Make, and because users of ZSH may want to avoid sleeping for no reasons, a new variable was introduced: ZSH=1. When provided when running tests, the shell will be switched to ZSH, and subsecond resolution will work as expected. Tests have been fixed to work with ZSH as well. All this only applies to tests, Erlang.mk itself is so far not affected by this issue.
-rw-r--r--test/Makefile30
-rw-r--r--test/core_app.mk32
-rw-r--r--test/core_compat.mk8
-rw-r--r--test/core_deps.mk24
4 files changed, 74 insertions, 20 deletions
diff --git a/test/Makefile b/test/Makefile
index ba612fa..fffc171 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -2,6 +2,14 @@
# Copyright (c) 2014, Viktor Söderqvist <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
+# ZSH users have a more modern shell which doesn't need to
+# have the same safeguards as other shells. To use ZSH instead
+# of the default shell, set ZSH=1.
+
+ifdef ZSH
+SHELL := $(shell which zsh)
+endif
+
# Temporary application name, taken from rule name.
APP = $(subst -,_,$@)
@@ -19,6 +27,24 @@ else
PLATFORM = unix
endif
+# Some systems do not have sub-second file times resolution.
+# This is the case for older systems like OSX that uses the HFS+
+# file system. HFS+ has a 1 second time resolution. This is a
+# problem because the Erlang.mk tests rely on file modification
+# times to ensure files were rebuilt. To fix this issue, we
+# detect here whether the system supports sub-second resolution,
+# and maybe sleep during test execution.
+#
+# Also see:
+# * http://arstechnica.com/apple/2011/07/mac-os-x-10-7/12/#hfs-problems
+# * https://apple.stackexchange.com/questions/51650/linus-torvalds-and-the-os-x-filesystem
+
+ifeq ($(shell touch a; sleep 0.01; touch b; sleep 0.01; touch c; test c -nt b -a b -nt a; echo $$?; rm a b c),1)
+SLEEP = sleep 1
+else
+SLEEP =
+endif
+
# OTP master, for downloading files for testing.
OTP_MASTER = https://raw.githubusercontent.com/erlang/otp/master
@@ -47,11 +73,11 @@ else ifeq ($V,1)
else ifeq ($V,2)
t = @echo " TEST " $@;
v = V=0
- i = @echo == $@:
+ i = @echo "== $@:"
else
t =
v = V=1
- i = @echo == $@:
+ i = @echo "== $@:"
endif
# Main targets.
diff --git a/test/core_app.mk b/test/core_app.mk
index 84c6588..ffa14a4 100644
--- a/test/core_app.mk
+++ b/test/core_app.mk
@@ -69,7 +69,9 @@ core-app-asn1: build clean-core-app-asn1
$(APP)/include/CAP.hrl \
$(APP)/src/CAP.erl \
$(APP)/src/use_cap.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/asn1/CAP.asn1
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/asn1/CAP.asn1 | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -322,7 +324,9 @@ core-app-generate-erl: build clean-core-app-generate-erl
$(APP)/ebin/$(APP).app \
$(APP)/ebin/generated.beam \
$(APP)/src/generated.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/script.sh
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/script.sh | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -430,7 +434,9 @@ core-app-generate-erl-include: build clean-core-app-generate-erl-include
$(APP)/ebin/$(APP).app \
$(APP)/ebin/generated.beam \
$(APP)/src/generated.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/include/included.hrl
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/include/included.hrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -489,7 +495,9 @@ core-app-generate-erl-prepend: build clean-core-app-generate-erl-prepend
$(APP)/ebin/$(APP).app \
$(APP)/ebin/generated.beam \
$(APP)/src/generated.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/script.sh
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/script.sh | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -589,7 +597,9 @@ core-app-hrl: build clean-core-app-hrl
$(APP)/ebin/$(APP).app \
$(APP)/ebin/use_red.beam \
$(APP)/src/use_red.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/include/red.hrl
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/include/red.hrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -677,7 +687,9 @@ core-app-hrl-recursive: build clean-core-app-hrl-recursive
$(APP)/ebin/$(APP).app \
$(APP)/ebin/use_red.beam \
$(APP)/src/use_red.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/include/pill.hrl
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/include/pill.hrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -776,7 +788,9 @@ core-app-mib: build clean-core-app-mib
$(APP)/include/EX1-MIB.hrl \
$(APP)/priv/mibs/EX1-MIB.bin \
$(APP)/src/use_v1.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/mibs/EX1-MIB.mib
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/mibs/EX1-MIB.mib | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -886,7 +900,9 @@ NO_MAKEDEP ?= 1\
$(APP)/ebin/$(APP).app \
$(APP)/ebin/use_red.beam \
$(APP)/src/use_red.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/include/red.hrl
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/include/red.hrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -906,7 +922,9 @@ NO_MAKEDEP ?= 1\
$(APP)/ebin/$(APP).app \
$(APP)/ebin/use_red.beam \
$(APP)/src/use_red.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/include/red.hrl
+ $t $(SLEEP)
$t NO_MAKEDEP= $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/include/red.hrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -1074,7 +1092,9 @@ core-app-xrl: build clean-core-app-xrl
$(APP)/ebin/$(APP).app \
$(APP)/ebin/erlang_scan.beam \
$(APP)/src/erlang_scan.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/src/erlang_scan.xrl
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/src/erlang_scan.xrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -1174,7 +1194,9 @@ core-app-xrl-include: build clean-core-app-xrl-include
$(APP)/ebin/$(APP).app \
$(APP)/ebin/xfl_lexer.beam \
$(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/src/xfl_lexer.xrl
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/src/xfl_lexer.xrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -1193,7 +1215,9 @@ core-app-xrl-include: build clean-core-app-xrl-include
$(APP)/ebin/$(APP).app \
$(APP)/ebin/xfl_lexer.beam \
$(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/src/typechecks.hrl
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/src/typechecks.hrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -1212,7 +1236,9 @@ core-app-xrl-include: build clean-core-app-xrl-include
$(APP)/ebin/$(APP).app \
$(APP)/ebin/xfl_lexer.beam \
$(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/src/errvals.hrl
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/src/errvals.hrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -1308,7 +1334,9 @@ core-app-yrl: build clean-core-app-yrl
$(APP)/ebin/$(APP).app \
$(APP)/ebin/xref_parser.beam \
$(APP)/src/xref_parser.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/src/xref_parser.yrl
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/src/xref_parser.yrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -1402,7 +1430,9 @@ core-app-yrl-include: build clean-core-app-yrl-include
$(APP)/ebin/$(APP).app \
$(APP)/ebin/core_parse.beam \
$(APP)/src/core_parse.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/src/core_parse.yrl
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/src/core_parse.yrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
@@ -1421,7 +1451,9 @@ core-app-yrl-include: build clean-core-app-yrl-include
$(APP)/ebin/$(APP).app \
$(APP)/ebin/core_parse.beam \
$(APP)/src/core_parse.erl | sort > $(APP)/EXPECT
+ $t $(SLEEP)
$t touch $(APP)/src/core_parse.hrl
+ $t $(SLEEP)
$t $(MAKE) -C $(APP) $v
$t find $(APP) -type f -newer $(APP)/src/core_parse.hrl | sort | diff $(APP)/EXPECT -
$t rm $(APP)/EXPECT
diff --git a/test/core_compat.mk b/test/core_compat.mk
index b8c0681..62dfe93 100644
--- a/test/core_compat.mk
+++ b/test/core_compat.mk
@@ -38,9 +38,7 @@ core-compat-auto-rebar: build clean-core-compat-auto-rebar
$i "Create a temporary file"
$t touch $(APP)/older_file
-
- $i "Wait a second"
- $t sleep 1
+ $t $(SLEEP)
$i "Build the application again"
$t $(MAKE) -C $(APP) $v
@@ -79,9 +77,7 @@ core-compat-rebar: build clean-core-compat-rebar
$i "Create a temporary file"
$t touch $(APP)/older_file
-
- $i "Wait a second"
- $t sleep 1
+ $t $(SLEEP)
$i "Run 'make rebar.config' again"
$t $(MAKE) -C $(APP) rebar.config $v
diff --git a/test/core_deps.mk b/test/core_deps.mk
index 3d01eb7..a75e655 100644
--- a/test/core_deps.mk
+++ b/test/core_deps.mk
@@ -37,7 +37,7 @@ dep_8cc = git https://github.com/rui314/8cc master\
$t $(APP)/deps/8cc/8cc -h $v
$i "Check that the application was compiled correctly"
- $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
[ok = application:load(App) || App <- [$(APP)]], \
{ok, Deps} = application:get_key($(APP), applications), \
false = lists:member('8cc', Deps), \
@@ -68,7 +68,7 @@ dep_imagejs = git https://github.com/jklmnn/imagejs master\
$t test -f $(APP)/deps/imagejs/Makefile.bmp
$i "Check that the application was compiled correctly"
- $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
[ok = application:load(App) || App <- [$(APP)]], \
{ok, Deps} = application:get_key($(APP), applications), \
false = lists:member(imagejs, Deps), \
@@ -119,7 +119,7 @@ dep_jquery = git https://github.com/jquery/jquery master\
$t test -d $(APP)/deps/jquery
$i "Check that the application was compiled correctly"
- $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
[ok = application:load(App) || App <- [$(APP)]], \
{ok, Deps} = application:get_key($(APP), applications), \
false = lists:member(jquery, Deps), \
@@ -218,7 +218,7 @@ EDOC_OPTS = {doclet, edown_doclet}\
$t test ! -e $(APP)/deps
$i "Check that the application was compiled correctly"
- $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
[ok = application:load(App) || App <- [$(APP)]], \
{ok, Deps} = application:get_key($(APP), applications), \
false = lists:member(edown, Deps), \
@@ -282,7 +282,7 @@ core-deps-fetch-custom: build clean-core-deps-fetch-custom
$t sed -i.bak '2i\
DEPS = boop\
dep_boop = beep boop\
-dep_fetch_beep = mkdir -p \$$(DEPS_DIR)/\$$1\
+dep_fetch_beep = mkdir -p \$$(DEPS_DIR)/\$$1/ebin/\
' $(APP)/Makefile
ifdef LEGACY
@@ -631,7 +631,7 @@ OTP_DEPS = crypto\
$t test ! -e $(APP)/deps
$i "Check that the application was compiled correctly"
- $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
[ok = application:load(App) || App <- [$(APP), crypto]], \
{ok, Deps} = application:get_key($(APP), applications), \
true = lists:member(crypto, Deps), \
@@ -698,7 +698,7 @@ REL_DEPS = recon\
$t test ! -e $(APP)/deps
$i "Check that the application was compiled correctly"
- $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
[ok = application:load(App) || App <- [$(APP)]], \
{ok, Deps} = application:get_key($(APP), applications), \
false = lists:member(recon, Deps), \
@@ -712,7 +712,7 @@ REL_DEPS = recon\
$i "Check that the application was compiled correctly"
$t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \
- [ok = application:load(App) || App <- [$(APP)]], \
+ [ok = application:load(App) || App <- [$(APP), recon]], \
{ok, Deps} = application:get_key($(APP), applications), \
false = lists:member(recon, Deps), \
halt()"
@@ -766,7 +766,7 @@ SHELL_DEPS = tddreloader\
$t test ! -e $(APP)/deps
$i "Check that the application was compiled correctly"
- $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
[ok = application:load(App) || App <- [$(APP)]], \
{ok, Deps} = application:get_key($(APP), applications), \
false = lists:member(tddreloader, Deps), \
@@ -783,7 +783,7 @@ SHELL_DEPS = tddreloader\
$i "Check that the application was compiled correctly"
$t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \
- [ok = application:load(App) || App <- [$(APP)]], \
+ [ok = application:load(App) || App <- [$(APP), tddreloader]], \
{ok, Deps} = application:get_key($(APP), applications), \
false = lists:member(tddreloader, Deps), \
halt()"
@@ -811,7 +811,7 @@ TEST_DEPS = triq\
$t test ! -e $(APP)/deps
$i "Check that the application was compiled correctly"
- $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
[ok = application:load(App) || App <- [$(APP)]], \
{ok, Deps} = application:get_key($(APP), applications), \
false = lists:member(triq, Deps), \
@@ -825,7 +825,7 @@ TEST_DEPS = triq\
$i "Check that the application was compiled correctly"
$t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval " \
- [ok = application:load(App) || App <- [$(APP)]], \
+ [ok = application:load(App) || App <- [$(APP), triq]], \
{ok, Deps} = application:get_key($(APP), applications), \
false = lists:member(triq, Deps), \
halt()"