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

randombit / botan / 13215274653

08 Feb 2025 11:38AM UTC coverage: 91.655% (-0.009%) from 91.664%
13215274653

Pull #4650

github

web-flow
Merge 107f31833 into bc555cd3c
Pull Request #4650: Reorganize code and reduce header dependencies

94836 of 103471 relevant lines covered (91.65%)

11230958.94 hits per line

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

87.32
/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,014✔
19
   if(!a.has_value() || !b.has_value()) {
1,792✔
20
      return std::nullopt;
21
   }
22

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

26
}  // namespace
27

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

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

39
void Testsuite::record(const Test::Result& result) {
2,428✔
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 {
794✔
48
   return std::count_if(m_results.begin(), m_results.end(), [](const auto& r) { return r.failed(); });
5,253✔
49
}
50

51
std::chrono::system_clock::time_point Testsuite::timestamp() const {
397✔
52
   return std::transform_reduce(
397✔
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,125✔
58
}
59

60
std::optional<std::chrono::nanoseconds> Testsuite::elapsed_time() const {
397✔
61
   return std::transform_reduce(
397✔
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,124✔
66
      [](const auto& result) { return result.elapsed_time; });
1,259✔
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,428✔
84
   auto& suite = m_testsuites.try_emplace(name, name).first->second;
2,428✔
85
   suite.record(result);
2,428✔
86
}
2,428✔
87

88
void Reporter::record(const std::string& testsuite_name, const std::vector<Botan_Tests::Test::Result>& results) {
794✔
89
   std::map<std::string, Botan_Tests::Test::Result> combined;
794✔
90
   for(const auto& result : results) {
100,572✔
91
      const auto& who = result.who();
99,778✔
92
      auto i = combined.find(who);
99,778✔
93
      if(i == combined.end()) {
99,778✔
94
         combined.insert(std::make_pair(who, Botan_Tests::Test::Result(who)));
14,568✔
95
         i = combined.find(who);
4,856✔
96
      }
97

98
      i->second.merge(result);
99,778✔
99
   }
100

101
   next_testsuite(testsuite_name);
794✔
102
   for(const auto& result : combined) {
5,650✔
103
      record(testsuite_name, result.second);
4,856✔
104
   }
105
}
794✔
106

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

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

121
size_t Reporter::tests_failed() const {
1✔
122
   return std::transform_reduce(
1✔
123
      m_testsuites.begin(), m_testsuites.end(), size_t(0), std::plus{}, [](const auto& testsuite) {
397✔
124
         return testsuite.second.tests_failed();
794✔
125
      });
1✔
126
}
127

128
std::chrono::nanoseconds Reporter::elapsed_time() const {
2✔
129
   return std::chrono::high_resolution_clock::now() - m_start_time;
2✔
130
}
131

132
}  // 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

© 2025 Coveralls, Inc