diff options
| author | Leitwolf11 | 2026-11-01 19:11:27 +0300 |
|---|---|---|
| committer | Leitwolf11 | 2026-11-01 19:11:27 +0300 |
| commit | 2aea9dafd283d69bec459ea0d495c25d1f6a0f94 (patch) | |
| tree | e478374100157fe4d0aef16e582dbcabda51e2c1 /tests | |
| parent | c51d15273e87267215e5877edc268e7db354187b (diff) | |
| download | catch3-2aea9dafd283d69bec459ea0d495c25d1f6a0f94.tar.gz | |
Keep the mock lock alive to the end of the process
A static mutex needs an exit-time destructor, which Clang's warnings
refuse, and a mock of static lifetime can outlive it. The test seam is
held the same way, and a test covers a mock method with nothing after
its parameters, which needs an empty variadic argument to stay valid
under -Wpedantic.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Progmasoft/Mock.tests.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/tests/Progmasoft/Mock.tests.cpp b/tests/Progmasoft/Mock.tests.cpp index 5c8272c7..0329bc41 100644 --- a/tests/Progmasoft/Mock.tests.cpp +++ b/tests/Progmasoft/Mock.tests.cpp @@ -69,15 +69,27 @@ namespace CATCH3_MOCK_METHOD(std::unique_ptr<int>, Take, (), override); }; - /// Production code with a seam for a free function. - std::function<long()> clockSeam = [] { - return 0L; + /// A mock with no base class, and so nothing after its parameters. + class MockCounter final + { + public: + CATCH3_MOCK_METHOD(int, Twice, (int)); }; + /// A seam production code calls a free function through. + std::function<long()> & + ClockSeam() + { + static auto *seam = new std::function<long()>{ [] { + return 0L; + } }; + return *seam; + } + long SecondsSince(long start) { - return clockSeam() - start; + return ClockSeam()() - start; } long (*pointerSeam)() = nullptr; @@ -103,6 +115,14 @@ TEST_CASE("A mock method answers as its expectation says", "[progmasoft][mock]") writing.Put(Scores{ { "a", 1 } }); } +TEST_CASE("A mock method needs nothing after its parameters", + "[progmasoft][mock]") +{ + MockCounter counter; + CATCH3_EXPECT_CALL(counter.TwiceMock)(2).Returns(4); + CHECK(counter.Twice(2) == 4); +} + TEST_CASE("Every parameter reaches an action", "[progmasoft][mock]") { MockStore store; @@ -248,7 +268,7 @@ TEST_CASE("A mock stands in for a free function behind a seam", CATCH3_MOCK_FUNCTION(clock, long()); CATCH3_EXPECT_CALL(clock)().Returns(50L); { - const ScopedSeam seam(clockSeam, clock.AsFunction()); + const ScopedSeam seam(ClockSeam(), clock.AsFunction()); CHECK(SecondsSince(20) == 30); } CHECK(SecondsSince(0) == 0); |