-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathformat_test_results.m
40 lines (40 loc) · 1.54 KB
/
format_test_results.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function str = format_test_results(stats)
durations = [stats.Duration];
names = {stats.Name};
success_mask = [stats.Passed];
fail_mask = [stats.Failed];
incomplete_mask = [stats.Incomplete];
details = {stats.Details};
total_test_time = sum(durations);
str = sprintf('### Jenkins Build Statistics\n');
str = [str sprintf('* Total testing time: %.2f sec\n', total_test_time)];
str = [str sprintf('* Number of passed checks: %d\n', sum(success_mask))];
str = [str sprintf('* Number of failed checks: %d\n', sum(fail_mask))];
str = [str sprintf('* Number of incomplete checks: %d\n', sum(incomplete_mask))];
str = [str newline];
str = [str sprintf('#### Table of Failed Checks\n')];
str = [str format_md_table(fail_mask, details, names, durations)];
str = [str newline];
str = [str sprintf('#### Table of Incomplete Checks\n')];
str = [str format_md_table(incomplete_mask, details, names, durations)];
end
function str = format_md_table(mask, details, names, durations)
str = sprintf('| Test name | File | Line number | Duration |\n');
str = [str sprintf('| --- | --- | --- | --- |\n')];
indices = find(mask);
for i = 1:numel(indices)
idx = indices(i);
report_whole = details{idx}.DiagnosticRecord.Report;
report_elems = split(report_whole);
filepath = report_elems{end - 3};
% parts = {};
if contains(filepath, '/')
parts = split(filepath, '/');
else
parts = split(filepath, '\');
end
filename = parts{end};
linenum = str2double(report_elems{end});
str = [str, sprintf('| %s | %s | %d | %.2f |\n', names{idx}, filename, linenum, durations(idx))];
end
end