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,34 +1,33 @@
#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 {
static constexpr utempl::ConstexprString kName = "other"; static constexpr utempl::ConstexprString kName = "other";
auto Foo(auto& context) -> void { auto Foo(auto& context) -> void {
context.template FindComponent<"component2">(); // UB on runtime with old check context.template FindComponent<"component2">(); // UB on runtime with old check
// 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,48 +18,34 @@ 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>()
.Append<OtherComponent>() .Append<OtherComponent>()
.Append<OtherComponent2>() .Append<OtherComponent2>()
.AppendConfigParam<"threads", 8>() .AppendConfigParam<"threads", 8>()
.Sort(); .Sort();
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, {}>>() EXPECT_EQ(NAMEOF_TYPE(R), NAMEOF_TYPE(Need));
.FindAllComponents<SomeM>());
EXPECT_EQ(NAMEOF_TYPE(R),
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,35 +1,27 @@
#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{}
.Append<SomeOtherComponent>() .Append<SomeOtherComponent>()
.Append<SomeComponent>() .Append<SomeComponent>()
.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,37 +18,28 @@ 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>()
.Append<OtherComponent>() .Append<OtherComponent>()
.Append<OtherComponent2>() .Append<OtherComponent2>()
.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>();
}; };
}; };