Macros | Functions
includer_test.cc File Reference
#include "boost/test/unit_test.hpp"
#include "cetlib/filepath_maker.h"
#include "cetlib/includer.h"
#include "cetlib_except/exception.h"
#include <fstream>
#include <iostream>
#include <regex>
#include <sstream>
#include <string>
#include <system_error>
#include <unistd.h>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (includer test)
 

Functions

 BOOST_AUTO_TEST_CASE (no_inclusion_test)
 
 BOOST_AUTO_TEST_CASE (single_inclusion_test)
 
 BOOST_AUTO_TEST_CASE (double_inclusion_test)
 
 BOOST_AUTO_TEST_CASE (repeated_inclusion_test)
 
 BOOST_AUTO_TEST_CASE (malformed_inclusion_test)
 
 BOOST_AUTO_TEST_CASE (simple_recursive_inclusion_test)
 
 BOOST_AUTO_TEST_CASE (complex_recursive_inclusion_test)
 
 BOOST_AUTO_TEST_CASE (string_inclusion_test)
 
 BOOST_AUTO_TEST_CASE (backtrace_test)
 
 BOOST_AUTO_TEST_CASE (highlighted_backtrace_test)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (includer test)

Definition at line 7 of file includer_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( no_inclusion_test  )

Definition at line 128 of file includer_test.cc.

129 {
130  write_files();
131 
132  cet::includer const a{file_a, policy};
133  std::string const result1{a.begin(), a.end()};
134  BOOST_TEST(result1 == expected_string(contents_a));
135 
136  cet::includer const b{file_b, policy};
137  std::string const result2{b.begin(), b.end()};
138  BOOST_TEST(result2 == expected_string(contents_b));
139 
140  cet::includer const c{file_c, policy};
141  std::string const result3{c.begin(), c.end()};
142  BOOST_TEST(result3 == expected_string(contents_c));
143 }
std::string string
Definition: nybbler.cc:12
const double a
static bool * b
Definition: config.cpp:1043
BOOST_AUTO_TEST_CASE ( single_inclusion_test  )

Definition at line 145 of file includer_test.cc.

146 {
147  cet::includer const i{file_i, policy};
148  std::string const result{i.begin(), i.end()};
149  BOOST_TEST(result == expected_string("begin\n") +
150  expected_string(contents_a) +
151  expected_string("end\n"));
152 }
static QCString result
std::string string
Definition: nybbler.cc:12
BOOST_AUTO_TEST_CASE ( double_inclusion_test  )

Definition at line 154 of file includer_test.cc.

155 {
156  cet::includer j(file_j, policy);
157  std::string result(j.begin(), j.end());
158  BOOST_TEST(result ==
159  expected_string("begin\n") + expected_string(contents_a) +
160  expected_string(contents_b) + expected_string(contents_c) +
161  expected_string("end\n"));
162 }
static QCString result
std::string string
Definition: nybbler.cc:12
BOOST_AUTO_TEST_CASE ( repeated_inclusion_test  )

Definition at line 164 of file includer_test.cc.

165 {
166  cet::includer k(file_k, policy);
167  std::string result(k.begin(), k.end());
168  BOOST_TEST(result ==
169  expected_string("begin\n") + expected_string("begin\n") +
170  expected_string(contents_a) + expected_string(contents_b) +
171  expected_string(contents_c) + expected_string("end\n") +
172  expected_string("begin\n") + expected_string(contents_a) +
173  expected_string("end\n") + expected_string("end\n"));
174 }
static QCString result
std::string string
Definition: nybbler.cc:12
BOOST_AUTO_TEST_CASE ( malformed_inclusion_test  )

Definition at line 176 of file includer_test.cc.

177 {
178  BOOST_CHECK_THROW(cet::includer(file_x1, policy), cet::exception);
179  BOOST_CHECK_THROW(cet::includer(file_x2, policy), cet::exception);
180  BOOST_CHECK_THROW(cet::includer(file_x3, policy), cet::exception);
181 }
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
BOOST_AUTO_TEST_CASE ( simple_recursive_inclusion_test  )

Definition at line 183 of file includer_test.cc.

