-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Labels
Description
We'd like to have the ability to expect the throwing of an C++ exception in CCSpec tests. We'd also like to reuse the usual expect(...).to(...) syntax:
expect([] { throw 32; }).to(throw_exception<int>());
expect([] { throw "It's dead, Jim!"; }).to(throw_exception<const char *>());
expect([] {
std::function<int(int,int)> bar;
bar();
}).to(throwException<std::bad_function_call>());
expect([] { 1 + 1 }).notTo(throw_exception<std::bad_function_call>());So we'd need a new special matcher class ThrowException that copes with exceptions. Its friend constructor would be throw_exception. The constructor takes a template argument as the type of exception to match. For now the constructor can be nullary (later on it can also take a message to match std::exception::what()).
For now, if the matcher expects an exception but no exception is thrown, the error message can be:
[function object] should throw [Exception name]
OR
[function object] should not throw [Exception name]