philsquared/Catch — pull request #160 by formiaczek (2013-04-03 14:14:56+00:00)
Title: added basic signal handling: this allows to see how far did we go in our...

... testing if, eg. the code under test hits a seg-fault.

First of all - thanks for a great test-framework! I find it very useful - both at work and when writing open-source c++ stuff.

I have seen my code hitting a segmentation fault few times, and had to add debug-code to my existing test cases to see what test was invoking the buggy code.

I created a wrapper, that was simply registering signal handler(s), and from this handler I simply printed out some info on what was the last test / check that has executed successfully, and this gives a huge hint on where to look for the fault cause. (please have a look if this is the right thing - perhaps it should be done differently?)

I thought this could be in catch, thus my pull request.

below is my example code, which reveals also a possible bug?. But this (and few other ideas) are probably for other pull requests I guess:)

Cheers,
Lukasz.

test code:

#define CATCH_CONFIG_MAIN
#include

#define REQUIRE_NOT_NULL( expr ) REQUIRE((expr) != (void*)NULL)
#define REQUIRE_NULL( expr ) REQUIRE((expr) == (void*)NULL)

#include

TEST_CASE("my testcase", "should pass")
{
char* ptr1 = NULL;
char* ptr2 = ptr1++;

REQUIRE_NOTHROW(ptr2++);

// these two cause seg-fault (similarly for xxNOT_NULL with ptr2):
// (it worked with previous versions of catch, so it might be a BUG of some sort?)
REQUIRE(ptr1 == NULL);
REQUIRE_NULL(ptr1);

// this one is expected to fail, obviously..
REQUIRE_NOTHROW(ptr2[32] = 'd');
}

and this gives me following info, when executing:

./example_test

=================

Segmentation violation

while executing test: "my testcase"

(last successful check was: "ptr2++"
in: example_test.cpp, line: 26)