5#ifndef DUNE_COMMON_TEST_TESTSUITE_HH
6#define DUNE_COMMON_TEST_TESTSUITE_HH
13#include <dune/common/test/collectorstream.hh>
74 CollectorStream
check(
bool condition, std::string
name=
"")
80 return CollectorStream([condition,
name,
this](std::string reason) {
101 return CollectorStream([condition,
name,
this](std::string reason) {
109 struct AnyException{};
110 struct NoException{};
112 template <
class Exception= AnyException,
class Expression>
113 bool evaluateThrowCondition(Expression&& expr)
116 catch (
const Exception& e)
122 return std::is_same_v<Exception,AnyException>;
125 return std::is_same_v<Exception,NoException>;
143 template <
class Exception= AnyException,
class Expression>
146 return check(evaluateThrowCondition<Exception>(expr),
name);
162 template <
class Expression>
165 return check(evaluateThrowCondition<NoException>(expr),
name);
182 template <
class Exception= AnyException,
class Expression>
185 return require(evaluateThrowCondition<Exception>(expr),
name);
201 template <
class Expression>
204 return require(evaluateThrowCondition<NoException>(expr),
name);
228 explicit operator bool ()
const
273 std::ostringstream s;
274 s << type <<
" FAILED";
276 s <<
"(" <<
name <<
")";
287 std::cout << message << std::endl;
A few common exception classes.
void message(const std::string &msg)
store string in internal message buffer
Definition exceptions.cc:32
Dune namespace.
Definition alignedallocator.hh:13
Base class for Dune-Exceptions.
Definition exceptions.hh:96
A Simple helper class to organize your test suite.
Definition testsuite.hh:31
std::string name() const
Query name.
Definition testsuite.hh:238
static void announceCheckResult(bool throwException, std::string type, std::string name, std::string reason)
Definition testsuite.hh:284
CollectorStream checkNoThrow(Expression &&expr, std::string name="")
Checks that the expression doesn't throw.
Definition testsuite.hh:163
CollectorStream requireNoThrow(Expression &&expr, std::string name="")
Requires that the expression doesn't throw.
Definition testsuite.hh:202
std::string name_
Definition testsuite.hh:296
static std::string composeMessage(std::string type, std::string name, std::string reason)
Definition testsuite.hh:271
TestSuite(std::string name="", ThrowPolicy policy=ThrowOnRequired)
Create TestSuite.
Definition testsuite.hh:58
void subTest(const TestSuite &subTest)
Collect data from a sub-TestSuite.
Definition testsuite.hh:214
TestSuite(ThrowPolicy policy, std::string name="")
Create TestSuite.
Definition testsuite.hh:45
std::size_t checks_
Definition testsuite.hh:297
int exit() const
Exit the test.
Definition testsuite.hh:263
CollectorStream require(bool condition, std::string name="")
Check a required condition.
Definition testsuite.hh:95
CollectorStream check(bool condition, std::string name="")
Check condition.
Definition testsuite.hh:74
bool throwPolicy_
Definition testsuite.hh:299
CollectorStream checkThrow(Expression &&expr, std::string name="")
Checks that the expression throws.
Definition testsuite.hh:144
CollectorStream requireThrow(Expression &&expr, std::string name="")
Requires that the expression throws.
Definition testsuite.hh:183
std::size_t failedChecks_
Definition testsuite.hh:298
bool report() const
Print a summary of this TestSuite.
Definition testsuite.hh:248
ThrowPolicy
Definition testsuite.hh:34
@ ThrowOnRequired
Definition testsuite.hh:36
@ AlwaysThrow
Definition testsuite.hh:35