fold/tests/unit/test_tu_quarantine.cpp
trvon fcf474e4f0
Some checks failed
build / build-linux (pull_request) Failing after 7m32s
build / build-macos (pull_request) Has been cancelled
build / release (pull_request) Has been cancelled
refactor(cli): one TU path normalizer for coverage, fan-out and quarantine
Problem: normalizeClangTuPath, normalizeQuarantinePath and fan-out's
normalizePath were three copies of the same absolute + weakly_canonical
routine. Coverage, worker records and the quarantine file must agree on a
TU's spelling, and three copies can drift apart.

Fix: move the routine to fold/cli/tu_path.hpp as normalizeTuPath and use it
at every site. No behaviour change.

Test: existing test_scan_coverage (path spellings), test_tu_quarantine and
test_subprocess_fanout, updated to the new name. Full suite: 140/140.
2026-09-24 21:46:12 -06:00

61 lines
2.1 KiB
C++

#include <catch2/catch_test_macros.hpp>
#include <chrono>
#include <filesystem>
#include <fstream>
#include <string>
#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));
}