Skip to content

Commit

Permalink
Don't crash when test summary contains more values than we want
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikaka27 committed Dec 6, 2024
1 parent 0418c10 commit d452ad1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/common_test/src/ct_logs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
-define(abs(Name), filename:absname(Name)).

-define(now, os:timestamp()).
-define(expected_summary_size, 4).
-define(minimum_summary_size, 3).

-record(log_cache, {version,
all_runs = [],
Expand Down Expand Up @@ -1819,10 +1821,8 @@ year() ->
count_cases(Dir) ->
SumFile = filename:join(Dir, ?run_summary),
case read_summary(SumFile, [summary]) of
{ok, [{Succ,Fail,Skip}]} ->
{Succ,Fail,Skip,undefined};
{ok, [Summary]} ->
Summary;
get_expected_num_of_summary_values(Summary);
{error, _} ->
LogFile = filename:join(Dir, ?suitelog_name),
case file:read_file(LogFile) of
Expand Down Expand Up @@ -1861,6 +1861,16 @@ read_summary(Name, Keys) ->
{error, Reason}
end.

get_expected_num_of_summary_values(Summary) when tuple_size(Summary) > ?expected_summary_size ->
List = tuple_to_list(Summary),
list_to_tuple(lists:sublist(List, ?expected_summary_size));
get_expected_num_of_summary_values(Summary) when tuple_size(Summary) == ?expected_summary_size ->
Summary;
get_expected_num_of_summary_values(Summary) when tuple_size(Summary) >= ?minimum_summary_size ->
List = tuple_to_list(Summary),
Pad = lists:duplicate(?expected_summary_size - length(List), undefined),
list_to_tuple(lists:append(List, Pad)).

count_cases1("=failed" ++ Rest, {Success, _Fail, UserSkip,AutoSkip}) ->
{NextLine, Count} = get_number(Rest),
count_cases1(NextLine, {Success, Count, UserSkip,AutoSkip});
Expand Down

0 comments on commit d452ad1

Please sign in to comment.