diff options
| author | Leitwolf | 2026-11-14 16:46:04 +0300 |
|---|---|---|
| committer | GitHub | 2026-11-14 16:46:04 +0300 |
| commit | 94a996a3ceafa9f0004ffc28a7de5c543cdb51c2 (patch) | |
| tree | e8db06877788de36d3fd4166472c4511f0c0412a /tests/Progmasoft/CoverageFixture.cpp | |
| parent | 586a42e35788d269871dcadbed2ec59b6b8a9203 (diff) | |
| parent | 5ad02bccfcb925df02d1273901b6e248d477c5fa (diff) | |
| download | catch3-94a996a3ceafa9f0004ffc28a7de5c543cdb51c2.tar.gz | |
Merge pull request #39 from Progmasoft/feature/per-test-coverage
Keep per-test coverage with --coverage (roadmap step 4)
Diffstat (limited to 'tests/Progmasoft/CoverageFixture.cpp')
| -rw-r--r-- | tests/Progmasoft/CoverageFixture.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/Progmasoft/CoverageFixture.cpp b/tests/Progmasoft/CoverageFixture.cpp new file mode 100644 index 00000000..e728bbca --- /dev/null +++ b/tests/Progmasoft/CoverageFixture.cpp @@ -0,0 +1,44 @@ +// Copyright (c) 2026 Progmasoft. +// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-2.0 + +// A test binary built with coverage instrumentation, for the integration +// tests of `--coverage`: each test reaches lines the other does not. The +// markers at the ends of lines let the tests find those lines. + +#include <Progmasoft/Catch3/TestMacros.hpp> + +namespace +{ + int + AddOne(int value) + { + return value + 1; // coverage: add-one + } + + int + SubtractOne(int value) + { + return value - 1; // coverage: subtract-one + } + + int + NonNegative(int value) + { + if (value < 0) // coverage: branch + { + return 0; + } + return value; + } +} // namespace + +TEST_CASE("Adds one", "[coverage]") +{ + CHECK(AddOne(1) == 2); + CHECK(NonNegative(AddOne(1)) == 2); +} + +TEST_CASE("Subtracts one", "[coverage]") +{ + CHECK(SubtractOne(1) == 0); +} |