diff options
| author | Martin Hořeňovský | 2026-02-10 09:16:03 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-02-10 09:37:19 +0100 |
| commit | daadf42a0e21ac09abc1f286f875078b24e2dd4d (patch) | |
| tree | 1a680c2c82f71ad1701ce0b8e3c28ce9e50470b9 /tests/ExtraTests | |
| parent | d079ee13ab137547ab26bd1ed5ca2858d7fbd847 (diff) | |
| download | catch3-daadf42a0e21ac09abc1f286f875078b24e2dd4d.tar.gz | |
Add --warn InfiniteGenerators
Diffstat (limited to 'tests/ExtraTests')
| -rw-r--r-- | tests/ExtraTests/CMakeLists.txt | 13 | ||||
| -rw-r--r-- | tests/ExtraTests/X95-InfiniteGenerators.cpp | 36 |
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt index 7e761931..d663efc8 100644 --- a/tests/ExtraTests/CMakeLists.txt +++ b/tests/ExtraTests/CMakeLists.txt @@ -589,3 +589,16 @@ set_tests_properties(ThreadSafetyTests::UnscopedMessagesAndAssertions PASS_REGULAR_EXPRESSION "assertions: 401 \\| 401 failed as expected" RUN_SERIAL ON ) + +add_executable(InfiniteGenerators ${TESTS_DIR}/X95-InfiniteGenerators.cpp) +target_link_libraries(InfiniteGenerators PRIVATE Catch2::Catch2WithMain) + +add_test( + NAME Warnings::InfiniteGenerators + COMMAND $<TARGET_FILE:InfiniteGenerators> --warn InfiniteGenerators +) +set_tests_properties(Warnings::InfiniteGenerators + PROPERTIES + PASS_REGULAR_EXPRESSION "test cases: 1 \\| 1 failed" + TIMEOUT 5 +) diff --git a/tests/ExtraTests/X95-InfiniteGenerators.cpp b/tests/ExtraTests/X95-InfiniteGenerators.cpp new file mode 100644 index 00000000..31389107 --- /dev/null +++ b/tests/ExtraTests/X95-InfiniteGenerators.cpp @@ -0,0 +1,36 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that GENERATE over infinite generator errors out when the tests are + * run with `-warn InfiniteGenerators` + */ + +#include <catch2/catch_test_macros.hpp> +#include <catch2/generators/catch_generators.hpp> + +namespace { + static int ONE = 1; + class infinite_generator : public Catch::Generators::IGenerator<int> { + public: + + int const& get() const override { return ONE; } + bool next() override { return true; } + auto isFinite() const -> bool override { return false; } + }; + + static auto make_infinite_generator() + -> Catch::Generators::GeneratorWrapper<int> { + return { new infinite_generator() }; + } + +} // namespace + +TEST_CASE() { + auto _ = GENERATE( make_infinite_generator() ); +} |