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, assert fine, can't test unit-test, because undefined behavior is, well, undefined.

  • defined behavior. should consistent regardless of ndebug presence. , throwing exception, in opinion, right thing here, instead of calling std::abort, useless user (can't intercepted , processed properly).


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -