c++ - How to suppress termination in Google test when assert() unexpectedly triggers? -
here it's discussed how catch failing assert, e.g. setup fixture assert() fails , see nice output. need opposite. want test assert() succeeds. in case fails want have nice output. @ point terminates when snags on assert().
#define limit 5 struct obj { int getindex(int index) { assert(index < limit); // stuff; } } obj obj; test(fails_whenoutofrange) { assert_death(obj->getindex(6), ""); } test(succeeds_wheninrange) { obj->getindex(4); } above contrived example. want second test not terminate in case fails, example if set limit 3. after all, assert_death suppresses somehow termination when assert() fails.
the following opinion, seems me either testing wrong thing, or using wrong tool.
assert (c assert()) not verifying input, catching impossible situations. disappear release code, example, can't rely on it.
what should test function specification rather implementation. , should decide, specification invalid input values:
undefined behavior,
assertfine, can't test unit-test, because undefined behavior is, well, undefined.defined behavior. should consistent regardless of
ndebugpresence. , throwing exception, in opinion, right thing here, instead of callingstd::abort, useless user (can't intercepted , processed properly).
Comments
Post a Comment