Skip to content

Commit

Permalink
Merge pull request #1029 from processone/coveralls
Browse files Browse the repository at this point in the history
Add support for test code coverage
  • Loading branch information
mremond committed Mar 21, 2016
2 parents 3441157 + 9547596 commit 4be9cc1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ before_install:
- sudo apt-get -qq update
- sudo apt-get -qq -o Dpkg::Options::=--force-confold install mysql-server-5.6
# /END MYSQL 5.6

- pip install --user coveralls-merge

install:
- sudo apt-get -qq install libexpat1-dev libyaml-dev libpam0g-dev libsqlite3-dev
Expand Down Expand Up @@ -57,5 +57,8 @@ after_script:
after_failure:
- find logs -name ejabberd.log -exec cat '{}' ';'

after_success:
- coveralls-merge erlang.json

notifications:
email: false
5 changes: 5 additions & 0 deletions cover.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{level, details}.
{incl_dirs, ["src", "ebin"]}.
{excl_mods, [eldap, 'ELDAPv3']}.
{export, "logs/all.coverdata"}.

4 changes: 4 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@

{erl_opts, [nowarn_deprecated_function,
{if_var_false, debug, no_debug_info},
{if_var_true, debug, debug_info},
{if_var_true, roster_gateway_workaround, {d, 'ROSTER_GATWAY_WORKAROUND'}},
{if_var_match, db_type, mssql, {d, 'mssql'}},
{if_var_true, erlang_deprecated_types, {d, 'ERL_DEPRECATED_TYPES'}},
Expand Down Expand Up @@ -111,6 +112,9 @@

{eunit_compile_opts, [{i, "tools"}]}.

{cover_enabled, true}.
{cover_export_enabled, true}.

{post_hook_configure, [{"fast_tls", []},
{"stringprep", []},
{"fast_yaml", []},
Expand Down
27 changes: 26 additions & 1 deletion rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
%%% Created : 1 May 2013 by Evgeniy Khramtsov <ekhramtsov@process-one.net>
%%%-------------------------------------------------------------------

ModCfg0 = fun(F, Cfg, [Key|Tail], Op, Default) ->
{OldVal,PartCfg} = case lists:keytake(Key, 1, Cfg) of
{value, {_, V1}, V2} -> {V1, V2};
false -> {if Tail == [] -> Default; true -> [] end, Cfg}
end,
case Tail of
[] ->
[{Key, Op(OldVal)} | PartCfg];
_ ->
[{Key, F(F, OldVal, Tail, Op, Default)} | PartCfg]
end
end,
ModCfg = fun(Cfg, Keys, Op, Default) -> ModCfg0(ModCfg0, Cfg, Keys, Op, Default) end.

Cfg = case file:consult(filename:join(filename:dirname(SCRIPT), "vars.config")) of
{ok, Terms} ->
Terms;
Expand Down Expand Up @@ -107,9 +121,20 @@ Conf5 = case lists:keytake(floating_deps, 1, Conf3) of
Conf3
end,

%% When running Travis test, upload test coverage result to coveralls:
Conf6 = case os:getenv("TRAVIS") of
"true" ->
JobId = os:getenv("TRAVIS_JOB_ID"),
CfgTemp = ModCfg(Conf5, [deps], fun(V) -> [{coveralls, ".*", {git, "https://github.com/markusn/coveralls-erl.git", "master"}}|V] end, []),
ModCfg(CfgTemp, [post_hooks], fun(V) -> V ++ [{ct, "echo '\n%%! -pa ebin/ deps/coveralls/ebin\nmain(_)->{ok,F}=file:open(\"erlang.json\",[write]),io:fwrite(F,\"~s\",[coveralls:convert_file(\"logs/all.coverdata\", \""++JobId++"\", \"travis-ci\")]).' > getcover.erl"},
{ct, "escript ./getcover.erl"}] end, []);
_ ->
Conf5
end,

%io:format("ejabberd configuration:~n ~p~n", [Conf5]),

Conf5.
Conf6.

%% Local Variables:
%% mode: erlang
Expand Down

0 comments on commit 4be9cc1

Please sign in to comment.