184 {
185  BOOST_CHECK_EXCEPTION(
186  cet::includer(file_r, policy), cet::exception, [](cet::exception const& e) {
187  return e.category() == "Recursive #include directive:";
188  });
189 }
const double e
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
BOOST_AUTO_TEST_CASE ( complex_recursive_inclusion_test  )

Definition at line 191 of file includer_test.cc.

192 {
193  BOOST_CHECK_EXCEPTION(cet::includer(file_r2, policy),
195  [](cet::exception const& e) {
196  return e.category() ==
197  "Recursive #include directive:";
198  });
199 }
const double e
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
BOOST_AUTO_TEST_CASE ( string_inclusion_test  )

Definition at line 201 of file includer_test.cc.

202 {
203  std::string a = contents_a;
204  std::istringstream is_a(a);
205  cet::includer inc_a(is_a, policy);
206  std::string result_a(inc_a.begin(), inc_a.end());
207  BOOST_TEST(result_a == a);
208 
209  std::string i = contents_i;
210  std::istringstream is_i(i);
211  cet::includer inc_i(is_i, policy);
212  std::string result_i(inc_i.begin(), inc_i.end());
213  BOOST_TEST(result_i == expected_string("begin\n") +
214  expected_string(contents_a) +
215  expected_string("end\n"));
216 }
std::string string
Definition: nybbler.cc:12
const double a
BOOST_AUTO_TEST_CASE ( backtrace_test  )

Definition at line 218 of file includer_test.cc.

219 {
220  cet::includer j(file_j, policy);
221  auto it = j.begin();
222  std::advance(it, 5);
223  BOOST_TEST_REQUIRE(*it == '\n');
224  std::cerr << j.whereis(it) << "\n";
225  std::cerr << "\n";
226  std::string cmp("line 1, character 6, of file \"././j.txt\"");
227  BOOST_TEST_REQUIRE(j.whereis(it) == cmp);
228  std::advance(it, 10);
229  BOOST_TEST_REQUIRE(*it == 'y');
230  std::cerr << j.whereis(it) << "\n";
231  std::cerr << "\n";
232  cmp = "line 2, character 4, of file \"././a.txt\"\n"
233  "included from line 2 of file \"././j.txt\"";
234  BOOST_TEST_REQUIRE(j.whereis(it) == cmp);
235  std::advance(it, 10);
236  BOOST_TEST_REQUIRE(*it == '7');
237  std::cerr << j.whereis(it) << "\n";
238  cmp = "line 2, character 2, of file \"././b.txt\"\n"
239  "included from line 3 of file \"././j.txt\"";
240  BOOST_TEST_REQUIRE(j.whereis(it) == cmp);
241 }
std::string string
Definition: nybbler.cc:12
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
BOOST_AUTO_TEST_CASE ( highlighted_backtrace_test  )

Definition at line 243 of file includer_test.cc.

244 {
245  cet::includer j(file_j, policy);
246  auto it = j.begin();
247  std::advance(it, 5);
248  BOOST_TEST_REQUIRE(*it == '\n');
249  std::cerr << j.highlighted_whereis(it) << "\n";
250  std::cerr << "\n";
251  std::string cmp("line 1, character 6, of file \"././j.txt\"");
252  cmp += "\n\nbegin\n ^";
253  BOOST_TEST_REQUIRE(j.highlighted_whereis(it) == cmp);
254  std::advance(it, 10);
255  BOOST_TEST_REQUIRE(*it == 'y');
256  std::cerr << j.highlighted_whereis(it) << "\n";
257  std::cerr << "\n";
258  cmp = "line 2, character 4, of file \"././a.txt\"\n"
259  "included from line 2 of file \"././j.txt\"";
260  cmp += "\n\nvwxyz\n ^";
261  BOOST_TEST_REQUIRE(j.highlighted_whereis(it) == cmp);
262  std::advance(it, 10);
263  BOOST_TEST_REQUIRE(*it == '7');
264  std::cerr << j.highlighted_whereis(it) << "\n";
265  cmp = "line 2, character 2, of file \"././b.txt\"\n"
266  "included from line 3 of file \"././j.txt\"";
267  cmp += "\n\n67890\n ^";
268  BOOST_TEST_REQUIRE(j.highlighted_whereis(it) == cmp);
269 }
std::string string
Definition: nybbler.cc:12
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))