7 #define BOOST_TEST_MODULE (includer test) 8 #include "boost/test/unit_test.hpp" 12 #include "cetlib_except/exception.h" 19 #include <system_error> 48 "#include \"./a.txt\" \t \n" 52 "#include \"./a.txt\"\n" 53 "#include \"./b.txt\"\t\r\n" 54 "#include \"./c.txt\"\r" 58 "#include \"./j.txt\"\n" 59 "#include \"./i.txt\"\n" 63 "#include \"./r.txt\"\n" 67 "#include \"./r3.txt\"\n" 71 "#include \"./j.txt\"\n" 72 "#include \"./r4.txt\"\n" 76 "#include \"./linked/r2.txt\"\n" 79 std::string const contents_x1 =
"#include\"./a.txt\"\n";
80 std::string const contents_x2 =
"#include ./a.txt\"\n";
81 std::string const contents_x3 =
"#include \"./a.txt\n";
86 return std::regex_replace(str, std::regex(
"\r"),
"\n");
92 std::ofstream
a(file_a);
94 std::ofstream
b(file_b);
96 std::ofstream
c(file_c);
98 std::ofstream i(file_i);
100 std::ofstream j(file_j);
102 std::ofstream
k(file_k);
104 std::ofstream
r(file_r);
106 std::ofstream r2(file_r2);
108 std::ofstream r3(file_r3);
110 std::ofstream r4(file_r4);
112 std::ofstream
x1(file_x1);
114 std::ofstream
x2(file_x2);
116 std::ofstream
x3(file_x3);
118 if (
symlink(
".",
"linked") == -1) {
119 throw std::system_error(std::error_code(
errno, std::system_category()));
126 BOOST_AUTO_TEST_SUITE(includer_test)
134 BOOST_TEST(result1 == expected_string(contents_a));
138 BOOST_TEST(result2 == expected_string(contents_b));
142 BOOST_TEST(result3 == expected_string(contents_c));
149 BOOST_TEST(
result == expected_string(
"begin\n") +
150 expected_string(contents_a) +
151 expected_string(
"end\n"));
159 expected_string(
"begin\n") + expected_string(contents_a) +
160 expected_string(contents_b) + expected_string(contents_c) +
161 expected_string(
"end\n"));
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"));
185 BOOST_CHECK_EXCEPTION(
187 return e.category() ==
"Recursive #include directive:";
196 return e.category() ==
197 "Recursive #include directive:";
204 std::istringstream is_a(a);
207 BOOST_TEST(result_a == a);
210 std::istringstream is_i(i);
213 BOOST_TEST(result_i == expected_string(
"begin\n") +
214 expected_string(contents_a) +
215 expected_string(
"end\n"));
224 std::cerr << j.
whereis(it) <<
"\n";
226 std::string cmp(
"line 1, character 6, of file \"././j.txt\"");
228 std::advance(it, 10);
230 std::cerr << j.
whereis(it) <<
"\n";
232 cmp =
"line 2, character 4, of file \"././a.txt\"\n" 233 "included from line 2 of file \"././j.txt\"";
235 std::advance(it, 10);
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\"";
251 std::string cmp(
"line 1, character 6, of file \"././j.txt\"");
252 cmp +=
"\n\nbegin\n ^";
254 std::advance(it, 10);
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 ^";
262 std::advance(it, 10);
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 ^";
271 BOOST_AUTO_TEST_SUITE_END()
const_iterator end() const
const_iterator begin() const
std::string highlighted_whereis(const_iterator const &it) const
int errno
Contains the last error code.
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
BOOST_AUTO_TEST_CASE(no_inclusion_test)
std::string whereis(const_iterator const &it) const
cet::coded_exception< error, detail::translate > exception