prune_config_t.cc
Go to the documentation of this file.
1 // vim: set sw=2 expandtab :
2 #define BOOST_TEST_MODULE (prune_config test)
3 #include "boost/test/unit_test.hpp"
4 
8 #include "fhiclcpp/parse.h"
9 
10 #include <string>
11 
12 using namespace std;
13 using namespace art;
14 
15 namespace {
16  void
17  check_configuration(std::string const& config) noexcept(false)
18  {
19  auto raw_config = fhicl::parse_document(config);
20  detail::prune_config_if_enabled(false, true, raw_config);
21  }
22 
23  void
24  check_exception(std::string const& config, std::string const& error_msg)
25  {
26  BOOST_CHECK_EXCEPTION(
27  check_configuration(config), art::Exception, [&error_msg](auto const& e) {
28  return e.categoryCode() == art::errors::Configuration &&
29  e.what() == error_msg;
30  });
31  }
32 }
33 
34 BOOST_AUTO_TEST_SUITE(prune_config_t)
35 
36 BOOST_AUTO_TEST_CASE(empty_config)
37 {
38  check_configuration({});
39 }
40 
41 BOOST_AUTO_TEST_CASE(duplicate_label)
42 {
43  std::string const config{"process_name: \"test\" "
44  "physics: { "
45  " analyzers: { "
46  " p: { module_type: PMTestAnalyzer } "
47  " } "
48  " filters: { "
49  " p: { module_type: PMTestFilter } "
50  " } "
51  " p1: [ p ] "
52  "}"};
53  std::string const err_msg{
54  "---- Configuration BEGIN\n"
55  " An error occurred while processing module configurations.\n"
56  " Module label 'p' has been used in 'physics.analyzers' and "
57  "'physics.filters'.\n"
58  " Module labels must be unique across an art process.\n"
59  "---- Configuration END\n"};
60  check_exception(config, err_msg);
61 }
62 
63 BOOST_AUTO_TEST_CASE(inhomogeneous_path)
64 {
65  std::string const config{"process_name: \"test\" "
66  "physics: { "
67  " analyzers: { "
68  " a: { module_type: PMTestAnalyzer } "
69  " } "
70  " filters: { "
71  " f: { module_type: PMTestFilter } "
72  " } "
73  " producers: { "
74  " p: { module_type: PMTestProducer } "
75  " } "
76  " p1: [ f, p, a ] "
77  "}"};
78  std::string const err_msg{
79  "---- Configuration BEGIN\n"
80  " An error occurred while processing a path configuration.\n"
81  " The following modules specified in path p1 are observers when all\n"
82  " other modules are modifiers:\n"
83  " 'a'\n"
84  "---- Configuration END\n"};
85  check_exception(config, err_msg);
86 }
87 
88 BOOST_AUTO_TEST_CASE(nonexistent_path_1)
89 {
90  std::string const config{"physics.trigger_paths: [x1]"};
91  std::string const err_msg{
92  "---- Configuration BEGIN\n"
93  " The following error occurred while processing path configurations:\n"
94  " Unknown path x1 has been specified in 'trigger_paths'.\n"
95  "---- Configuration END\n"};
96  check_exception(config, err_msg);
97 }
98 
99 BOOST_AUTO_TEST_CASE(nonexistent_path_2)
100 {
101  std::string const config{"physics.end_paths: [x1, d6]"};
102  std::string const err_msg{
103  "---- Configuration BEGIN\n"
104  " The following error occurred while processing path configurations:\n"
105  " Unknown path x1 has been specified in 'end_paths'.\n"
106  " Unknown path d6 has been specified in 'end_paths'.\n"
107  "---- Configuration END\n"};
108  check_exception(config, err_msg);
109 }
110 
111 BOOST_AUTO_TEST_CASE(unconfigured_label)
112 {
113  std::string const config{"process_name: \"test\" "
114  "physics: { "
115  " p1: [ \"-f\", p, a ] "
116  "}"};
117  std::string const err_msg{
118  "---- Configuration BEGIN\n"
119  " The following error occurred while processing a path "
120  "configuration:\n"
121  " Entry with name f in path p1 does not have a module configuration.\n"
122  "---- Configuration END\n"};
123  check_exception(config, err_msg);
124 }
125 
126 BOOST_AUTO_TEST_CASE(illegal_label)
127 {
128  std::string const config{"process_name: \"test\" "
129  "physics: {"
130  " p1: [ \"!f-g\" ]"
131  "}"};
132  std::string const err_msg{
133  "---- Configuration BEGIN\n"
134  " There was an error parsing the entry \"!f-g\"in a FHiCL sequence.\n"
135  " The '!' or '-' character may appear as only the first character in the "
136  "path entry.\n"
137  "---- Configuration END\n"};
138  check_exception(config, err_msg);
139 }
140 
141 BOOST_AUTO_TEST_CASE(illegal_action_for_non_filter)
142 {
143  std::string const config{"process_name: \"test\" "
144  "physics: {"
145  " producers: { p: {} }"
146  " p1: [ \"!p\" ]"
147  "}"};
148  std::string const err_msg{"---- Configuration BEGIN\n"
149  " The following error occurred while "
150  "processing a path configuration:\n"
151  " Entry with name p in path p1 is a producer and "
152  "cannot have a '!' or '-' prefix.\n"
153  "---- Configuration END\n"};
154  check_exception(config, err_msg);
155 }
156 
157 BOOST_AUTO_TEST_CASE(unconfigured_label_with_trigger_paths)
158 {
159  std::string const config{"process_name: \"test\" "
160  "physics: { "
161  " p1: [ f ] "
162  " trigger_paths: [ p1 ] "
163  "}"};
164  std::string const err_msg{
165  "---- Configuration BEGIN\n"
166  " The following error occurred while processing a path "
167  "configuration:\n"
168  " Entry with name f in path p1 does not have a module configuration.\n"
169  "---- Configuration END\n"};
170  check_exception(config, err_msg);
171 }
172 
173 BOOST_AUTO_TEST_CASE(misspecified_end_path)
174 {
175  // Incorrectly included end path as trigger path
176  std::string const config{"process_name: MisspecifiedEndPath\n"
177  "physics.analyzers.a1: {\n"
178  " module_type: DummyAnalyzer\n"
179  "}\n"
180  "physics.e1: [a1]\n"
181  "physics.trigger_paths: [e1]\n"};
182  std::string const err_msg{
183  "---- Configuration BEGIN\n"
184  " The following error occurred while processing a path "
185  "configuration:\n"
186  " The 'trigger_paths' override parameter contains the path e1, which has "
187  "an\n"
188  " analyzer with the name a1.\n"
189  " \n"
190  " Path e1 should instead be included as part of the 'end_paths' "
191  "parameter.\n"
192  " Contact artists@fnal.gov for guidance.\n"
193  "---- Configuration END\n"};
194  check_exception(config, err_msg);
195 }
196 
197 BOOST_AUTO_TEST_CASE(misspecified_trigger_path)
198 {
199  // Incorrectly included trigger path as end path
200  std::string const config{"process_name: MisspecifiedTriggerPath\n"
201  "physics.producers.d1: {\n"
202  " module_type: DummyProducer\n"
203  "}\n"
204  "physics.p1: [d1]\n"
205  "physics.end_paths: [p1]\n"};
206  std::string const err_msg{
207  "---- Configuration BEGIN\n"
208  " The following error occurred while processing a path "
209  "configuration:\n"
210  " The 'end_paths' override parameter contains the path p1, which has a\n"
211  " producer with the name d1.\n"
212  " \n"
213  " Path p1 should instead be included as part of the 'trigger_paths' "
214  "parameter.\n"
215  " Contact artists@fnal.gov for guidance.\n"
216  "---- Configuration END\n"};
217  check_exception(config, err_msg);
218 }
219 
220 BOOST_AUTO_TEST_CASE(unsupported_physics_parameters)
221 {
222  // Incorrectly included parameter in "physics" block
223  std::string const config{"process_name: pathMisspecification "
224  "physics: { "
225  " producers : {} "
226  " filters : {} "
227  " analyzers : {} "
228  " test : atom "
229  " check : { "
230  " cannot : put "
231  " random : table } }"};
232  std::string const err_msg{
233  "---- Configuration BEGIN\n"
234  " \n"
235  " You have specified the following unsupported parameters in the\n"
236  " \"physics\" block of your configuration:\n"
237  " \n"
238  " \"physics.check\" (table)\n"
239  " \"physics.test\" (atom)\n"
240  " \n"
241  " Supported parameters include the following tables:\n"
242  " \"physics.producers\"\n"
243  " \"physics.filters\"\n"
244  " \"physics.analyzers\"\n"
245  " and sequences. Atomic configuration parameters are not allowed.\n"
246  " \n"
247  "---- Configuration END\n"};
248  check_exception(config, err_msg);
249 }
250 BOOST_AUTO_TEST_SUITE_END()
std::string string
Definition: nybbler.cc:12
STL namespace.
EnabledModules prune_config_if_enabled(bool prune_config, bool report_enabled, fhicl::intermediate_table &config)
const double e
static Config * config
Definition: config.cpp:1054
BOOST_AUTO_TEST_CASE(empty_config)
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