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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

88.41
/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) {
653✔
18
   if(!a.has_value() || !b.has_value()) {
1,240✔
19
      return std::nullopt;
20
   }
21

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

25
}
26

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

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

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

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

44
size_t Testsuite::tests_failed() const {
622✔
45
   return std::count_if(m_results.begin(), m_results.end(), [](const auto& r) { return r.failed(); });
3,597✔
46
}
47

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

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

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

68
void Reporter::set_property(const std::string& name, const std::string& value) {
11✔
69
   m_properties.insert_or_assign(name, value);
11✔
70
}
11✔
71

72
void Reporter::next_test_run() {
2✔
73
   m_start_time = std::chrono::high_resolution_clock::now();
2✔
74
   ++m_current_test_run;
2✔
75
   m_testsuites.clear();
2✔
76

77
   next_run();
2✔
78
}
2✔
79

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

85
void Reporter::record(const std::string& testsuite_name, const std::vector<Botan_Tests::Test::Result>& results) {
622✔
86
   std::map<std::string, Botan_Tests::Test::Result> combined;
622✔
87
   for(const auto& result : results) {
90,938✔
88
      const auto& who = result.who();
90,316✔
89
      auto i = combined.find(who);
90,316✔
90
      if(i == combined.end()) {
90,316✔
91
         combined.insert(std::make_pair(who, Botan_Tests::Test::Result(who)));
6,572✔
92
         i = combined.find(who);
3,286✔
93
      }
94

95
      i->second.merge(result);
90,316✔
96
   }
97

98
   next_testsuite(testsuite_name);
622✔
99
   for(const auto& result : combined) {
3,908✔
100
      record(testsuite_name, result.second);
3,286✔
101
   }
102
}
622✔
103

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

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

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

125
std::chrono::nanoseconds Reporter::elapsed_time() const {
2✔
126
   return std::chrono::high_resolution_clock::now() - m_start_time;
2✔
127
}
128

129
}
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