lundi 29 février 2016

Boost unit test framework: include main function of my codebase

I have a codebase on which I want to perform tests. One of the files of this codebase contains code that I want to test, in addition to the main function of the program.

When I add this file to my CMakeLists, it complains about the inclusion of multiple main functions.

Here's how things look:

RunTest.cpp:

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE Main
#include <boost/test/unit_test.hpp>

MyTest1.cpp:

#define BOOST_TEST_MODULE test_1_module
#define BOOST_TEST_DYNAMIC_LINK
#include <boost/test/unit_test.hpp>
#include <boost/test/parameterized_test.hpp>
#include <boost/test/unit_test_log.hpp>
#include <boost/test/results_collector.hpp>

#include "../MyCode.h"

BOOST_AUTO_TEST_SUITE(test_suite_one)

BOOST_AUTO_TEST_CASE {
...
}

BOOST_AUTO_TEST_SUITE_END()

Here's what my CMakeLists look like:

SET (
    TestRunner

    RunTest.cpp
    MyCode.cpp #contains a main function
)

ADD_EXECUTABLE(TestRunner $TestRunner)

How can I solve this? Is there any way to ask boost to ignore the main function in my codebase?

Aucun commentaire:

Enregistrer un commentaire