/// <summary> /// Generates a command line args instance with pre-determined values. /// </summary> /// <returns>A new BoostTestRunnerCommandLineArgs instance populated with pre-determined values.</returns> private static BoostTestRunnerCommandLineArgs GenerateCommandLineArgs() { 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.CatchSystemErrors = false; args.DetectFPExceptions = true; args.StandardOutFile = "stdout.log"; args.StandardErrorFile = "stderr.log"; return args; }
/// <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); }
public void Execute(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings, IProcessExecutionContext executionContext) { var fixedArgs = args; if (args != null) { // Adapt a copy of the command-line arguments to avoid changing the original fixedArgs = AdaptArguments(args.Clone()); } using (var stderr = new TemporaryFile(IsStandardErrorFileDifferent(args, fixedArgs) ? fixedArgs.StandardErrorFile : null)) { this.Runner.Execute(fixedArgs, settings, executionContext); // Extract the report output to its intended location string source = (fixedArgs == null) ? null : fixedArgs.StandardErrorFile; string destination = (args == null) ? null : args.ReportFile; if ((source != null) && (destination != null)) { try { ExtractReport(source, destination, string.IsNullOrEmpty(stderr.Path)); } catch (Exception ex) { Logger.Exception(ex, "Failed to extract test report from standard error [{0}] to report file [{1}] ({2})", source, destination, ex.Message); } } } }
/// <summary> /// Constructor /// </summary> /// <param name="runner">The IBoostTestRunner which will be used to run the tests</param> /// <param name="tests">The Visual Studio test cases which will be executed</param> /// <param name="args">The command-line arguments for the IBoostTestRunner representing the Visual Studio test cases</param> /// <param name="settings">Additional settings required for correct configuration of the test runner</param> public TestRun(IBoostTestRunner runner, IEnumerable<VSTestCase> tests, BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { this.Runner = runner; this.Tests = tests; this.Arguments = args; this.Settings = settings; }
/// <summary> /// Adapts the command line environment for Boost Test released in Boost 1.62 /// </summary> /// <remarks>https://github.com/etas/vs-boost-unit-test-adapter/issues/158</remarks> /// <param name="args">The command line arguments/environment to adapt</param> /// <returns>An adapted 'args'</returns> private BoostTestRunnerCommandLineArgs AdaptArguments(BoostTestRunnerCommandLineArgs args) { // Boost Test for Boost 1.62 causes an incorrect cast issue with the --log_sink (and --report_sink) command line argument if (args.Log != Sink.StandardOutput) { // Make use of environment variables instead of command-line // arguments to retain support for Boost Test in Boost 1.61 string logSink = args.Log.ToString(); if (args.Log != Sink.StandardError) { // Remove the ':' used as the volume separator since the Boost Test framework interprets it as a logger separator logSink = ((Path.IsPathRooted(logSink) && (logSink[1] == ':')) ? logSink.Substring(2) : logSink); } // BOOST_TEST_LOGGER (--logger) overrides --log_sink, --log_format and --log_level args.Environment["BOOST_TEST_LOGGER"] = string.Format( CultureInfo.InvariantCulture, "{0},{1},{2}", BoostTestRunnerCommandLineArgs.OutputFormatToString(args.LogFormat), BoostTestRunnerCommandLineArgs.LogLevelToString(args.LogLevel), logSink ); } // Boost Test (Boost 1.62) --report_sink workaround - force report output to standard error due to cast issue with --report_sink args.Report = Sink.StandardError; if (string.IsNullOrEmpty(args.StandardErrorFile)) { args.StandardErrorFile = TestPathGenerator.Generate(this.Source, FileExtensions.StdErrFile); } return args; }
/// <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); }
public int Execute(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings, IProcessExecutionContext executionContext) { var fixedArgs = args; if (args != null) { // Adapt a copy of the command-line arguments to avoid changing the original fixedArgs = AdaptArguments(args.Clone()); } using (var stderr = new TemporaryFile(IsStandardErrorFileDifferent(args, fixedArgs) ? fixedArgs.StandardErrorFile : null)) { int resultCode = this.Runner.Execute(fixedArgs, settings, executionContext); // Extract the report output to its intended location string source = (fixedArgs == null) ? null : fixedArgs.StandardErrorFile; string destination = (args == null) ? null : args.ReportFile; if ((source != null) && (destination != null)) { try { ExtractReport(source, destination, string.IsNullOrEmpty(stderr.Path)); } catch (Exception ex) { Logger.Exception(ex, "Failed to extract test report from standard error [{0}] to report file [{1}] ({2})", source, destination, ex.Message); } } return(resultCode); } }
/// <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> /// Adapts the command line environment for Boost Test released in Boost 1.62 /// </summary> /// <remarks>https://github.com/etas/vs-boost-unit-test-adapter/issues/158</remarks> /// <param name="args">The command line arguments/environment to adapt</param> /// <returns>An adapted 'args'</returns> private BoostTestRunnerCommandLineArgs AdaptArguments(BoostTestRunnerCommandLineArgs args) { // Boost Test for Boost 1.62 causes an incorrect cast issue with the --log_sink (and --report_sink) command line argument if (args.Log != Sink.StandardOutput) { // Make use of environment variables instead of command-line // arguments to retain support for Boost Test in Boost 1.61 string logSink = args.Log.ToString(); if (args.Log != Sink.StandardError) { // Remove the ':' used as the volume separator since the Boost Test framework interprets it as a logger separator logSink = ((Path.IsPathRooted(logSink) && (logSink[1] == ':')) ? logSink.Substring(2) : logSink); } // BOOST_TEST_LOGGER (--logger) overrides --log_sink, --log_format and --log_level args.Environment["BOOST_TEST_LOGGER"] = string.Format( CultureInfo.InvariantCulture, "{0},{1},{2}", BoostTestRunnerCommandLineArgs.OutputFormatToString(args.LogFormat), BoostTestRunnerCommandLineArgs.LogLevelToString(args.LogLevel), logSink ); } // Boost Test (Boost 1.62) --report_sink workaround - force report output to standard error due to cast issue with --report_sink args.Report = Sink.StandardError; if (string.IsNullOrEmpty(args.StandardErrorFile)) { args.StandardErrorFile = TestPathGenerator.Generate(this.Source, FileExtensions.StdErrFile); } return(args); }
public virtual void Debug(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings, IFrameworkHandle framework) { Utility.Code.Require(settings, "settings"); using (Process process = Debug(framework, GetStartInfo(args, settings))) { MonitorProcess(process, settings.Timeout); } }
public virtual void Run(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { Utility.Code.Require(settings,"settings"); using (Process process = Run(GetStartInfo(args, settings))) { MonitorProcess(process, settings.Timeout); } }
public virtual void Run(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings) { Utility.Code.Require(settings, "settings"); using (Process process = Run(GetStartInfo(args, settings))) { MonitorProcess(process, settings.Timeout); } }
/// <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); }
public virtual int Execute(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings, IProcessExecutionContext executionContext) { Utility.Code.Require(settings, "settings"); Utility.Code.Require(executionContext, "executionContext"); using (Process process = executionContext.LaunchProcess(GetExecutionContextArgs(args, settings))) { return(MonitorProcess(process, settings.Timeout)); } }
/// <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 }); }
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\"")); }
/// <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; }
/// <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; }
public BoostTestRunnerCommandLineArgs Clone() { BoostTestRunnerCommandLineArgs clone = new BoostTestRunnerCommandLineArgs(); clone.WorkingDirectory = this.WorkingDirectory; // Shallow copy clone.Environment = new Dictionary <string, string>(this.Environment); // Deep copy clone.Tests = new List <string>(this.Tests); clone.LogFormat = this.LogFormat; clone.LogLevel = this.LogLevel; clone._logFile = this._logFile; clone.ReportFormat = this.ReportFormat; clone.ReportLevel = this.ReportLevel; clone._reportFile = this._reportFile; clone.DetectMemoryLeaks = this.DetectMemoryLeaks; clone._stdOutFile = this._stdOutFile; clone._stdErrFile = this._stdErrFile; clone.ShowProgress = this.ShowProgress; clone.BuildInfo = this.BuildInfo; clone.AutoStartDebug = this.AutoStartDebug; clone.CatchSystemErrors = this.CatchSystemErrors; // Shallow copy clone.BreakExecPath = new List <ExecutionPath>(this.BreakExecPath); clone.ColorOutput = this.ColorOutput; clone.ResultCode = this.ResultCode; clone.Random = this.Random; clone.UseAltStack = this.UseAltStack; clone.DetectFPExceptions = this.DetectFPExceptions; clone.SavePattern = this.SavePattern; clone.ListContent = this.ListContent; return(clone); }
/// <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 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\"")); }
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 StdOutStdErrSink() { BoostTestRunnerCommandLineArgs args = new BoostTestRunnerCommandLineArgs() { Log = Sink.StandardError, Report = Sink.StandardOutput }; Assert.That(args.ToString(), Is.EqualTo("\"--log_sink=stderr\" \"--report_sink=stdout\"")); }
/// <summary> /// Delete output files. /// </summary> /// <param name="args">The BoostTestRunnerCommandLineArgs which contains references to output files.</param> private static void CleanOutput(BoostTestRunnerCommandLineArgs args) { DeleteFile(args.LogFile); DeleteFile(args.ReportFile); DeleteFile(args.StandardOutFile); DeleteFile(args.StandardErrorFile); }
public BoostTestRunnerCommandLineArgs Clone() { BoostTestRunnerCommandLineArgs clone = new BoostTestRunnerCommandLineArgs(); clone.WorkingDirectory = this.WorkingDirectory; // Deep copy clone.Tests = new List<string>(this.Tests); clone.LogFormat = this.LogFormat; clone.LogLevel = this.LogLevel; clone._logFile = this._logFile; clone.ReportFormat = this.ReportFormat; clone.ReportLevel = this.ReportLevel; clone._reportFile = this._reportFile; clone.DetectMemoryLeaks = this.DetectMemoryLeaks; clone._stdOutFile = this._stdOutFile; clone._stdErrFile = this._stdErrFile; clone.ShowProgress = this.ShowProgress; clone.BuildInfo = this.BuildInfo; clone.AutoStartDebug = this.AutoStartDebug; clone.CatchSystemErrors = this.CatchSystemErrors; // Shallow copy clone.BreakExecPath = new List<ExecutionPath>(this.BreakExecPath); clone.ColorOutput = this.ColorOutput; clone.ResultCode = this.ResultCode; clone.Random = this.Random; clone.UseAltStack = this.UseAltStack; clone.DetectFPExceptions = this.DetectFPExceptions; clone.SavePattern = this.SavePattern; clone.ListContent = this.ListContent; return clone; }
/// <summary> /// Copy Constructor. Creates a shallow copy of the provided instance. /// </summary> /// <param name="args">The instance to be copied.</param> protected BoostTestRunnerCommandLineArgs(BoostTestRunnerCommandLineArgs args) { Utility.Code.Require(args, "args"); this.WorkingDirectory = args.WorkingDirectory; // Shallow copy this.Tests = args.Tests; this.LogFormat = args.LogFormat; this.LogLevel = args.LogLevel; this.LogFile = args.LogFile; this.ReportFormat = args.ReportFormat; this.ReportLevel = args.ReportLevel; this.ReportFile = args.ReportFile; this.DetectMemoryLeaks = args.DetectMemoryLeaks; this.StandardOutFile = args.StandardOutFile; this.StandardErrorFile = args.StandardErrorFile; }
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, ITestCaseDiscoverySink discoverySink) { Code.Require(sources, "sources"); Code.Require(discoverySink, "discoverySink"); // Populate loop-invariant attributes and settings BoostTestAdapterSettings settings = BoostTestAdapterSettingsProvider.GetSettings(discoveryContext); BoostTestRunnerFactoryOptions options = new BoostTestRunnerFactoryOptions() { ExternalTestRunnerSettings = settings.ExternalTestRunner }; BoostTestRunnerSettings runnerSettings = new BoostTestRunnerSettings() { Timeout = settings.DiscoveryTimeoutMilliseconds }; BoostTestRunnerCommandLineArgs args = new BoostTestRunnerCommandLineArgs() { ListContent = ListContentFormat.DOT }; foreach (var source in sources) { try { args.SetWorkingEnvironment(source, settings, ((_vsProvider == null) ? null : _vsProvider.Instance)); } catch (COMException ex) { Logger.Exception(ex, "Could not retrieve WorkingDirectory from Visual Studio Configuration"); } try { IBoostTestRunner runner = _factory.GetRunner(source, options); using (TemporaryFile output = new TemporaryFile(TestPathGenerator.Generate(source, ".list.content.gv"))) { // --list_content output is redirected to standard error args.StandardErrorFile = output.Path; Logger.Debug("list_content file: {0}", args.StandardErrorFile); runner.Run(args, runnerSettings); // Parse --list_content=DOT output using (FileStream stream = File.OpenRead(args.StandardErrorFile)) { TestFrameworkDOTDeserialiser deserialiser = new TestFrameworkDOTDeserialiser(source); // Pass in a visitor to avoid a 2-pass loop in order to notify test cases to VS // // NOTE Due to deserialisation, make sure that only test cases are visited. Test // suites may be visited after their child test cases are visited. deserialiser.Deserialise(stream, new VSDiscoveryVisitorTestsOnly(source, discoverySink)); } } } catch (Exception ex) { Logger.Exception(ex, "Exception caught while discovering tests for {0} ({1} - {2})", source, ex.Message, ex.HResult); } } }
/// <summary> /// Retrieves and assigns parameters by resolving configurations from different possible resources /// </summary> /// <param name="source">The TestCases source</param> /// <param name="settings">The Boost Test adapter settings currently in use</param> /// <returns>A string for the default working directory</returns> private void GetDebugConfigurationProperties(string source, BoostTestAdapterSettings settings, BoostTestRunnerCommandLineArgs args) { try { args.SetWorkingEnvironment(source, settings, ((_vsProvider == null) ? null : _vsProvider.Instance)); } catch (COMException ex) { Logger.Exception(ex, "Could not retrieve WorkingDirectory from Visual Studio Configuration-{0}", ex.Message); } }
/// <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; }
public void DefaultCommandLineArgs() { BoostTestRunnerCommandLineArgs args = new BoostTestRunnerCommandLineArgs(); Assert.That(args.ToString(), Is.Empty); }
public void Debug(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings, IFrameworkHandle framework) { throw new NotImplementedException(); }
public virtual void Execute(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings, IProcessExecutionContext executionContext) { Utility.Code.Require(settings, "settings"); Utility.Code.Require(executionContext, "executionContext"); using (Process process = executionContext.LaunchProcess(GetExecutionContextArgs(args, settings))) { MonitorProcess(process, settings.Timeout); } }
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> /// Determines whether or not the 'StandarderrorFile' property is different from the 2 BoostTestRunnerCommandLineArgs instances /// </summary> /// <param name="lhs">the left-hand side instance to compare</param> /// <param name="rhs">the right-hand side instance to compare</param> /// <returns>true if the 'StandarderrorFile' property is different; false otherwise</returns> private static bool IsStandardErrorFileDifferent(BoostTestRunnerCommandLineArgs lhs, BoostTestRunnerCommandLineArgs rhs) { return((lhs != rhs) && (lhs != null) && (rhs != null) && (lhs.StandardErrorFile != rhs.StandardErrorFile)); }
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)); }
/// <summary> /// Determines whether or not the 'StandarderrorFile' property is different from the 2 BoostTestRunnerCommandLineArgs instances /// </summary> /// <param name="lhs">the left-hand side instance to compare</param> /// <param name="rhs">the right-hand side instance to compare</param> /// <returns>true if the 'StandarderrorFile' property is different; false otherwise</returns> private static bool IsStandardErrorFileDifferent(BoostTestRunnerCommandLineArgs lhs, BoostTestRunnerCommandLineArgs rhs) { return (lhs != rhs) && (lhs != null) && (rhs != null) && (lhs.StandardErrorFile != rhs.StandardErrorFile); }
public int Execute(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings, IProcessExecutionContext executionContext) { return(Runner.Execute(args, settings, executionContext)); }
public void Execute(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings, IProcessExecutionContext context) { Copy("BoostTestAdapterNunit.Resources.ListContentDOT.sample.8.list.content.gv", args.StandardErrorFile); }
/// <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 }; }