Comment #1 on issue 12 by
plaztiks...@gmail.com: information on missing
Here is a sketch for one possible approach: getting the typeinfo at runtime.
It initializes an array of typeinfo (that correlates to the vtable offsets)
with the typeinfo for the mocked class by default. As the mock has
expectations set on specific members, the array is filled in with the more
specific typeinfo. (It "learns" as you program the mock.) I don't know of a
way to fill in the (R)C::*() typeinfo ahead of time, even minimally -- that
would be awesome to figure out.
This simple approach is already a huge leap forward. Now when a mock is
misused, I see this in my test runner output insteead of
just "[std::exception]":
protocol/http/appblade/http_cfe_blade_test.cc:66: Failure:
http_cfe_blade_tests ->
does_not_create_appblade_when_request_parsing_not_done
an exception was thrown during test: [partial_implementation_exception:
bool (Message::*)()]
protocol/http/appblade/http_cfe_blade_test.cc:85: Failure:
http_cfe_blade_tests -> gives_parsed_request_to_appblade_returned_by_manager
an exception was thrown during test: [missing_implementation_exception:
Request]
The top failure is an example of when an expectation is set and the member
information is therefore more detailed. The latter failure is an example of
when an expectation for the mock wasn't set, and is therefore less
detailed. Even with the less detail, I can look at the test and see which
mock supplied to my class's ctor needs additional expectations without a
debugger.
An alternate approach would be to use a macro (like cgreen), which would
allow us just to capture the text for a given member:
#define expect(mock, member) mock.expect(member, #member)
// ...
void test(void) { mock_object<foo> mock_foo; expect(mock_foo,
foo::method).when().thenReturn(); }
macros violate namespaces, but it may be worth it if we can't fill in more
typeinfo ahead of time.
The next step is to have the partial_implementation_exception provide more
information about which argument/constraint failed comparison.
Attachments:
mockitopp.better_exception_info.patch 37.4 KB