Fix clang-tidy and clang-format for tests and examples/src/constexpr_check.cpp

This commit is contained in:
sha512sum 2024-07-07 00:48:00 +00:00
parent e5b4a231fc
commit f7ecbd6d20
4 changed files with 58 additions and 85 deletions

View file

@ -1,17 +1,15 @@
#include <cserver/components/loggable_component_base.hpp> #include <cserver/components/loggable_component_base.hpp>
struct SomeComponent { struct SomeComponent {
static constexpr utempl::ConstexprString kName = "component"; static constexpr utempl::ConstexprString kName = "component";
constexpr SomeComponent(auto&) {}; explicit constexpr SomeComponent(auto&) {};
}; };
struct SomeComponent2 { struct SomeComponent2 {
static constexpr utempl::ConstexprString kName = "component2"; static constexpr utempl::ConstexprString kName = "component2";
constexpr SomeComponent2(auto&) {}; explicit constexpr SomeComponent2(auto&) {};
}; };
struct OtherComponent { struct OtherComponent {
@ -22,13 +20,14 @@ struct OtherComponent {
// Compile time error with new check(check via loopholes) // Compile time error with new check(check via loopholes)
}; };
constexpr OtherComponent(auto& context) { explicit constexpr OtherComponent(auto& context) {
context.template FindComponent<"component">(); context.template FindComponent<"component">();
Foo(context); Foo(context);
}; };
}; };
// clang-format off
// NOLINTBEGIN
auto main() -> int { auto main() -> int {
cserver::ServiceContextBuilder{} cserver::ServiceContextBuilder{}
.AppendConfigParam<"threads", 8>() .AppendConfigParam<"threads", 8>()
@ -38,3 +37,4 @@ auto main() -> int {
.Sort() .Sort()
.Run(); .Run();
}; };
// NOLINTEND

View file

@ -1,12 +1,16 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <cserver/engine/components.hpp> #include <cserver/engine/components.hpp>
#include <nameof.hpp> #include <nameof.hpp>
COMPONENT_REQUIRES(Some, requires(T t){{t.f()} -> std::same_as<void>;}); COMPONENT_REQUIRES(
Some, requires(T t) {
{ t.f() } -> std::same_as<void>;
});
struct SomeComponent { struct SomeComponent {
static constexpr utempl::ConstexprString kName = "some"; static constexpr utempl::ConstexprString kName = "some";
constexpr SomeComponent(auto& context) { explicit constexpr SomeComponent(auto& context) {
context.template FindAllComponents<SomeM>(); context.template FindAllComponents<SomeM>();
}; };
}; };
@ -14,18 +18,15 @@ struct SomeComponent {
struct OtherComponent { struct OtherComponent {
static constexpr utempl::ConstexprString kName = "other"; static constexpr utempl::ConstexprString kName = "other";
auto f() -> void {}; auto f() -> void {};
constexpr OtherComponent(auto& context) {}; explicit constexpr OtherComponent(auto& context) {};
}; };
struct OtherComponent2 { struct OtherComponent2 {
static constexpr utempl::ConstexprString kName = "other2"; static constexpr utempl::ConstexprString kName = "other2";
auto f() -> void {}; auto f() -> void {};
constexpr OtherComponent2(auto& context) {}; explicit constexpr OtherComponent2(auto& context) {};
}; };
TEST(Meta, AllDependencies) { TEST(Meta, AllDependencies) {
constexpr auto builder = cserver::ServiceContextBuilder{} constexpr auto builder = cserver::ServiceContextBuilder{}
.Append<SomeComponent>() .Append<SomeComponent>()
@ -36,26 +37,15 @@ TEST(Meta, AllDependencies) {
constexpr auto dependencies = builder.GetDependencyGraph(); constexpr auto dependencies = builder.GetDependencyGraph();
using Need = utempl::Tuple<OtherComponent&, OtherComponent2&>; using Need = utempl::Tuple<OtherComponent&, OtherComponent2&>;
using R = decltype( using R =
builder decltype(builder.GetServiceContext().GetContextFor<cserver::ComponentConfig<"some", SomeComponent, {}>>().FindAllComponents<SomeM>());
.GetServiceContext()
.GetContextFor<cserver::ComponentConfig<"some", SomeComponent, {}>>()
.FindAllComponents<SomeM>());
EXPECT_EQ(NAMEOF_TYPE(R), EXPECT_EQ(NAMEOF_TYPE(R), NAMEOF_TYPE(Need));
NAMEOF_TYPE(Need));
using DependenciesNeed = const cserver::DependencyGraph< using DependenciesNeed = const cserver::DependencyGraph<
cserver::DependencyGraphElement< cserver::DependencyGraphElement<"other", {}>,
"other", cserver::DependencyGraphElement<"other2", {}>,
{}>, cserver::DependencyGraphElement<"some", {utempl::ConstexprString{"other"}, utempl::ConstexprString{"other2"}}>>;
cserver::DependencyGraphElement<
"other2",
{}>,
cserver::DependencyGraphElement<
"some",
{utempl::ConstexprString{"other"}, utempl::ConstexprString{"other2"}}>>;
EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), NAMEOF_TYPE(DependenciesNeed));
NAMEOF_TYPE(DependenciesNeed));
}; };

