From d452ad155d0dd27bc486923a9cddc70fa2755b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=C4=85sowski?= Date: Fri, 6 Dec 2024 17:12:50 +0100 Subject: [PATCH] Don't crash when test summary contains more values than we want --- lib/common_test/src/ct_logs.erl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index 679d9109423b..cd45fe7385f5 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -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 = [], @@ -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 @@ -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});