• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 14591945233

22 Apr 2025 09:54AM UTC coverage: 91.317%. Remained the same
14591945233

Pull #4834

github

web-flow
Merge 2d2eacebc into 4c413a8ac
Pull Request #4834: Fix the test reporter to print the name of the testsuite being waited for

95655 of 104750 relevant lines covered (91.32%)

13046289.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.67
/src/tests/runner/test_reporter.cpp
1
/*
2
* (C) 2022 Jack Lloyd
3
* (C) 2022 René Meusel, Rohde & Schwarz Cybersecurity
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include "test_reporter.h"
9

10
#include <algorithm>
11
#include <numeric>
12

13
namespace Botan_Tests {
14

15
namespace {
16

17
template <typename T>
18
constexpr std::optional<T> operator+(const std::optional<T>& a, const std::optional<T>& b) {
1,023✔
19
   if(!a.has_value() || !b.has_value()) {
1,805✔
20
      return std::nullopt;
21
   }
22

23
   return a.value() + b.value();
1,408✔
24
}
25

26
}  // namespace
27

28
TestSummary::TestSummary(const Test::Result& result) :
2,441✔
29
      name(result.who()),
2,441✔
30
      code_location(result.code_location()),
4,882✔
31
      assertions(result.tests_run()),
2,441✔
32
      notes(result.notes()),
2,441✔
33
      failures(result.failures()),
2,441✔
34
      timestamp(result.timestamp()),
2,441✔
35
      elapsed_time(result.elapsed_time()) {}
2,441✔
36

37
Testsuite::Testsuite(std::string name) : m_name(std::move(name)) {}
401✔
38

39
void Testsuite::record(const Test::Result& result) {
2,441✔
40
   m_results.emplace_back(result);
×
41
}
×
42

43
size_t Testsuite::tests_passed() const {
×
44
   return std::count_if(m_results.begin(), m_results.end(), [](const auto& r) { return r.passed(); });
×
45
}
46

47
size_t Testsuite::tests_failed() const {
802✔
48
   return std::count_if(m_results.begin(), m_results.end(), [](const auto& r) { return r.failed(); });
5,283✔
49
}
50

51
std::chrono::system_clock::time_point Testsuite::timestamp() const {
401✔
52
   return std::transform_reduce(
401✔
53
      m_results.begin(),
54
      m_results.end(),
55
      std::chrono::system_clock::time_point::max(),
56
      [](const auto& a, const auto& b) { return std::min(a, b); },
1,593✔
57
      [](const auto& result) { return result.timestamp; });
1,127✔
58
}
59

60
std::optional<std::chrono::nanoseconds> Testsuite::elapsed_time() const {
401✔
61
   return std::transform_reduce(
401✔
62
      m_results.begin(),
63
      m_results.end(),
64
      std::make_optional(std::chrono::nanoseconds::zero()),
65
      [](const auto& a, const auto& b) { return a + b; },
2,140✔
66
      [](const auto& result) { return result.elapsed_time; });
1,266✔
67
}
68

69
Reporter::Reporter(const Test_Options& opts) : m_total_test_runs(opts.test_runs()), m_current_test_run(0) {}
2✔
70

71
void Reporter::set_property(const std::string& name, const std::string& value) {
14✔
72
   m_properties.insert_or_assign(name, value);
14✔
73
}
14✔
74

75
void Reporter::next_test_run() {
2✔
76
   m_start_time = std::chrono::high_resolution_clock::now();
2✔
77
   ++m_current_test_run;
2✔
78
   m_testsuites.clear();
2✔
79

80
   next_run();
2✔
81
}
2✔
82

83
void Reporter::record(const std::string& name, const Test::Result& result) {
2,441✔
84
   auto& suite = m_testsuites.try_emplace(name, name).first->second;
2,441✔
85
   suite.record(result);
2,441✔
86
}
2,441✔
87

88
void Reporter::waiting_for_next_results(const std::string& test_name) {
802✔
89
   next_testsuite(test_name);
802✔
90
}
802✔
91

92
void Reporter::record(const std::string& testsuite_name, const std::vector<Botan_Tests::Test::Result>& results) {
802✔
93
   std::map<std::string, Botan_Tests::Test::Result> combined;
802✔
94
   for(const auto& result : results) {
100,100✔
95
      const auto& who = result.who();
99,298✔
96
      auto i = combined.find(who);
99,298✔
97
      if(i == combined.end()) {
99,298✔
98
         combined.insert(std::make_pair(who, Botan_Tests::Test::Result(who)));
14,646✔
99
         i = combined.find(who);
4,882✔
100
      }
101

102
      i->second.merge(result);
99,298✔
103
   }
104

105
   for(const auto& result : combined) {
5,684✔
106
      record(testsuite_name, result.second);
4,882✔
107
   }
108
}
802✔
109

110
size_t Reporter::tests_run() const {
1✔
111
   return std::transform_reduce(
1✔
112
      m_testsuites.begin(), m_testsuites.end(), size_t(0), std::plus{}, [](const auto& testsuite) {
401✔
113
         return testsuite.second.tests_run();
401✔
114
      });
1✔
115
}
116

117
size_t Reporter::tests_passed() const {
×
118
   return std::transform_reduce(
×
119
      m_testsuites.begin(), m_testsuites.end(), size_t(0), std::plus{}, [](const auto& testsuite) {
×
120
         return testsuite.second.tests_passed();
×
121
      });
×
122
}
123

124
size_t Reporter::tests_failed() const {
1✔
125
   return std::transform_reduce(
1✔
126
      m_testsuites.begin(), m_testsuites.end(), size_t(0), std::plus{}, [](const auto& testsuite) {
401✔
127
         return testsuite.second.tests_failed();
802✔
128
      });
1✔
129
}
130

131
std::chrono::nanoseconds Reporter::elapsed_time() const {
2✔
132
   return std::chrono::high_resolution_clock::now() - m_start_time;
2✔
133
}
134

135
}  // namespace Botan_Tests
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc