mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-21 23:44:58 +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:
@@ -24,13 +24,16 @@ odometer::reading run(double const Km, double const Metres) {
|
|||||||
return reading;
|
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 {
|
struct scratch_directory {
|
||||||
std::filesystem::path path;
|
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::remove_all(path);
|
||||||
std::filesystem::create_directories(path);
|
std::filesystem::create_directories(path);
|
||||||
}
|
}
|
||||||
|
scratch_directory(scratch_directory const &) = delete;
|
||||||
|
scratch_directory &operator=(scratch_directory const &) = delete;
|
||||||
~scratch_directory() {
|
~scratch_directory() {
|
||||||
std::error_code error;
|
std::error_code error;
|
||||||
std::filesystem::remove_all(path, error);
|
std::filesystem::remove_all(path, error);
|
||||||
|
|||||||
@@ -12323,7 +12323,7 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con
|
|||||||
gauge.Load(Parser, DynamicObject);
|
gauge.Load(Parser, DynamicObject);
|
||||||
// the counter shows the odometer of the vehicle, kept between the sessions (eu07/maszyna#72). its offset
|
// the counter shows the odometer of the vehicle, kept between the sessions (eu07/maszyna#72). its offset
|
||||||
// was the state it started each session with, now it is that only for a vehicle with no known state
|
// was the state it started each session with, now it is that only for a vehicle with no known state
|
||||||
if (auto const seed{odometer::counter_seed(gauge.offset(), gauge.scale())})
|
if (auto const seed{odometer::counter_seed(gauge.offset(), gauge.scale())}; seed.has_value())
|
||||||
mvControlled->Odometer.seed(*seed);
|
mvControlled->Odometer.seed(*seed);
|
||||||
gauge.offset(0.f);
|
gauge.offset(0.f);
|
||||||
gauge.AssignDouble(&mvControlled->Odometer.km);
|
gauge.AssignDouble(&mvControlled->Odometer.km);
|
||||||
|
|||||||
@@ -153,9 +153,9 @@ double guessed_state(std::string const &Vehicle) {
|
|||||||
|
|
||||||
reading starting_state(store const &States, std::string const &Vehicle, std::filesystem::path const &Vehicledirectory) {
|
reading starting_state(store const &States, std::string const &Vehicle, std::filesystem::path const &Vehicledirectory) {
|
||||||
reading result;
|
reading result;
|
||||||
if (auto const saved{States.find(Vehicle)}) {
|
if (auto const saved{States.find(Vehicle)}; saved.has_value()) {
|
||||||
result.begin(*saved, origin::saved);
|
result.begin(*saved, origin::saved);
|
||||||
} else if (auto const legacy{legacy_state(Vehicledirectory, Vehicle)}) {
|
} else if (auto const legacy{legacy_state(Vehicledirectory, Vehicle)}; legacy.has_value()) {
|
||||||
result.begin(*legacy, origin::legacy);
|
result.begin(*legacy, origin::legacy);
|
||||||
} else {
|
} else {
|
||||||
result.begin(guessed_state(Vehicle), origin::guessed);
|
result.begin(guessed_state(Vehicle), origin::guessed);
|
||||||
|
|||||||
Reference in New Issue
Block a user