Compare commits

...

5 Commits

Author SHA1 Message Date
Martin Hořeňovský
fecf606a05 Add option to skip forward to the generator interface 2025-10-06 11:47:38 +02:00
Martin Hořeňovský
363ca5af18 Add lifetime annotations to more places using StringRef 2025-10-04 16:38:07 +02:00
Martin Hořeňovský
cb6d713774 Add lifetimebound annotation to StringRef 2025-10-04 16:12:17 +02:00
Martin Hořeňovský
8e4ab5dd8f Annotate matcher combinators with CATCH_ATTR_LIFETIMEBOUND
The matcher combinators do not take ownership of the matchers
being combined, which can catch the users off-guard, when code like
this

```cpp
using Catch::Matchers::EndsWith;
using Catch::Matchers::ContainsSubstring;

auto combinedMatcher = EndsWith("as a service")
                       && ContainsSubstring("web scale");

REQUIRE_THAT( getSomeString(), combinedMatcher );
```

leads to use-after-free, as the `combinedMatcher` refers to matcher
temporaries that no longer exists. With this commit, users of Clang,
MSVC or other compiler that understands the `lifetimebound` attribute,
should get a warning.
2025-10-03 22:27:29 +02:00
Martin Hořeňovský
8219ed79f2 Add CATCH_ATTR_LIFETIMEBOUND macro polyfill over lifetimebound attr 2025-10-03 22:15:27 +02:00
31 changed files with 453 additions and 59 deletions

View File

@@ -252,9 +252,23 @@ struct IGenerator : GeneratorUntypedBase {
// Returns user-friendly string showing the current generator element // Returns user-friendly string showing the current generator element
// Does not have to be overridden, IGenerator provides default implementation // Does not have to be overridden, IGenerator provides default implementation
virtual std::string stringifyImpl() const; virtual std::string stringifyImpl() const;
/**
* Customization point for `skipToNthElement`
*
* Does not have to be overridden, there is a default implementation.
* Can be overridden for better performance.
*
* If there are not enough elements, shall throw an error.
*
* Going backwards is not supported.
*/
virtual void skipToNthElementImpl( std::size_t n );
}; };
``` ```
> `skipToNthElementImpl` was added in Catch2 vX.Y.Z
However, to be able to use your custom generator inside `GENERATE`, it However, to be able to use your custom generator inside `GENERATE`, it
will need to be wrapped inside a `GeneratorWrapper<T>`. will need to be wrapped inside a `GeneratorWrapper<T>`.
`GeneratorWrapper<T>` is a value wrapper around a `GeneratorWrapper<T>` is a value wrapper around a

View File

@@ -39,6 +39,22 @@ public:
current_number = m_dist(m_rand); current_number = m_dist(m_rand);
return true; return true;
} }
// Note: this improves the performance only a bit, but it is here
// to show how you can override the skip functionality.
void skipToNthElementImpl( std::size_t n ) override {
auto current_index = currentElementIndex();
assert(current_index <= n);
// We cannot jump forward the underlying generator directly,
// because we do not know how many bits each distributed number
// would consume to be generated.
for (; current_index < n; ++current_index) {
(void)m_dist(m_rand);
}
// We do not have to touch the current element index; it is handled
// by the base class.
}
}; };
// Avoids -Wweak-vtables // Avoids -Wweak-vtables

View File

