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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <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>
        /// 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;
        }
        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);
            }
        }
        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 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 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 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 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;
        }
        /// <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 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>
        /// 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 Debug(BoostTestRunnerCommandLineArgs args, BoostTestRunnerSettings settings, IFrameworkHandle framework)
 {
     throw new NotImplementedException();
 }
        /// <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 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 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);
                }
            }
        }
Ejemplo n.º 20
0
        /// <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 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
            };
        }