TEST( "MyTestGroup", "MyTest" )
BEGINTEST
{
//test body
}
ENDTEST
Perhaps not ideal, but it works.
As for segfaults, you could probably install a signal handler which could then
report failure to gtest, but I haven't tried this.
It's tracked by
http://code.google.com/p/googletest/issues/detail?id=313, which I just
created.
The issue depends on
http://code.google.com/p/googletest/issues/detail?id=44 and
http://code.google.com/p/googletest/issues/detail?id=312. The former
has just been fixed in the trunk, and Vlad will be working on the
latter soon.
> Is that correct? Do you know when that will make it to a release
> version?
You can check out the latest revision from the SVN trunk. It's rather
stable. The next release will probably be one month away -- that's
just my best guess.
> Will it do anything to handle segfaults rather than just
> aborting everything?
No, it doesn't try to handle segfaults. Only C++ exceptions and SEH exceptions.
>
> Thanks for the help; I'm rather new to Google Test and unit testing in
> C++, so forgive me if I've overlooked something obvious.
>
> - Daniel
>
--
Zhanyong
Yes. Try derive your exception class from std::exception.
> Right now it just prints: 'Unknown C
> ++ exception thrown in the test body.'. I basically just want it to
> print the name of the function and whatever what() returns.
>
>> As for segfaults, you could probably install a signal handler which could then
>> report failure to gtest, but I haven't tried this.
>
> Would this be the best approach?
I don't worry much about segfaults. They will cause the test to fail.
It's not ideal that they abort the test, but that just means you have
to fix the test crash before you can see the result of the rest of the
test methods, or you can use --gtest_filter to exclude the crashing
test method. If you run into crashes a lot, you probably want to
rewrite your tests to crash less often.
> Are there any plans to make Google
> Test handle segfaults? What about reasons for doing or not doing so?
No, we don't plan to.
If you don't want to run the test body in a child process, it's
impossible to recover cleanly from a segfault (think about object
destructors that get skipped), so it makes no sense to continue with
other test methods when one test method segfaults. That defeats the
whole purpose of gtest handling segfaults.
If you run the test body in a child process, when it's possible to
recover cleanly. There is a proposed patch to do that exactly.
However, it adds a lot of complexity to gtest, isn't essential, and
has its gotcha too (the same ones as death tests, see the advanced
guide wiki for more info), so I prefer not to accept the patch.
--
Zhanyong
>> As for segfaults, you could probably install a signal handler which could then
>> report failure to gtest, but I haven't tried this.
>
> Would this be the best approach?
I don't worry much about segfaults. They will cause the test to fail.
It's not ideal that they abort the test, but that just means you have
to fix the test crash before you can see the result of the rest of the
test methods, or you can use --gtest_filter to exclude the crashing
test method. If you run into crashes a lot, you probably want to
rewrite your tests to crash less often.
If you run the test body in a child process, when it's possible to
recover cleanly. There is a proposed patch to do that exactly.
However, it adds a lot of complexity to gtest, isn't essential, and
has its gotcha too (the same ones as death tests, see the advanced
guide wiki for more info), so I prefer not to accept the patch.
"Check is a unit testing framework for C. It features a simple
interface for defining unit tests, putting little in the way of the
developer. Tests are run in a separate address space, so Check can
catch both assertion failures and code errors that cause segmentation
faults or other signals."
or "CUnitWin32"
"It has to work in Microsoft Windows... Tests should be independent.
That means global/static variables HAVE to be in a known state. That
means each test has to execute as a separate process."
http://code.google.com/p/cunitwin32/
2010/9/23 Joey Oravec <joeyo...@gmail.com>
--
--
C. Keith Ray
Web: http://industriallogic.com
Twitter: @CKeithRay, @IndustrialLogic
Amplify Your Agility
Coaching | Training | Assessment | eLearning