mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-22 19:33:29 +01:00
Fix forwarding in SingleValueGenerator and generator creation
Fixes #1809
This commit is contained in:
parent
0fbf4f3e15
commit
82baef62e2
@ -49,7 +49,6 @@ namespace Generators {
|
||||
class SingleValueGenerator final : public IGenerator<T> {
|
||||
T m_value;
|
||||
public:
|
||||
SingleValueGenerator(T const& value) : m_value( value ) {}
|
||||
SingleValueGenerator(T&& value) : m_value(std::move(value)) {}
|
||||
|
||||
T const& get() const override {
|
||||
@ -112,21 +111,21 @@ namespace Generators {
|
||||
m_generators.emplace_back(std::move(generator));
|
||||
}
|
||||
void populate(T&& val) {
|
||||
m_generators.emplace_back(value(std::move(val)));
|
||||
m_generators.emplace_back(value(std::forward<T>(val)));
|
||||
}
|
||||
template<typename U>
|
||||
void populate(U&& val) {
|
||||
populate(T(std::move(val)));
|
||||
populate(T(std::forward<U>(val)));
|
||||
}
|
||||
template<typename U, typename... Gs>
|
||||
void populate(U&& valueOrGenerator, Gs... moreGenerators) {
|
||||
void populate(U&& valueOrGenerator, Gs &&... moreGenerators) {
|
||||
populate(std::forward<U>(valueOrGenerator));
|
||||
populate(std::forward<Gs>(moreGenerators)...);
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename... Gs>
|
||||
Generators(Gs... moreGenerators) {
|
||||
Generators(Gs &&... moreGenerators) {
|
||||
m_generators.reserve(sizeof...(Gs));
|
||||
populate(std::forward<Gs>(moreGenerators)...);
|
||||
}
|
||||
@ -158,7 +157,7 @@ namespace Generators {
|
||||
struct as {};
|
||||
|
||||
template<typename T, typename... Gs>
|
||||
auto makeGenerators( GeneratorWrapper<T>&& generator, Gs... moreGenerators ) -> Generators<T> {
|
||||
auto makeGenerators( GeneratorWrapper<T>&& generator, Gs &&... moreGenerators ) -> Generators<T> {
|
||||
return Generators<T>(std::move(generator), std::forward<Gs>(moreGenerators)...);
|
||||
}
|
||||
template<typename T>
|
||||
@ -166,11 +165,11 @@ namespace Generators {
|
||||
return Generators<T>(std::move(generator));
|
||||
}
|
||||
template<typename T, typename... Gs>
|
||||
auto makeGenerators( T&& val, Gs... moreGenerators ) -> Generators<T> {
|
||||
auto makeGenerators( T&& val, Gs &&... moreGenerators ) -> Generators<T> {
|
||||
return makeGenerators( value( std::forward<T>( val ) ), std::forward<Gs>( moreGenerators )... );
|
||||
}
|
||||
template<typename T, typename U, typename... Gs>
|
||||
auto makeGenerators( as<T>, U&& val, Gs... moreGenerators ) -> Generators<T> {
|
||||
auto makeGenerators( as<T>, U&& val, Gs &&... moreGenerators ) -> Generators<T> {
|
||||
return makeGenerators( value( T( std::forward<U>( val ) ) ), std::forward<Gs>( moreGenerators )... );
|
||||
}
|
||||
|
||||
|
@ -315,6 +315,21 @@ TEST_CASE("GENERATE capture macros", "[generators][internals][approvals]") {
|
||||
REQUIRE(value == value2);
|
||||
}
|
||||
|
||||
TEST_CASE("#1809 - GENERATE_COPY and SingleValueGenerator does not compile", "[generators][compilation][approvals]") {
|
||||
// Verify Issue #1809 fix, only needs to compile.
|
||||
auto a = GENERATE_COPY(1, 2);
|
||||
(void)a;
|
||||
auto b = GENERATE_COPY(as<long>{}, 1, 2);
|
||||
(void)b;
|
||||
int i = 1;
|
||||
int j = 2;
|
||||
auto c = GENERATE_COPY(i, j);
|
||||
(void)c;
|
||||
auto d = GENERATE_COPY(as<long>{}, i, j);
|
||||
(void)d;
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST_CASE("Multiple random generators in one test case output different values", "[generators][internals][approvals]") {
|
||||
SECTION("Integer") {
|
||||
auto random1 = Catch::Generators::random(0, 1000);
|
||||
|
Loading…
Reference in New Issue
Block a user