path_specs_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (path_specs test)
2 #include "boost/test/unit_test.hpp"
3 
6 #include "fhiclcpp/parse.h"
7 
8 using namespace art;
9 
10 namespace {
11  std::string const trigger_paths{"trigger_paths"};
12 
13  auto
14  path_specs_from(std::string const& spec_str)
15  {
16  auto const table = fhicl::parse_document(spec_str);
17  auto const& sequence = table.find(trigger_paths);
18  auto const path_entries = detail::sequence_to_entries(sequence, true);
19  return detail::path_specs(path_entries, trigger_paths);
20  }
21 
22  auto
23  trigger_path_specs_for(std::string const& sequence_str)
24  {
25  return path_specs_from(trigger_paths + ": " + sequence_str);
26  }
27 
28  auto
29  spec_for(std::string const& name, size_t const i)
30  {
31  return PathSpec{name, PathID{i}};
32  }
33 }
34 
35 BOOST_AUTO_TEST_SUITE(path_specs_t)
36 
37 BOOST_AUTO_TEST_CASE(empty_path_spec)
38 {
39  BOOST_TEST(trigger_path_specs_for("[]").empty());
40 }
41 
43 {
44  auto const path_specs = trigger_path_specs_for("[a]");
45  BOOST_TEST(size(path_specs) == 1ull);
46  BOOST_TEST(path_specs[0] == spec_for("a", 0));
47 }
48 
49 BOOST_AUTO_TEST_CASE(one_entry_with_bit_number)
50 {
51  auto const path_specs = trigger_path_specs_for("['1:a']");
52  BOOST_TEST(size(path_specs) == 1ull);
53  BOOST_TEST(path_specs[0] == spec_for("a", 1));
54 }
55 
56 BOOST_AUTO_TEST_CASE(entries_skipping_bits)
57 {
58  auto const path_specs = trigger_path_specs_for("[a, '2:c', '3:d']");
59  BOOST_TEST(size(path_specs) == 3ull);
60  BOOST_TEST(path_specs[0] == spec_for("a", 0));
61  BOOST_TEST(path_specs[1] == spec_for("c", 2));
62  BOOST_TEST(path_specs[2] == spec_for("d", 3));
63 }
64 
65 BOOST_AUTO_TEST_CASE(entries_skipping_bits_with_nil)
66 {
67  auto const path_specs = path_specs_from("trigger_paths: [a]\n"
68  "trigger_paths[100]: c");
69  BOOST_TEST(size(path_specs) == 2ull);
70  BOOST_TEST(path_specs[0] == spec_for("a", 0));
71  BOOST_TEST(path_specs[1] == spec_for("c", 100));
72 }
73 
74 BOOST_AUTO_TEST_CASE(repeated_path_name)
75 {
76  BOOST_CHECK_EXCEPTION(
77  trigger_path_specs_for("[a, a]"), art::Exception, [](auto const& e) {
78  return e.categoryCode() == art::errors::Configuration and
79  e.explain_self().find("has already been specified in the ") !=
80  std::string::npos;
81  });
82  BOOST_CHECK_EXCEPTION(
83  trigger_path_specs_for("[a, '1:a']"), art::Exception, [](auto const& e) {
84  return e.categoryCode() == art::errors::Configuration and
85  e.explain_self().find(
86  "has already been specified (perhaps implicitly) ") !=
87  std::string::npos;
88  });
89  BOOST_CHECK_EXCEPTION(
90  trigger_path_specs_for("['0:a', '1:a']"),
92  [](auto const& e) {
93  return e.categoryCode() == art::errors::Configuration and
94  e.explain_self().find(
95  "has already been specified (perhaps implicitly) ") !=
96  std::string::npos;
97  });
98  auto const path_specs = trigger_path_specs_for("['1:a', '1:a']");
99  BOOST_CHECK(size(path_specs) == 1ull);
100  BOOST_CHECK(path_specs[0] == spec_for("a", 1));
101 }
102 
103 BOOST_AUTO_TEST_CASE(repeated_path_id)
104 {
105  BOOST_CHECK_EXCEPTION(
106  trigger_path_specs_for("['1:a', 'b']"), art::Exception, [](auto const& e) {
107  return e.categoryCode() == art::errors::Configuration and
108  e.explain_self().find("has already been assigned to path name ") !=
109  std::string::npos;
110  });
111  BOOST_CHECK_EXCEPTION(
112  trigger_path_specs_for("['3:a', '3:b']"),
114  [](auto const& e) {
115  return e.categoryCode() == art::errors::Configuration and
116  e.explain_self().find("has already been assigned to path name ") !=
117  std::string::npos;
118  });
119 }
120 
121 BOOST_AUTO_TEST_SUITE_END()
static QCString name
Definition: declinfo.cpp:673
BOOST_AUTO_TEST_CASE(empty_path_spec)
Definition: path_specs_t.cc:37
std::vector< ModuleSpec > sequence_to_entries(sequence_t const &seq, bool const allow_nil_entries)
std::string string
Definition: nybbler.cc:12
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
const double e
std::vector< PathSpec > path_specs(std::vector< std::string > const &path_spec_strs)
Definition: PathSpec.cc:34
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
Definition: parse.cc:720
std::vector< art::PathSpec > path_specs(std::vector< ModuleSpec > const &selection_override_entries, std::string const &path_selection_override)
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97