Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement exception expectation #4

Open
zhangsu opened this issue Oct 18, 2015 · 1 comment
Open

Implement exception expectation #4

zhangsu opened this issue Oct 18, 2015 · 1 comment

Comments

@zhangsu
Copy link
Owner

zhangsu commented Oct 18, 2015

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]

@zhangsu
Copy link
Owner Author

zhangsu commented Oct 18, 2015

Assigning to @r2ysxu

@zhangsu zhangsu assigned zhangsu and unassigned zhangsu Oct 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant