private static string RunTest(TestableZPlayerProcess testableZPlayer, ZMachineTestScript zMachineTestScript) { var scriptLines = zMachineTestScript.Lines; string failedExpectation = string.Empty; testableZPlayer.Start(); var lastCommand = string.Empty; if (_quietMode) { Console.WriteLine("QUIET mode..."); } var lastOutput = testableZPlayer.CaptureOutputUntilTheNextCommandRequest(); EchoToConsole(lastOutput); var scriptLineIdx = 0; do { var scriptLine = scriptLines[scriptLineIdx]; if (scriptLine.HasCommand) { testableZPlayer.ExecuteCommand(scriptLine.Command); EchoToConsole($"{scriptLine.Command}\n"); lastCommand = scriptLine.Command; lastOutput = testableZPlayer.CaptureOutputUntilTheNextCommandRequest(); EchoToConsole(lastOutput); } if (!scriptLine.MeetsExpectation(lastOutput)) { failedExpectation = CreateFailureMessage(lastCommand, scriptLine, lastOutput); break; } scriptLineIdx++; ShowProgress(scriptLine); } while (scriptLineIdx < scriptLines.Count); Console.WriteLine($"\nCommand Log: {LogExecutedCommands(testableZPlayer.ExecutedCommands, zMachineTestScript.ScriptFile)}"); return(failedExpectation); }
static void Main(string[] args) { var programFile = args[0]; var testFile = args[1]; var playerFile = @"D:\Src\ZMachineLib\ZPlay\bin\Debug\netcoreapp3.0\zplay.exe"; CheckFilesExists(playerFile, programFile, testFile); _quietMode = args.Length == 3; var zMachineTestScript = new ZMachineTestScript(testFile); using var zPlayer = new TestableZPlayerProcess(playerFile, programFile); var failedExpectation = RunTest(zPlayer, zMachineTestScript); zPlayer.Close(); ShowFinalMessage(programFile, testFile, failedExpectation); }