diff options
| author | Martin Hořeňovský | 2022-05-16 11:56:11 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2022-05-16 11:56:21 +0200 |
| commit | af8b54ecd59f8174aaaa97682e3544f2820a0900 (patch) | |
| tree | 1e9738c570b986822c235917ef20afc5ecb89017 /src/catch2/interfaces | |
| parent | 07bec74096d91e68efa97587554004740d9aa32a (diff) | |
| download | catch3-af8b54ecd59f8174aaaa97682e3544f2820a0900.tar.gz | |
Generators now keep track of the index of current element
This might become potentially useful in the future, when we want
to provide the ability to forward jump generators, to be able to
simply reproduce specific input to a test.
I am not yet sure how it would work, but the basic idea is that
it could be similar to the `-c` switch for selecting specific
`SECTION` in a test case.
Diffstat (limited to 'src/catch2/interfaces')
| -rw-r--r-- | src/catch2/interfaces/catch_interfaces_generatortracker.hpp | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/src/catch2/interfaces/catch_interfaces_generatortracker.hpp b/src/catch2/interfaces/catch_interfaces_generatortracker.hpp index fa475e28..2efc4a58 100644 --- a/src/catch2/interfaces/catch_interfaces_generatortracker.hpp +++ b/src/catch2/interfaces/catch_interfaces_generatortracker.hpp @@ -14,6 +14,17 @@ namespace Catch { namespace Generators { class GeneratorUntypedBase { + // Counts based on `next` returning true + std::size_t m_currentElementIndex = 0; + + /** + * Attempts to move the generator to the next element + * + * Returns true iff the move succeeded (and a valid element + * can be retrieved). + */ + virtual bool next() = 0; + public: GeneratorUntypedBase() = default; // Generation of copy ops is deprecated (and Clang will complain) @@ -23,11 +34,25 @@ namespace Catch { virtual ~GeneratorUntypedBase(); // = default; - // Attempts to move the generator to the next element - // - // Returns true iff the move succeeded (and a valid element - // can be retrieved). - virtual bool next() = 0; + /** + * Attempts to move the generator to the next element + * + * Serves as a non-virtual interface to `next`, so that the + * top level interface can provide sanity checking and shared + * features. + * + * As with `next`, returns true iff the move succeeded and + * the generator has new valid element to provide. + */ + bool countedNext() { + auto ret = next(); + if ( ret ) { + ++m_currentElementIndex; + } + return ret; + } + + std::size_t currentElementIndex() const { return m_currentElementIndex; } }; using GeneratorBasePtr = Catch::Detail::unique_ptr<GeneratorUntypedBase>; |