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

randombit / botan / 5230455705

10 Jun 2023 02:30PM UTC coverage: 91.715% (-0.03%) from 91.746%
5230455705

push

github

randombit
Merge GH #3584 Change clang-format AllowShortFunctionsOnASingleLine config from All to Inline

77182 of 84154 relevant lines covered (91.72%)

11975295.43 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 <numeric>
11

12
namespace Botan_Tests {
13

14
namespace {
15

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

22
   return a.value() + b.value();
23
}
24

25
}  // namespace
26

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

36
Testsuite::Testsuite(std::string name) : m_name(std::move(name)) {}
37

38
void Testsuite::record(const Test::Result& result) {
39
   m_results.emplace_back(result);
40
}
41

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

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

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

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

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

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

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

79
   next_run();
80
}
81

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

87
void Reporter::record(const std::string& testsuite_name, const std::vector<Botan_Tests::Test::Result>& results) {
88
   std::map<std::string, Botan_Tests::Test::Result> combined;
89
   for(const auto& result : results) {
90
      const auto& who = result.who();
91
      auto i = combined.find(who);
92
      if(i == combined.end()) {
93
         combined.insert(std::make_pair(who, Botan_Tests::Test::Result(who)));
94
         i = combined.find(who);
95
      }
96

97
      i->second.merge(result);
98
   }
99

100
   next_testsuite(testsuite_name);
101
   for(const auto& result : combined) {
102
      record(testsuite_name, result.second);
103
   }
104
}
105

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

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

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

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

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