Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12953: access to master_test_suite().{argc, argv}
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2018-06-23 06:14:19
#12953: access to master_test_suite().{argc, argv}
-------------------------------+-----------------------------
Reporter: ope-devel@⦠| Owner: Raffi Enficiaud
Type: Feature Requests | Status: assigned
Milestone: Boost 1.66.0 | Component: test
Version: Boost 1.63.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+-----------------------------
Comment (by ope.devel@â¦):
Hi Raffi,
sorry for the later answer, I lost over the time this thread :-( Thanks
for investigation but I assume it doesn't work yet (or I mis omething)
$ bin/bt_dataset_args -- test
ArgCount = 0
Mock ArgCount = 0
Running 1 test case...
Unfortuately I don't see something to add an attachement here, therefore I
embedd my test code. The '--' comment line separate different translation
units, if it matters. The loader is re-used several time for completly
different tests.
Thanks,
Olaf
{{{
//------------------------------------------------------------------------------
#define BOOST_TEST_MODULE "Cool Parser Test Suite"
#include <boost/test/included/unit_test.hpp>
//------------------------------------------------------------------------------
#include <boost/test/data/test_case.hpp>
#include <boost/filesystem/fstream.hpp>
#include <iostream>
namespace testsuite {
namespace fs = boost::filesystem;
struct app_mock
{
int const argc;
char** const argv;
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;
}
class dataset_loader
{
public:
typedef std::vector<fs::path> pathname_type;
typedef std::vector<std::string> data_type;
public:
pathname_type const& test_case_name() const { return m_test_case; }
data_type const& input() const { return m_input; }
data_type const& expect() const { return m_expected; }
public:
dataset_loader(fs::path const& path);
private:
void read_files(fs::path const& path);
private:
pathname_type m_test_case;
data_type m_input;
data_type m_expected;
std::string input_extension;
std::string
expected_extension;
};
} // namespace testsuite
namespace testsuite {
dataset_loader::dataset_loader(fs::path const& path)
: input_extension{".input" }
, expected_extension{ ".expected" }
{
BOOST_TEST_INFO("dataset_loader load test files from " << path);
auto const
argc{boost::unit_test::framework::master_test_suite().argc};
auto const
argv{boost::unit_test::framework::master_test_suite().argv};
std::cout << "ArgCount = " << argc << '\n';
for(unsigned i = 0; i != argc; i++) {
std::cout << "ArgValue = " << argv[i] << '\n';
}
app_mock m;
std::cout << "Mock ArgCount = " << m.argc << '\n';
for(int i = 0; i != m.argc; i++) {
std::cout << "Mock ArgValue = " << m.argv[i] << '\n';
}
read_files(path);
}
void dataset_loader::read_files(fs::path const& path)
{
// real code suppressed, cmd line args for load prefix and extensions
required
BOOST_TEST_INFO("read files " << path << input_extension);
}
} // namespace testsuite
//------------------------------------------------------------------------------
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE( concrete_testsuite )
using ::boost::unit_test::data::monomorphic::operator^;
struct concrete_dataset : public testsuite::dataset_loader
{
concrete_dataset()
: dataset_loader{ "test_case/number_42" }
{ }
} const concrete_dataset;
BOOST_DATA_TEST_CASE(cool_test,
concrete_dataset.input() ^ concrete_dataset.expect(),
input, expect)
{
// ...
BOOST_TEST(input == expect);
}
BOOST_AUTO_TEST_SUITE_END()
}}}
-- Ticket URL: <https://svn.boost.org/trac10/ticket/12953#comment:6> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2018-06-23 06:18:48 UTC