18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 08:04:57 +01:00

fix: make the odometer test's scratch directory in the build directory for CI

Sonar (S5443) flags the shared temporary directory; the tests now use one
in their working directory. Also makes the scratch directory non-copyable
and spells out the optional checks Sonar asked about.
This commit is contained in:
jerrrrycho
2026-11-08 04:23:30 +01:00
parent 6dc42e976f
commit 1083f3cb5d
3 changed files with 8 additions and 5 deletions

View File

@@ -24,13 +24,16 @@ odometer::reading run(double const Km, double const Metres) {
return reading;
}
// a directory of its own for a test, removed afterwards
// a directory of its own for a test, removed afterwards. it's made in the working directory of the tests (the build
// directory), not in the shared temporary one
struct scratch_directory {
std::filesystem::path path;
explicit scratch_directory(std::string const &Name) : path{std::filesystem::temp_directory_path() / ("eu07_unit_" + Name)} {
explicit scratch_directory(std::string const &Name) : path{std::filesystem::current_path() / ("eu07_unit_" + Name)} {
std::filesystem::remove_all(path);
std::filesystem::create_directories(path);
}
scratch_directory(scratch_directory const &) = delete;
scratch_directory &operator=(scratch_directory const &) = delete;
~scratch_directory() {
std::error_code error;
std::filesystem::remove_all(path, error);