[Boost.Test] access to boost::unit_test::framework::master_test_suite().{argc, argv} outside from BOOST_TEST
Hello, my test program uses boost.test datasets. I've wrote a filesystem loader for the input and expected data. Now I run into the problem, that boost::unit_test::framework::master_test_suite().{argc, argv} is only setup inside the tests self. My loader isn't a test case ... I can check it by using a simple mock, like struct app_mock { app_mock(); int const argc; char** const argv; }; app_mock::app_mock() : argc(boost::unit_test::framework::master_test_suite().argc) , argv(boost::unit_test::framework::master_test_suite().argv) { } BOOST_AUTO_TEST_CASE( app_mocker ) { app_mock app; std::cout << "Count = " << app.argc << '\n'; for(int i = 0; i != app.argc; i++) std::cout << "Arg = " << app.argv[i] << '\n'; } $ my_test -- my_args Count = 2 path/to/exe my_args these works, but as mentioned: dataset_loader::dataset_loader(fs::path const& path) { app_mock app; std::cout << "ARGC = " << boost::unit_test::framework::master_test_suite().argc << '\n'; read_files(path); } is always zero. How can I read the argc/argv values? Thanks, Olaf
my test program uses boost.test datasets. I've wrote a filesystem loader for the input and expected data. Now I run into the problem, that boost::unit_test::framework::master_test_suite().{argc, argv} is only setup inside the tests self. My loader isn't a test case ... I can check it by using a simple mock, like
struct app_mock { app_mock();
int const argc; char** const argv; };
app_mock::app_mock() : argc(boost::unit_test::framework::master_test_suite().argc) , argv(boost::unit_test::framework::master_test_suite().argv) { }
BOOST_AUTO_TEST_CASE( app_mocker ) { app_mock app; std::cout << "Count = " << app.argc << '\n'; for(int i = 0; i != app.argc; i++) std::cout << "Arg = " << app.argv[i] << '\n'; } BOOST_GLOBAL_FIXTURE(app_mock);
also important here.
$ my_test -- my_args
Count = 2
path/to/exe
my_args
these works, but as mentioned:
dataset_loader::dataset_loader(fs::path const& path) { app_mock app;
std::cout << "ARGC = " << boost::unit_test::framework::master_test_suite().argc << '\n'; read_files(path); }
is always zero.
How can I read the argc/argv values?
Thanks,
Olaf
Le 31/03/2017 à 21:22, Olaf Peter via Boost a écrit :
Hello,
my test program uses boost.test datasets. I've wrote a filesystem loader for the input and expected data. Now I run into the problem, that boost::unit_test::framework::master_test_suite().{argc, argv} is only setup inside the tests self. My loader isn't a test case ... I can check it by using a simple mock, like
struct app_mock { app_mock();
int const argc; char** const argv; };
app_mock::app_mock() : argc(boost::unit_test::framework::master_test_suite().argc) , argv(boost::unit_test::framework::master_test_suite().argv) { }
BOOST_AUTO_TEST_CASE( app_mocker ) { app_mock app; std::cout << "Count = " << app.argc << '\n'; for(int i = 0; i != app.argc; i++) std::cout << "Arg = " << app.argv[i] << '\n'; }
$ my_test -- my_args
Count = 2
path/to/exe
my_args
these works, but as mentioned:
dataset_loader::dataset_loader(fs::path const& path) { app_mock app;
std::cout << "ARGC = " << boost::unit_test::framework::master_test_suite().argc << '\n'; read_files(path); }
is always zero.
How can I read the argc/argv values?
Thanks,
Olaf
The datasets are creating static objects on file scope, that generate the definition of the unit tests. I believe you can achieve what you want here by loading the data from a suite fixture associated to the dataset test case. Otherwise, bring the topic to a trac issue. Thanks, Raffi
Hello Raffi,
my test program uses boost.test datasets. I've wrote a filesystem loader for the input and expected data. Now I run into the problem, that boost::unit_test::framework::master_test_suite().{argc, argv} is only setup inside the tests self. My loader isn't a test case ... I can check it by using a simple mock, like
struct app_mock { app_mock();
int const argc; char** const argv; };
app_mock::app_mock() : argc(boost::unit_test::framework::master_test_suite().argc) , argv(boost::unit_test::framework::master_test_suite().argv) { }
BOOST_AUTO_TEST_CASE( app_mocker ) { app_mock app; std::cout << "Count = " << app.argc << '\n'; for(int i = 0; i != app.argc; i++) std::cout << "Arg = " << app.argv[i] << '\n'; }
$ my_test -- my_args
Count = 2
path/to/exe
my_args
these works, but as mentioned:
dataset_loader::dataset_loader(fs::path const& path) { app_mock app;
std::cout << "ARGC = " << boost::unit_test::framework::master_test_suite().argc << '\n'; read_files(path); }
is always zero.
How can I read the argc/argv values?
Thanks,
Olaf
The datasets are creating static objects on file scope, that generate the definition of the unit tests.
I believe you can achieve what you want here by loading the data from a suite fixture associated to the dataset test case. Otherwise, bring the topic to a trac issue.
As far I can see, it can't work, since how can I pass arguments to the constructor? My use case is ::x3_test::dataset_loader foo_dataset{ "test/foo" }; BOOST_DATA_TEST_CASE(foo, foo_dataset.input() ^ foo_dataset.expect() ^ foo_dataset.test_file_name(), input, expected, file) { ... } where a lot of datasets are required with different paths to the test files. Otherwise a simple: struct foo_dataset : public ::dataset_loader { foo_dataset() : dataset_loader { "test/foo" } { } }; BOOST_DATA_TEST_CASE_F( foo_dataset, foo_test_case, foo_dataset.input() ^ foo_dataset.expect() ^ foo_dataset.test_file_name(), input, expected, file) { ... } doesn't compile: error: 'foo_test_case' has not been declared. Thanks, Olaf
Am 04.04.2017 um 20:34 schrieb Olaf Peter via Boost:
Hello Raffi,
my test program uses boost.test datasets. I've wrote a filesystem loader for the input and expected data. Now I run into the problem, that boost::unit_test::framework::master_test_suite().{argc, argv} is only setup inside the tests self. My loader isn't a test case ... I can check it by using a simple mock, like
struct app_mock { app_mock();
int const argc; char** const argv; };
app_mock::app_mock() : argc(boost::unit_test::framework::master_test_suite().argc) , argv(boost::unit_test::framework::master_test_suite().argv) { }
BOOST_AUTO_TEST_CASE( app_mocker ) { app_mock app; std::cout << "Count = " << app.argc << '\n'; for(int i = 0; i != app.argc; i++) std::cout << "Arg = " << app.argv[i] << '\n'; }
$ my_test -- my_args
Count = 2
path/to/exe
my_args
these works, but as mentioned:
dataset_loader::dataset_loader(fs::path const& path) { app_mock app;
std::cout << "ARGC = " << boost::unit_test::framework::master_test_suite().argc << '\n'; read_files(path); }
is always zero.
How can I read the argc/argv values?
Thanks,
Olaf
The datasets are creating static objects on file scope, that generate the definition of the unit tests.
I believe you can achieve what you want here by loading the data from a suite fixture associated to the dataset test case. Otherwise, bring the topic to a trac issue.
As far I can see, it can't work, since how can I pass arguments to the constructor? My use case is [...]
I like to come back to this problem. Following the docs I can provide an own main(), as described at http://www.boost.org/doc/libs/1_64_0/libs/test/doc/html/boost_test/adv_scena.... Here I can hijack argc/argv and use it accessible somewhere statically. But, how to get the BTU specific argc/argv pruned arguments? Thanks, Olaf
participants (2)
-
Olaf Peter
-
Raffi Enficiaud