mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-02 12:49:12 +01:00
Start a Windows build of the simulator through Wine on Linux
Where wine is on the PATH, an eu07.exe in the installation is found after any native binary and needs no execute bit.
This commit is contained in:
@@ -79,4 +79,79 @@ public class ExecutableLocatorTests
|
||||
|
||||
Assert.Equal(new[] { "eu07" }, installation.Executables.ListCandidates());
|
||||
}
|
||||
|
||||
private static readonly string Wine = Path.Combine("/usr/bin", "wine");
|
||||
|
||||
private static TestInstallation WithWine(InMemoryFileSystem files)
|
||||
{
|
||||
var installation = new TestInstallation(files.WithExecutable(Wine));
|
||||
installation.Environment.With("PATH", "/usr/bin");
|
||||
return installation;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Without_wine_a_windows_build_on_linux_is_not_a_candidate()
|
||||
{
|
||||
var installation = new TestInstallation(
|
||||
new InMemoryFileSystem().WithFile(TestInstallation.At("eu07.exe"), PortableExecutable));
|
||||
|
||||
installation.Executables.Resolve(new SimulatorSettings(), out var problem);
|
||||
|
||||
Assert.Equal(ExeProblem.NotFound, problem);
|
||||
Assert.Null(installation.Executables.Wine());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void With_wine_a_windows_build_on_linux_is_found_even_without_the_execute_bit()
|
||||
{
|
||||
var installation = WithWine(
|
||||
new InMemoryFileSystem().WithFile(TestInstallation.At("eu07.exe"), PortableExecutable));
|
||||
|
||||
string resolved = installation.Executables.Resolve(new SimulatorSettings(), out var problem);
|
||||
|
||||
Assert.EndsWith("eu07.exe", resolved);
|
||||
Assert.Equal(ExeProblem.WrongPlatform, problem);
|
||||
Assert.Equal(new[] { "eu07.exe" }, installation.Executables.ListCandidates());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_native_build_wins_over_the_windows_one()
|
||||
{
|
||||
var installation = WithWine(new InMemoryFileSystem()
|
||||
.WithFile(TestInstallation.At("eu07.exe"), PortableExecutable)
|
||||
.WithExecutable(TestInstallation.At("eu07-dev"), Elf));
|
||||
|
||||
string resolved = installation.Executables.Resolve(new SimulatorSettings(), out var problem);
|
||||
|
||||
Assert.EndsWith("eu07-dev", resolved);
|
||||
Assert.Equal(ExeProblem.None, problem);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Wine_starts_the_windows_build_and_a_native_one_starts_itself()
|
||||
{
|
||||
string exe = TestInstallation.At("eu07.exe");
|
||||
string native = TestInstallation.At("eu07");
|
||||
var installation = WithWine(new InMemoryFileSystem()
|
||||
.WithFile(exe, PortableExecutable)
|
||||
.WithExecutable(native, Elf));
|
||||
string[] arguments = { "-s", "$td.scn" };
|
||||
|
||||
var (wine, wineArguments) = installation.Executables.LaunchCommand(exe, arguments);
|
||||
var (program, programArguments) = installation.Executables.LaunchCommand(native, arguments);
|
||||
|
||||
Assert.Equal(Wine, wine);
|
||||
Assert.Equal(new[] { exe, "-s", "$td.scn" }, wineArguments);
|
||||
Assert.Equal(native, program);
|
||||
Assert.Equal(arguments, programArguments);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Wine_is_never_looked_for_on_windows()
|
||||
{
|
||||
var installation = WithWine(new InMemoryFileSystem());
|
||||
installation.Environment.AsWindows();
|
||||
|
||||
Assert.Null(installation.Executables.Wine());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,27 @@ public class StartSimulationTests
|
||||
Assert.NotNull(launcher.Executable);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_windows_build_on_linux_is_started_through_wine()
|
||||
{
|
||||
string wine = Path.Combine("/usr/bin", "wine");
|
||||
string exe = Path.Combine(Path.GetTempPath(), "maszyna", "eu07.exe");
|
||||
var (start, launcher, installation) = Rig(files => files
|
||||
.WithExecutable(wine)
|
||||
.WithFile(exe, "MZ\u0090\u0000"));
|
||||
installation.Environment.With("PATH", "/usr/bin");
|
||||
installation.SettingsStore.Settings.ExecutablePath = exe;
|
||||
|
||||
var result = start.Execute(freeFly: true, saveSettings: false);
|
||||
|
||||
// Unpacked from the Windows zip, it has no execute bit - Wine does not need one.
|
||||
Assert.Equal(SimulationStartOutcome.Started, result.Outcome);
|
||||
Assert.Equal(wine, launcher.Executable);
|
||||
Assert.Equal(exe, launcher.Arguments![0]);
|
||||
Assert.Equal("-s", launcher.Arguments[1]);
|
||||
Assert.Equal(installation.Paths.Root, launcher.WorkingDirectory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_file_that_cannot_be_run_is_not()
|
||||
{
|
||||
@@ -68,8 +89,8 @@ public class StartSimulationTests
|
||||
|
||||
var launcher = new RecordingLauncher();
|
||||
var start = new StartSimulation(state, installation.SettingsStore, installation.Library.Vehicles,
|
||||
installation.Files, installation.Paths, launcher, installation.Random,
|
||||
installation.Log);
|
||||
installation.Executables, installation.Files, installation.Paths, launcher,
|
||||
installation.Random, installation.Log);
|
||||
return (start, launcher, installation);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user