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>
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

View file

@ -1,12 +1,16 @@
#include <gtest/gtest.h>
#include <cserver/engine/components.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 {
static constexpr utempl::ConstexprString kName = "some";
constexpr SomeComponent(auto& context) {
explicit constexpr SomeComponent(auto& context) {
context.template FindAllComponents<SomeM>();
};
};
@ -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) {
constexpr auto builder = cserver::ServiceContextBuilder{}
.Append<SomeComponent>()
.Append<OtherComponent>()
.Append<OtherComponent2>()
.AppendConfigParam<"threads", 8>()
.Sort();
.Append<SomeComponent>()
.Append<OtherComponent>()
.Append<OtherComponent2>()
.AppendConfigParam<"threads", 8>()
.Sort();
constexpr auto dependencies = builder.GetDependencyGraph();
using Need = utempl::Tuple<OtherComponent&, OtherComponent2&>;
using R = decltype(
builder
.GetServiceContext()
.GetContextFor<cserver::ComponentConfig<"some", SomeComponent, {}>>()
.FindAllComponents<SomeM>());
using R =
decltype(builder.GetServiceContext().GetContextFor<cserver::ComponentConfig<"some", SomeComponent, {}>>().FindAllComponents<SomeM>());
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));
};

View file

@ -1,35 +1,27 @@
#include <gtest/gtest.h>
#include <cserver/engine/components.hpp>
#include <nameof.hpp>
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<SomeOtherComponent>()
.Append<SomeComponent>()
.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<SomeOtherComponent>()
.Append<SomeComponent>()
.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));
};

View file

@ -1,12 +1,16 @@
#include <gtest/gtest.h>
#include <cserver/engine/components.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 {
static constexpr utempl::ConstexprString kName = "some";
constexpr SomeComponent(auto& context) {
explicit constexpr SomeComponent(auto& context) {
context.template FindComponent<SomeM>();
};
};
@ -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<SomeComponent>()
.Append<OtherComponent>()
.Append<OtherComponent2>()
.AppendConfigParam<"threads", 8>()
.Sort();
.Append<SomeComponent>()
.Append<OtherComponent>()
.Append<OtherComponent2>()
.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<"other", {}>,
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<SomeM>();
};
};