diff options
| author | Martin Hořeňovský | 2026-02-15 20:27:15 +0100 |
|---|---|---|
| committer | GitHub | 2026-02-15 20:27:15 +0100 |
| commit | 3a0cf7e75fdc571ff9ed25303fb268665f6260c0 (patch) | |
| tree | 25cd180f4419e0ef2f6fbe3664f91b548c59d8c2 /src/catch2/generators | |
| parent | b6c7b217d4bcb5030ce1e04180f35d02bcf5d93f (diff) | |
| download | catch3-3a0cf7e75fdc571ff9ed25303fb268665f6260c0.tar.gz | |
Support filtering on both sections and generators (#3069)
Not being able to filter generators to specific element has been regularly
causing problems. It was possible to use a dynamic section to run tests
for specific element in a generator, at least if the element had a nice
string representation, but the test case would still run once per element
in the generator.
With this change, it is possible to have the generator return only one
specific element, and do so based on the index, rather than the string
representation of the element. This enables simple debugging of tests
that fail for specific generator element.
Diffstat (limited to 'src/catch2/generators')
| -rw-r--r-- | src/catch2/generators/catch_generators.cpp | 10 | ||||
| -rw-r--r-- | src/catch2/generators/catch_generators.hpp | 9 | ||||
| -rw-r--r-- | src/catch2/generators/catch_generators_all.hpp | 1 | ||||
| -rw-r--r-- | src/catch2/generators/catch_generators_throw.cpp | 24 | ||||
| -rw-r--r-- | src/catch2/generators/catch_generators_throw.hpp | 23 |
5 files changed, 49 insertions, 18 deletions
diff --git a/src/catch2/generators/catch_generators.cpp b/src/catch2/generators/catch_generators.cpp index 3514e9f6..f7927eee 100644 --- a/src/catch2/generators/catch_generators.cpp +++ b/src/catch2/generators/catch_generators.cpp @@ -7,8 +7,6 @@ // SPDX-License-Identifier: BSL-1.0 #include <catch2/generators/catch_generators.hpp> -#include <catch2/internal/catch_enforce.hpp> -#include <catch2/generators/catch_generator_exception.hpp> #include <catch2/interfaces/catch_interfaces_capture.hpp> namespace Catch { @@ -17,14 +15,6 @@ namespace Catch { namespace Generators { -namespace Detail { - - [[noreturn]] - void throw_generator_exception(char const* msg) { - Catch::throw_exception(GeneratorException{ msg }); - } -} // end namespace Detail - GeneratorUntypedBase::~GeneratorUntypedBase() = default; IGeneratorTracker* acquireGeneratorTracker(StringRef generatorName, SourceLineInfo const& lineInfo ) { diff --git a/src/catch2/generators/catch_generators.hpp b/src/catch2/generators/catch_generators.hpp index 719775fb..b833fd83 100644 --- a/src/catch2/generators/catch_generators.hpp +++ b/src/catch2/generators/catch_generators.hpp @@ -9,6 +9,7 @@ #define CATCH_GENERATORS_HPP_INCLUDED #include <catch2/catch_tostring.hpp> +#include <catch2/generators/catch_generators_throw.hpp> #include <catch2/interfaces/catch_interfaces_generatortracker.hpp> #include <catch2/internal/catch_source_line_info.hpp> #include <catch2/internal/catch_stringref.hpp> @@ -22,14 +23,6 @@ namespace Catch { namespace Generators { -namespace Detail { - - //! Throws GeneratorException with the provided message - [[noreturn]] - void throw_generator_exception(char const * msg); - -} // end namespace detail - template<typename T> class IGenerator : public GeneratorUntypedBase { std::string stringifyImpl() const override { diff --git a/src/catch2/generators/catch_generators_all.hpp b/src/catch2/generators/catch_generators_all.hpp index c12d314e..e6121858 100644 --- a/src/catch2/generators/catch_generators_all.hpp +++ b/src/catch2/generators/catch_generators_all.hpp @@ -26,5 +26,6 @@ #include <catch2/generators/catch_generators_adapters.hpp> #include <catch2/generators/catch_generators_random.hpp> #include <catch2/generators/catch_generators_range.hpp> +#include <catch2/generators/catch_generators_throw.hpp> #endif // CATCH_GENERATORS_ALL_HPP_INCLUDED diff --git a/src/catch2/generators/catch_generators_throw.cpp b/src/catch2/generators/catch_generators_throw.cpp new file mode 100644 index 00000000..e7eda225 --- /dev/null +++ b/src/catch2/generators/catch_generators_throw.cpp @@ -0,0 +1,24 @@ + +// 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 + +#include <catch2/generators/catch_generator_exception.hpp> +#include <catch2/generators/catch_generators_throw.hpp> +#include <catch2/internal/catch_enforce.hpp> + +namespace Catch { + namespace Generators { + namespace Detail { + + [[noreturn]] + void throw_generator_exception( char const* msg ) { + Catch::throw_exception( GeneratorException{ msg } ); + } + + } // namespace Detail + } // namespace Generators +} // namespace Catch diff --git a/src/catch2/generators/catch_generators_throw.hpp b/src/catch2/generators/catch_generators_throw.hpp new file mode 100644 index 00000000..2725eb6e --- /dev/null +++ b/src/catch2/generators/catch_generators_throw.hpp @@ -0,0 +1,23 @@ + +// 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 +#ifndef CATCH_GENERATORS_THROW_HPP_INCLUDED +#define CATCH_GENERATORS_THROW_HPP_INCLUDED + +namespace Catch { + namespace Generators { + namespace Detail { + + //! Throws GeneratorException with the provided message + [[noreturn]] + void throw_generator_exception( char const* msg ); + + } // namespace Detail + } // namespace Generators +} // namespace Catch + +#endif // CATCH_GENERATORS_THROW_HPP_INCLUDED |