aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--README.md20
-rw-r--r--core/deps.mk2
-rw-r--r--erlang.mk14
-rw-r--r--packages.v2.tsv2
-rw-r--r--plugins/erlydtl.mk12
-rw-r--r--test/Makefile161
7 files changed, 207 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index d7bb08d..2efc976 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@ BUILD_CONFIG = $(shell sed "s/\#.*//" $(BUILD_CONFIG_FILE))
ERLANG_MK = erlang.mk
-.PHONY: all
+.PHONY: all check
all: pkg
awk 'FNR==1 && NR!=1{print ""}1' $(patsubst %,%.mk,$(BUILD_CONFIG)) > $(ERLANG_MK)
@@ -25,3 +25,6 @@ all: pkg
pkg:
cat packages.v2.tsv | awk 'BEGIN { FS = "\t" }; { print $$1 "\t" $$3 "\t" $$5 "\t" $$6 }' > packages.v1.tsv
cp packages.v1.tsv packages.v1.txt
+
+check:
+ make -C test
diff --git a/README.md b/README.md
index 9b3ecbb..a9ac8af 100644
--- a/README.md
+++ b/README.md
@@ -115,6 +115,17 @@ dep_cowboy = git https://github.com/ninenines/cowboy 1.0.0
They will always be compiled using the command `make`. If the dependency
does not feature a Makefile, then erlang.mk will be used for building.
+For subversion dependencies, the url specifies trunk, branch or
+tag. To specify a particular revision, use `@revision` at the end of
+the url. No separate specification of branch, tag, or revision is
+required or possible.
+
+``` erlang
+DEPS = ex1 ex2
+dep_ex1 = svn https://example.com/svn/trunk/project/ex1
+dep_ex2 = svn svn://example.com/svn/branches/erlang-proj/ex2@264
+```
+
You can also specify test-only dependencies. These dependencies will only
be downloaded when running `make tests`. The format is the same as above,
except the variable `TEST_DEPS` holds the list of test-only dependencies.
@@ -367,7 +378,14 @@ ErlyDTL plugin
This plugin is available by default. It adds automatic
compilation of ErlyDTL templates found in `templates/*.dtl`
-or any subdirectory.
+or any subdirectory.
+
+By default it ignores names of subdirectories and compiles
+`a/b/templatename.dtl` into `templatename_dtl.beam`. To include
+subdirectories names in the compiled module name add
+`DTL_FULL_PATH=1` into your Makefile - `a/b/templatename.dtl`
+will be compiled into `a_b_templatename_dtl.beam`.
+
Escript plugin
--------------
diff --git a/core/deps.mk b/core/deps.mk
index 80bedda..7d4b974 100644
--- a/core/deps.mk
+++ b/core/deps.mk
@@ -49,6 +49,8 @@ define dep_fetch
elif [ "$$$$VS" = "hg" ]; then \
hg clone -U $$$$REPO $(DEPS_DIR)/$(1); \
cd $(DEPS_DIR)/$(1) && hg update -q $$$$COMMIT; \
+ elif [ "$$$$VS" = "svn" ]; then \
+ svn checkout $$$$REPO $(DEPS_DIR)/$(1); \
else \
echo "Unknown or invalid dependency: $(1). Please consult the erlang.mk README for instructions." >&2; \
exit 78; \
diff --git a/erlang.mk b/erlang.mk
index c5a1086..5aa1ac2 100644
--- a/erlang.mk
+++ b/erlang.mk
@@ -135,6 +135,8 @@ define dep_fetch
elif [ "$$$$VS" = "hg" ]; then \
hg clone -U $$$$REPO $(DEPS_DIR)/$(1); \
cd $(DEPS_DIR)/$(1) && hg update -q $$$$COMMIT; \
+ elif [ "$$$$VS" = "svn" ]; then \
+ svn checkout $$$$REPO $(DEPS_DIR)/$(1); \
else \
echo "Unknown or invalid dependency: $(1). Please consult the erlang.mk README for instructions." >&2; \
exit 78; \
@@ -918,6 +920,10 @@ distclean-elvis:
# Copyright (c) 2013-2014, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
+# Configuration.
+
+DTL_FULL_PATH ?= 0
+
# Verbosity.
dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
@@ -928,9 +934,11 @@ dtl_verbose = $(dtl_verbose_$(V))
define compile_erlydtl
$(dtl_verbose) erl -noshell -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \
Compile = fun(F) -> \
- Module = list_to_atom( \
- string:to_lower(filename:basename(F, ".dtl")) ++ "_dtl"), \
- erlydtl:compile(F, Module, [{out_dir, "ebin/"}]) \
+ S = fun (1) -> re:replace(filename:rootname(string:sub_string(F, 11), ".dtl"), "/", "_", [{return, list}, global]); \
+ (0) -> filename:basename(F, ".dtl") \
+ end, \
+ Module = list_to_atom(string:to_lower(S($(DTL_FULL_PATH))) ++ "_dtl"), \
+ {ok, _} = erlydtl:compile(F, Module, [{out_dir, "ebin/"}, return_errors, {doc_root, "templates"}]) \
end, \
_ = [Compile(F) || F <- string:tokens("$(1)", " ")], \
init:stop()'
diff --git a/packages.v2.tsv b/packages.v2.tsv
index 9cbb697..d405aac 100644
--- a/packages.v2.tsv
+++ b/packages.v2.tsv
@@ -50,7 +50,7 @@ ranch git https://github.com/ninenines/ranch 1.1.0 http://ninenines.eu Socket ac
resource_discovery git https://github.com/erlware/resource_discovery master http://erlware.org/ An application used to dynamically discover resources present in an Erlang node cluster.
sfmt-erlang git https://github.com/jj1bdx/sfmt-erlang master https://github.com/jj1bdx/sfmt-erlang SFMT pseudo random number generator for Erlang.
sheriff git https://github.com/extend/sheriff master http://ninenines.eu Parse transform for type based validation.
-shotgun git https://github.com/inaka/shotgun.git 0.1 https://github.com/inaka/shotgun.git better than just a gun
+shotgun git https://github.com/inaka/shotgun.git 0.1.0 https://github.com/inaka/shotgun.git better than just a gun
sumo_db git https://github.com/inaka/sumo_db.git 1 https://github.com/inaka/sumo_db.git Erlang Persistency Framework
swab git https://github.com/crownedgrouse/swab.git master https://github.com/crownedgrouse/swab General purpose buffer handling module
sync git https://github.com/rustyio/sync.git master https://github.com/rustyio/sync On-the-fly recompiling and reloading in Erlang.
diff --git a/plugins/erlydtl.mk b/plugins/erlydtl.mk
index e288072..8d8795f 100644
--- a/plugins/erlydtl.mk
+++ b/plugins/erlydtl.mk
@@ -1,6 +1,10 @@
# Copyright (c) 2013-2014, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
+# Configuration.
+
+DTL_FULL_PATH ?= 0
+
# Verbosity.
dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
@@ -11,9 +15,11 @@ dtl_verbose = $(dtl_verbose_$(V))
define compile_erlydtl
$(dtl_verbose) erl -noshell -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \
Compile = fun(F) -> \
- Module = list_to_atom( \
- string:to_lower(filename:basename(F, ".dtl")) ++ "_dtl"), \
- erlydtl:compile(F, Module, [{out_dir, "ebin/"}]) \
+ S = fun (1) -> re:replace(filename:rootname(string:sub_string(F, 11), ".dtl"), "/", "_", [{return, list}, global]); \
+ (0) -> filename:basename(F, ".dtl") \
+ end, \
+ Module = list_to_atom(string:to_lower(S($(DTL_FULL_PATH))) ++ "_dtl"), \
+ {ok, _} = erlydtl:compile(F, Module, [{out_dir, "ebin/"}, return_errors, {doc_root, "templates"}]) \
end, \
_ = [Compile(F) || F <- string:tokens("$(1)", " ")], \
init:stop()'
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..619c3e5
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,161 @@
+# 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.
+
+# Verbosity.
+
+V ?= 0
+
+# 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
+ i = @echo
+else ifeq ($V,1)
+ # Show test commands
+ t =
+ v = V=0 &>/dev/null
+ i = @echo ==
+else ifeq ($V,2)
+ # Show briefly what erlang.mk is doing
+ t = @echo " TEST " $@;
+ v = V=0
+ i = @echo ==
+else
+ # Show all commands with maximum verbosity
+ t =
+ v = V=1
+ i = @echo ==
+endif
+
+.PHONY: all clean app ct eunit
+
+all: app ct eunit clean
+ $i '+---------------------+'
+ $i '| All tests passed. |'
+ $i '+---------------------+'
+
+clean:
+ $t rm -rf app1
+
+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` == 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."
+
+ct: app1
+ $i "ct: Testing tests-ct and related targets."
+ $i "Setting up test suite."
+ $t mkdir -p app1/test
+ $t printf "%s\n" \
+ "-module(m_SUITE)." \
+ "-export([all/0, testcase1/1])." \
+ "all() -> [testcase1]." \
+ "testcase1(_) -> 2 = m:succ(1)." \
+ > app1/test/m_SUITE.erl
+ $t make -C app1 tests-ct $v
+ $i "Checking files created by 'make tests-ct'."
+ $t [ ! -e app1/test/m_SUITE.beam ]
+ $t [ -e app1/ebin/m.beam ]
+ $t [ -e app1/logs ]
+ $i "Checking that 'make clean-ct' does not delete logs."
+ $t make -C app1 clean-ct $v
+ $t [ -e app1/logs ]
+ $i "Testing target 'ct-mysuite' where mysuite_SUITE is a test suite."
+ $t make -C app1 ct-m $v
+ $i "Checking that 'make tests-ct' returns non-zero for a failing suite."
+ $t printf "%s\n" \
+ "-module(failing_SUITE)." \
+ "-export([all/0, testcase1/1])." \
+ "all() -> [testcase1]." \
+ "testcase1(_) -> 42 = m:succ(1)." \
+ > app1/test/failing_SUITE.erl
+ $t if make -C app1 ct-failing $v ; then false ; fi
+ $i "Checking that 'make ct-distclean' deletes logs."
+ $t make -C app1 distclean-ct $v
+ $t [ ! -e app1/logs ]
+ $t [ -e app1/ebin/m.beam ]
+ $i "Cleaning up test data."
+ $t rm -rf app1/test
+ $i "Test 'ct' passed."
+
+eunit: app1
+ $i "eunit: Testing the 'eunit' target."
+ $t mkdir -p eunit
+ $i "Running eunit test case inside module src/t.erl"
+ $t printf '%s\n' \
+ '-module(t).' \
+ '-export([succ/1]).' \
+ 'succ(N) -> N + 1.' \
+ '-ifdef(TEST).' \
+ '-include_lib("eunit/include/eunit.hrl").' \
+ 'succ_test() ->' \
+ ' ?assertEqual(2, succ(1)),' \
+ ' os:cmd("echo t >> test-eunit.log").' \
+ '-endif.' \
+ > app1/src/t.erl
+ $t make -C app1 eunit $v
+ $i "Checking that the eunit test in module t."
+ $t echo t | cmp app1/test-eunit.log -
+ $t rm app1/test-eunit.log
+ $i "Running eunit tests in a separate directory."
+ $t mkdir -p app1/eunit
+ $t printf '%s\n' \
+ '-module(t_tests).' \
+ '-include_lib("eunit/include/eunit.hrl").' \
+ 'succ_test() ->' \
+ ' ?assertEqual(2, t:succ(1)),' \
+ ' os:cmd("echo t_tests >> test-eunit.log").' \
+ > app1/eunit/t_tests.erl
+ $t printf '%s\n' \
+ '-module(x_tests).' \
+ '-include_lib("eunit/include/eunit.hrl").' \
+ 'succ_test() ->' \
+ ' ?assertEqual(2, t:succ(1)),' \
+ ' os:cmd("echo x_tests >> test-eunit.log").' \
+ > app1/eunit/x_tests.erl
+ $t make -C app1 eunit EUNIT_DIR=eunit $v
+ $i "Checking that 'make eunit' didn't run the tests in t_tests twice, etc."
+ $t printf "%s\n" t t_tests x_tests | cmp app1/test-eunit.log -
+ $t rm app1/test-eunit.log
+ $i "Checking that 'make eunit' returns non-zero for a failing test."
+ $t rm -f app1/eunit/*
+ $t printf "%s\n" \
+ "-module(t_tests)." \
+ '-include_lib("eunit/include/eunit.hrl").' \
+ "succ_test() ->" \
+ " ?assertEqual(42, t:succ(1))." \
+ > app1/eunit/t_tests.erl
+ $t if make -C app1 eunit EUNIT_DIR=eunit $v ; then false ; fi
+ $t rm -rf app1/eunit app1/src/t.erl app1/test-eunit.log
+ $i "Test 'eunit' passed."
+
+# Test application used for testing.
+app1:
+ $i "Setting up app."
+ $t mkdir -p app1
+ $t cp ../erlang.mk app1/
+ $t make -C app1 -f erlang.mk bootstrap-lib
+ $t printf "%s\n" \
+ "-module(m)." \
+ "-export([succ/1])." \
+ "succ(N) -> N + 1." \
+ > app1/src/m.erl