/// <summary> /// Builds a ProcessStartInfo instance using the provided command line string. /// </summary> /// <param name="args">The command line arguments.</param> /// <param name="settings">The Boost Test runner settings currently being applied.</param> /// <returns>A ProcessStartInfo instance.</returns> protected virtual ProcessStartInfo GetStartInfo(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { Utility.Code.Require(args, "args"); ProcessStartInfo startInfo = new ProcessStartInfo { CreateNoWindow = true, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = args.WorkingDirectory, FileName = this.TestRunnerExecutable, Arguments = args.ToString(), RedirectStandardError = false, RedirectStandardInput = false }; if (args.Environment != null) { foreach (var variable in args.Environment) { // Sets variable accordingly to the environment if (startInfo.EnvironmentVariables.ContainsKey(variable.Key)) { string value = startInfo.EnvironmentVariables[variable.Key]; startInfo.EnvironmentVariables[variable.Key] = string.IsNullOrEmpty(value) ? variable.Value : (value + ';' + variable.Value); } else { startInfo.EnvironmentVariables.Add(variable.Key, variable.Value); } } } return(startInfo); }
/// <summary> /// Provides a ProcessExecutionContextArgs structure containing the necessary information to launch the test process. /// Aggregates the BoostTestRunnerCommandLineArgs structure with the command-line arguments specified at configuration stage. /// </summary> /// <param name="args">The Boost Test Framework command line arguments</param> /// <param name="settings">The Boost Test Runner settings</param> /// <returns>A valid ProcessExecutionContextArgs structure to launch the test executable</returns> protected override ProcessExecutionContextArgs GetExecutionContextArgs(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { Code.Require(args, "args"); ProcessExecutionContextArgs info = base.GetExecutionContextArgs(args, settings); BoostTestRunnerCommandLineArgs tmpArgs = args.Clone(); tmpArgs.StandardErrorFile = null; tmpArgs.StandardOutFile = null; CommandEvaluator evaluator = BuildEvaluator(this.Source, tmpArgs, settings); CommandEvaluationResult result = evaluator.Evaluate(this.Settings.ExecutionCommandLine.Arguments); string cmdLineArgs = result.Result; if (!result.MappedVariables.Contains(BoostArgsPlaceholder)) { cmdLineArgs = result.Result + (result.Result.EndsWith(" ", StringComparison.Ordinal) ? string.Empty : " ") + args.ToString(); } BoostTestRunnerCommandLineArgs redirection = new BoostTestRunnerCommandLineArgs { StandardOutFile = args.StandardOutFile, StandardErrorFile = args.StandardErrorFile }; cmdLineArgs += redirection.ToString(); info.FilePath = evaluator.Evaluate(this.Settings.ExecutionCommandLine.FileName).Result; info.Arguments = cmdLineArgs; return(info); }
/// <summary> /// Provides a preset CommandEvaluator instance for evaluating strings containing the source, timeout and boost-args placeholders. /// </summary> /// <param name="source">The source placeholder value</param> /// <param name="args">The boost arguments placeholder value</param> /// <param name="settings">The test runner settings which contains the timeout placeholder value</param> /// <returns>A CommandEvaluator instance for evaluating strings containing the source, timeout and boost-args placeholders.</returns> private static CommandEvaluator BuildEvaluator(string source, BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { CommandEvaluator evaluator = BuildEvaluator(source); evaluator.SetVariable(TimeoutPlaceholder, Math.Max(0, settings.Timeout).ToString(CultureInfo.InvariantCulture)); evaluator.SetVariable(BoostArgsPlaceholder, args.ToString()); return(evaluator); }
/// <summary> /// Provides a ProcessExecutionContextArgs structure containing the necessary information to launch the test process. /// Aggregates the BoostTestRunnerCommandLineArgs structure with the command-line arguments specified at configuration stage. /// </summary> /// <param name="args">The Boost Test Framework command line arguments</param> /// <param name="settings">The Boost Test Runner settings</param> /// <returns>A valid ProcessExecutionContextArgs structure to launch the test executable</returns> protected virtual ProcessExecutionContextArgs GetExecutionContextArgs(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { Code.Require(args, "args"); return(new ProcessExecutionContextArgs() { FilePath = this.TestRunnerExecutable, WorkingDirectory = args.WorkingDirectory, Arguments = args.ToString(), EnvironmentVariables = args.Environment }); }
/// <summary> /// Provides a ProcessStartInfo structure containing the necessary information to launch the test process. /// Aggregates the BoostTestRunnerCommandLineArgs structure with the command-line arguments specified at configuration stage. /// </summary> /// <param name="args">The Boost Test Framework command line arguments</param> /// <param name="settings">The Boost Test Runner settings</param> /// <returns>A valid ProcessStartInfo structure to launch the test executable</returns> protected override ProcessStartInfo GetStartInfo(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { ProcessStartInfo info = base.GetStartInfo(args, settings); CommandEvaluator evaluator = BuildEvaluator(this.Source, args, settings); CommandEvaluationResult result = evaluator.Evaluate(this.Settings.ExecutionCommandLine.Arguments); string cmdLineArgs = result.Result; if (!result.MappedVariables.Contains(BoostArgsPlaceholder)) { cmdLineArgs = result.Result + (result.Result.EndsWith(" ", StringComparison.Ordinal) ? string.Empty : " ") + args.ToString(); } info.FileName = this.Settings.ExecutionCommandLine.FileName; info.Arguments = cmdLineArgs; return info; }
public string GetListContentOutput(string exeName) { var args = new BoostTestRunnerCommandLineArgs { ListContent = true }; // get the tests list from the output string output; using (var p = new Process()) using (Timer timeoutTimer = new Timer(TimeoutTimerCallback, p, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite)) { _processStartInfo.FileName = exeName; _processStartInfo.Arguments = args.ToString(); p.StartInfo = _processStartInfo; p.Start(); timeoutTimer.Change(Timeout, Timeout); output = p.StandardError.ReadToEnd(); // for some reason the list content output is in the standard error p.WaitForExit(Timeout); } return output; }
public void SampleCommandLineArgs() { BoostTestRunnerCommandLineArgs args = new BoostTestRunnerCommandLineArgs(); args.Tests.Add("test"); args.Tests.Add("suite/*"); args.LogFormat = OutputFormat.XML; args.LogLevel = LogLevel.TestSuite; args.LogFile = "log.xml"; args.ReportFormat = OutputFormat.XML; args.ReportLevel = ReportLevel.Detailed; args.ReportFile = "report.xml"; args.DetectMemoryLeaks = 0; args.StandardOutFile = "stdout.log"; args.StandardErrorFile = "stderr.log"; Assert.That(args.ToString(), Is.EqualTo("\"--run_test=test,suite/*\" \"--log_format=xml\" \"--log_level=test_suite\" \"--log_sink=log.xml\" \"--report_format=xml\" \"--report_level=detailed\" \"--report_sink=report.xml\" \"--detect_memory_leak=0\" > \"stdout.log\" 2> \"stderr.log\"")); }
/// <summary> /// Provides a preset CommandEvaluator instance for evaluating strings containing the source, timeout and boost-args placeholders. /// </summary> /// <param name="source">The source placeholder value</param> /// <param name="args">The boost arguments placeholder value</param> /// <param name="settings">The test runner settings which contains the timeout placeholder value</param> /// <returns>A CommandEvaluator instance for evaluating strings containing the source, timeout and boost-args placeholders.</returns> private static CommandEvaluator BuildEvaluator(string source, BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { CommandEvaluator evaluator = BuildEvaluator(source); if (settings.Timeout > -1) { evaluator.SetVariable(TimeoutPlaceholder, settings.Timeout.ToString(CultureInfo.InvariantCulture)); } evaluator.SetVariable(BoostArgsPlaceholder, args.ToString()); return evaluator; }
/// <summary> /// Builds a ProcessStartInfo instance using the provided command line string. /// </summary> /// <param name="args">The command line arguments.</param> /// <param name="settings">The Boost Test runner settings currently being applied.</param> /// <returns>A ProcessStartInfo instance.</returns> protected virtual ProcessStartInfo GetStartInfo(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { Utility.Code.Require(args, "args"); ProcessStartInfo startInfo = new ProcessStartInfo { CreateNoWindow = true, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = args.WorkingDirectory, FileName = this.TestRunnerExecutable, Arguments = args.ToString(), RedirectStandardError = false, RedirectStandardInput = false }; return startInfo; }
/// <summary> /// Provides a ProcessStartInfo structure containing the necessary information to launch the test process. /// Aggregates the BoostTestRunnerCommandLineArgs structure with the command-line arguments specified at configuration stage. /// </summary> /// <param name="args">The Boost Test Framework command line arguments</param> /// <param name="settings">The Boost Test Runner settings</param> /// <returns>A valid ProcessStartInfo structure to launch the test executable</returns> protected override ProcessStartInfo GetStartInfo(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { ProcessStartInfo info = base.GetStartInfo(args, settings); CommandEvaluator evaluator = BuildEvaluator(this.Source, args, settings); CommandEvaluationResult result = evaluator.Evaluate(this.Settings.ExecutionCommandLine.Arguments); string cmdLineArgs = result.Result; if (!result.MappedVariables.Contains(BoostArgsPlaceholder)) { cmdLineArgs = result.Result + (result.Result.EndsWith(" ", StringComparison.Ordinal) ? string.Empty : " ") + args.ToString(); } info.FileName = this.Settings.ExecutionCommandLine.FileName; info.Arguments = cmdLineArgs; return(info); }
public void DefaultCommandLineArgs() { BoostTestRunnerCommandLineArgs args = new BoostTestRunnerCommandLineArgs(); Assert.That(args.ToString(), Is.Empty); }
public void FilePaths() { BoostTestRunnerCommandLineArgs args = new BoostTestRunnerCommandLineArgs(); args.LogFile = "log.xml"; Assert.That(args.LogFile, Is.EqualTo("log.xml")); Assert.That(args.ToString(), Is.EqualTo("\"--log_sink=log.xml\"")); args.WorkingDirectory = @"C:\"; Assert.That(args.LogFile, Is.EqualTo(@"C:\log.xml")); Assert.That(args.ToString(), Is.EqualTo("\"--log_sink=C:\\log.xml\"")); args.LogFile = @"D:\Temp\log.xml"; Assert.That(args.LogFile, Is.EqualTo(@"D:\Temp\log.xml")); Assert.That(args.ToString(), Is.EqualTo("\"--log_sink=D:\\Temp\\log.xml\"")); }
public void ListContentCommandLineArgs() { BoostTestRunnerCommandLineArgs args = new BoostTestRunnerCommandLineArgs(); args.ListContent = ListContentFormat.DOT; args.StandardOutFile = @"C:\Temp\list_content.dot.out"; args.StandardErrorFile = @"C:\Temp\list_content.dot.err"; const string expected = "\"--list_content=DOT\" > \"C:\\Temp\\list_content.dot.out\" 2> \"C:\\Temp\\list_content.dot.err\""; Assert.That(args.ToString(), Is.EqualTo(expected)); args.ReportFormat = OutputFormat.XML; args.ReportFile = @"C:\Temp\list_content.report.xml"; // list content only includes the --list_content and the output redirection commands Assert.That(args.ToString(), Is.EqualTo(expected)); }
public void StdOutStdErrSink() { BoostTestRunnerCommandLineArgs args = new BoostTestRunnerCommandLineArgs() { Log = Sink.StandardError, Report = Sink.StandardOutput }; Assert.That(args.ToString(), Is.EqualTo("\"--log_sink=stderr\" \"--report_sink=stdout\"")); }
public bool IsListContentSupported(string exeName) { Code.Require(exeName, "exeName"); var args = new BoostTestRunnerCommandLineArgs { Help = true }; string output; using (var p = new Process()) using (Timer timeoutTimer = new Timer(TimeoutTimerCallback, p, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite)) { _processStartInfo.FileName = exeName; _processStartInfo.Arguments = args.ToString(); p.StartInfo = _processStartInfo; p.Start(); timeoutTimer.Change(Timeout, Timeout); output = p.StandardOutput.ReadToEnd(); p.WaitForExit(Timeout); } args.Help = false; args.ListContent = true; if (!output.Contains(args.ToString())) { return false; } // check for the presence of PDB file var exeDir = Path.GetDirectoryName(exeName); var exeNameNoExt = Path.GetFileNameWithoutExtension(exeName); var pdbName = exeNameNoExt + ".PDB"; var pdbPath = Path.Combine(exeDir, pdbName); if (!File.Exists(pdbPath)) return false; return true; }
/// <summary> /// Provides a ProcessExecutionContextArgs structure containing the necessary information to launch the test process. /// Aggregates the BoostTestRunnerCommandLineArgs structure with the command-line arguments specified at configuration stage. /// </summary> /// <param name="args">The Boost Test Framework command line arguments</param> /// <param name="settings">The Boost Test Runner settings</param> /// <returns>A valid ProcessExecutionContextArgs structure to launch the test executable</returns> protected override ProcessExecutionContextArgs GetExecutionContextArgs(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { ProcessExecutionContextArgs info = base.GetExecutionContextArgs(args, settings); BoostTestRunnerCommandLineArgs tmpArgs = args.Clone(); tmpArgs.StandardErrorFile = null; tmpArgs.StandardOutFile = null; CommandEvaluator evaluator = BuildEvaluator(this.Source, tmpArgs, settings); CommandEvaluationResult result = evaluator.Evaluate(this.Settings.ExecutionCommandLine.Arguments); string cmdLineArgs = result.Result; if (!result.MappedVariables.Contains(BoostArgsPlaceholder)) { cmdLineArgs = result.Result + (result.Result.EndsWith(" ", StringComparison.Ordinal) ? string.Empty : " ") + args.ToString(); } BoostTestRunnerCommandLineArgs redirection = new BoostTestRunnerCommandLineArgs { StandardOutFile = args.StandardOutFile, StandardErrorFile = args.StandardErrorFile }; cmdLineArgs += redirection.ToString(); info.FilePath = this.Settings.ExecutionCommandLine.FileName; info.Arguments = cmdLineArgs; return info; }
/// <summary> /// Provides a ProcessExecutionContextArgs structure containing the necessary information to launch the test process. /// Aggregates the BoostTestRunnerCommandLineArgs structure with the command-line arguments specified at configuration stage. /// </summary> /// <param name="args">The Boost Test Framework command line arguments</param> /// <param name="settings">The Boost Test Runner settings</param> /// <returns>A valid ProcessExecutionContextArgs structure to launch the test executable</returns> protected virtual ProcessExecutionContextArgs GetExecutionContextArgs(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { Code.Require(args, "args"); return new ProcessExecutionContextArgs() { FilePath = this.TestRunnerExecutable, WorkingDirectory = args.WorkingDirectory, Arguments = args.ToString(), EnvironmentVariables = args.Environment }; }