14 #include <hilti/rt/context.h> 15 #include <hilti/rt/doctest.h> 16 #include <hilti/rt/filesystem.h> 17 #include <hilti/rt/util.h> 24 std::string path = hilti::rt::filesystem::temp_directory_path() /
"hilti-rt-tests-XXXXXX";
26 auto fd = ::mkstemp(path.data());
33 std::vector<std::string> lines()
const {
34 auto file = std::ifstream(_path);
37 std::vector<std::string> lines;
38 while ( std::getline(file, line) )
39 lines.push_back(line);
44 const auto& path()
const {
return _path; }
47 if ( hilti::rt::filesystem::exists(_path) )
48 hilti::rt::filesystem::remove_all(_path);
52 hilti::rt::filesystem::path _path;
58 CaptureIO(std::ostream& stream) : _old(stream.rdbuf(_buffer.rdbuf())), _stream(&stream) {}
61 auto str()
const {
return _buffer.str(); }
64 std::stringstream _buffer = std::stringstream{};
65 std::streambuf* _old =
nullptr;
66 std::ostream* _stream =
nullptr;
73 _prev = context::detail::current();
74 context::detail::current() = current;
77 ~
TestContext() { context::detail::current() = _prev; }