Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Test behavior in the test module, not constants

Codacy (cppcheck) found both conditions always true. The module now
checks a generated repetition count with catch3_main, and sections that
each start from the same fixture with its own main.

Claude-Session: https://claude.ai/code/session_01Ji7xZMYjc4zankoc7hGBE1
Commit
5a63d9c746daa1748db7622a5e3effb9ca5c4b40
Author
Leitwolf11 ·
Parents
c7c952b01ef0

Files · Download .tar.gz

Changes

 tests/Progmasoft/BazelModule/OwnMain.tests.cpp  | 17 +++++++++++++++--
 tests/Progmasoft/BazelModule/WithMain.tests.cpp | 24 ++++++++++++++++++++----
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/tests/Progmasoft/BazelModule/OwnMain.tests.cpp b/tests/Progmasoft/BazelModule/OwnMain.tests.cpp
index e544bf4d..92c4d711 100644
--- a/tests/Progmasoft/BazelModule/OwnMain.tests.cpp
+++ b/tests/Progmasoft/BazelModule/OwnMain.tests.cpp
@@ -4,10 +4,23 @@
 // Tests linked with @progmasoft_catch3//:catch3, with a main of their own.
 #include <Progmasoft/Catch3/Session.hpp>
 #include <Progmasoft/Catch3/TestMacros.hpp>
+#include <algorithm>
+#include <vector>
 
-TEST_CASE("A test runs under its own main", "[module]")
+TEST_CASE("Sections run against a fresh fixture", "[module]")
 {
-    REQUIRE(1 + 1 == 2);
+    std::vector<int> values{ 3, 1, 2 };
+
+    SECTION("sorting orders the values")
+    {
+        std::sort(values.begin(), values.end());
+        REQUIRE(std::is_sorted(values.begin(), values.end()));
+        CHECK(values.front() < values.back());
+    }
+    SECTION("each section starts from the same values")
+    {
+        CHECK_FALSE(std::is_sorted(values.begin(), values.end()));
+    }
 }
 
 int
diff --git a/tests/Progmasoft/BazelModule/WithMain.tests.cpp b/tests/Progmasoft/BazelModule/WithMain.tests.cpp
index b3843f9f..60f67ed1 100644
--- a/tests/Progmasoft/BazelModule/WithMain.tests.cpp
+++ b/tests/Progmasoft/BazelModule/WithMain.tests.cpp
@@ -2,12 +2,28 @@
 // SPDX-License-Identifier: LGPL-3.0-or-later
 
 // Tests linked with @progmasoft_catch3//:catch3_main, which brings main.
+#include <Progmasoft/Catch3/Generators/Generators.hpp>
 #include <Progmasoft/Catch3/TestMacros.hpp>
 #include <string>
 
-TEST_CASE("A test runs from the published module", "[module]")
+namespace
 {
-    const std::string name = "progmasoft_catch3";
-    REQUIRE(name.size() == 17);
-    CHECK(name.rfind("progmasoft_", 0) == 0);
+    std::string
+    Repeat(const std::string &text, int count)
+    {
+        std::string result;
+        for (int i = 0; i < count; ++i)
+        {
+            result += text;
+        }
+        return result;
+    }
+} // namespace
+
+TEST_CASE("Generated values reach the test", "[module]")
+{
+    const int count = GENERATE(0, 1, 3);
+    const std::string repeated = Repeat("ab", count);
+    REQUIRE(repeated.size() == static_cast<std::size_t>(2 * count));
+    CHECK(repeated.find("ba") == (count > 1 ? 1U : std::string::npos));
 }