test: add scoped file helper tests and update test build targets

This commit is contained in:
user
2026-07-18 23:39:36 +04:00
parent 11622fed54
commit 428d74aeb3
3 changed files with 126 additions and 6 deletions
+27
View File
@@ -0,0 +1,27 @@
#pragma once
#include <filesystem>
#include <stdexcept>
#include <string>
class ScopedFile {
public:
explicit ScopedFile(std::string fileName) : fileName_(std::move(fileName)) {}
void throwIfExists() const {
if (std::filesystem::exists(fileName_)) {
throw std::runtime_error("Test file already exists: " + fileName_);
}
}
const std::string &getFileName() const { return fileName_; }
~ScopedFile() noexcept(false) {
std::error_code ec;
std::filesystem::remove(fileName_, ec);
}
private:
std::string fileName_;
};