forked from Alepha/Alepha
Basic support for exception verification in tests
This probably needs to be expanded upon. The basic functionality added is to permit a test expectation clause to be a function which takes some kind of exception type. That function can then perform any arbitrary checks and analyses it needs to confirm that the exception which was caught passes muster for that test case.
This commit is contained in:
@ -53,6 +53,12 @@ namespace
|
||||
struct DerivedError : std::runtime_error
|
||||
{
|
||||
using std::runtime_error::runtime_error;
|
||||
|
||||
std::optional< int > value_;
|
||||
|
||||
explicit DerivedError( const std::string &s, int value_ ) : std::runtime_error{ s }, value_( value_ ) {}
|
||||
|
||||
int value() const { return value_.value(); }
|
||||
};
|
||||
|
||||
"Can we use Aggregates with universal cases, correctly?"_test <=
|
||||
@ -60,7 +66,7 @@ namespace
|
||||
<
|
||||
[]( const int x )
|
||||
{
|
||||
if( x < 0 ) throw DerivedError{ "Cannot be negative." };
|
||||
if( x < 0 ) throw DerivedError{ "Cannot be negative.", x };
|
||||
return Aggregate{ x, x, x };
|
||||
}
|
||||
>
|
||||
@ -73,6 +79,11 @@ namespace
|
||||
{ "Expect exception type exception", { -42 }, std::type_identity< std::exception >{} },
|
||||
{ "Expect exception value specific", { -42 }, DerivedError{ "Cannot be negative." } },
|
||||
{ "Expect exception value specific (loose)", { -42 }, std::runtime_error{ "Cannot be negative." } },
|
||||
{ "Expect exception value specific (loose)", { -42 },
|
||||
[]( const DerivedError &e )
|
||||
{
|
||||
return e.value() == -42;
|
||||
} },
|
||||
|
||||
/* These cases should fail, but we don't want to fail them in normal builds. */
|
||||
/* A few different ways of disabling these tests are shown below. */
|
||||
|
||||
Reference in New Issue
Block a user