Skip to content

Instantly share code, notes, and snippets.

@zkessin
Created August 24, 2012 20:49
Show Gist options
  • Save zkessin/3455466 to your computer and use it in GitHub Desktop.
Save zkessin/3455466 to your computer and use it in GitHub Desktop.
Erlang Code Coverage
-module(cover).
-export([ cover/0]).
cover()->
io:format("~n********************************************************************************~n"),
io:format("Running Tests~n~n"),
cover:start(),
_R = cover:compile_beam_directory("ebin/"),
Modules = cover:modules(),
[eunit:test(Module) || Module <- Modules],
Coverage = [cover:analyse(Module, calls, line) || Module <- Modules],
L = lists:merge([Lines || {ok, Lines} <- Coverage]),
NonTestModules = lists:filter(fun({{Module, _}, _} )->
Es = lists:reverse(string:tokens(atom_to_list(Module),"_") ),
lists:nth(1, Es) =/= "test"
end,L),
Zeros = lists:filter(fun ({{_Module, _Line}, Count}) ->
Count =:= 0
end, NonTestModules),
[io:format("src/~p.erl:~p: No Code Coverage~n",[Module, Line])|| {{Module, Line}, 0} <-Zeros],
init:stop().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment