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;
308 #endif // DUNE_COMMON_TEST_TESTSUITE_HH void subTest(const TestSuite &subTest)
Collect data from a sub-TestSuite.
Definition: testsuite.hh:214
bool report() const
Print a summary of this TestSuite.
Definition: testsuite.hh:248
bool throwPolicy_
Definition: testsuite.hh:299
CollectorStream requireThrow(Expression &&expr, std::string name="")
Requires that the expression throws.
Definition: testsuite.hh:183
TestSuite(ThrowPolicy policy, std::string name="")
Create TestSuite.
Definition: testsuite.hh:45
CollectorStream checkNoThrow(Expression &&expr, std::string name="")
Checks that the expression doesn't throw.
Definition: testsuite.hh:163
A Simple helper class to organize your test suite.
Definition: testsuite.hh:30
std::size_t failedChecks_
Definition: testsuite.hh:298
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
Definition: testsuite.hh:36
CollectorStream checkThrow(Expression &&expr, std::string name="")
Checks that the expression throws.
Definition: testsuite.hh:144
std::size_t checks_
Definition: testsuite.hh:297
CollectorStream check(bool condition, std::string name="")
Check condition.
Definition: testsuite.hh:74
Dune namespace
Definition: alignedallocator.hh:12
static std::string composeMessage(std::string type, std::string name, std::string reason)
Definition: testsuite.hh:271
CollectorStream require(bool condition, std::string name="")
Check a required condition.
Definition: testsuite.hh:95
void message(const std::string &msg)
store string in internal message buffer
Definition: exceptions.cc:32
A few common exception classes.
std::string name_
Definition: testsuite.hh:296
static void announceCheckResult(bool throwException, std::string type, std::string name, std::string reason)
Definition: testsuite.hh:284
TestSuite(std::string name="", ThrowPolicy policy=ThrowOnRequired)
Create TestSuite.
Definition: testsuite.hh:58
ThrowPolicy
Definition: testsuite.hh:33
Definition: testsuite.hh:35
std::string name() const
Query name.
Definition: testsuite.hh:238
CollectorStream requireNoThrow(Expression &&expr, std::string name="")
Requires that the expression doesn't throw.
Definition: testsuite.hh:202
int exit() const
Exit the test.
Definition: testsuite.hh:263