#include #include #include #include #include #include "fold/cli/tu_quarantine.hpp" namespace { class TempDir { public: TempDir() : path_(std::filesystem::temp_directory_path() / ("fold-quarantine-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()))) { std::filesystem::create_directories(path_); } ~TempDir() { std::filesystem::remove_all(path_); } [[nodiscard]] const std::filesystem::path& path() const { return path_; } private: std::filesystem::path path_; }; } // namespace TEST_CASE("TU quarantine loads signal suffixes and ignores comments", "[cli][quarantine]") { TempDir temp; const auto source = temp.path() / "source.cpp"; std::ofstream(source) << "int value;\n"; std::ofstream(temp.path() / "quarantine.txt") << "# quarantined translation units\n" << source.string() << ":11 \n\n"; const auto paths = fold::cli::loadQuarantine(temp.path().string()); REQUIRE(paths.size() == 1); CHECK(paths.contains(fold::cli::normalizeTuPath(source.string()))); } TEST_CASE("TU quarantine append is normalized and idempotent", "[cli][quarantine]") { TempDir temp; const auto source = temp.path() / "nested" / "source.cpp"; std::filesystem::create_directories(source.parent_path()); std::ofstream(source) << "int value;\n"; const auto noncanonical = (source.parent_path() / ".." / "nested" / "source.cpp").string(); fold::cli::appendQuarantine(temp.path().string(), noncanonical, 6); fold::cli::appendQuarantine(temp.path().string(), source.string(), 11); const auto paths = fold::cli::loadQuarantine(temp.path().string()); REQUIRE(paths.size() == 1); CHECK(paths.contains(fold::cli::normalizeTuPath(source.string()))); std::ifstream input(temp.path() / "quarantine.txt"); std::string line; REQUIRE(std::getline(input, line)); CHECK(line == fold::cli::normalizeTuPath(source.string()) + "\tsignal:6"); CHECK_FALSE(std::getline(input, line)); }