1 #define BOOST_TEST_MODULE (fhicl - get test) 3 #include "boost/test/unit_test.hpp" 7 #include <initializer_list> 15 class redirect_streams {
19 std::cout.rdbuf(oldstdout_);
20 std::cerr.rdbuf(oldstderr_);
35 std::stringstream stdout_{};
36 std::stringstream stderr_{};
37 std::streambuf* oldstdout_{std::cout.rdbuf(stdout_.rdbuf())};
38 std::streambuf* oldstderr_{std::cerr.rdbuf(stderr_.rdbuf())};
42 run(std::vector<char const*>
args)
44 args.insert(
begin(args),
"fhicl-get");
45 redirect_streams sentry{};
47 return make_tuple(
rc, sentry.stdout(), sentry.stderr());
51 BOOST_AUTO_TEST_SUITE(fhicl_get_test)
58 BOOST_TEST(
stderr.find(
"Missing input configuration file.") !=
66 BOOST_TEST(stdout.find(
"Usage: fhicl-get [options] [key] <file>") !=
74 run({
"--atom-as",
"string",
"fhicl-get-t.fcl"});
76 BOOST_TEST(stdout ==
"");
79 "A key must be specified unless the '--names-in' option is used.") !=
86 run({
"--atom-as",
"string",
"a.billy",
"fhicl-get-t.fcl"});
88 BOOST_TEST(stdout ==
"the kid\n");
95 run({
"--atom-as",
"double",
"c",
"fhicl-get-t.fcl"});
97 BOOST_TEST(stdout ==
"1.25\n");
104 run({
"--atom-as",
"int",
"d",
"fhicl-get-t.fcl"});
106 BOOST_TEST(stdout ==
"42\n");
113 run({
"--atom-as",
"bool",
"e",
"fhicl-get-t.fcl"});
115 BOOST_TEST(stdout ==
"0\n");
122 run({
"--sequence-of",
"int",
"f",
"fhicl-get-t.fcl"});
124 BOOST_TEST(stdout ==
"1\n3\n");
131 run({
"--atom-as",
"float",
"e",
"fhicl-get-t.fcl"});
133 BOOST_TEST(stdout ==
"");
134 BOOST_TEST(
stderr.find(
"The specified type 'float' is not supported") !=
142 BOOST_TEST(stdout ==
"a\nb\nc\nd\ne\nf\n");
150 BOOST_TEST(stdout ==
"billy\n");
158 BOOST_TEST(stdout ==
"");
165 run({
"--names-in",
"g.h",
"fhicl-get-t.fcl"});
167 BOOST_TEST(stdout ==
"");
170 "A parameter with the fully-qualified key 'g.h' does not exist.") !=
177 run({
"--names-in",
"g.h",
"--allow-missing",
"fhicl-get-t.fcl"});
179 BOOST_TEST(stdout ==
"");
186 run({
"--names-in",
"c",
"--allow-missing",
"fhicl-get-t.fcl"});
188 BOOST_TEST(stdout ==
"");
190 stderr.find(
"The parameter named 'c' does not have a table value.") !=
194 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(no_arguments)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
int fhicl_get_impl(int argc, char **argv)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.