refactor: Use more scoped enums (#7086)

This commit is contained in:
Alex Kremer
2026-05-11 16:39:48 +01:00
committed by GitHub
parent 779b49cd93
commit cdee9a675c
379 changed files with 2771 additions and 2864 deletions

View File

@@ -14,7 +14,7 @@ class SuiteJournalSink : public beast::Journal::Sink
public:
SuiteJournalSink(
std::string const& partition,
beast::severities::Severity threshold,
beast::Severity threshold,
beast::unit_test::Suite& suite)
: Sink(threshold, false), partition_(partition + " "), suite_(suite)
{
@@ -22,20 +22,20 @@ public:
// For unit testing, always generate logging text.
[[nodiscard]] bool
active(beast::severities::Severity level) const override
active(beast::Severity level) const override
{
return true;
}
void
write(beast::severities::Severity level, std::string const& text) override;
write(beast::Severity level, std::string const& text) override;
void
writeAlways(beast::severities::Severity level, std::string const& text) override;
writeAlways(beast::Severity level, std::string const& text) override;
};
inline void
SuiteJournalSink::write(beast::severities::Severity level, std::string const& text)
SuiteJournalSink::write(beast::Severity level, std::string const& text)
{
// Only write the string if the level at least equals the threshold.
if (level >= threshold())
@@ -43,26 +43,26 @@ SuiteJournalSink::write(beast::severities::Severity level, std::string const& te
}
inline void
SuiteJournalSink::writeAlways(beast::severities::Severity level, std::string const& text)
SuiteJournalSink::writeAlways(beast::Severity level, std::string const& text)
{
using namespace beast::severities;
using beast::Severity;
char const* const s = [level]() {
switch (level)
{
case KTrace:
case Severity::Trace:
return "TRC:";
case KDebug:
case Severity::Debug:
return "DBG:";
case KInfo:
case Severity::Info:
return "INF:";
case KWarning:
case Severity::Warning:
return "WRN:";
case KError:
case Severity::Error:
return "ERR:";
default:
break;
case KFatal:
case Severity::Fatal:
break;
}
return "FTL:";
@@ -82,7 +82,7 @@ public:
SuiteJournal(
std::string const& partition,
beast::unit_test::Suite& suite,
beast::severities::Severity threshold = beast::severities::KFatal)
beast::Severity threshold = beast::Severity::Fatal)
: sink_(partition, threshold, suite), journal_(sink_)
{
}
@@ -100,13 +100,12 @@ class StreamSink : public beast::Journal::Sink
std::stringstream strm_;
public:
StreamSink(beast::severities::Severity threshold = beast::severities::KDebug)
: Sink(threshold, false)
StreamSink(beast::Severity threshold = beast::Severity::Debug) : Sink(threshold, false)
{
}
void
write(beast::severities::Severity level, std::string const& text) override
write(beast::Severity level, std::string const& text) override
{
if (level < threshold())
return;
@@ -114,7 +113,7 @@ public:
}
void
writeAlways(beast::severities::Severity level, std::string const& text) override
writeAlways(beast::Severity level, std::string const& text) override
{
strm_ << text << std::endl;
}

View File

@@ -75,19 +75,19 @@ Results::add(SuiteResults const& r)
if (iter != top.end())
{
if (top.size() == MaxTop && iter == top.end() - 1)
if (top.size() == kMAX_TOP && iter == top.end() - 1)
{
// avoid invalidating the iterator
*iter = run_time{static_string{static_string::string_view_type{r.name}}, elapsed};
}
else
{
if (top.size() == MaxTop)
if (top.size() == kMAX_TOP)
top.resize(top.size() - 1);
top.emplace(iter, static_string{static_string::string_view_type{r.name}}, elapsed);
}
}
else if (top.size() < MaxTop)
else if (top.size() < kMAX_TOP)
{
top.emplace_back(static_string{static_string::string_view_type{r.name}}, elapsed);
}
@@ -103,14 +103,14 @@ Results::merge(Results const& r)
failed += r.failed;
// combine the two top collections
boost::container::static_vector<run_time, 2 * MaxTop> topResult;
boost::container::static_vector<run_time, 2 * kMAX_TOP> topResult;
topResult.resize(top.size() + r.top.size());
std::ranges::merge(top, r.top, topResult.begin(), [](run_time const& t1, run_time const& t2) {
return t1.second > t2.second;
});
if (topResult.size() > MaxTop)
topResult.resize(MaxTop);
if (topResult.size() > kMAX_TOP)
topResult.resize(kMAX_TOP);
top = topResult;
}

View File

@@ -59,15 +59,13 @@ struct Results
// pointers from different memory spaces do not co-mingle
using run_time = std::pair<static_string, typename clock_type::duration>;
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum { MaxTop = 10 };
static constexpr auto kMAX_TOP = 10;
std::size_t suites = 0;
std::size_t cases = 0;
std::size_t total = 0;
std::size_t failed = 0;
boost::container::static_vector<run_time, MaxTop> top;
boost::container::static_vector<run_time, kMAX_TOP> top;
typename clock_type::time_point start = clock_type::now();
void