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

randombit / botan / 20579846577

29 Dec 2025 06:24PM UTC coverage: 90.415% (+0.2%) from 90.243%
20579846577

push

github

web-flow
Merge pull request #5167 from randombit/jack/src-size-reductions

Changes to reduce unnecessary inclusions

101523 of 112285 relevant lines covered (90.42%)

12817276.56 hits per line

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

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

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

26
}  // namespace
27

28
TestSummary::TestSummary(const Test::Result& result) :
2,508✔
29
      m_name(result.who()),
2,508✔
30
      m_code_location(result.code_location()),
2,508✔
31
      m_assertions(result.tests_run()),
2,508✔
32
      m_notes(result.notes()),
2,508✔
33
      m_failures(result.failures()),
2,508✔
34
      m_timestamp(
2,508✔
35
         std::chrono::duration_cast<std::chrono::system_clock::duration>(std::chrono::nanoseconds(result.timestamp()))),
2,508✔
36
      m_elapsed_time(result.elapsed_time()) {}
5,444✔
37

38
Testsuite::Testsuite(std::string name) : m_name(std::move(name)) {}
412✔
39

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

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

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

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

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

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

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

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

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

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

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

93
void Reporter::record(const std::string& testsuite_name, const std::vector<Botan_Tests::Test::Result>& results) {
824✔
94
   std::map<std::string, Botan_Tests::Test::Result> combined;
824✔
95
   for(const auto& result : results) {
101,626✔
96
      const auto& who = result.who();
100,802✔
97
      auto i = combined.find(who);
100,802✔
98
      if(i == combined.end()) {
100,802✔
99
         combined.insert(std::make_pair(who, Botan_Tests::Test::Result(who)));
20,064✔
100
         i = combined.find(who);
5,016✔
101
      }
102

103
      i->second.merge(result);
100,802✔
104
   }
105

106
   for(const auto& result : combined) {
5,840✔
107
      record(testsuite_name, result.second);
5,016✔
108
   }
109
}
824✔
110

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

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

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

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

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