static Maybe <Version> GetPython3Version() { var executable = PythonBootstrapper.FindPythonExecutable(); var command = new CommandLine(executable).Argument("--version"); var runner = new TestCommandLineRunner(new InMemoryLog(), new CalamariVariables()); var result = runner.Execute(command.Build()); if (result.ExitCode != 0) { return(Maybe <Version> .None); } var allCapturedMessages = runner.Output.AllMessages.Aggregate((a, b) => $"{a}, {b}"); var pythonVersionMatch = PythonVersionFinder.Match(allCapturedMessages); if (!pythonVersionMatch.Success) { return(Maybe <Version> .None); } var major = pythonVersionMatch.Groups[1].Value; var minor = pythonVersionMatch.Groups[2].Value; return(new Version(int.Parse(major), int.Parse(minor)).AsSome()); }
public void ScriptShouldFailIfExecutableDoesNotExist() { const string executable = "TestingCalamariThisExecutableShouldNeverExist"; var subject = new TestCommandLineRunner(new InMemoryLog(), new CalamariVariables()); var result = subject.Execute(new CommandLineInvocation(executable, "--version")); result.HasErrors.Should().BeTrue(); subject.Output.Errors.Should().Contain(CommandLineRunner.ConstructWin32ExceptionMessage(executable)); }