View file

@ -1,20 +1,18 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <cserver/engine/components.hpp> #include <cserver/engine/components.hpp>
#include <nameof.hpp> #include <nameof.hpp>
struct SomeComponent { struct SomeComponent {
static constexpr utempl::ConstexprString kName = "some"; static constexpr utempl::ConstexprString kName = "some";
constexpr SomeComponent(auto&) {}; explicit constexpr SomeComponent(auto&) {};
}; };
struct SomeOtherComponent { struct SomeOtherComponent {
SomeComponent& component; SomeComponent& component;
static constexpr utempl::ConstexprString kName = "other"; 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) { TEST(Dependencies, Get) {
constexpr auto dependencies = cserver::ServiceContextBuilder{} constexpr auto dependencies = cserver::ServiceContextBuilder{}
@ -23,13 +21,7 @@ TEST(Dependencies, Get) {
.AppendConfigParam<"threads", 8>() .AppendConfigParam<"threads", 8>()
.Sort() .Sort()
.GetDependencyGraph(); .GetDependencyGraph();
using Need = const cserver::DependencyGraph< using Need = const cserver::DependencyGraph<cserver::DependencyGraphElement<"some", {}>,
cserver::DependencyGraphElement< cserver::DependencyGraphElement<"other", {utempl::ConstexprString{"some"}}>>;
"some", EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), NAMEOF_TYPE(Need));
{}>,
cserver::DependencyGraphElement<
"other",
{utempl::ConstexprString{"some"}}>>;
EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)),
NAMEOF_TYPE(Need));
}; };

View file

@ -1,12 +1,16 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <cserver/engine/components.hpp> #include <cserver/engine/components.hpp>
#include <nameof.hpp> #include <nameof.hpp>
COMPONENT_REQUIRES(Some, requires(T t){{t.f()} -> std::same_as<void>;}); COMPONENT_REQUIRES(
Some, requires(T t) {
{ t.f() } -> std::same_as<void>;
});
struct SomeComponent { struct SomeComponent {
static constexpr utempl::ConstexprString kName = "some"; static constexpr utempl::ConstexprString kName = "some";
constexpr SomeComponent(auto& context) { explicit constexpr SomeComponent(auto& context) {
context.template FindComponent<SomeM>(); context.template FindComponent<SomeM>();
}; };
}; };
@ -14,16 +18,15 @@ struct SomeComponent {
struct OtherComponent { struct OtherComponent {
static constexpr utempl::ConstexprString kName = "other"; static constexpr utempl::ConstexprString kName = "other";
auto f() -> void {}; auto f() -> void {};
constexpr OtherComponent(auto& context) {}; explicit constexpr OtherComponent(auto& context) {};
}; };
struct OtherComponent2 { struct OtherComponent2 {
static constexpr utempl::ConstexprString kName = "other2"; static constexpr utempl::ConstexprString kName = "other2";
auto f() -> void {}; auto f() -> void {};
constexpr OtherComponent2(auto& context) {}; explicit constexpr OtherComponent2(auto& context) {};
}; };
TEST(Meta, OneDependency) { TEST(Meta, OneDependency) {
constexpr auto builder = cserver::ServiceContextBuilder{} constexpr auto builder = cserver::ServiceContextBuilder{}
.Append<SomeComponent>() .Append<SomeComponent>()
@ -32,19 +35,11 @@ TEST(Meta, OneDependency) {
.AppendConfigParam<"threads", 8>() .AppendConfigParam<"threads", 8>()
.Sort(); .Sort();
constexpr auto dependencies = builder.GetDependencyGraph(); constexpr auto dependencies = builder.GetDependencyGraph();
using Need = const cserver::DependencyGraph< using Need = const cserver::DependencyGraph<cserver::DependencyGraphElement<"other", {}>,
cserver::DependencyGraphElement< cserver::DependencyGraphElement<"some", {utempl::ConstexprString{"other"}}>,
"other", cserver::DependencyGraphElement<"other2", {}>>;
{}>,
cserver::DependencyGraphElement<
"some",
{utempl::ConstexprString{"other"}}>,
cserver::DependencyGraphElement<
"other2",
{}>>;
EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), NAMEOF_TYPE(Need));
NAMEOF_TYPE(Need));
}; };
struct SomeStruct2 { struct SomeStruct2 {
@ -52,7 +47,3 @@ struct SomeStruct2 {
context.template FindAllComponents<SomeM>(); context.template FindAllComponents<SomeM>();
}; };
}; };