diff --git a/.github/actions/clang_format/action.yml b/.github/actions/clang_format/action.yml index 7763115a8..f49774bfc 100644 --- a/.github/actions/clang_format/action.yml +++ b/.github/actions/clang_format/action.yml @@ -18,6 +18,8 @@ runs: shell: bash - name: Run formatter + continue-on-error: true + id: run_formatter run: | ./.githooks/pre-commit shell: bash @@ -27,3 +29,8 @@ runs: shell: bash run: | git diff --color --exit-code | tee "clang-format.patch" + + - name: Fail job + if: ${{ steps.run_formatter.outcome != 'success' }} + shell: bash + run: exit 1 diff --git a/unittests/data/cassandra/impl/FakesAndMocks.h b/unittests/data/cassandra/impl/FakesAndMocks.h index cb22cb5ab..31df196c8 100644 --- a/unittests/data/cassandra/impl/FakesAndMocks.h +++ b/unittests/data/cassandra/impl/FakesAndMocks.h @@ -43,8 +43,8 @@ struct FakeResultOrError { return err; } - FakeResult - value() const + static FakeResult + value() { return FakeResult{}; } @@ -65,8 +65,8 @@ struct FakeFuture { return data; } - FakeMaybeError - await() const + static FakeMaybeError + await() { return {}; } @@ -103,14 +103,14 @@ struct MockHandle { struct FakeRetryPolicy { FakeRetryPolicy(boost::asio::io_context&){}; // required by concept - std::chrono::milliseconds + static std::chrono::milliseconds calculateDelay(uint32_t /* attempt */) { return std::chrono::milliseconds{1}; } - bool - shouldRetry(CassandraError) const + static bool + shouldRetry(CassandraError) { return false; } diff --git a/unittests/rpc/handlers/impl/FakesAndMocks.h b/unittests/rpc/handlers/impl/FakesAndMocks.h index be28fe14e..2f3c4817f 100644 --- a/unittests/rpc/handlers/impl/FakesAndMocks.h +++ b/unittests/rpc/handlers/impl/FakesAndMocks.h @@ -70,8 +70,8 @@ class HandlerFake { using Output = TestOutput; using Result = rpc::HandlerReturnType; - rpc::RpcSpecConstRef - spec([[maybe_unused]] uint32_t apiVersion) const + static rpc::RpcSpecConstRef + spec([[maybe_unused]] uint32_t apiVersion) { using namespace rpc::validation; @@ -83,8 +83,8 @@ class HandlerFake { return rpcSpec; } - Result - process(Input input, [[maybe_unused]] rpc::Context const& ctx) const + static Result + process(Input input, [[maybe_unused]] rpc::Context const& ctx) { return Output{input.hello + '_' + std::to_string(input.limit.value_or(0))}; } @@ -95,8 +95,8 @@ class NoInputHandlerFake { using Output = TestOutput; using Result = rpc::HandlerReturnType; - Result - process([[maybe_unused]] rpc::Context const& ctx) const + static Result + process([[maybe_unused]] rpc::Context const& ctx) { return Output{"test"}; } @@ -109,8 +109,8 @@ class FailingHandlerFake { using Output = TestOutput; using Result = rpc::HandlerReturnType; - rpc::RpcSpecConstRef - spec([[maybe_unused]] uint32_t apiVersion) const + static rpc::RpcSpecConstRef + spec([[maybe_unused]] uint32_t apiVersion) { using namespace rpc::validation; @@ -122,8 +122,8 @@ class FailingHandlerFake { return rpcSpec; } - Result - process([[maybe_unused]] Input input, [[maybe_unused]] rpc::Context const& ctx) const + static Result + process([[maybe_unused]] Input input, [[maybe_unused]] rpc::Context const& ctx) { // always fail return rpc::Error{rpc::Status{"Very custom error"}}; diff --git a/unittests/util/FakeAmendmentBlockAction.h b/unittests/util/FakeAmendmentBlockAction.h index d49fec5f6..639f9f7b2 100644 --- a/unittests/util/FakeAmendmentBlockAction.h +++ b/unittests/util/FakeAmendmentBlockAction.h @@ -25,7 +25,7 @@ struct FakeAmendmentBlockAction { std::reference_wrapper callCount; void - operator()() + operator()() const { ++(callCount.get()); } diff --git a/unittests/util/FakeFetchResponse.h b/unittests/util/FakeFetchResponse.h index d6d0d675e..12a5fd3ec 100644 --- a/unittests/util/FakeFetchResponse.h +++ b/unittests/util/FakeFetchResponse.h @@ -21,6 +21,7 @@ #include #include +#include #include class FakeBook { @@ -135,7 +136,7 @@ class FakeTransactionsList { public: std::size_t - transactions_size() + transactions_size() const { return size_; } @@ -146,7 +147,7 @@ class FakeObjectsList { public: std::size_t - objects_size() + objects_size() const { return size_; } @@ -165,7 +166,7 @@ struct FakeFetchResponse { } FakeFetchResponse(std::string blob, uint32_t id = 0, bool objectNeighborsIncluded = false) - : id{id}, objectNeighborsIncluded{objectNeighborsIncluded}, ledgerHeader{blob} + : id{id}, objectNeighborsIncluded{objectNeighborsIncluded}, ledgerHeader{std::move(blob)} { } @@ -175,14 +176,14 @@ struct FakeFetchResponse { return other.id == id; } - FakeTransactionsList - transactions_list() const + static FakeTransactionsList + transactions_list() { return {}; } - FakeObjectsList - ledger_objects() const + static FakeObjectsList + ledger_objects() { return {}; } diff --git a/unittests/util/Fixtures.h b/unittests/util/Fixtures.h index cc1cd31b6..6cbb9b264 100644 --- a/unittests/util/Fixtures.h +++ b/unittests/util/Fixtures.h @@ -19,6 +19,7 @@ #pragma once +#include "data/BackendInterface.h" #include "util/MockBackend.h" #include "util/MockCounters.h" #include "util/MockETLService.h" @@ -26,10 +27,24 @@ #include "util/MockSubscriptionManager.h" #include "util/log/Logger.h" -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include +#include +#include +#include +#include #include /** @@ -181,7 +196,7 @@ struct MockBackendTest : virtual public NoLoggerFixture { SetUp() override { NoLoggerFixture::SetUp(); - util::Config cfg; + util::Config const cfg; mockBackendPtr = std::make_shared(cfg); } void diff --git a/unittests/util/MockSubscriptionManager.h b/unittests/util/MockSubscriptionManager.h index cf78d9b89..95b51886c 100644 --- a/unittests/util/MockSubscriptionManager.h +++ b/unittests/util/MockSubscriptionManager.h @@ -28,9 +28,7 @@ struct MockSubscriptionManager { public: using session_ptr = std::shared_ptr; - MockSubscriptionManager() - { - } + MockSubscriptionManager() = default; MOCK_METHOD(boost::json::object, subLedger, (boost::asio::yield_context, session_ptr), ()); diff --git a/unittests/util/MockWsBase.h b/unittests/util/MockWsBase.h index b05f1b5c9..1919ad119 100644 --- a/unittests/util/MockWsBase.h +++ b/unittests/util/MockWsBase.h @@ -19,8 +19,14 @@ #pragma once +#include "util/Taggable.h" #include "web/interface/ConnectionBase.h" +#include + +#include +#include + struct MockSession : public web::ConnectionBase { std::string message; void @@ -30,6 +36,7 @@ struct MockSession : public web::ConnectionBase { } void + // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) send(std::string&& msg, boost::beast::http::status = boost::beast::http::status::ok) override { message += msg; @@ -49,6 +56,7 @@ struct MockDeadSession : public web::ConnectionBase { } void + // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) send(std::string&&, boost::beast::http::status = boost::beast::http::status::ok) override { } diff --git a/unittests/util/TestHttpSyncClient.h b/unittests/util/TestHttpSyncClient.h index 6e377a617..37173c6f5 100644 --- a/unittests/util/TestHttpSyncClient.h +++ b/unittests/util/TestHttpSyncClient.h @@ -19,12 +19,36 @@ #pragma once -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include #include +#include +#include namespace http = boost::beast::http; namespace net = boost::asio; @@ -126,8 +150,8 @@ class WebSocketSyncClient { ws_.set_option(boost::beast::websocket::stream_base::decorator([additionalHeaders = std::move(additionalHeaders )](boost::beast::websocket::request_type& req) { req.set(http::field::user_agent, std::string(BOOST_BEAST_VERSION_STRING) + " websocket-client-coro"); - for (auto& header : additionalHeaders) { - req.set(header.name, std::move(header.value)); + for (auto const& header : additionalHeaders) { + req.set(header.name, header.value); } })); @@ -176,7 +200,7 @@ struct HttpsSyncClient { if (!SSL_set_tlsext_host_name(stream.native_handle(), host.c_str())) #pragma GCC diagnostic pop { - boost::beast::error_code ec{static_cast(::ERR_get_error()), net::error::get_ssl_category()}; + boost::beast::error_code const ec{static_cast(::ERR_get_error()), net::error::get_ssl_category()}; throw boost::beast::system_error{ec}; }