// TestRunner.cpp
#define CATCH_CONFIG_RUNNER#include "catch.hpp"
void RunTests(){ Catch::Session session;
session.run();}
// Project1Test.cpp
#include "catch.hpp"
TEST_CASE( "Unit test 1", "[Project1]")
{
// Test case body.
}
// More TEST_CASE definitions...
REQUIRE( false );
prompt>g++ -Wall -I../../Catch/single_include -o main.exe main.cpp TestRunner.cpp Project1Test.cpp && main
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
is a Catch v1.0 b11 host application.
Run with -? for options
-------------------------------------------------------------------------------
Unit test 1
-------------------------------------------------------------------------------
Project1Test.cpp:5
...............................................................................
Project1Test.cpp:8: FAILED:
REQUIRE( false )
===============================================================================
1 test case - failed (1 assertion - failed)
The general conclusion here is: make your life easier - do not write your tests in libraries!
Hi Maxim,
It looks almost certain that you're seeing the "optimised out constructors" issue that the gtest doc references - it's one of the caveats of the auto-registering technique that Catch (and many other test frameworks) employs. I don't believe it's actually a bug, as that doc suggests, but rather just an optimisation that is outside the scope of the standard (as the standard says nothing about libraries). I could be wrong there, though,
As far as I know the touch() method is the only reliable workaround (I've experimented with the dllexport technique in the passed - with varying results - doesn't seem reliable enough to use). I've only ever had to do that once - with an in-house test framework on a project I worked on once where the tests had to be written in the same dll as the code they were testing! - presumably a misguided attempt to give the tests access to internal interfaces).Obviously the best solution is simple to not put the tests in a separate lib (or dll) in the first place (as Martin suggests).
Is there a compelling reason for doing so?
Regards,[)oIhIL..