Files
StarterNG/StarterNG.Tests/SimulatorAftermathTests.cs
Hirek 43600f29c6 fix(exit): no box of the starter after eu07_starter.exe or the simulator already said why
Started through eu07_starter.exe, a simulator that failed got two boxes in a
row: the one of eu07_starter.exe, then the starter's own with the exit code.
The starter's box is now left out where the player already has one:
- an error code of the system (0xC...) through eu07_starter.exe: it explained
  the code, or caught the crash the simulator then reported in its own box;
  Ctrl+C (0xC000013A), which it leaves without a word, still gets the box;
- code 1 through eu07_starter.exe with the simulator's log not written since
  the start: eu07_starter.exe did not start it (missing, refused by its checks,
  or the player's No) and said why;
- 0xE0450010, the simulator's own notice of a processor it cannot run on,
  with or without eu07_starter.exe.
The log of the starter still records each of these exits.
2026-11-30 20:37:23 +01:00

85 lines
3.6 KiB
C#

using StarterNG.Application;
using StarterNG.Tests.Fakes;
namespace StarterNG.Tests;
public class SimulatorAftermathTests
{
private static readonly string Build =
Path.Combine(Path.GetTempPath(), "maszyna", "cmake-build-diag", "bin", "eu07_2026-10-04_fc195880");
[Fact]
public void Minidumps_of_this_run_are_found_in_the_installation_and_under_crashpad()
{
var installation = new TestInstallation(new InMemoryFileSystem()
.WithExecutable(Build)
.WithFile(TestInstallation.At("crash_2026-10-04_13-03-12.dmp"), "MDMP")
.WithFile(TestInstallation.At("crashdumps", "reports", "1a2b.dmp"), "MDMP"));
installation.Files.LastWriteTimeUtc = new DateTime(2026, 10, 4, 11, 3, 12, DateTimeKind.Utc);
var aftermath = new SimulatorAftermath(installation.Files, installation.Paths, installation.Log);
var thisRun = aftermath.CrashDumpsSince(new DateTime(2026, 10, 4, 11, 3, 0, DateTimeKind.Utc), Build);
var later = aftermath.CrashDumpsSince(new DateTime(2026, 10, 4, 12, 0, 0, DateTimeKind.Utc), Build);
Assert.Equal(2, thisRun.Count);
Assert.Contains(thisRun, dump => dump.EndsWith("crash_2026-10-04_13-03-12.dmp"));
Assert.Empty(later);
}
[Fact]
public void The_end_of_the_simulator_log_is_read_for_a_silent_crash()
{
var installation = new TestInstallation(new InMemoryFileSystem()
.WithFile(TestInstallation.At("log.txt"), "first\r\nsecond\r\n\r\nthird\r\n"));
var started = installation.Files.LastWriteTimeUtc.AddMinutes(-1);
var tail = new SimulatorAftermath(installation.Files, installation.Paths, installation.Log)
.SimulatorLogTail(2, started);
Assert.Equal(new[] { "second", "third" }, tail);
}
[Fact]
public void A_log_not_written_since_the_start_says_nothing_of_this_run()
{
// Dead before it opened its log: what is there is the session before.
var installation = new TestInstallation(new InMemoryFileSystem()
.WithFile(TestInstallation.At("log.txt"), "yesterday's error\r\n"));
var started = installation.Files.LastWriteTimeUtc.AddMinutes(10);
var tail = new SimulatorAftermath(installation.Files, installation.Paths, installation.Log)
.SimulatorLogTail(2, started);
Assert.Empty(tail);
}
[Fact]
public void A_log_written_a_moment_before_the_start_was_taken_counts()
{
// The start is taken just after the launch, as for the crash dumps.
var installation = new TestInstallation(new InMemoryFileSystem()
.WithFile(TestInstallation.At("log.txt"), "opening\r\n"));
var started = installation.Files.LastWriteTimeUtc.AddSeconds(3);
var tail = new SimulatorAftermath(installation.Files, installation.Paths, installation.Log)
.SimulatorLogTail(2, started);
Assert.Equal(new[] { "opening" }, tail);
}
[Fact]
public void The_simulator_ran_when_it_wrote_its_log_since_the_start()
{
var installation = new TestInstallation(new InMemoryFileSystem()
.WithFile(TestInstallation.At("log.txt"), "opening\r\n"));
var aftermath = new SimulatorAftermath(installation.Files, installation.Paths, installation.Log);
var written = installation.Files.LastWriteTimeUtc;
Assert.True(aftermath.SimulatorRanSince(written.AddMinutes(-1)));
Assert.False(aftermath.SimulatorRanSince(written.AddMinutes(10)));
Assert.False(new SimulatorAftermath(new InMemoryFileSystem(), installation.Paths, installation.Log)
.SimulatorRanSince(written));
}
}