From f7ecbd6d2083d5de005c6267a73c6d374ff1fc4b Mon Sep 17 00:00:00 2001 From: sha512sum Date: Sun, 7 Jul 2024 00:48:00 +0000 Subject: [PATCH] Fix clang-tidy and clang-format for tests and examples/src/constexpr_check.cpp --- examples/src/constexpr_check.cpp | 16 +++++----- tests/all_meta.cpp | 54 +++++++++++++------------------- tests/dependencies.cpp | 30 +++++++----------- tests/meta.cpp | 43 ++++++++++--------------- 4 files changed, 58 insertions(+), 85 deletions(-) diff --git a/examples/src/constexpr_check.cpp b/examples/src/constexpr_check.cpp index dec73c2..a0f9d4a 100644 --- a/examples/src/constexpr_check.cpp +++ b/examples/src/constexpr_check.cpp @@ -1,34 +1,33 @@ #include - struct SomeComponent { static constexpr utempl::ConstexprString kName = "component"; - constexpr SomeComponent(auto&) {}; + explicit constexpr SomeComponent(auto&) {}; }; - struct SomeComponent2 { static constexpr utempl::ConstexprString kName = "component2"; - constexpr SomeComponent2(auto&) {}; + explicit constexpr SomeComponent2(auto&) {}; }; struct OtherComponent { static constexpr utempl::ConstexprString kName = "other"; auto Foo(auto& context) -> void { - context.template FindComponent<"component2">(); // UB on runtime with old check - // Compile time error with new check(check via loopholes) + context.template FindComponent<"component2">(); // UB on runtime with old check + // Compile time error with new check(check via loopholes) }; - constexpr OtherComponent(auto& context) { + explicit constexpr OtherComponent(auto& context) { context.template FindComponent<"component">(); Foo(context); }; }; - +// clang-format off +// NOLINTBEGIN auto main() -> int { cserver::ServiceContextBuilder{} .AppendConfigParam<"threads", 8>() @@ -38,3 +37,4 @@ auto main() -> int { .Sort() .Run(); }; +// NOLINTEND diff --git a/tests/all_meta.cpp b/tests/all_meta.cpp index 562c236..f74fa39 100644 --- a/tests/all_meta.cpp +++ b/tests/all_meta.cpp @@ -1,12 +1,16 @@ #include + #include #include -COMPONENT_REQUIRES(Some, requires(T t){{t.f()} -> std::same_as;}); +COMPONENT_REQUIRES( + Some, requires(T t) { + { t.f() } -> std::same_as; + }); struct SomeComponent { static constexpr utempl::ConstexprString kName = "some"; - constexpr SomeComponent(auto& context) { + explicit constexpr SomeComponent(auto& context) { context.template FindAllComponents(); }; }; @@ -14,48 +18,34 @@ struct SomeComponent { struct OtherComponent { static constexpr utempl::ConstexprString kName = "other"; auto f() -> void {}; - constexpr OtherComponent(auto& context) {}; + explicit constexpr OtherComponent(auto& context) {}; }; struct OtherComponent2 { static constexpr utempl::ConstexprString kName = "other2"; auto f() -> void {}; - constexpr OtherComponent2(auto& context) {}; + explicit constexpr OtherComponent2(auto& context) {}; }; - - - -TEST(Meta, AllDependencies) { +TEST(Meta, AllDependencies) { constexpr auto builder = cserver::ServiceContextBuilder{} - .Append() - .Append() - .Append() - .AppendConfigParam<"threads", 8>() - .Sort(); + .Append() + .Append() + .Append() + .AppendConfigParam<"threads", 8>() + .Sort(); constexpr auto dependencies = builder.GetDependencyGraph(); using Need = utempl::Tuple; - using R = decltype( - builder - .GetServiceContext() - .GetContextFor>() - .FindAllComponents()); + using R = + decltype(builder.GetServiceContext().GetContextFor>().FindAllComponents()); + + EXPECT_EQ(NAMEOF_TYPE(R), NAMEOF_TYPE(Need)); - EXPECT_EQ(NAMEOF_TYPE(R), - NAMEOF_TYPE(Need)); - using DependenciesNeed = const cserver::DependencyGraph< - cserver::DependencyGraphElement< - "other", - {}>, - cserver::DependencyGraphElement< - "other2", - {}>, - cserver::DependencyGraphElement< - "some", - {utempl::ConstexprString{"other"}, utempl::ConstexprString{"other2"}}>>; + cserver::DependencyGraphElement<"other", {}>, + cserver::DependencyGraphElement<"other2", {}>, + cserver::DependencyGraphElement<"some", {utempl::ConstexprString{"other"}, utempl::ConstexprString{"other2"}}>>; - EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), - NAMEOF_TYPE(DependenciesNeed)); + EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), NAMEOF_TYPE(DependenciesNeed)); }; diff --git a/tests/dependencies.cpp b/tests/dependencies.cpp index 723b977..6792415 100644 --- a/tests/dependencies.cpp +++ b/tests/dependencies.cpp @@ -1,35 +1,27 @@ #include + #include #include struct SomeComponent { static constexpr utempl::ConstexprString kName = "some"; - constexpr SomeComponent(auto&) {}; + explicit constexpr SomeComponent(auto&) {}; }; - struct SomeOtherComponent { SomeComponent& component; static constexpr utempl::ConstexprString kName = "other"; - constexpr SomeOtherComponent(auto& context) : component(context.template FindComponent<"some">()) { - }; + explicit constexpr SomeOtherComponent(auto& context) : component(context.template FindComponent<"some">()) {}; }; - TEST(Dependencies, Get) { constexpr auto dependencies = cserver::ServiceContextBuilder{} - .Append() - .Append() - .AppendConfigParam<"threads", 8>() - .Sort() - .GetDependencyGraph(); - using Need = const cserver::DependencyGraph< - cserver::DependencyGraphElement< - "some", - {}>, - cserver::DependencyGraphElement< - "other", - {utempl::ConstexprString{"some"}}>>; - EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), - NAMEOF_TYPE(Need)); + .Append() + .Append() + .AppendConfigParam<"threads", 8>() + .Sort() + .GetDependencyGraph(); + using Need = const cserver::DependencyGraph, + cserver::DependencyGraphElement<"other", {utempl::ConstexprString{"some"}}>>; + EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), NAMEOF_TYPE(Need)); }; diff --git a/tests/meta.cpp b/tests/meta.cpp index 160c313..cd80a59 100644 --- a/tests/meta.cpp +++ b/tests/meta.cpp @@ -1,12 +1,16 @@ #include + #include #include -COMPONENT_REQUIRES(Some, requires(T t){{t.f()} -> std::same_as;}); +COMPONENT_REQUIRES( + Some, requires(T t) { + { t.f() } -> std::same_as; + }); struct SomeComponent { static constexpr utempl::ConstexprString kName = "some"; - constexpr SomeComponent(auto& context) { + explicit constexpr SomeComponent(auto& context) { context.template FindComponent(); }; }; @@ -14,37 +18,28 @@ struct SomeComponent { struct OtherComponent { static constexpr utempl::ConstexprString kName = "other"; auto f() -> void {}; - constexpr OtherComponent(auto& context) {}; + explicit constexpr OtherComponent(auto& context) {}; }; struct OtherComponent2 { static constexpr utempl::ConstexprString kName = "other2"; auto f() -> void {}; - constexpr OtherComponent2(auto& context) {}; + explicit constexpr OtherComponent2(auto& context) {}; }; - TEST(Meta, OneDependency) { constexpr auto builder = cserver::ServiceContextBuilder{} - .Append() - .Append() - .Append() - .AppendConfigParam<"threads", 8>() - .Sort(); + .Append() + .Append() + .Append() + .AppendConfigParam<"threads", 8>() + .Sort(); constexpr auto dependencies = builder.GetDependencyGraph(); - using Need = const cserver::DependencyGraph< - cserver::DependencyGraphElement< - "other", - {}>, - cserver::DependencyGraphElement< - "some", - {utempl::ConstexprString{"other"}}>, - cserver::DependencyGraphElement< - "other2", - {}>>; + using Need = const cserver::DependencyGraph, + cserver::DependencyGraphElement<"some", {utempl::ConstexprString{"other"}}>, + cserver::DependencyGraphElement<"other2", {}>>; - EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), - NAMEOF_TYPE(Need)); + EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), NAMEOF_TYPE(Need)); }; struct SomeStruct2 { @@ -52,7 +47,3 @@ struct SomeStruct2 { context.template FindAllComponents(); }; }; - - - -