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-26 18:36:41
#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 Raffi Enficiaud):
Hi Olaf,
Thank you for your precise reply. The keys for adapting those developments
to your problem are:
* you should instanciate a dataset, otherwise it gets ... instanciated at
in the global scope we do not have access to the `master_test_suite`
`argc` and `argv`. This is what happens with your `foo_dataset`
* to ensure that the returned elements are all consistent, you can play
with the arity of the dataset. So instead of creating 2/3 as you do, you
just create one that returns tuples. Those tuples will get expanded
automatically.
* the zip size constraint is happening at the access to the dataset. If
this is constructed lazylly as in the branch, this access is delayed.
Here is an adaptation of your problem to the new code:
{{{
class dataset_loader_arity3
{
public:
typedef std::vector<std::string> data_type;
data_type m_expected;
data_type m_input;
typedef std::string sample;
enum { arity = 3 };
public:
dataset_loader_arity3(std::string some_additional) :
m_some_additional(some_additional)
{
int argc = boost::unit_test::framework::master_test_suite().argc;
char** argv = boost::unit_test::framework::master_test_suite().argv;
for(unsigned i = 1; i != argc; i++) {
std::string current(argv[i]);
std::cout << "current " << current << std::endl;
if(current.find("--param1") != std::string::npos) {
m_expected.push_back(current);
}
else {
m_input.push_back(current);
}
}
}
struct iterator {
iterator(
data_type::const_iterator v_expected,
data_type::const_iterator v_input,
std::string additional)
: m_input(v_input)
, m_expected(v_expected)
, m_additional(additional)
{}
// bug in joins, see 13380. We should return a non temporary
std::tuple<std::string, std::string, std::string> operator*()
const {
return std::tuple<std::string, std::string,
std::string>(*m_input, *m_expected, *m_input + " -" + m_additional + "- "
+ *m_expected);
}
void operator++()
{
++m_input;
++m_expected;
}
private:
data_type::const_iterator m_input, m_expected;
std::string m_additional;
};
boost::unit_test::data::size_t size() const {
return m_input.size();
}
// iterator
iterator begin() const { return iterator(m_expected.begin(),
m_input.begin(), m_some_additional); }
private:
std::string m_some_additional;
};
namespace boost { namespace unit_test { namespace data {
namespace monomorphic {
template <>
struct is_dataset<dataset_loader_arity3> : boost::mpl::true_ {};
}
} } }
BOOST_DATA_TEST_CASE(master_access_make_ds_with_arity,
boost::unit_test::data::make_delayed<dataset_loader_arity3>(
"something-in-the-middle"),
input, expected, additional)
{
std::cout << "input: " << input << " -- expected: " << expected << "
-- additional: " << additional << std::endl;
BOOST_TEST(true);
}
}}}
You can see in `master_access_make_ds_with_arity` that 3 variables are
given to the test case. I construct 2 of them from the command line, and
the third is created on the fly. This last one depends on a static/global
variable in the example, that is passed to the `ctor` of the dataset when
needed.
All the magic is happening in the `iterator` of the dataset. I think this
example is relatively close to yours. Let me know if you have any further
question, but I think on my side, the ticket is more or less addressed :)
Best,
Raffi
-- Ticket URL: <https://svn.boost.org/trac10/ticket/12953#comment:11> 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-26 18:43:23 UTC