Can't use main function witch boost tests

44 views Asked by At

About problem

When I include main function to program where I use BOOST TEST I see this:

error: conflicting declaration of C function ‘int main()’ 10 | int main(void)

I don't know it should work becouse I started learn Boost test a few days ago. If it should work (main with tests) please tell me why it don't work. If it shouldn't work tell me how to connect tests with main functions.

Thanks for your help :)

Code

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

template<typename numOne, typename numTwo>
decltype(auto) addNums(numOne&& num1, numTwo&& num2) noexcept
{
    return num1 + num2;
}

int main(void)
{
    std::cout << addNums(3,4);
}

BOOST_AUTO_TEST_CASE(testOne)
{
    BOOST_CHECK(addNums(3, 3) == 6);
}
1

There are 1 answers

1
sehe On

Boost Test knows several Usage Variants

Some of them allow you to use custom runners, e.g. the entry point. The documentation example from that page shows:

#define BOOST_TEST_MODULE test module name
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp>

// entry point:
int main(int argc, char* argv[], char* envp[])
{
  return boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
}