public XmlOutput Run(TestCaseGroup group) { if (_cancelled) { return(null); } _logbuilder.Clear(); // Prepare testcase list file CreateTestcaseListFile(group); // Run tests var process = new Process(); process.StartInfo.FileName = group.Source; process.StartInfo.Arguments = GenerateCommandlineArguments_Combined(group.Source, false); process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.WorkingDirectory = WorkingDirectory(group.Source); LogDebug($"Source for test case: {group.Source}{Environment.NewLine}"); LogDebug($"Commandline arguments used to run tests case: {process.StartInfo.Arguments}{Environment.NewLine}"); process.Start(); _process = process; var output = process.StandardOutput.ReadToEndAsync(); if (_settings.TestCaseTimeout > 0) { process.WaitForExit(_settings.TestCaseTimeout); } else { process.WaitForExit(); } if (!process.HasExited) { process.Kill(); LogVerbose($"Killed process.{Environment.NewLine}"); Log = _logbuilder.ToString(); } _process = null; LogDebug(output.Result); Log = _logbuilder.ToString(); return(new XmlOutput(output.Result, _settings)); }
private void CreateTestcaseListFile(TestCaseGroup group) { // Create content to write to file StringBuilder filecontentbuilder = new StringBuilder(); foreach (var name in group.Names) { var processedname = GenerateTestnameForCommandline(name); filecontentbuilder.Append($"{processedname}{Environment.NewLine}"); } var filecontent = filecontentbuilder.ToString(); File.WriteAllText($"{group.Source}.testcaselist", filecontent, Encoding.UTF8); }
public void CreateTestcaseListFile(TestCaseGroup group, string caselistfilename) { // Create content to write to file StringBuilder filecontentbuilder = new StringBuilder(); filecontentbuilder.Append($"# testcase list generated by Test Adpater for Catch2{Environment.NewLine}"); foreach (var name in group.Names) { var processedname = GenerateTestnameForCommandline(name); filecontentbuilder.Append($"{processedname}{Environment.NewLine}"); } var filecontent = filecontentbuilder.ToString(); File.WriteAllText(caselistfilename, filecontent, Encoding.UTF8); }
public XmlOutput Run(TestCaseGroup group) { if (_cancelled) { return(null); } _logbuilder.Clear(); string caselistfilename = MakeCaselistFilename(group.Source); string reportfilename = MakeReportFilename(group.Source); // Prepare testcase list file CreateTestcaseListFile(group, caselistfilename); // Run tests var process = new Process(); process.StartInfo.FileName = group.Source; process.StartInfo.Arguments = GenerateCommandlineArguments_Combined(caselistfilename, reportfilename); process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.WorkingDirectory = WorkingDirectory(group.Source); _settings.AddEnviromentVariables(process.StartInfo.EnvironmentVariables); LogDebug($"Source for test case: {group.Source}{Environment.NewLine}"); LogDebug($"Commandline arguments used to run tests case: {process.StartInfo.Arguments}{Environment.NewLine}"); process.Start(); _process = process; bool timeout = false; if (_settings.CombinedTimeout > 0) { process.WaitForExit(_settings.CombinedTimeout); } else { process.WaitForExit(); } _process = null; if (!process.HasExited) { process.Kill(); process.WaitForExit(); LogVerbose($"Killed process.{Environment.NewLine}"); Log = _logbuilder.ToString(); timeout = true; } process.Close(); // Read and process generated report string report = ReadReport(reportfilename); // Also does cleanup of reportfile LogDebug(report); Log = _logbuilder.ToString(); // Cleanup temporary files (don't delete files when loglevel is debug) if (_settings.LoggingLevel != LoggingLevels.Debug) { TryDeleteFile(caselistfilename); TryDeleteFile(reportfilename); } return(new XmlOutput(report, timeout, _settings)); }