1

I'm using Catch to write unit tests and came across a problem where my test fails because an exception is thrown, even though I use REQUIRE_THROWS_AS. This is my test:

SECTION("Get column index for inexistent name") {
    REQUIRE_THROWS_AS(result->column_index("inexistent"), std::out_of_range);
}

And this is the exception I get on my console:

$ tests/unit_tests "Test Result"
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: Name not found.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
unit_tests is a Catch v1.5.8 host application.
Run with -? for options

-------------------------------------------------------------------------------
Test Result
  Query empty table
  Get column index for inexistent name
-------------------------------------------------------------------------------
<path to file>:22
...............................................................................

<path to file>:46: FAILED:
due to a fatal error condition:
  SIGABRT - Abort (abnormal termination) signal

===============================================================================
test cases: 1 | 1 failed
assertions: 8 | 7 passed | 1 failed

If I understand Catch this exception is exactly what I'm trying to catch right?

ruipacheco
  • 15,025
  • 19
  • 82
  • 138
  • I don't know Catch, it looks like the exception is throws before `REQUIRE_THROWS_AS` gets a chance to do anything. You probably need something like `REQUIRE_THROWS_AS(result->column_index, "inexistent", std::out_of_range);` so `REQUIRE_THROWS_AS` has a chance to make a try-catch block for you. – nwp Jan 12 '17 at 11:30
  • Have you tried stepping through the test? As nwp said, it would prove if your exception is thrown where you think it's thrown – UKMonkey Jan 12 '17 at 11:33
  • 1
    It seems you caught exception not at the pointed place, Try temporary replace macro with try{}catch(){}catch(...){} and debug it. – Alex P. Jan 13 '17 at 09:56
  • `REQUIRE_THROWS_AS` should works because [one had opposite problem](http://stackoverflow.com/questions/35757334/catch-unit-testing-framework-require-throws-as) – Alex P. Jan 13 '17 at 10:04
  • And Don't use C++ exceptions across DLL boundaries. It also could be the reason. – Alex P. Jan 13 '17 at 10:17
  • Please use a debugger to pinpoint the source of the abort() and then we can give more help. – JBRWilkinson Jan 15 '17 at 23:37

1 Answers1

0

make clean solved the problem.

ruipacheco
  • 15,025
  • 19
  • 82
  • 138