From b08cee18c424fdb9c365d37b820d349d872bbccd Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Thu, 8 Aug 2024 16:09:10 -0600 Subject: [PATCH] :children_crossing: Improve error message for cyclic flows --- .github/workflows/unit_tests.yml | 6 +++--- include/flow/graph_builder.hpp | 3 ++- test/CMakeLists.txt | 1 + test/flow/fail/cyclic_flow.cpp | 23 +++++++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 test/flow/fail/cyclic_flow.cpp diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 2c0f6e73..3bbb31aa 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -86,7 +86,7 @@ jobs: cxx_flags: "" - version: 13 compiler: gcc - install: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo apt update && sudo apt-get install -y gcc-13 g++-13 + install: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo apt update && sudo apt install -y gcc-13 g++-13 cc: "gcc-13" cxx: "g++-13" - version: 12 @@ -232,7 +232,7 @@ jobs: - compiler: gcc cc: "gcc-13" cxx: "g++-13" - install: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo apt update && sudo apt-get install -y gcc-13 g++-13 + install: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo apt update && sudo apt install -y gcc-13 g++-13 toolchain_root: "/usr" steps: @@ -288,7 +288,7 @@ jobs: - name: Install build tools run: | sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - sudo apt update && sudo apt-get install -y gcc-${{env.DEFAULT_GCC_VERSION}} g++-${{env.DEFAULT_GCC_VERSION}} ninja-build valgrind + sudo apt update && sudo apt install -y gcc-${{env.DEFAULT_GCC_VERSION}} g++-${{env.DEFAULT_GCC_VERSION}} ninja-build valgrind - name: Restore CPM cache env: diff --git a/include/flow/graph_builder.hpp b/include/flow/graph_builder.hpp index d124c80b..83604675 100644 --- a/include/flow/graph_builder.hpp +++ b/include/flow/graph_builder.hpp @@ -147,7 +147,8 @@ struct graph_builder { constexpr static auto built() { constexpr auto v = Initialized::value; constexpr auto built = build(v); - static_assert(built.has_value()); + static_assert(built.has_value(), + "Topological sort failed: cycle in flow"); return *built; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8263d957..54a93eab 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -119,6 +119,7 @@ add_unit_test( catalog2_lib catalog_strings) +add_compile_fail_test(flow/fail/cyclic_flow.cpp LIBRARIES warnings cib) add_compile_fail_test(msg/fail/callback_bad_field_name.cpp LIBRARIES warnings cib) add_compile_fail_test(msg/fail/field_location.cpp LIBRARIES warnings cib) diff --git a/test/flow/fail/cyclic_flow.cpp b/test/flow/fail/cyclic_flow.cpp new file mode 100644 index 00000000..c0810291 --- /dev/null +++ b/test/flow/fail/cyclic_flow.cpp @@ -0,0 +1,23 @@ +#include +#include + +// EXPECT: Topological sort failed: cycle in flow + +namespace { +using namespace flow::literals; + +constexpr auto a = flow::milestone<"a">(); +constexpr auto b = flow::milestone<"b">(); + +struct TestFlowAlpha : public flow::service<> {}; + +struct CyclicFlowConfig { + constexpr static auto config = cib::config( + cib::exports, cib::extend(a >> b >> a)); +}; +} // namespace + +auto main() -> int { + cib::nexus nexus{}; + nexus.service(); +}