|
Boost Users : |
From: Jason House (jasonhouse_at_[hidden])
Date: 2006-09-04 21:40:21
Jason House wrote:
> As I currently understand boost.test, it provides its own main function.
> If I want to make a separate executable to run the tests, that seems
> straight forward. But how would I embed the testing inside a normal
> program with a simple command-line switch for running them?
It seems that no matter what I do, I keep getting a linking error with
my latest attempt to get this to work:
/usr/local/lib/libboost_unit_test_framework.so:
undefined reference to `init_unit_test_suite(int, char**)'
I am using boost 1.33.1. Below is what I consider to be the relevant
part of my code that's giving me trouble. Most of it is copy/paste
right out of online examples with only minor customization. What's
really strange is that I get another unrelated link error. If I comment
out my definition of init_unit_test_suite, my link errors reduce (and
init_unit_test_suite is the only undefined symbol). If I comment out
the unit test code completely, the program compiles and links without
problem. I'm really baffled what could be going wrong.
int main(int argc, char **argv){
...
boost::program_options::variables_map vm;
...
if (vm.count("unit_test")){
// code lifted from boost/test/impl/unit_test_main.ipp::main
using namespace boost::unit_test;
try{
int argc_alt = 1; // customized
char* argv_alt[] = {"housebot.exe"}; // customized
framework::init( argc_alt, argv_alt ); // customized
framework::run();
results_reporter::make_report();
return runtime_config::no_result_code()
? boost::exit_success
: results_collector.results(
framework::master_test_suite().p_id ).result_code();
}
catch( std::logic_error const& ex ) {
std::cerr << "Boost.Test internal framework error: "
<< ex.what() << std::endl;
return boost::exit_exception_failure;
}
catch( ... ) {
std::cerr << "Boost.Test internal framework error: unknown reason"
<< std::endl;
return boost::exit_exception_failure;
}
}
...
}
boost::unit_test::test_suite::test_suite* get_connection_test_suite();
boost::unit_test::test_suite::test_suite*
init_unit_test_suite( int, char* [] ) {
boost::unit_test::test_suite::test_suite* test =
get_connection_test_suite();
return test;
}
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