0

I am getting very frustrated in trying to getting Boost test to use argc and argv. Based on other answers from Stack Overflow, the following code (with Boost 1.67.0) is the closest I've gotten. However, it won't compile, because it expects an extra }. I have put an extra } in various places, and have tried many other things, but I can't for the life of me get this to work. EDIT: the code has balanced {}. I suspect some subtlety having to do with the Boost macros, but I can't tell what it is.

Will someone please tell me specifically what changes to make this code compile and do what it is supposed to do. Right now, I am very highly frustrated.

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

#include <iostream>
#include <vector>
#include <string>

using std::cout;
using std::endl;
using std::vector;
using std::string;

struct F_ArgsFixture {
   F_ArgsFixture()
   : argc(boost::unit_test::framework::master_test_suite().argc),
     argv(boost::unit_test::framework::master_test_suite().argv)
   {
   }

   ~F_ArgsFixture() {}

   int argc;
   char **argv;
};

BOOST_FIXTURE_TEST_SUITE( how_to, F_ArgsFixture )

BOOST_FIXTURE_TEST_CASE( test_name1, F_ArgsFixture )
{
   F_ArgsFixture FF;
   string x = FF.argv[1];
   cout << "1 " << x << endl;
}

BOOST_FIXTURE_TEST_CASE( test_name2, F_ArgsFixture )
{
   F_ArgsFixture FF;
   string x = FF.argv[1];
   cout << "2 " << x << endl;
}
  • FYI, I expanded the documentation about command line handling, should be in boost 1.70. – Raffi Mar 28 '19 at 20:06

1 Answers1

0

As the documentation indicates, the problems with your code are the following:

  • BOOST_FIXTURE_TEST_SUITE declares the fixture for each of the test-case of the suite, so there is no need to call BOOST_FIXTURE_TEST_CASE inside the test-suite, and BOOST_AUTO_TEST_CASE is enough
  • BOOST_FIXTURE_TEST_SUITE starts a new test-suite, and this test suite should be closed by BOOST_AUTO_TEST_SUITE_END()

A version of the code that compiles can be found here

Raffi
  • 3,068
  • 31
  • 33