@@ -98,6 +98,7 @@ set(IMPL_HEADERS
${SOURCES_DIR}/internal/catch_jsonwriter.hpp ${SOURCES_DIR}/internal/catch_jsonwriter.hpp
${SOURCES_DIR}/internal/catch_lazy_expr.hpp ${SOURCES_DIR}/internal/catch_lazy_expr.hpp
${SOURCES_DIR}/internal/catch_leak_detector.hpp ${SOURCES_DIR}/internal/catch_leak_detector.hpp
${SOURCES_DIR}/internal/catch_lifetimebound.hpp
${SOURCES_DIR}/internal/catch_list.hpp ${SOURCES_DIR}/internal/catch_list.hpp
${SOURCES_DIR}/internal/catch_logical_traits.hpp ${SOURCES_DIR}/internal/catch_logical_traits.hpp
${SOURCES_DIR}/internal/catch_message_info.hpp ${SOURCES_DIR}/internal/catch_message_info.hpp

View File

@@ -79,6 +79,7 @@
#include <catch2/internal/catch_jsonwriter.hpp> #include <catch2/internal/catch_jsonwriter.hpp>
#include <catch2/internal/catch_lazy_expr.hpp> #include <catch2/internal/catch_lazy_expr.hpp>
#include <catch2/internal/catch_leak_detector.hpp> #include <catch2/internal/catch_leak_detector.hpp>
#include <catch2/internal/catch_lifetimebound.hpp>
#include <catch2/internal/catch_list.hpp> #include <catch2/internal/catch_list.hpp>
#include <catch2/internal/catch_logical_traits.hpp> #include <catch2/internal/catch_logical_traits.hpp>
#include <catch2/internal/catch_message_info.hpp> #include <catch2/internal/catch_message_info.hpp>

View File

@@ -7,6 +7,8 @@
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
#include <catch2/interfaces/catch_interfaces_generatortracker.hpp> #include <catch2/interfaces/catch_interfaces_generatortracker.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <string> #include <string>
namespace Catch { namespace Catch {
@@ -21,6 +23,30 @@ namespace Catch {
return ret; return ret;
} }
void GeneratorUntypedBase::skipToNthElementImpl( std::size_t n ) {
for ( size_t i = m_currentElementIndex; i < n; ++i ) {
bool isValid = next();
if ( !isValid ) {
Detail::throw_generator_exception(
"Coud not jump to Nth element: not enough elements" );
}
}
}
void GeneratorUntypedBase::skipToNthElement( std::size_t n ) {
if ( n < m_currentElementIndex ) {
Detail::throw_generator_exception(
"Tried to jump generator backwards" );
}
skipToNthElementImpl(n);
// Fixup tracking after moving the generator forward
// * Ensure that the correct element index is set after skipping
// * Invalidate cache
m_currentElementIndex = n;
m_stringReprCache.clear();
}
StringRef GeneratorUntypedBase::currentElementAsString() const { StringRef GeneratorUntypedBase::currentElementAsString() const {
if ( m_stringReprCache.empty() ) { if ( m_stringReprCache.empty() ) {
m_stringReprCache = stringifyImpl(); m_stringReprCache = stringifyImpl();

View File

@@ -35,6 +35,15 @@ namespace Catch {
//! Customization point for `currentElementAsString` //! Customization point for `currentElementAsString`
virtual std::string stringifyImpl() const = 0; virtual std::string stringifyImpl() const = 0;
/**
* Customization point for skipping to the n-th element
*
* Defaults to successively calling `countedNext`. If there
* are not enough elements to reach the nth one, will throw
* an error.
*/
virtual void skipToNthElementImpl( std::size_t n );
public: public:
GeneratorUntypedBase() = default; GeneratorUntypedBase() = default;
// Generation of copy ops is deprecated (and Clang will complain) // Generation of copy ops is deprecated (and Clang will complain)
@@ -58,6 +67,13 @@ namespace Catch {
std::size_t currentElementIndex() const { return m_currentElementIndex; } std::size_t currentElementIndex() const { return m_currentElementIndex; }
/**
* Moves the generator forward **to** the n-th element
*
* Cannot move backwards.
*/
void skipToNthElement( std::size_t n );
/** /**
* Returns generator's current element as user-friendly string. * Returns generator's current element as user-friendly string.
* *

View File

@@ -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
#ifndef CATCH_LIFETIMEBOUND_HPP_INCLUDED
#define CATCH_LIFETIMEBOUND_HPP_INCLUDED
#if !defined( __has_cpp_attribute )
# define CATCH_ATTR_LIFETIMEBOUND
#elif __has_cpp_attribute( msvc::lifetimebound )
# define CATCH_ATTR_LIFETIMEBOUND [[msvc::lifetimebound]]
#elif __has_cpp_attribute( clang::lifetimebound )
# define CATCH_ATTR_LIFETIMEBOUND [[clang::lifetimebound]]
#elif __has_cpp_attribute( lifetimebound )
# define CATCH_ATTR_LIFETIMEBOUND [[lifetimebound]]
#else
# define CATCH_ATTR_LIFETIMEBOUND
#endif
#endif // CATCH_LIFETIMEBOUND_HPP_INCLUDED

View File

@@ -8,6 +8,7 @@
#ifndef CATCH_STRING_MANIP_HPP_INCLUDED #ifndef CATCH_STRING_MANIP_HPP_INCLUDED
#define CATCH_STRING_MANIP_HPP_INCLUDED #define CATCH_STRING_MANIP_HPP_INCLUDED
#include <catch2/internal/catch_lifetimebound.hpp>
#include <catch2/internal/catch_stringref.hpp> #include <catch2/internal/catch_stringref.hpp>
#include <cstdint> #include <cstdint>
@@ -28,10 +29,10 @@ namespace Catch {
//! Returns a new string without whitespace at the start/end //! Returns a new string without whitespace at the start/end
std::string trim( std::string const& str ); std::string trim( std::string const& str );
//! Returns a substring of the original ref without whitespace. Beware lifetimes! //! Returns a substring of the original ref without whitespace. Beware lifetimes!
StringRef trim(StringRef ref); StringRef trim( StringRef ref CATCH_ATTR_LIFETIMEBOUND );
// !!! Be aware, returns refs into original string - make sure original string outlives them // !!! Be aware, returns refs into original string - make sure original string outlives them
std::vector<StringRef> splitStringRef( StringRef str, char delimiter ); std::vector<StringRef> splitStringRef( StringRef str CATCH_ATTR_LIFETIMEBOUND, char delimiter );
bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
/** /**
@@ -49,7 +50,7 @@ namespace Catch {
StringRef m_label; StringRef m_label;
public: public:
constexpr pluralise(std::uint64_t count, StringRef label): constexpr pluralise(std::uint64_t count, StringRef label CATCH_ATTR_LIFETIMEBOUND):
m_count(count), m_count(count),
m_label(label) m_label(label)
{} {}

View File

@@ -8,11 +8,12 @@
#ifndef CATCH_STRINGREF_HPP_INCLUDED #ifndef CATCH_STRINGREF_HPP_INCLUDED
#define CATCH_STRINGREF_HPP_INCLUDED #define CATCH_STRINGREF_HPP_INCLUDED
#include <catch2/internal/catch_lifetimebound.hpp>
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#include <iosfwd> #include <iosfwd>
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
namespace Catch { namespace Catch {
@@ -36,14 +37,16 @@ namespace Catch {
public: // construction public: // construction
constexpr StringRef() noexcept = default; constexpr StringRef() noexcept = default;
StringRef( char const* rawChars ) noexcept; StringRef( char const* rawChars CATCH_ATTR_LIFETIMEBOUND ) noexcept;
constexpr StringRef( char const* rawChars, size_type size ) noexcept constexpr StringRef( char const* rawChars CATCH_ATTR_LIFETIMEBOUND,
size_type size ) noexcept
: m_start( rawChars ), : m_start( rawChars ),
m_size( size ) m_size( size )
{} {}
StringRef( std::string const& stdString ) noexcept StringRef(
std::string const& stdString CATCH_ATTR_LIFETIMEBOUND ) noexcept
: m_start( stdString.c_str() ), : m_start( stdString.c_str() ),
m_size( stdString.size() ) m_size( stdString.size() )
{} {}
@@ -89,7 +92,7 @@ namespace Catch {
} }
// Returns the current start pointer. May not be null-terminated. // Returns the current start pointer. May not be null-terminated.
constexpr char const* data() const noexcept { constexpr char const* data() const noexcept CATCH_ATTR_LIFETIMEBOUND {
return m_start; return m_start;
} }

View File

@@ -8,6 +8,7 @@
#ifndef CATCH_TEST_CASE_TRACKER_HPP_INCLUDED #ifndef CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
#define CATCH_TEST_CASE_TRACKER_HPP_INCLUDED #define CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
#include <catch2/internal/catch_lifetimebound.hpp>
#include <catch2/internal/catch_source_line_info.hpp> #include <catch2/internal/catch_source_line_info.hpp>
#include <catch2/internal/catch_unique_ptr.hpp> #include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_stringref.hpp> #include <catch2/internal/catch_stringref.hpp>
@@ -48,7 +49,7 @@ namespace TestCaseTracking {
StringRef name; StringRef name;
SourceLineInfo location; SourceLineInfo location;
constexpr NameAndLocationRef( StringRef name_, constexpr NameAndLocationRef( StringRef name_ CATCH_ATTR_LIFETIMEBOUND,
SourceLineInfo location_ ): SourceLineInfo location_ ):
name( name_ ), location( location_ ) {} name( name_ ), location( location_ ) {}

View File

@@ -10,6 +10,7 @@
#include <catch2/matchers/internal/catch_matchers_impl.hpp> #include <catch2/matchers/internal/catch_matchers_impl.hpp>
#include <catch2/internal/catch_move_and_forward.hpp> #include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_lifetimebound.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -79,11 +80,15 @@ namespace Matchers {
return description; return description;
} }
friend MatchAllOf operator&& (MatchAllOf&& lhs, MatcherBase<ArgT> const& rhs) { friend MatchAllOf operator&&( MatchAllOf&& lhs,
MatcherBase<ArgT> const& rhs
CATCH_ATTR_LIFETIMEBOUND ) {
lhs.m_matchers.push_back(&rhs); lhs.m_matchers.push_back(&rhs);
return CATCH_MOVE(lhs); return CATCH_MOVE(lhs);
} }
friend MatchAllOf operator&& (MatcherBase<ArgT> const& lhs, MatchAllOf&& rhs) { friend MatchAllOf
operator&&( MatcherBase<ArgT> const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatchAllOf&& rhs ) {
rhs.m_matchers.insert(rhs.m_matchers.begin(), &lhs); rhs.m_matchers.insert(rhs.m_matchers.begin(), &lhs);
return CATCH_MOVE(rhs); return CATCH_MOVE(rhs);
} }
@@ -131,11 +136,15 @@ namespace Matchers {
return description; return description;
} }
friend MatchAnyOf operator|| (MatchAnyOf&& lhs, MatcherBase<ArgT> const& rhs) { friend MatchAnyOf operator||( MatchAnyOf&& lhs,
MatcherBase<ArgT> const& rhs
CATCH_ATTR_LIFETIMEBOUND ) {
lhs.m_matchers.push_back(&rhs); lhs.m_matchers.push_back(&rhs);
return CATCH_MOVE(lhs); return CATCH_MOVE(lhs);
} }
friend MatchAnyOf operator|| (MatcherBase<ArgT> const& lhs, MatchAnyOf&& rhs) { friend MatchAnyOf
operator||( MatcherBase<ArgT> const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatchAnyOf&& rhs ) {
rhs.m_matchers.insert(rhs.m_matchers.begin(), &lhs); rhs.m_matchers.insert(rhs.m_matchers.begin(), &lhs);
return CATCH_MOVE(rhs); return CATCH_MOVE(rhs);
} }
@@ -155,7 +164,8 @@ namespace Matchers {
MatcherBase<ArgT> const& m_underlyingMatcher; MatcherBase<ArgT> const& m_underlyingMatcher;
public: public:
explicit MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ): explicit MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher
CATCH_ATTR_LIFETIMEBOUND ):
m_underlyingMatcher( underlyingMatcher ) m_underlyingMatcher( underlyingMatcher )
{} {}
@@ -171,16 +181,22 @@ namespace Matchers {
} // namespace Detail } // namespace Detail
template <typename T> template <typename T>
Detail::MatchAllOf<T> operator&& (MatcherBase<T> const& lhs, MatcherBase<T> const& rhs) { Detail::MatchAllOf<T>
operator&&( MatcherBase<T> const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatcherBase<T> const& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return Detail::MatchAllOf<T>{} && lhs && rhs; return Detail::MatchAllOf<T>{} && lhs && rhs;
} }
template <typename T> template <typename T>
Detail::MatchAnyOf<T> operator|| (MatcherBase<T> const& lhs, MatcherBase<T> const& rhs) { Detail::MatchAnyOf<T>
operator||( MatcherBase<T> const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatcherBase<T> const& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return Detail::MatchAnyOf<T>{} || lhs || rhs; return Detail::MatchAnyOf<T>{} || lhs || rhs;
} }
template <typename T> template <typename T>
Detail::MatchNotOf<T> operator! (MatcherBase<T> const& matcher) { Detail::MatchNotOf<T>
operator!( MatcherBase<T> const& matcher CATCH_ATTR_LIFETIMEBOUND ) {
return Detail::MatchNotOf<T>{ matcher }; return Detail::MatchNotOf<T>{ matcher };
} }

View File

@@ -11,6 +11,7 @@
#include <catch2/matchers/catch_matchers.hpp> #include <catch2/matchers/catch_matchers.hpp>
#include <catch2/internal/catch_stringref.hpp> #include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_move_and_forward.hpp> #include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_lifetimebound.hpp>
#include <catch2/internal/catch_logical_traits.hpp> #include <catch2/internal/catch_logical_traits.hpp>
#include <array> #include <array>
@@ -114,7 +115,8 @@ namespace Matchers {
MatchAllOfGeneric(MatchAllOfGeneric&&) = default; MatchAllOfGeneric(MatchAllOfGeneric&&) = default;
MatchAllOfGeneric& operator=(MatchAllOfGeneric&&) = default; MatchAllOfGeneric& operator=(MatchAllOfGeneric&&) = default;
MatchAllOfGeneric(MatcherTs const&... matchers) : m_matchers{ {std::addressof(matchers)...} } {} MatchAllOfGeneric(MatcherTs const&... matchers CATCH_ATTR_LIFETIMEBOUND)
: m_matchers{ {std::addressof(matchers)...} } {}
explicit MatchAllOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {} explicit MatchAllOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {}
template<typename Arg> template<typename Arg>
@@ -136,8 +138,8 @@ namespace Matchers {
template<typename... MatchersRHS> template<typename... MatchersRHS>
friend friend
MatchAllOfGeneric<MatcherTs..., MatchersRHS...> operator && ( MatchAllOfGeneric<MatcherTs..., MatchersRHS...> operator && (
MatchAllOfGeneric<MatcherTs...>&& lhs, MatchAllOfGeneric<MatcherTs...>&& lhs CATCH_ATTR_LIFETIMEBOUND,
MatchAllOfGeneric<MatchersRHS...>&& rhs) { MatchAllOfGeneric<MatchersRHS...>&& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return MatchAllOfGeneric<MatcherTs..., MatchersRHS...>{array_cat(CATCH_MOVE(lhs.m_matchers), CATCH_MOVE(rhs.m_matchers))}; return MatchAllOfGeneric<MatcherTs..., MatchersRHS...>{array_cat(CATCH_MOVE(lhs.m_matchers), CATCH_MOVE(rhs.m_matchers))};
} }
@@ -145,8 +147,8 @@ namespace Matchers {
template<typename MatcherRHS> template<typename MatcherRHS>
friend std::enable_if_t<is_matcher_v<MatcherRHS>, friend std::enable_if_t<is_matcher_v<MatcherRHS>,
MatchAllOfGeneric<MatcherTs..., MatcherRHS>> operator && ( MatchAllOfGeneric<MatcherTs..., MatcherRHS>> operator && (
MatchAllOfGeneric<MatcherTs...>&& lhs, MatchAllOfGeneric<MatcherTs...>&& lhs CATCH_ATTR_LIFETIMEBOUND,
MatcherRHS const& rhs) { MatcherRHS const& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return MatchAllOfGeneric<MatcherTs..., MatcherRHS>{array_cat(CATCH_MOVE(lhs.m_matchers), static_cast<void const*>(&rhs))}; return MatchAllOfGeneric<MatcherTs..., MatcherRHS>{array_cat(CATCH_MOVE(lhs.m_matchers), static_cast<void const*>(&rhs))};
} }
@@ -154,8 +156,8 @@ namespace Matchers {
template<typename MatcherLHS> template<typename MatcherLHS>
friend std::enable_if_t<is_matcher_v<MatcherLHS>, friend std::enable_if_t<is_matcher_v<MatcherLHS>,
MatchAllOfGeneric<MatcherLHS, MatcherTs...>> operator && ( MatchAllOfGeneric<MatcherLHS, MatcherTs...>> operator && (
MatcherLHS const& lhs, MatcherLHS const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatchAllOfGeneric<MatcherTs...>&& rhs) { MatchAllOfGeneric<MatcherTs...>&& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return MatchAllOfGeneric<MatcherLHS, MatcherTs...>{array_cat(static_cast<void const*>(std::addressof(lhs)), CATCH_MOVE(rhs.m_matchers))}; return MatchAllOfGeneric<MatcherLHS, MatcherTs...>{array_cat(static_cast<void const*>(std::addressof(lhs)), CATCH_MOVE(rhs.m_matchers))};
} }
}; };
@@ -169,7 +171,8 @@ namespace Matchers {
MatchAnyOfGeneric(MatchAnyOfGeneric&&) = default; MatchAnyOfGeneric(MatchAnyOfGeneric&&) = default;
MatchAnyOfGeneric& operator=(MatchAnyOfGeneric&&) = default; MatchAnyOfGeneric& operator=(MatchAnyOfGeneric&&) = default;
MatchAnyOfGeneric(MatcherTs const&... matchers) : m_matchers{ {std::addressof(matchers)...} } {} MatchAnyOfGeneric(MatcherTs const&... matchers CATCH_ATTR_LIFETIMEBOUND)
: m_matchers{ {std::addressof(matchers)...} } {}
explicit MatchAnyOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {} explicit MatchAnyOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {}
template<typename Arg> template<typename Arg>
@@ -190,8 +193,8 @@ namespace Matchers {
//! Avoids type nesting for `GenericAnyOf || GenericAnyOf` case //! Avoids type nesting for `GenericAnyOf || GenericAnyOf` case
template<typename... MatchersRHS> template<typename... MatchersRHS>
friend MatchAnyOfGeneric<MatcherTs..., MatchersRHS...> operator || ( friend MatchAnyOfGeneric<MatcherTs..., MatchersRHS...> operator || (
MatchAnyOfGeneric<MatcherTs...>&& lhs, MatchAnyOfGeneric<MatcherTs...>&& lhs CATCH_ATTR_LIFETIMEBOUND,
MatchAnyOfGeneric<MatchersRHS...>&& rhs) { MatchAnyOfGeneric<MatchersRHS...>&& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return MatchAnyOfGeneric<MatcherTs..., MatchersRHS...>{array_cat(CATCH_MOVE(lhs.m_matchers), CATCH_MOVE(rhs.m_matchers))}; return MatchAnyOfGeneric<MatcherTs..., MatchersRHS...>{array_cat(CATCH_MOVE(lhs.m_matchers), CATCH_MOVE(rhs.m_matchers))};
} }
@@ -199,8 +202,8 @@ namespace Matchers {
template<typename MatcherRHS> template<typename MatcherRHS>
friend std::enable_if_t<is_matcher_v<MatcherRHS>, friend std::enable_if_t<is_matcher_v<MatcherRHS>,
MatchAnyOfGeneric<MatcherTs..., MatcherRHS>> operator || ( MatchAnyOfGeneric<MatcherTs..., MatcherRHS>> operator || (
MatchAnyOfGeneric<MatcherTs...>&& lhs, MatchAnyOfGeneric<MatcherTs...>&& lhs CATCH_ATTR_LIFETIMEBOUND,
MatcherRHS const& rhs) { MatcherRHS const& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return MatchAnyOfGeneric<MatcherTs..., MatcherRHS>{array_cat(CATCH_MOVE(lhs.m_matchers), static_cast<void const*>(std::addressof(rhs)))}; return MatchAnyOfGeneric<MatcherTs..., MatcherRHS>{array_cat(CATCH_MOVE(lhs.m_matchers), static_cast<void const*>(std::addressof(rhs)))};
} }
@@ -208,8 +211,8 @@ namespace Matchers {
template<typename MatcherLHS> template<typename MatcherLHS>
friend std::enable_if_t<is_matcher_v<MatcherLHS>, friend std::enable_if_t<is_matcher_v<MatcherLHS>,
MatchAnyOfGeneric<MatcherLHS, MatcherTs...>> operator || ( MatchAnyOfGeneric<MatcherLHS, MatcherTs...>> operator || (
MatcherLHS const& lhs, MatcherLHS const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatchAnyOfGeneric<MatcherTs...>&& rhs) { MatchAnyOfGeneric<MatcherTs...>&& rhs CATCH_ATTR_LIFETIMEBOUND) {
return MatchAnyOfGeneric<MatcherLHS, MatcherTs...>{array_cat(static_cast<void const*>(std::addressof(lhs)), CATCH_MOVE(rhs.m_matchers))}; return MatchAnyOfGeneric<MatcherLHS, MatcherTs...>{array_cat(static_cast<void const*>(std::addressof(lhs)), CATCH_MOVE(rhs.m_matchers))};
} }
}; };
@@ -225,7 +228,8 @@ namespace Matchers {
MatchNotOfGeneric(MatchNotOfGeneric&&) = default; MatchNotOfGeneric(MatchNotOfGeneric&&) = default;
MatchNotOfGeneric& operator=(MatchNotOfGeneric&&) = default; MatchNotOfGeneric& operator=(MatchNotOfGeneric&&) = default;
explicit MatchNotOfGeneric(MatcherT const& matcher) : m_matcher{matcher} {} explicit MatchNotOfGeneric(MatcherT const& matcher CATCH_ATTR_LIFETIMEBOUND)
: m_matcher{matcher} {}
template<typename Arg> template<typename Arg>
bool match(Arg&& arg) const { bool match(Arg&& arg) const {
@@ -237,7 +241,9 @@ namespace Matchers {
} }
//! Negating negation can just unwrap and return underlying matcher //! Negating negation can just unwrap and return underlying matcher
friend MatcherT const& operator ! (MatchNotOfGeneric<MatcherT> const& matcher) { friend MatcherT const&
operator!( MatchNotOfGeneric<MatcherT> const& matcher
CATCH_ATTR_LIFETIMEBOUND ) {
return matcher.m_matcher; return matcher.m_matcher;
} }
}; };
@@ -247,20 +253,22 @@ namespace Matchers {
// compose only generic matchers // compose only generic matchers
template<typename MatcherLHS, typename MatcherRHS> template<typename MatcherLHS, typename MatcherRHS>
std::enable_if_t<Detail::are_generic_matchers_v<MatcherLHS, MatcherRHS>, Detail::MatchAllOfGeneric<MatcherLHS, MatcherRHS>> std::enable_if_t<Detail::are_generic_matchers_v<MatcherLHS, MatcherRHS>, Detail::MatchAllOfGeneric<MatcherLHS, MatcherRHS>>
operator && (MatcherLHS const& lhs, MatcherRHS const& rhs) { operator&&( MatcherLHS const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatcherRHS const& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return { lhs, rhs }; return { lhs, rhs };
} }
template<typename MatcherLHS, typename MatcherRHS> template<typename MatcherLHS, typename MatcherRHS>
std::enable_if_t<Detail::are_generic_matchers_v<MatcherLHS, MatcherRHS>, Detail::MatchAnyOfGeneric<MatcherLHS, MatcherRHS>> std::enable_if_t<Detail::are_generic_matchers_v<MatcherLHS, MatcherRHS>, Detail::MatchAnyOfGeneric<MatcherLHS, MatcherRHS>>
operator || (MatcherLHS const& lhs, MatcherRHS const& rhs) { operator||( MatcherLHS const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatcherRHS const& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return { lhs, rhs }; return { lhs, rhs };
} }
//! Wrap provided generic matcher in generic negator //! Wrap provided generic matcher in generic negator
template<typename MatcherT> template<typename MatcherT>
std::enable_if_t<Detail::is_generic_matcher_v<MatcherT>, Detail::MatchNotOfGeneric<MatcherT>> std::enable_if_t<Detail::is_generic_matcher_v<MatcherT>, Detail::MatchNotOfGeneric<MatcherT>>
operator ! (MatcherT const& matcher) { operator!( MatcherT const& matcher CATCH_ATTR_LIFETIMEBOUND ) {
return Detail::MatchNotOfGeneric<MatcherT>{matcher}; return Detail::MatchNotOfGeneric<MatcherT>{matcher};
} }
@@ -268,25 +276,29 @@ namespace Matchers {
// compose mixed generic and non-generic matchers // compose mixed generic and non-generic matchers
template<typename MatcherLHS, typename ArgRHS> template<typename MatcherLHS, typename ArgRHS>
std::enable_if_t<Detail::is_generic_matcher_v<MatcherLHS>, Detail::MatchAllOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>> std::enable_if_t<Detail::is_generic_matcher_v<MatcherLHS>, Detail::MatchAllOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>>
operator && (MatcherLHS const& lhs, MatcherBase<ArgRHS> const& rhs) { operator&&( MatcherLHS const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatcherBase<ArgRHS> const& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return { lhs, rhs }; return { lhs, rhs };
} }
template<typename ArgLHS, typename MatcherRHS> template<typename ArgLHS, typename MatcherRHS>
std::enable_if_t<Detail::is_generic_matcher_v<MatcherRHS>, Detail::MatchAllOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>> std::enable_if_t<Detail::is_generic_matcher_v<MatcherRHS>, Detail::MatchAllOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>>
operator && (MatcherBase<ArgLHS> const& lhs, MatcherRHS const& rhs) { operator&&( MatcherBase<ArgLHS> const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatcherRHS const& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return { lhs, rhs }; return { lhs, rhs };
} }
template<typename MatcherLHS, typename ArgRHS> template<typename MatcherLHS, typename ArgRHS>
std::enable_if_t<Detail::is_generic_matcher_v<MatcherLHS>, Detail::MatchAnyOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>> std::enable_if_t<Detail::is_generic_matcher_v<MatcherLHS>, Detail::MatchAnyOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>>
operator || (MatcherLHS const& lhs, MatcherBase<ArgRHS> const& rhs) { operator||( MatcherLHS const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatcherBase<ArgRHS> const& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return { lhs, rhs }; return { lhs, rhs };
} }
template<typename ArgLHS, typename MatcherRHS> template<typename ArgLHS, typename MatcherRHS>
std::enable_if_t<Detail::is_generic_matcher_v<MatcherRHS>, Detail::MatchAnyOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>> std::enable_if_t<Detail::is_generic_matcher_v<MatcherRHS>, Detail::MatchAnyOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>>
operator || (MatcherBase<ArgLHS> const& lhs, MatcherRHS const& rhs) { operator||( MatcherBase<ArgLHS> const& lhs CATCH_ATTR_LIFETIMEBOUND,
MatcherRHS const& rhs CATCH_ATTR_LIFETIMEBOUND ) {
return { lhs, rhs }; return { lhs, rhs };
} }

View File

@@ -105,6 +105,7 @@ internal_headers = [
'internal/catch_jsonwriter.hpp', 'internal/catch_jsonwriter.hpp',
'internal/catch_lazy_expr.hpp', 'internal/catch_lazy_expr.hpp',
'internal/catch_leak_detector.hpp', 'internal/catch_leak_detector.hpp',
'internal/catch_lifetimebound.hpp',
'internal/catch_list.hpp', 'internal/catch_list.hpp',
'internal/catch_logical_traits.hpp', 'internal/catch_logical_traits.hpp',
'internal/catch_message_info.hpp', 'internal/catch_message_info.hpp',

View File

@@ -168,6 +168,7 @@ Nor would this
:test-result: PASS GENERATE can combine literals and generators :test-result: PASS GENERATE can combine literals and generators
:test-result: PASS Generators -- adapters :test-result: PASS Generators -- adapters
:test-result: PASS Generators -- simple :test-result: PASS Generators -- simple
:test-result: PASS Generators can be skipped forward
:test-result: PASS Generators internals :test-result: PASS Generators internals
:test-result: PASS Greater-than inequalities with different epsilons :test-result: PASS Greater-than inequalities with different epsilons
:test-result: PASS Hashers with different seed produce different hash with same test case :test-result: PASS Hashers with different seed produce different hash with same test case

View File

@@ -166,6 +166,7 @@
:test-result: PASS GENERATE can combine literals and generators :test-result: PASS GENERATE can combine literals and generators
:test-result: PASS Generators -- adapters :test-result: PASS Generators -- adapters
:test-result: PASS Generators -- simple :test-result: PASS Generators -- simple
:test-result: PASS Generators can be skipped forward
:test-result: PASS Generators internals :test-result: PASS Generators internals
:test-result: PASS Greater-than inequalities with different epsilons :test-result: PASS Greater-than inequalities with different epsilons
:test-result: PASS Hashers with different seed produce different hash with same test case :test-result: PASS Hashers with different seed produce different hash with same test case

View File

@@ -787,6 +787,13 @@ Generators.tests.cpp:<line number>: passed: j < i for: -1 < 3
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 1 Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 1
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 2 Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 2
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 3 Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 3
GeneratorsImpl.tests.cpp:<line number>: passed: generator.currentElementIndex() == 0 for: 0 == 0
GeneratorsImpl.tests.cpp:<line number>: passed: generator.currentElementIndex() == 3 for: 3 == 3
GeneratorsImpl.tests.cpp:<line number>: passed: generator.get() == 3 for: 3 == 3
GeneratorsImpl.tests.cpp:<line number>: passed: generator.currentElementIndex() == 5 for: 5 == 5
GeneratorsImpl.tests.cpp:<line number>: passed: generator.get() == 5 for: 5 == 5
GeneratorsImpl.tests.cpp:<line number>: passed: generator.skipToNthElement( 3 )
GeneratorsImpl.tests.cpp:<line number>: passed: generator.skipToNthElement( 6 )
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 123 for: 123 == 123 GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 123 for: 123 == 123
GeneratorsImpl.tests.cpp:<line number>: passed: !(gen.next()) for: !false GeneratorsImpl.tests.cpp:<line number>: passed: !(gen.next()) for: !false
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1 GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1
@@ -2888,7 +2895,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0 InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
Misc.tests.cpp:<line number>: passed: Misc.tests.cpp:<line number>: passed:
Misc.tests.cpp:<line number>: passed: Misc.tests.cpp:<line number>: passed:
test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected test cases: 436 | 318 passed | 95 failed | 6 skipped | 17 failed as expected
assertions: 2303 | 2105 passed | 157 failed | 41 failed as expected assertions: 2310 | 2112 passed | 157 failed | 41 failed as expected

View File

@@ -785,6 +785,13 @@ Generators.tests.cpp:<line number>: passed: j < i for: -1 < 3
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 1 Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 1
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 2 Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 2
Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 3 Generators.tests.cpp:<line number>: passed: 4u * i > str.size() for: 12 > 3
GeneratorsImpl.tests.cpp:<line number>: passed: generator.currentElementIndex() == 0 for: 0 == 0
GeneratorsImpl.tests.cpp:<line number>: passed: generator.currentElementIndex() == 3 for: 3 == 3
GeneratorsImpl.tests.cpp:<line number>: passed: generator.get() == 3 for: 3 == 3
GeneratorsImpl.tests.cpp:<line number>: passed: generator.currentElementIndex() == 5 for: 5 == 5
GeneratorsImpl.tests.cpp:<line number>: passed: generator.get() == 5 for: 5 == 5
GeneratorsImpl.tests.cpp:<line number>: passed: generator.skipToNthElement( 3 )
GeneratorsImpl.tests.cpp:<line number>: passed: generator.skipToNthElement( 6 )
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 123 for: 123 == 123 GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 123 for: 123 == 123
GeneratorsImpl.tests.cpp:<line number>: passed: !(gen.next()) for: !false GeneratorsImpl.tests.cpp:<line number>: passed: !(gen.next()) for: !false
GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1 GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1
@@ -2877,7 +2884,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0 InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
Misc.tests.cpp:<line number>: passed: Misc.tests.cpp:<line number>: passed:
Misc.tests.cpp:<line number>: passed: Misc.tests.cpp:<line number>: passed:
test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected test cases: 436 | 318 passed | 95 failed | 6 skipped | 17 failed as expected
assertions: 2303 | 2105 passed | 157 failed | 41 failed as expected assertions: 2310 | 2112 passed | 157 failed | 41 failed as expected

View File

@@ -1719,6 +1719,6 @@ due to unexpected exception with message:
Why would you throw a std::string? Why would you throw a std::string?
=============================================================================== ===============================================================================
test cases: 435 | 335 passed | 76 failed | 7 skipped | 17 failed as expected test cases: 436 | 336 passed | 76 failed | 7 skipped | 17 failed as expected
assertions: 2282 | 2105 passed | 136 failed | 41 failed as expected assertions: 2289 | 2112 passed | 136 failed | 41 failed as expected

View File

@@ -5831,6 +5831,43 @@ Generators.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
12 > 3 12 > 3
-------------------------------------------------------------------------------
Generators can be skipped forward
-------------------------------------------------------------------------------
GeneratorsImpl.tests.cpp:<line number>
...............................................................................
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( generator.currentElementIndex() == 0 )
with expansion:
0 == 0
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( generator.currentElementIndex() == 3 )
with expansion:
3 == 3
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( generator.get() == 3 )
with expansion:
3 == 3
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( generator.currentElementIndex() == 5 )
with expansion:
5 == 5
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( generator.get() == 5 )
with expansion:
5 == 5
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS( generator.skipToNthElement( 3 ) )
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS( generator.skipToNthElement( 6 ) )
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Generators internals Generators internals
Single value Single value
@@ -19295,6 +19332,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED: Misc.tests.cpp:<line number>: PASSED:
=============================================================================== ===============================================================================
test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected test cases: 436 | 318 passed | 95 failed | 6 skipped | 17 failed as expected
assertions: 2303 | 2105 passed | 157 failed | 41 failed as expected assertions: 2310 | 2112 passed | 157 failed | 41 failed as expected

View File

@@ -5829,6 +5829,43 @@ Generators.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
12 > 3 12 > 3
-------------------------------------------------------------------------------
Generators can be skipped forward
-------------------------------------------------------------------------------
GeneratorsImpl.tests.cpp:<line number>
...............................................................................
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( generator.currentElementIndex() == 0 )
with expansion:
0 == 0
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( generator.currentElementIndex() == 3 )
with expansion:
3 == 3
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( generator.get() == 3 )
with expansion:
3 == 3
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( generator.currentElementIndex() == 5 )
with expansion:
5 == 5
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE( generator.get() == 5 )
with expansion:
5 == 5
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS( generator.skipToNthElement( 3 ) )
GeneratorsImpl.tests.cpp:<line number>: PASSED:
REQUIRE_THROWS( generator.skipToNthElement( 6 ) )
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Generators internals Generators internals
Single value Single value
@@ -19284,6 +19321,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED: Misc.tests.cpp:<line number>: PASSED:
=============================================================================== ===============================================================================
test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected test cases: 436 | 318 passed | 95 failed | 6 skipped | 17 failed as expected
assertions: 2303 | 2105 passed | 157 failed | 41 failed as expected assertions: 2310 | 2112 passed | 157 failed | 41 failed as expected

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact <testsuitesloose text artifact
> >
<testsuite name="<exe-name>" errors="17" failures="140" skipped="12" tests="2315" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="17" failures="140" skipped="12" tests="2322" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties> <properties>
<property name="random-seed" value="1"/> <property name="random-seed" value="1"/>
<property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/> <property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@@ -837,6 +837,7 @@ at Message.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Generators -- simple" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators -- simple" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators -- simple/one" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators -- simple/one" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators -- simple/two" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators -- simple/two" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators can be skipped forward" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators internals" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Single value" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators internals/Single value" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Preset values" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators internals/Preset values" time="{duration}" status="run"/>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuites> <testsuites>
<testsuite name="<exe-name>" errors="17" failures="140" skipped="12" tests="2315" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="17" failures="140" skipped="12" tests="2322" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties> <properties>
<property name="random-seed" value="1"/> <property name="random-seed" value="1"/>
<property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/> <property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@@ -836,6 +836,7 @@ at Message.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Generators -- simple" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators -- simple" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators -- simple/one" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators -- simple/one" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators -- simple/two" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators -- simple/two" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators can be skipped forward" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators internals" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Single value" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators internals/Single value" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Generators internals/Preset values" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators internals/Preset values" time="{duration}" status="run"/>

View File

@@ -144,6 +144,7 @@ at AssertionHandler.tests.cpp:<line number>
</file> </file>
<file path="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp"> <file path="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp">
<testCase name="Filter generator throws exception for empty generator" duration="{duration}"/> <testCase name="Filter generator throws exception for empty generator" duration="{duration}"/>
<testCase name="Generators can be skipped forward" duration="{duration}"/>
<testCase name="Generators internals" duration="{duration}"/> <testCase name="Generators internals" duration="{duration}"/>
<testCase name="Generators internals/Single value" duration="{duration}"/> <testCase name="Generators internals/Single value" duration="{duration}"/>
<testCase name="Generators internals/Preset values" duration="{duration}"/> <testCase name="Generators internals/Preset values" duration="{duration}"/>

View File

@@ -143,6 +143,7 @@ at AssertionHandler.tests.cpp:<line number>
</file> </file>
<file path="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp"> <file path="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp">
<testCase name="Filter generator throws exception for empty generator" duration="{duration}"/> <testCase name="Filter generator throws exception for empty generator" duration="{duration}"/>
<testCase name="Generators can be skipped forward" duration="{duration}"/>
<testCase name="Generators internals" duration="{duration}"/> <testCase name="Generators internals" duration="{duration}"/>
<testCase name="Generators internals/Single value" duration="{duration}"/> <testCase name="Generators internals/Single value" duration="{duration}"/>
<testCase name="Generators internals/Preset values" duration="{duration}"/> <testCase name="Generators internals/Preset values" duration="{duration}"/>

View File

@@ -1430,6 +1430,20 @@ ok {test-number} - 4u * i > str.size() for: 12 > 1
ok {test-number} - 4u * i > str.size() for: 12 > 2 ok {test-number} - 4u * i > str.size() for: 12 > 2
# Generators -- simple # Generators -- simple
ok {test-number} - 4u * i > str.size() for: 12 > 3 ok {test-number} - 4u * i > str.size() for: 12 > 3
# Generators can be skipped forward
ok {test-number} - generator.currentElementIndex() == 0 for: 0 == 0
# Generators can be skipped forward
ok {test-number} - generator.currentElementIndex() == 3 for: 3 == 3
# Generators can be skipped forward
ok {test-number} - generator.get() == 3 for: 3 == 3
# Generators can be skipped forward
ok {test-number} - generator.currentElementIndex() == 5 for: 5 == 5
# Generators can be skipped forward
ok {test-number} - generator.get() == 5 for: 5 == 5
# Generators can be skipped forward
ok {test-number} - generator.skipToNthElement( 3 )
# Generators can be skipped forward
ok {test-number} - generator.skipToNthElement( 6 )
# Generators internals # Generators internals
ok {test-number} - gen.get() == 123 for: 123 == 123 ok {test-number} - gen.get() == 123 for: 123 == 123
# Generators internals # Generators internals
@@ -4627,5 +4641,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} - ok {test-number} -
# xmlentitycheck # xmlentitycheck
ok {test-number} - ok {test-number} -
1..2315 1..2322

View File

@@ -1428,6 +1428,20 @@ ok {test-number} - 4u * i > str.size() for: 12 > 1
ok {test-number} - 4u * i > str.size() for: 12 > 2 ok {test-number} - 4u * i > str.size() for: 12 > 2
# Generators -- simple # Generators -- simple
ok {test-number} - 4u * i > str.size() for: 12 > 3 ok {test-number} - 4u * i > str.size() for: 12 > 3
# Generators can be skipped forward
ok {test-number} - generator.currentElementIndex() == 0 for: 0 == 0
# Generators can be skipped forward
ok {test-number} - generator.currentElementIndex() == 3 for: 3 == 3
# Generators can be skipped forward
ok {test-number} - generator.get() == 3 for: 3 == 3
# Generators can be skipped forward
ok {test-number} - generator.currentElementIndex() == 5 for: 5 == 5
# Generators can be skipped forward
ok {test-number} - generator.get() == 5 for: 5 == 5
# Generators can be skipped forward
ok {test-number} - generator.skipToNthElement( 3 )
# Generators can be skipped forward
ok {test-number} - generator.skipToNthElement( 6 )
# Generators internals # Generators internals
ok {test-number} - gen.get() == 123 for: 123 == 123 ok {test-number} - gen.get() == 123 for: 123 == 123
# Generators internals # Generators internals
@@ -4616,5 +4630,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} - ok {test-number} -
# xmlentitycheck # xmlentitycheck
ok {test-number} - ok {test-number} -
1..2315 1..2322

View File

@@ -414,6 +414,8 @@
##teamcity[testFinished name='Generators -- adapters' duration="{duration}"] ##teamcity[testFinished name='Generators -- adapters' duration="{duration}"]
##teamcity[testStarted name='Generators -- simple'] ##teamcity[testStarted name='Generators -- simple']
##teamcity[testFinished name='Generators -- simple' duration="{duration}"] ##teamcity[testFinished name='Generators -- simple' duration="{duration}"]
##teamcity[testStarted name='Generators can be skipped forward']
##teamcity[testFinished name='Generators can be skipped forward' duration="{duration}"]
##teamcity[testStarted name='Generators internals'] ##teamcity[testStarted name='Generators internals']
##teamcity[testFinished name='Generators internals' duration="{duration}"] ##teamcity[testFinished name='Generators internals' duration="{duration}"]
##teamcity[testStarted name='Greater-than inequalities with different epsilons'] ##teamcity[testStarted name='Greater-than inequalities with different epsilons']

View File

@@ -414,6 +414,8 @@
##teamcity[testFinished name='Generators -- adapters' duration="{duration}"] ##teamcity[testFinished name='Generators -- adapters' duration="{duration}"]
##teamcity[testStarted name='Generators -- simple'] ##teamcity[testStarted name='Generators -- simple']
##teamcity[testFinished name='Generators -- simple' duration="{duration}"] ##teamcity[testFinished name='Generators -- simple' duration="{duration}"]
##teamcity[testStarted name='Generators can be skipped forward']
##teamcity[testFinished name='Generators can be skipped forward' duration="{duration}"]
##teamcity[testStarted name='Generators internals'] ##teamcity[testStarted name='Generators internals']
##teamcity[testFinished name='Generators internals' duration="{duration}"] ##teamcity[testFinished name='Generators internals' duration="{duration}"]
##teamcity[testStarted name='Greater-than inequalities with different epsilons'] ##teamcity[testStarted name='Greater-than inequalities with different epsilons']

View File

@@ -6605,6 +6605,65 @@ Approx( 1.30000000000000004 )
</Section> </Section>
<OverallResult success="true" skips="0"/> <OverallResult success="true" skips="0"/>
</TestCase> </TestCase>
<TestCase name="Generators can be skipped forward" tags="[generators]" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.currentElementIndex() == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.currentElementIndex() == 3
</Original>
<Expanded>
3 == 3
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.get() == 3
</Original>
<Expanded>
3 == 3
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.currentElementIndex() == 5
</Original>
<Expanded>
5 == 5
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.get() == 5
</Original>
<Expanded>
5 == 5
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_THROWS" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.skipToNthElement( 3 )
</Original>
<Expanded>
generator.skipToNthElement( 3 )
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_THROWS" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.skipToNthElement( 6 )
</Original>
<Expanded>
generator.skipToNthElement( 6 )
</Expanded>
</Expression>
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="Generators internals" tags="[generators][internals]" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > <TestCase name="Generators internals" tags="[generators][internals]" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Section name="Single value" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > <Section name="Single value" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
@@ -22324,6 +22383,6 @@ Approx( -1.95996398454005449 )
</Section> </Section>
<OverallResult success="true" skips="0"/> <OverallResult success="true" skips="0"/>
</TestCase> </TestCase>
<OverallResults successes="2105" failures="157" expectedFailures="41" skips="12"/> <OverallResults successes="2112" failures="157" expectedFailures="41" skips="12"/>
<OverallResultsCases successes="317" failures="95" expectedFailures="17" skips="6"/> <OverallResultsCases successes="318" failures="95" expectedFailures="17" skips="6"/>
</Catch2TestRun> </Catch2TestRun>

View File

@@ -6605,6 +6605,65 @@ Approx( 1.30000000000000004 )
</Section> </Section>
<OverallResult success="true" skips="0"/> <OverallResult success="true" skips="0"/>
</TestCase> </TestCase>
<TestCase name="Generators can be skipped forward" tags="[generators]" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.currentElementIndex() == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.currentElementIndex() == 3
</Original>
<Expanded>
3 == 3
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.get() == 3
</Original>
<Expanded>
3 == 3
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.currentElementIndex() == 5
</Original>
<Expanded>
5 == 5
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.get() == 5
</Original>
<Expanded>
5 == 5
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_THROWS" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.skipToNthElement( 3 )
</Original>
<Expanded>
generator.skipToNthElement( 3 )
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_THROWS" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Original>
generator.skipToNthElement( 6 )
</Original>
<Expanded>
generator.skipToNthElement( 6 )
</Expanded>
</Expression>
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="Generators internals" tags="[generators][internals]" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > <TestCase name="Generators internals" tags="[generators][internals]" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Section name="Single value" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > <Section name="Single value" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
@@ -22323,6 +22382,6 @@ Approx( -1.95996398454005449 )
</Section> </Section>
<OverallResult success="true" skips="0"/> <OverallResult success="true" skips="0"/>
</TestCase> </TestCase>
<OverallResults successes="2105" failures="157" expectedFailures="41" skips="12"/> <OverallResults successes="2112" failures="157" expectedFailures="41" skips="12"/>
<OverallResultsCases successes="317" failures="95" expectedFailures="17" skips="6"/> <OverallResultsCases successes="318" failures="95" expectedFailures="17" skips="6"/>
</Catch2TestRun> </Catch2TestRun>

View File

@@ -586,3 +586,21 @@ TEST_CASE("from_range(container) supports ADL begin/end and arrays", "[generator
} }
} }
TEST_CASE( "Generators can be skipped forward", "[generators]" ) {
auto generator = Catch::Generators::FixedValuesGenerator<int>( { 0, 1, 2, 3, 4, 5 } );
REQUIRE( generator.currentElementIndex() == 0 );
generator.skipToNthElement( 3 );
REQUIRE( generator.currentElementIndex() == 3 );
REQUIRE( generator.get() == 3 );
generator.skipToNthElement( 5 );
REQUIRE( generator.currentElementIndex() == 5 );
REQUIRE( generator.get() == 5 );
// Backwards
REQUIRE_THROWS( generator.skipToNthElement( 3 ) );
// Past the end
REQUIRE_THROWS( generator.skipToNthElement( 6 ) );
}