14 #include <hilti/rt/context.h> 15 #include <hilti/rt/doctest.h> 16 #include <hilti/rt/filesystem.h> 17 #include <hilti/rt/logging.h> 18 #include <hilti/rt/util.h> 25 std::string path = hilti::rt::filesystem::temp_directory_path() /
"hilti-rt-tests-XXXXXX";
27 auto fd = ::mkstemp(path.data());
34 std::vector<std::string> lines()
const {
35 auto file = std::ifstream(_path);
38 std::vector<std::string> lines;
39 while ( std::getline(file, line) )
40 lines.push_back(line);
45 const auto& path()
const {
return _path; }
49 auto exists = hilti::rt::filesystem::exists(_path, ec);
52 fatalError(
fmt(
"failed to check whether %s exists: %s", _path, ec));
55 hilti::rt::filesystem::remove_all(_path, ec);
59 hilti::rt::filesystem::path _path;
65 CaptureIO(std::ostream& stream) : _old(stream.rdbuf(_buffer.rdbuf())), _stream(&stream) {}
68 auto str()
const {
return _buffer.str(); }
71 std::stringstream _buffer = std::stringstream{};
72 std::streambuf* _old =
nullptr;
73 std::ostream* _stream =
nullptr;
80 _prev = context::detail::current();
81 context::detail::current() = current;
84 ~
TestContext() { context::detail::current() = _prev; }
void fatalError(const std::string &msg) __attribute__((noreturn))
Definition: logging.cc:21
std::string fmt(const char *fmt, const Args &... args)
Definition: fmt.h:13