mirror of
https://github.com/catchorg/Catch2.git
synced 2025-01-16 07:08:01 +00:00
Compare commits
2 Commits
0614a4acb3
...
cbbebb65b6
Author | SHA1 | Date | |
---|---|---|---|
|
cbbebb65b6 | ||
|
fb08596b1b |
@ -12,17 +12,36 @@ are run once per each value in a generator.
|
||||
This is best explained with an example:
|
||||
```cpp
|
||||
TEST_CASE("Generators") {
|
||||
auto i = GENERATE(1, 2, 3);
|
||||
auto i = GENERATE(1, 2);
|
||||
SECTION("one") {
|
||||
auto j = GENERATE( -3, -2, -1 );
|
||||
auto j = GENERATE(-3, -2);
|
||||
REQUIRE(j < i);
|
||||
}
|
||||
SECTION("two") {
|
||||
auto k = GENERATE(4, 5, 6);
|
||||
REQUIRE(j != k);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The assertion in this test case will be run 9 times, because there
|
||||
are 3 possible values for `i` (1, 2, and 3) and there are 3 possible
|
||||
values for `j` (-3, -2, and -1).
|
||||
The `SECTION` "one" will be run 4 (2*2) times, because the outer
|
||||
generator has 2 elements in it, and the inner generator also has 2
|
||||
elements in it. The `SECTION` "two" will be run 6 (2*3) times. The
|
||||
sections will be run in order "one", "one", "two", "two", "two", "one",
|
||||
...
|
||||
|
||||
It is also possible to have multiple generators at the same level of
|
||||
nesting. The result is the same as when generators are inside nested
|
||||
sections, that is, the result will be a cartesian product of all
|
||||
elements. This means that in the snippet below, the test case will be
|
||||
run 6 (2*3) times.
|
||||
|
||||
```cpp
|
||||
TEST_CASE("Generators") {
|
||||
auto i = GENERATE(1, 2);
|
||||
auto j = GENERATE(3, 4, 5);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
There are 2 parts to generators in Catch2, the `GENERATE` macro together
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
/*
|
||||
* Created by Jozef on 12/11/2018.
|
||||
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||
@ -90,7 +91,7 @@
|
||||
#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3)
|
||||
#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4)
|
||||
#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5)
|
||||
#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _4, _5, _6)
|
||||
#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6)
|
||||
#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7)
|
||||
#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8)
|
||||
#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9)
|
||||
|
@ -36,6 +36,9 @@ Generators.tests.cpp:<line number>: passed: i != j for: 1 != 3
|
||||
Generators.tests.cpp:<line number>: passed: i != j for: 1 != 4
|
||||
Generators.tests.cpp:<line number>: passed: i != j for: 2 != 3
|
||||
Generators.tests.cpp:<line number>: passed: i != j for: 2 != 4
|
||||
Misc.tests.cpp:<line number>: passed:
|
||||
Misc.tests.cpp:<line number>: passed:
|
||||
Misc.tests.cpp:<line number>: passed:
|
||||
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42' with 1 message: 'expected exception'
|
||||
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception'
|
||||
Exception.tests.cpp:<line number>: passed: thisThrows() with 1 message: 'answer := 42'
|
||||
|
@ -1380,6 +1380,6 @@ due to unexpected exception with message:
|
||||
Why would you throw a std::string?
|
||||
|
||||
===============================================================================
|
||||
test cases: 312 | 238 passed | 70 failed | 4 failed as expected
|
||||
assertions: 1707 | 1555 passed | 131 failed | 21 failed as expected
|
||||
test cases: 315 | 241 passed | 70 failed | 4 failed as expected
|
||||
assertions: 1710 | 1558 passed | 131 failed | 21 failed as expected
|
||||
|
||||
|
@ -309,6 +309,30 @@ Generators.tests.cpp:<line number>: PASSED:
|
||||
with expansion:
|
||||
2 != 4
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
#1954 - 7 arg template test case sig compiles - 1, 1, 1, 1, 1, 0, 0
|
||||
-------------------------------------------------------------------------------
|
||||
Misc.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
#1954 - 7 arg template test case sig compiles - 5, 1, 1, 1, 1, 0, 0
|
||||
-------------------------------------------------------------------------------
|
||||
Misc.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
#1954 - 7 arg template test case sig compiles - 5, 3, 1, 1, 1, 0, 0
|
||||
-------------------------------------------------------------------------------
|
||||
Misc.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
#748 - captures with unexpected exceptions
|
||||
outside assertions
|
||||
@ -13639,6 +13663,6 @@ Misc.tests.cpp:<line number>
|
||||
Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
===============================================================================
|
||||
test cases: 312 | 222 passed | 86 failed | 4 failed as expected
|
||||
assertions: 1724 | 1555 passed | 148 failed | 21 failed as expected
|
||||
test cases: 315 | 225 passed | 86 failed | 4 failed as expected
|
||||
assertions: 1727 | 1558 passed | 148 failed | 21 failed as expected
|
||||
|
||||
|
@ -309,6 +309,30 @@ Generators.tests.cpp:<line number>: PASSED:
|
||||
with expansion:
|
||||
2 != 4
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
#1954 - 7 arg template test case sig compiles - 1, 1, 1, 1, 1, 0, 0
|
||||
-------------------------------------------------------------------------------
|
||||
Misc.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
#1954 - 7 arg template test case sig compiles - 5, 1, 1, 1, 1, 0, 0
|
||||
-------------------------------------------------------------------------------
|
||||
Misc.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
#1954 - 7 arg template test case sig compiles - 5, 3, 1, 1, 1, 0, 0
|
||||
-------------------------------------------------------------------------------
|
||||
Misc.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
#748 - captures with unexpected exceptions
|
||||
outside assertions
|
||||
@ -489,6 +513,6 @@ Condition.tests.cpp:<line number>: FAILED:
|
||||
CHECK( true != true )
|
||||
|
||||
===============================================================================
|
||||
test cases: 23 | 18 passed | 3 failed | 2 failed as expected
|
||||
assertions: 55 | 48 passed | 4 failed | 3 failed as expected
|
||||
test cases: 26 | 21 passed | 3 failed | 2 failed as expected
|
||||
assertions: 58 | 51 passed | 4 failed | 3 failed as expected
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuitesloose text artifact
|
||||
>
|
||||
<testsuite name="<exe-name>" errors="17" failures="132" tests="1725" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="17" failures="132" tests="1728" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<properties>
|
||||
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
|
||||
<property name="random-seed" value="1"/>
|
||||
@ -35,6 +35,9 @@ Nor would this
|
||||
<testcase classname="<exe-name>.global" name="#1912 -- test spec parser handles escaping/backslash in test name" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="#1913 - GENERATE inside a for loop should not keep recreating the generator" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="#1913 - GENERATEs can share a line" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="#1954 - 7 arg template test case sig compiles - 1, 1, 1, 1, 1, 0, 0" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="#1954 - 7 arg template test case sig compiles - 5, 1, 1, 1, 1, 0, 0" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="#1954 - 7 arg template test case sig compiles - 5, 3, 1, 1, 1, 0, 0" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="#748 - captures with unexpected exceptions/outside assertions" time="{duration}" status="run">
|
||||
<error type="TEST_CASE">
|
||||
FAILED:
|
||||
|
@ -1352,6 +1352,9 @@ Message.tests.cpp:<line number>
|
||||
<file path="projects/<exe-name>/UsageTests/Misc.tests.cpp">
|
||||
<testCase name="# A test name that starts with a #" duration="{duration}"/>
|
||||
<testCase name="#1175 - Hidden Test" duration="{duration}"/>
|
||||
<testCase name="#1954 - 7 arg template test case sig compiles - 1, 1, 1, 1, 1, 0, 0" duration="{duration}"/>
|
||||
<testCase name="#1954 - 7 arg template test case sig compiles - 5, 1, 1, 1, 1, 0, 0" duration="{duration}"/>
|
||||
<testCase name="#1954 - 7 arg template test case sig compiles - 5, 3, 1, 1, 1, 0, 0" duration="{duration}"/>
|
||||
<testCase name="#835 -- errno should not be touched by Catch" duration="{duration}">
|
||||
<skipped message="CHECK(f() == 0)">
|
||||
FAILED:
|
||||
|
@ -318,6 +318,15 @@ Nor would this
|
||||
</Expression>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="#1954 - 7 arg template test case sig compiles - 1, 1, 1, 1, 1, 0, 0" tags="[!hide][.][compilation][regression]" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="#1954 - 7 arg template test case sig compiles - 5, 1, 1, 1, 1, 0, 0" tags="[!hide][.][compilation][regression]" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="#1954 - 7 arg template test case sig compiles - 5, 3, 1, 1, 1, 0, 0" tags="[!hide][.][compilation][regression]" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="#748 - captures with unexpected exceptions" tags="[!hide][!shouldfail][!throws][.][failing]" filename="projects/<exe-name>/UsageTests/Exception.tests.cpp" >
|
||||
<Section name="outside assertions" filename="projects/<exe-name>/UsageTests/Exception.tests.cpp" >
|
||||
<Info>
|
||||
@ -16309,7 +16318,7 @@ loose text artifact
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="1555" failures="149" expectedFailures="21"/>
|
||||
<OverallResults successes="1558" failures="149" expectedFailures="21"/>
|
||||
</Group>
|
||||
<OverallResults successes="1555" failures="148" expectedFailures="21"/>
|
||||
<OverallResults successes="1558" failures="148" expectedFailures="21"/>
|
||||
</Catch>
|
||||
|
@ -484,4 +484,10 @@ TEST_CASE( "#1175 - Hidden Test", "[.]" ) {
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEMPLATE_TEST_CASE_SIG("#1954 - 7 arg template test case sig compiles", "[regression][.compilation]",
|
||||
((int Tnx, int Tnu, int Tny, int Tph, int Tch, int Tineq, int Teq), Tnx, Tnu, Tny, Tph, Tch, Tineq, Teq),
|
||||
(1, 1, 1, 1, 1, 0, 0), (5, 1, 1, 1, 1, 0, 0), (5, 3, 1, 1, 1, 0, 0)) {
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
}} // namespace MiscTests
|
||||
|
Loading…
Reference in New Issue
Block a user