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

Time test functions, colorize output #15

Merged
merged 1 commit into from Dec 10, 2015
Merged
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
31 changes: 24 additions & 7 deletions src/etest_runner.erl
Expand Up @@ -22,13 +22,21 @@ run_all(Modules) ->

lists:foreach(fun run/1, Modules),

Errors = get(errors),
SummaryColor = case Errors == 0 of
true -> "\x1b[32;1m";
false -> "\x1b[31;1m"
end,
io:format(SummaryColor),

io:format("=========================================~n"
" Failed: ~p. Success: ~p. Total: ~p.~n~n", [
get(errors),
Errors,
get(success),
get(tests) ]),

erlang:halt(get(errors)).
io:format("\x1b[0m"),
erlang:halt(Errors).


run(Module) ->
Expand All @@ -44,11 +52,13 @@ run(Module) ->
Test()
catch
_:Error ->
io:format("\x1b[31m"),
io:format("Etest failed.\n"),
inc(errors),
io:format("::~p~n", [Error]),
CleanTrace = clean_trace(erlang:get_stacktrace()),
io:format("Stacktrace:~n~p~n~n", [CleanTrace])
io:format("Stacktrace:~n~p~n~n", [CleanTrace]),
io:format("\x1b[0m")
end
end,
lists:foreach(TryTest, ToRun).
Expand Down Expand Up @@ -80,12 +90,19 @@ testfuns(Module) ->
MakeApplicative = fun({FunName, _}) ->
fun() ->
inc(tests),

Msg = lists:flatten(io_lib:format("~p:~p ", [Module, FunName])),
io:format(
string:left(Msg, 80, $.) ++ "\n" ++
string:left("", 80, $=) ++ "\n"
),
io:format(string:left(Msg, 80, $.) ++ "\n"),

Before = erlang:monotonic_time(),
Module:FunName(),
After = erlang:monotonic_time(),

Seconds = erlang:convert_time_unit(After - Before, native, milli_seconds),
DurationStr = lists:flatten(io_lib:format(" ~pms", [Seconds])),
io:format(string:right(DurationStr, 80, $=)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right aligned test run time in milliseconds.

io:format("~n~n"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double spacing for a much less dense output.


inc(success)
end
end,
Expand Down