Boost logo

Boost Users :

From: daniel.hawson_at_[hidden]
Date: 2007-01-29 06:40:39


I'd encountered a problem with a particular way I'd set up a test application where some
BOOST_AUTO_TEST_CASE functions would be executed while others wouldn't. I suspect this
may be Visual Studio (2005) specific.
I've got a work-around, which I thought might help others in the same situation.

The scenario is this -
Main test application: testapp.cpp -
 #define BOOST_AUTO_TEST_MAIN "TestApp for some Lib"
 #include <boost/test/auto_unit_test.hpp>
 
 BOOST_AUTO_TEST_CASE(IGetExecutedByTestFramework)
 {
   BOOST_CHECK(false);
 }

External library, containing: somemodule_tests.cpp -
 #include "somemodule.h"
 #include <boost/test/auto_unit_test.hpp>
 
 //Test functionality provided by somemodule.h
 //...
 
 BOOST_AUTO_TEST_CASE(IDontGetExecuted)
 {
   BOOST_CHECK(false);
 }

My Visual Studio solution contains two projects -
 - mylibtestapp: A console executable to run all test cases in mylib
   Contains only testapp.cpp
 - mylib: A statically linked lib containing a bunch of .cpp/.h
files and, so far, just one ..._tests.cpp file.

The solution is set up so that mylibtestapp depends on mylib. It
also explicitly links with the boost 'unit_test_framework.lib'.
It compiles and links fine.
When running, only the 'IGetExecutedByTestFramework' gets executed.
I manually expanded the BOOST_AUTO_TEST_CASE macro for
'IDontGetExecuted' and the debugger wouldn't step into any of the
test registrar object constructor code, so I assume the linker
decided to strip out the code for some reason.
As soon as I added the following to somemodule_tests.cpp -
 int g_fiddle;
and change testapp.cpp to 'extern int g_fiddle;' and manually insert
the 'init_unit_test_suite(int argc, char* argv[])' with some trivial
use of 'g_fiddle' (using it in a printf), then both test cases get
executed.

After poking around with the linker options little further, I've
found that all unit tests will run as originally intended, without
having to use any extern frigs, so long as the mylibtestapp's
'Configuration Properties'>Linker>General>'Use Library Dependency
Inputs' is set to 'Yes'. The difference being that the linker
command-line now contains mylib.lib instead of the individual .o
files of mylib.

Weird.

-- 
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.12/655 - Release Date: 28/01/2007 13:12

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net