Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for testing dependencies; travis #976

Open
wants to merge 6 commits into
base: develop-3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .travis.yml
@@ -0,0 +1,10 @@
language: erlang
sudo: true
otp_release:
- 20.3.8
script:
- ./rebar3 eunit

## for deps tests:
# - ./rebar3 as test compile
# - make test
32 changes: 20 additions & 12 deletions Makefile
Expand Up @@ -8,9 +8,10 @@ REBAR ?= $(BASE_DIR)/rebar3
OVERLAY_VARS ?=
TEST_IGNORE ?=
TEST_DEPS_DIR ?= _build/test/lib
DEPS_DIR ?= _build/default/lib
REL_DIR ?= _build/default/rel
DEPS = $(patsubst $(TEST_DEPS_DIR)/%, %, $(wildcard $(TEST_DEPS_DIR)/*))
TEST_DEPS = $(filter-out $(TEST_IGNORE), $(DEPS))
DEPS = $(patsubst $(DEPS_DIR)/%, %, $(wildcard $(DEPS_DIR)/*))
TEST_DEPS = $(filter-out $(TEST_IGNORE), $(DEPS))

RIAK_CORE_STAT_PREFIX = riak
export RIAK_CORE_STAT_PREFIX
Expand Down Expand Up @@ -47,24 +48,31 @@ TEST_LOG_FILE := eunit.log
testclean:
@rm -f $(TEST_LOG_FILE)

TMP_CONFIG=rebar.config.tmp
TMP_CONFIG=rebar.config.deptest

TEST_IGNORE += riak

# Tricking rebar3 to use the dependencies from the top-level _build directory.
testdep-% :
@echo "--- Running EUnit tests for $* ---"
@rm -rf _build/deptest+test _build/deptest
@(cd $(TEST_DEPS_DIR)/$* && \
cp rebar.config $(TMP_CONFIG) && \
echo "" >> $(TMP_CONFIG) && \
echo '{profiles, [{deptest, [{base_dir, "../../.."}]}]}.' >> $(TMP_CONFIG) && \
REBAR_CONFIG=$(TMP_CONFIG) $(REBAR) as deptest eunit) || echo "Eunit: $* FAILED" >> $(TEST_LOG_FILE)
@rm -rf _build/deptest+test
@(cd $(TEST_DEPS_DIR)/$* \
&& escript ../../../../misc/deptest.escript rebar.config $(TMP_CONFIG) \
&& REBAR_CONFIG=$(TMP_CONFIG) $(REBAR) as deptest eunit) \
|| echo "Eunit: $* FAILED" >> $(TEST_LOG_FILE)
@(cd $(TEST_DEPS_DIR)/$* && rm -f $(TMP_CONFIG))

test-deps : deps compile testclean $(patsubst %, testdep-%, $(TEST_DEPS))
TEST_DEPS_RULES = $(patsubst %, testdep-%, $(TEST_DEPS))

# Test each dependency individually in its own VM
test : test-deps

test-deps : deps compile testclean $(TEST_DEPS_RULES)

test-riak:
$(REBAR) eunit


# Test each dependency individually in its own VM
test : test-riak test-deps
@if test -s $(TEST_LOG_FILE) ; then \
cat $(TEST_LOG_FILE) && \
exit `wc -l < $(TEST_LOG_FILE)`; \
Expand Down
29 changes: 29 additions & 0 deletions misc/deptest.escript
@@ -0,0 +1,29 @@
#!/usr/bin/env escript

%% A hack for running dependencies test, see Makefile#deptest. Adds riak’s _build as
%% a base_dir to the test profile, renames test profile to deptest

%% E. g. FileIn=rebar.config, FileOut=rebar.config.deptest
main([FileIn,FileOut]) ->
case file:consult(FileIn) of
{ok,Conf0} -> ok;
_ -> Conf0=[] % no rebar.config! amazing
end,
Conf = lists:ukeymerge(1, lists:keysort(1,Conf0), [{profiles,[]}]),
[Profiles] = [ P || {profiles,P} <- Conf ],

%% if no test profile, add an empty one
ProfilesT = lists:ukeymerge(1, lists:keysort(1,Profiles), [{test,[]}]),

NewProfiles
= [ case P of
%% rename test → deptest; add base_dir
{test,Spec} -> {deptest, [{base_dir,"../../.."} | Spec]};
X -> X
end
|| P <- ProfilesT ],

NewConf = lists:keyreplace(profiles, 1, Conf, {profiles,NewProfiles}),
file:write_file(FileOut, [io_lib:format("~tp.~n", [X]) || X <- NewConf]).