mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 20:54:59 +01:00
fix: a test run neither reads nor saves the player's odometer store
the autotests (--test, Global.test.enabled) run the vehicles of the player's game: their odometers count from the legacy or made up states in a store of their own, and nothing is written to eu07_odometers.txt
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
#include "vehicle.h"
|
||||
#include "utilities/Globals.h"
|
||||
#include "vehicle/odometer.h"
|
||||
|
||||
#include <filesystem>
|
||||
@@ -360,3 +361,25 @@ TEST_CASE("odometer: two simulations saving one file keep each other's states")
|
||||
CHECK(load().size() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("odometer: a test run neither reads nor saves the player's store") {
|
||||
if (false == Global.test.enabled)
|
||||
CHECK(odometer::persistent());
|
||||
// the autotests (--test) run the vehicles of the player's game, their runs aren't the player's
|
||||
struct test_mode {
|
||||
bool const was{Global.test.enabled};
|
||||
test_mode() { Global.test.enabled = true; }
|
||||
test_mode(test_mode const &) = delete;
|
||||
test_mode &operator=(test_mode const &) = delete;
|
||||
~test_mode() { Global.test.enabled = was; }
|
||||
} const testmode;
|
||||
// stops before the player's file is touched, if the gate is gone
|
||||
REQUIRE_FALSE(odometer::persistent());
|
||||
|
||||
auto &states{odometer::states()};
|
||||
states.record("tested", run(1000.0, 5000.0));
|
||||
CHECK(states.find("tested").value() == doctest::Approx(1005.0));
|
||||
CHECK(odometer::save());
|
||||
// a save to the file would have cleared it
|
||||
CHECK(states.modified());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user