Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/Progmasoft/RunnerFixture.cpp
diff options
context:
space:
mode:
authorLeitwolf2026-11-01 21:19:33 +0300
committerGitHub2026-11-01 21:19:33 +0300
commit5cbd481125b881a4c2eed74050be9899eb3f23a7 (patch)
tree496d26ff659e92cdf4e6fe27a4aa47bf52818052 /tests/Progmasoft/RunnerFixture.cpp
parent26a1588ae3ae183ae5c900caf3c294bdcb3f8855 (diff)
parent8603d31fd8c1a72e30cb444f278d7a0592383ba7 (diff)
downloadcatch3-5cbd481125b881a4c2eed74050be9899eb3f23a7.tar.gz
Merge pull request #30 from Progmasoft/feature/mocking
Add mocks that report through the assertion path
Diffstat (limited to 'tests/Progmasoft/RunnerFixture.cpp')
-rw-r--r--tests/Progmasoft/RunnerFixture.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/Progmasoft/RunnerFixture.cpp b/tests/Progmasoft/RunnerFixture.cpp
index 37d196a3..3a61d05c 100644
--- a/tests/Progmasoft/RunnerFixture.cpp
+++ b/tests/Progmasoft/RunnerFixture.cpp
@@ -4,6 +4,7 @@
// A test binary whose tests misbehave on purpose. The runner's integration
// tests start it and check what the runner made of each misbehaviour.
+#include <Progmasoft/Catch3/Mock.hpp>
#include <Progmasoft/Catch3/Runner.hpp>
#include <Progmasoft/Catch3/TestMacros.hpp>
#include <chrono>
@@ -184,6 +185,81 @@ TEST_CASE("fixture slow four", "[fixture][slow]")
CHECK(true);
}
+TEST_CASE("fixture mock unexpected call", "[fixture][mock]")
+{
+ Progmasoft::Catch3::MockFunction<int(std::string)> get{ "Get" };
+ CATCH3_EXPECT_CALL(get)("a").Returns(1);
+ CHECK(get("a") == 1);
+ CHECK(get("b") == 0);
+}
+
+TEST_CASE("fixture mock with no expectations", "[fixture][mock]")
+{
+ CATCH3_MOCK_FUNCTION(tick, void());
+ tick();
+}
+
+TEST_CASE("fixture mock unmet expectation", "[fixture][mock]")
+{
+ CATCH3_MOCK_FUNCTION(tick, void());
+ CATCH3_EXPECT_CALL(tick)().Times(2);
+ tick();
+}
+
+TEST_CASE("fixture mock too many calls", "[fixture][mock]")
+{
+ CATCH3_MOCK_FUNCTION(tick, void());
+ CATCH3_EXPECT_CALL(tick)();
+ tick();
+ tick();
+}
+
+TEST_CASE("fixture mock out of order", "[fixture][mock]")
+{
+ Progmasoft::Catch3::Sequence order;
+ CATCH3_MOCK_FUNCTION(first, void());
+ CATCH3_MOCK_FUNCTION(second, void());
+ CATCH3_EXPECT_CALL(first)().InSequence(order);
+ CATCH3_EXPECT_CALL(second)().InSequence(order);
+ second();
+}
+
+TEST_CASE("fixture mock past its step", "[fixture][mock]")
+{
+ Progmasoft::Catch3::Sequence order;
+ CATCH3_MOCK_FUNCTION(first, void());
+ CATCH3_MOCK_FUNCTION(second, void());
+ CATCH3_EXPECT_CALL(first)().AtLeast(1).InSequence(order);
+ CATCH3_EXPECT_CALL(second)().InSequence(order);
+ first();
+ second();
+ first();
+}
+
+TEST_CASE("fixture mock with nothing to return", "[fixture][mock]")
+{
+ CATCH3_MOCK_FUNCTION(name, std::string & ());
+ CATCH3_EXPECT_CALL(name)();
+ name();
+ FAIL("the call above leaves the test case");
+}
+
+TEST_CASE("fixture mock left by a failure", "[fixture][mock]")
+{
+ CATCH3_MOCK_FUNCTION(tick, void());
+ CATCH3_EXPECT_CALL(tick)();
+ FAIL("the test's own failure");
+}
+
+TEST_CASE("fixture mock outlives the run", "[fixture][mock-exit]")
+{
+ static auto *mock = new Progmasoft::Catch3::MockFunction<void()>{ "late" };
+ CATCH3_EXPECT_CALL (*mock)();
+ std::atexit([] {
+ delete mock;
+ });
+}
+
TEST_CASE("fixture skips", "[fixture][skip]")
{
SKIP("not on this machine");