Skip to content

Commit 70b30f4

Browse files
authored
Merge pull request #4445 from esl/fix-cover-html-files
Fix test-runner coverage report MIM-2340
2 parents 01dad37 + 67e84f1 commit 70b30f4

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

big_tests/run_common_test.erl

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,11 @@ analyze(_Props, CoverOpts, [CoverNode|_] = Nodes) ->
403403
report_time("Export merged cover data", fun() ->
404404
cover_export(CoverNode, "/tmp/mongoose_combined.coverdata")
405405
end),
406-
case os:getenv("GITHUB_RUN_ID") of
407-
false ->
408-
make_html(CoverNode, modules_to_analyze(CoverNode, CoverOpts));
406+
case {os:getenv("GITHUB_RUN_ID"), os:getenv("CIRCLECI")} of
407+
{false, false} ->
408+
Mods = modules_to_analyze(CoverNode, CoverOpts),
409+
Txt = "Export HTML report for " ++ integer_to_list(length(Mods)) ++ " modules",
410+
report_time(Txt, fun() -> make_html(CoverNode, Mods) end);
409411
_ ->
410412
ok
411413
end,
@@ -434,25 +436,35 @@ make_html(CoverNode, Modules) ->
434436
file:make_dir(CoverageDir),
435437
{ok, File} = file:open(FilePath, [write]),
436438
file:write(File, get_cover_header()),
437-
Fun = fun(Module, {CAcc, NCAcc}) ->
439+
Fun = fun(Module, {CAcc, NCAcc, Skipped, Failed, OK}) ->
438440
FileName = lists:flatten(io_lib:format("~s.COVER.html",[Module])),
439441

440442
%% We assume that import_code_paths/1 was called earlier
441443
case cover_analyse(CoverNode, Module) of
442444
{ok, {Module, {C, NC}}} ->
443-
file:write(File, row(atom_to_list(Module), C, NC, percent(C,NC),"coverage/"++FileName)),
444-
FilePathC = filename:join([CoverageDir, FileName]),
445-
cover_analyse_to_html_file(CoverNode, Module, FilePathC),
446-
{CAcc + C, NCAcc + NC};
445+
FilePathC = filename:join([Root, CoverageDir, FileName]),
446+
case cover_analyse_to_html_file(CoverNode, Module, FilePathC) of
447+
{ok, _} ->
448+
file:write(File, row(atom_to_list(Module), C, NC, percent(C,NC),"coverage/"++FileName)),
449+
{CAcc + C, NCAcc + NC, Skipped, Failed, OK + 1};
450+
Other ->
451+
%% Do not report link, if the destination file is not written
452+
file:write(File, row_no_link(atom_to_list(Module), C, NC, percent(C,NC))),
453+
error_logger:error_msg("issue=cover_analyse_to_html_file_failed module=~p reason=~p",
454+
[Module, Other]),
455+
{CAcc + C, NCAcc + NC, Skipped, Failed + 1, OK}
456+
end;
447457
Reason ->
448458
error_logger:error_msg("issue=cover_analyse_failed module=~p reason=~p",
449459
[Module, Reason]),
450-
{CAcc, NCAcc}
460+
{CAcc, NCAcc, Skipped + 1, Failed, OK}
451461
end
452462
end,
453-
{CSum, NCSum} = lists:foldl(Fun, {0, 0}, Modules),
463+
{CSum, NCSum, Skipped2, Failed2, OK2} = lists:foldl(Fun, {0, 0, 0, 0, 0}, Modules),
454464
file:write(File, row("Summary", CSum, NCSum, percent(CSum, NCSum), "#")),
455-
file:close(File).
465+
file:close(File),
466+
report_progress("make_html: ok - ~p, skipped - ~p, failed - ~p~n", [OK2, Skipped2, Failed2]),
467+
ok.
456468

457469
get_hosts_to_enable_preset(Props) ->
458470
[Host || Host <- get_all_hosts(Props), should_enable_preset(host_cluster(Host))].
@@ -483,6 +495,17 @@ row(Row, C, NC, Percent, Path) ->
483495
"</tr>\n"
484496
].
485497

498+
row_no_link(Row, C, NC, Percent) ->
499+
[
500+
"<tr>",
501+
"<td>", Row, "</td>",
502+
"<td>", integer_to_list(Percent), "%</td>",
503+
"<td>", integer_to_list(C), "</td>",
504+
"<td>", integer_to_list(NC), "</td>",
505+
"<td>", integer_to_list(C+NC), "</td>",
506+
"</tr>\n"
507+
].
508+
486509
get_cover_header() ->
487510
"<html>\n<head></head>\n<body bgcolor=\"white\" text=\"black\" link=\"blue\" vlink=\"purple\" alink=\"red\">\n"
488511
"<head><script src='sorttable.js'></script></head>"

0 commit comments

Comments
 (0)