test: add scoped file helper tests and update test build targets
This commit is contained in:
@@ -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_;
|
||||
};
|
||||
Reference in New Issue
Block a user