file
Tester.hClass Corrade::
Namespaces
- namespace Corrade
- Root namespace.
- namespace Corrade::TestSuite
- Test suite.
Classes
- class Corrade::TestSuite::Tester
- Base class for tests and benchmarks.
- class Corrade::TestSuite::Tester::TesterConfiguration
- Tester configuration.
- class Corrade::TestSuite::TestCaseDescriptionSourceLocation new in Git master
- Instanced test case description with source location.
Defines
- #define CORRADE_TEST_MAIN(Class)
- Create
main()
function for given TestSuite::Tester subclass. - #define CORRADE_VERIFY(...)
- Verify an expression in a test case.
- #define CORRADE_COMPARE(actual, expected)
- Compare two values in a test case.
- #define CORRADE_COMPARE_AS(actual, expected, ...)
- Compare two values in a test case with explicitly specified type.
- #define CORRADE_COMPARE_WITH(actual, expected, comparatorInstance)
- Compare two values in a test case with explicitly specified comparator.
- #define CORRADE_EXPECT_FAIL(message)
- Expect failure in a test case in all following checks in the same scope.
- #define CORRADE_EXPECT_FAIL_IF(condition, message)
- Conditionally expect failure in a test case in all following checks in the same scope.
- #define CORRADE_INFO(...) new in Git master
- Print an info message.
- #define CORRADE_WARN(...) new in Git master
- Print a warning message.
- #define CORRADE_FAIL(...) new in Git master
- Explicitly fail a test case.
- #define CORRADE_FAIL_IF(condition, message) new in Git master
- Explicitly fail a test case if a condition is true.
- #define CORRADE_SKIP(...)
- Skip a test case.
- #define CORRADE_SKIP_IF_NO_ASSERT() new in Git master
- Skip a test case if Corrade asserts are disabled.
- #define CORRADE_SKIP_IF_NO_DEBUG_ASSERT() new in Git master
- Skip a test case if Corrade debug asserts are disabled.
- #define CORRADE_ITERATION(...) new in 2020.06
- Annotate an iteration in a test case.
- #define CORRADE_BENCHMARK(batchSize)
- Run a benchmark in a test case.
Define documentation
#define CORRADE_TEST_MAIN(Class)
Create main()
function for given TestSuite::
Populates TestSuite::Class
, executes the test cases and returns from main()
with code based on the test results. This macro has to be used outside of any namespace.
#define CORRADE_VERIFY(...)
Verify an expression in a test case.
Parameters | |
---|---|
... | Expression to verify |
If the expression is not true, the expression is printed and execution of given test case is terminated. Example usage:
Containers::StringView s = "hello"; CORRADE_VERIFY(!s.isEmpty());
It is possible to use CORRADE_explicit operator bool()
without doing explicit conversion (e.g. using !!
), for example:
Containers::Pointer<int> i{new int}; CORRADE_VERIFY(i);
This macro is meant to be called in a test case in a TestSuite::CORRADE_*()
macro captures the caller function name for the test output, which may not be desired when being in a helper function or a lambda. To circumvent that, either call a dummy CORRADE_VERIFY(true)
at the top of your test case, or explicitly call setTestCaseName() with either a hardcoded name or e.g. CORRADE_
#define CORRADE_COMPARE(actual, expected)
Compare two values in a test case.
Parameters | |
---|---|
actual | Calculated value |
expected | Ground truth value |
If the values are not the same, they are printed for comparison and execution of given test case is terminated. Example usage:
int a = 5 + 3; CORRADE_COMPARE(a, 8);
Comparison of floating-point types is by default done as a fuzzy-compare, see TestSuite::
Note that this macro is usable only if the type passed to it is printable via Utility::
#define CORRADE_COMPARE_AS(actual, expected, ...)
Compare two values in a test case with explicitly specified type.
Parameters | |
---|---|
actual | Calculated value |
expected | Ground truth value |
... | Type to compare as |
Casts the values to a specified typ first and then continues the same as CORRADE_
CORRADE_COMPARE_AS(std::sin(0.0), 0.0f, float);
Note that this macro is usable only if the type passed to it is printable via Utility::
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_COMPARE_WITH(actual, expected, comparatorInstance)
Compare two values in a test case with explicitly specified comparator.
Parameters | |
---|---|
actual | Calculated value |
expected | Ground truth value |
comparatorInstance | Instance of a comparator to compare with |
A variant of CORRADE_
CORRADE_COMPARE_WITH("actual.txt", "expected.txt", TestSuite::Compare::File{"/common/path/prefix"});
Note that this macro is usable only if the type passed to it is compatible with given comparator, and in some cases the comparator may require the type to also be printable with Utility::
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_EXPECT_FAIL(message)
Expect failure in a test case in all following checks in the same scope.
Parameters | |
---|---|
message | Message which will be printed as an indication of an expected failure |
Expects a failure in all following CORRADE_
{ CORRADE_EXPECT_FAIL("Not implemented."); CORRADE_VERIFY(isFutureClear()); } int i = 6*7; CORRADE_COMPARE(i, 42);
The message
can be formatted in the same way as in CORRADE_
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_EXPECT_FAIL_IF(condition, message)
Conditionally expect failure in a test case in all following checks in the same scope.
Parameters | |
---|---|
condition | The failure is expected only if the condition evaluates to true |
message | Message which will be printed as an indication of an expected failure |
With CORRADE_if
block:
{ if(answer != 42) CORRADE_EXPECT_FAIL("This is not our universe."); CORRADE_COMPARE(6*9, 42); // always fails }
The solution is to use CORRADE_EXPECT_FAIL_IF()
:
{ CORRADE_EXPECT_FAIL_IF(answer != 42, "This is not our universe."); CORRADE_COMPARE(6*7, 49); // expect the failure if answer is not 42 }
Similarly to CORRADE_explicit operator bool
without doing explicit conversion (e.g. using !!
).
The message
can be formatted in the same way as in CORRADE_
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_INFO(...) new in Git master
Print an info message.
Parameters | |
---|---|
... | Message to print |
Compared to using Utility::INFO
, test case name and file/line info to be clear where the message comes from. This then replaces the usual OK
, which isn't printed to avoid redundancy in the output. The message can be formatted in the same way as in CORRADE_
CORRADE_INFO("The calculated delta is" << delta);
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_WARN(...) new in Git master
Print a warning message.
Parameters | |
---|---|
... | Warning to print |
Like CORRADE_WARN
instead, replacing the usual OK
message as well. A warning has no effect on the test result and doesn't end execution of the test case either. The message can be formatted in the same way as in CORRADE_
if(delta > 0.05f) CORRADE_WARN("The delta" << delta << "is higher than ideal"); CORRADE_VERIFY(delta < 0.1f);
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_FAIL(...) new in Git master
Explicitly fail a test case.
Parameters | |
---|---|
... | Failure message to print |
Useful for example to test a particular #define
, in which case there's no expression or value to pass to CORRADE_
#ifdef CORRADE_TARGET_BIG_ENDIAN CORRADE_FAIL("The test assumes Big Endian is extinct."); #endif union { char fourcc[4]; int value; } data{{'D', 'I', 'V', 'X'}}; CORRADE_COMPARE(data.value, 0x58564944);
Even though the failure is unconditional, the test case can still continue execution when combined with CORRADE_return
statements among other things.
The message is prefixed with FAIL
including a file and line where the failure happened and execution of given test case is terminated. The message can be formatted in the same way as in CORRADE_
void test() { … if(answer != 42) { CORRADE_FAIL("Answer to the Ultimate Question of Life, the Universe, " "and Everything is" << answer); } // Wrong, if the answer is 42, the test case is reported as not having any // checks }
In such a case, CORRADE_
CORRADE_FAIL_IF(answer != 42, "Answer to the Ultimate Question of Life, the " "Universe, and Everything is" << answer);
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_FAIL_IF(condition, message) new in Git master
Explicitly fail a test case if a condition is true.
Parameters | |
---|---|
condition | Condition that's expected to evaluate to false |
message | Failure message which will be printed if the condition is true |
Useful when the implicit failure diagnostic from CORRADE_FAIL
including a file and line where the failure happened and execution of given test case is terminated. The message can be formatted in the same way as in CORRADE_
CORRADE_FAIL_IF(answer != 42, "Answer to the Ultimate Question of Life, the " "Universe, and Everything is" << answer);
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_SKIP(...)
Skip a test case.
Parameters | |
---|---|
... | Message which will be printed as an indication of a skipped test |
Skips all following checks in given test case, printing a SKIP
in the output. Useful for e.g. indicating that given feature can't be tested on given platform:
if(!bigEndian) { CORRADE_SKIP("Big endian compatibility can't be tested on this system."); }
The message can be formatted in the same way as in CORRADE_
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_SKIP_IF_NO_ASSERT() new in Git master
Skip a test case if Corrade asserts are disabled.
If CORRADE_do {} while(false)
. To be used in test cases that verify CORRADE_
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_SKIP_IF_NO_DEBUG_ASSERT() new in Git master
Skip a test case if Corrade debug asserts are disabled.
If CORRADE_do {} while(false)
. To be used in test cases that verify CORRADE_
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_ITERATION(...) new in 2020.06
Annotate an iteration in a test case.
Parameters | |
---|---|
... | Value to print in a failure diagnostic |
Annotates loop iterations in order to provide clearer failure diagnostics next to the file/line info. Doesn't print anything if there was no failure. Applies to all following CORRADE_
The value can be formatted in the same way as in CORRADE_
This macro is meant to be called in a test case in a TestSuite::
#define CORRADE_BENCHMARK(batchSize)
Run a benchmark in a test case.
Benchmarks the following block or expression by measuring batchSize
iterations of given block. Desired use is in conjunction with TestSuite::volatile
variable or combining all the results to a variable, which is then being used outside of the loop.
void benchmark() { Containers::StringView a = "hello", b = "world"; CORRADE_BENCHMARK(1000) { volatile Containers::String c = a + b; } }
The resulting measured value is divided by batchSize
to represent cost of one iteration.
This macro is meant to be called in a test case in a TestSuite::