#include "testdir.hh" #include #include #include #include #include namespace { std::filesystem::path mktmpdir() { std::error_code ec; auto base = std::filesystem::temp_directory_path(ec); if (ec) return {}; for (int i = 0; i < 10; ++i) { auto name = std::format( "{}-{}", ::testing::UnitTest::GetInstance()->current_test_info()->name(), rand()); auto tmpdir = base / name; if (std::filesystem::exists(tmpdir)) continue; if (std::filesystem::create_directory(tmpdir, ec)) return tmpdir; } return {}; } } // namespace TestDir::TestDir() : path_(mktmpdir()) {} TestDir::~TestDir() { if (!path_.empty()) std::filesystem::remove_all(path_); }