Skip to content

Commit

Permalink
Fix some more clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasleibner committed Feb 4, 2025
1 parent ba4d4d9 commit 2063107
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
6 changes: 4 additions & 2 deletions example/parameterized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@

namespace boost::inline ext::ut {

namespace {
template <std::floating_point F>
static std::string format_test_parameter(const std::complex<F>& arg,
std::string format_test_parameter(const std::complex<F>& arg,
[[maybe_unused]] const int counter) {
std::ostringstream oss;
oss << arg.real() << '+' << arg.imag() << 'i';
return oss.str();
}
} // namespace

}
} // namespace boost::inline ext::ut

int main() {
using namespace boost::ut;
Expand Down
51 changes: 31 additions & 20 deletions test/ut/ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
#include <sstream>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#if __has_include(<format>)
#include <format>
#endif

namespace ut = boost::ut;

namespace test_has_member_object {
Expand All @@ -46,7 +43,7 @@ struct public_static_member_object_value {
};

struct public_member_function_value {
// NOLINTNEXTLINE(-readability-convert-member-functions-to-static)
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
int value() const { return 0; }
};

Expand All @@ -70,6 +67,7 @@ struct public_static_member_object_epsilon {
};

struct public_member_function_epsilon {
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
int epsilon() const { return 0; }
};

Expand All @@ -79,12 +77,13 @@ struct public_static_member_function_epsilon {

} // namespace test_has_member_object

constexpr auto to_string = [](const auto expr) {
constexpr auto to_string = [](const auto& expr) {
ut::printer printer{{.none = "", .pass = "", .fail = ""}};
printer << std::boolalpha << expr;
return printer.str();
};

namespace {
auto test_assert =
[](const bool result, const ut::reflection::source_location& sl =
ut::reflection::source_location::current()) {
Expand All @@ -94,6 +93,7 @@ auto test_assert =
std::abort();
}
};
}

struct fake_cfg {
struct assertion_call {
Expand Down Expand Up @@ -143,7 +143,7 @@ struct fake_cfg {
}

template <class TExpr>
auto on(ut::events::assertion<TExpr> assertion) -> bool {
auto on(const ut::events::assertion<TExpr>& assertion) -> bool {
assertion_calls.push_back({.expr = to_string(assertion.expr),
.location = assertion.location,
.result = assertion.expr});
Expand Down Expand Up @@ -173,7 +173,7 @@ template <class T>
class fake_calculator {
public:
auto enter(const T& value) -> void { values_.push_back(value); }
auto name(std::string value) -> void { name_ = value; }
auto name(std::string value) -> void { name_ = std::move(value); }
auto add() -> void {
result_ = std::accumulate(std::cbegin(values_), std::cend(values_), 0);
}
Expand Down Expand Up @@ -207,6 +207,7 @@ struct test_empty {
};

struct test_throw {
// NOLINTNEXTLINE(hicpp-exception-baseclass)
auto operator()() -> void { throw 42; }
};

Expand Down Expand Up @@ -291,13 +292,13 @@ struct test_summary_reporter : ut::reporter<ut::printer> {

auto count_runs(std::size_t& counter) -> void { runs_counter_ = &counter; }

auto on(ut::events::summary) -> void {
auto on(ut::events::summary) const -> void {
if (summary_counter_) {
++*summary_counter_;
}
}

auto on(ut::events::run_begin) -> void {
auto on(ut::events::run_begin) const -> void {
if (runs_counter_) {
++*runs_counter_;
}
Expand All @@ -312,16 +313,20 @@ struct test_summary_runner : ut::runner<test_summary_reporter> {
};

namespace ns {
namespace {
template <char... Cs>
constexpr auto operator""_i() -> int {
return sizeof...(Cs);
}
static auto f() -> int { return 0_i; }
auto f() -> int { return 0_i; }
}
} // namespace ns
static auto f() -> int {
namespace {
auto f() -> int {
using namespace ns;
return 42_i;
}
}

struct custom {
int i{};
Expand Down Expand Up @@ -363,15 +368,17 @@ struct custom_printable_type {
int value;
};

// NOLINTBEGIN(misc-use-anonymous-namespace)
static std::string format_test_parameter(const custom_printable_type& value,
[[maybe_unused]] const int counter) {
[[maybe_unused]] const int counter) {
return "custom_printable_type(" + std::to_string(value.value) + ")";
}

template <class... Ts>
static auto ut::cfg<ut::override, Ts...> = fake_cfg{};
// NOLINTEND(misc-use-anonymous-namespace)

int main() {
int main() { // NOLINT(readability-function-size)
{
using namespace ut;
using namespace std::literals::string_view_literals;
Expand Down Expand Up @@ -670,8 +677,8 @@ int main() {
{
std::stringstream out{};
std::stringstream err{};
auto old_cout = std::cout.rdbuf(out.rdbuf());
auto old_cerr = std::cerr.rdbuf(err.rdbuf());
auto* old_cout = std::cout.rdbuf(out.rdbuf());
auto* old_cerr = std::cerr.rdbuf(err.rdbuf());

auto reporter = test_reporter{};

Expand Down Expand Up @@ -864,7 +871,7 @@ int main() {
{
test_summary_runner run;
run.reporter_.count_summaries(summary_count);
test_assert(false == run.run({.report_errors = true}));
test_assert(!run.run({.report_errors = true}));
}
test_assert(1 == summary_count);
}
Expand All @@ -874,7 +881,7 @@ int main() {
{
auto run = test_summary_runner{};
run.reporter_.count_runs(run_count);
test_assert(false == run.run({.report_errors = true}));
test_assert(!run.run({.report_errors = true}));
}
test_assert(1 == run_count);
}
Expand Down Expand Up @@ -1405,6 +1412,7 @@ int main() {
}

{
// NOLINTBEGIN(hicpp-exception-baseclass)
test_cfg = fake_cfg{};

"exceptions"_test = [] {
Expand Down Expand Up @@ -1452,7 +1460,9 @@ int main() {

"should throw"_test = [] {
auto f = [](const auto should_throw) {
if (should_throw) throw 42;
if (should_throw) {
throw 42;
}
return 42;
};
expect(42_i == f(true));
Expand All @@ -1477,6 +1487,7 @@ int main() {
test_assert("events::exception message"sv == test_cfg.exception_calls[2]);
test_assert("Unknown exception"sv == test_cfg.exception_calls[3]);
test_assert(6 == std::size(test_cfg.assertion_calls));
// NOLINTEND(hicpp-exception-baseclass)
}

#if __has_include(<unistd.h>) and __has_include(<sys/wait.h>) and not defined(EMSCRIPTEN)
Expand Down Expand Up @@ -1930,7 +1941,7 @@ int main() {
calc.enter(value);
};
steps.when("I name it '{value}'") = [&](std::string value) {
calc.name(value);
calc.name(std::move(value));
};
steps.when("I press add") = [&] { calc.add(); };
steps.when("I press sub") = [&] { calc.sub(); };
Expand Down

0 comments on commit 2063107

Please sign in to comment.