/// <summary> /// Run debuggee (without any debugger) and compare the console output to the regex specified. /// </summary> /// <param name="config">test config to use</param> /// <param name="output">output helper</param> /// <param name="testName">test case name</param> /// <param name="debuggeeName">debuggee name (no path)</param> /// <param name="outputRegex">regex to match on console (standard and error) output</param> /// <returns></returns> public static async Task <int> Run(TestConfiguration config, ITestOutputHelper output, string testName, string debuggeeName, string outputRegex) { OutputHelper outputHelper = null; try { // Setup the logging from the options in the config file outputHelper = ConfigureLogging(config, output, testName); // Restore and build the debuggee. The debuggee name is lower cased because the // source directory name has been lowercased by the build system. DebuggeeConfiguration debuggeeConfig = await DebuggeeCompiler.Execute(config, debuggeeName.ToLowerInvariant(), outputHelper); outputHelper.WriteLine("Starting {0}", testName); outputHelper.WriteLine("{"); // Get the full debuggee launch command line (includes the host if required) string exePath = debuggeeConfig.BinaryExePath; string arguments = debuggeeConfig.BinaryDirPath; if (!string.IsNullOrWhiteSpace(config.HostExe)) { exePath = config.HostExe; arguments = Environment.ExpandEnvironmentVariables(string.Format("{0} {1} {2}", config.HostArgs, debuggeeConfig.BinaryExePath, debuggeeConfig.BinaryDirPath)); } TestLogger testLogger = new TestLogger(outputHelper.IndentedOutput); ProcessRunner processRunner = new ProcessRunner(exePath, arguments). WithLog(testLogger). WithTimeout(TimeSpan.FromMinutes(5)); processRunner.Start(); // Wait for the debuggee to finish before getting the debuggee output int exitCode = await processRunner.WaitForExit(); string debuggeeStandardOutput = testLogger.GetStandardOutput(); string debuggeeStandardError = testLogger.GetStandardError(); // The debuggee output is all the stdout first and then all the stderr output last string debuggeeOutput = debuggeeStandardOutput + debuggeeStandardError; if (string.IsNullOrEmpty(debuggeeOutput)) { throw new Exception("No debuggee output"); } // Remove any CR's in the match string because this assembly is built on Windows (with CRs) and // ran on Linux/OS X (without CRs). outputRegex = outputRegex.Replace("\r", ""); // Now match the debuggee output and regex match string if (!new Regex(outputRegex, RegexOptions.Multiline).IsMatch(debuggeeOutput)) { throw new Exception(string.Format("\nDebuggee output:\n\n'{0}'\n\nDid not match the expression:\n\n'{1}'", debuggeeOutput, outputRegex)); } return(exitCode); } catch (Exception ex) { // Log the exception outputHelper?.WriteLine(ex.ToString()); throw; } finally { outputHelper?.WriteLine("}"); outputHelper?.Dispose(); } }