/// <summary>
        /// Factory function which returns an appropriate IBoostTestRunner
        /// for the provided source or null if not applicable.
        /// </summary>
        /// <param name="source">The test source for which to retrieve the IBoostTestRunner</param>
        /// <returns>An IBoostTestRunner valid for the provided source or null if none are available</returns>
        protected IBoostTestRunner GetTestRunner(string source)
        {
            BoostTestRunnerFactoryOptions options = new BoostTestRunnerFactoryOptions();
            options.ExternalTestRunnerSettings = (this.Settings == null) ? null : this.Settings.ExternalTestRunner;

            return this.TestRunnerFactory.GetRunner(source, options);
        }
        public IBoostTestRunner GetRunner(string identifier, BoostTestRunnerFactoryOptions options)
        {
            IBoostTestRunner runner = A.Fake<IBoostTestRunner>();

            A.CallTo(() => runner.Source).Returns(identifier);
            A.CallTo(() => runner.ListContentSupported).Returns(ListContentSupport.Contains(identifier));

            return runner;
        }
        /// <summary>
        /// Acquires the Boost.Test from the settings and test module file path
        /// </summary>
        /// <param name="source">The test module file path</param>
        /// <param name="options">Test runner factory options</param>
        /// <returns>The specified Boost.Test version or null if the version cannot be assumed from the provided details</returns>
        private static Version GetBoostTestVersion(string source, BoostTestRunnerFactoryOptions options)
        {
            Version version = options?.ForcedBoostTestVersion;

            // Convention over configuration. Assume test runners utilising such an
            // extension pattern to be Boost 1.59 capable test runners.
            if ((version == null) && _forceListContentExtensionPattern.IsMatch(source))
            {
                version = Boost159;
            }

            return(version);
        }
        public IBoostTestRunner GetRunner(string identifier, BoostTestRunnerFactoryOptions options)
        {
            var key = Tuple.Create(identifier, options);

            IBoostTestRunner runner = null;

            if (!_cache.TryGetValue(key, out runner))
            {
                runner = BaseFactory.GetRunner(identifier, options);
                _cache.Add(key, runner);
            }

            return(runner);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Based on the provided file name, returns a suitable IBoostTestRunner
        /// instance or null if none are available.
        /// </summary>
        /// <param name="identifier">The identifier which is to be executed via the IBoostTestRunner.</param>
        /// <param name="options">test runner settings</param>
        /// <returns>A suitable IBoostTestRunner instance or null if none are available.</returns>
        public IBoostTestRunner GetRunner(string identifier, BoostTestRunnerFactoryOptions options)
        {
            IBoostTestRunner runner = null;

            if ((options != null) && (options.ExternalTestRunnerSettings != null))
            {
                // Provision an external test runner
                runner = GetExternalTestRunner(identifier, options.ExternalTestRunnerSettings);
            }

            // Provision a default internal runner
            if (runner == null)
            {
                runner = GetInternalTestRunner(identifier);
            }

            return(runner);
        }
        /// <summary>
        /// Based on the provided file name, returns a suitable IBoostTestRunner
        /// instance or null if none are available.
        /// </summary>
        /// <param name="identifier">The identifier which is to be executed via the IBoostTestRunner.</param>
        /// <param name="options">test runner settings</param>
        /// <returns>A suitable IBoostTestRunner instance or null if none are available.</returns>
        public IBoostTestRunner GetRunner(string identifier, BoostTestRunnerFactoryOptions options)
        {
            IBoostTestRunner runner = null;

            if ((options != null) && (options.ExternalTestRunnerSettings != null))
            {
                // Provision an external test runner
                runner = GetExternalTestRunner(identifier, options.ExternalTestRunnerSettings);
            }

            // Provision a default internal runner
            if (runner == null)
            {
                runner = GetInternalTestRunner(identifier);
            }

            return runner;
        }
        /// <summary>
        /// Based on the provided file name, returns a suitable IBoostTestRunner
        /// instance or null if none are available.
        /// </summary>
        /// <param name="identifier">The identifier which is to be executed via the IBoostTestRunner.</param>
        /// <param name="options">test runner settings</param>
        /// <returns>A suitable IBoostTestRunner instance or null if none are available.</returns>
        public IBoostTestRunner GetRunner(string identifier, BoostTestRunnerFactoryOptions options)
        {
            IBoostTestRunner runner = null;

            if ((options != null) && (options.ExternalTestRunnerSettings != null))
            {
                // Provision an external test runner
                runner = GetExternalTestRunner(identifier, options.ExternalTestRunnerSettings);
            }

            // Provision a default internal runner
            if (runner == null)
            {
                runner = GetInternalTestRunner(identifier);
            }

            if (runner != null)
            {
                // Apply specific Boost 1.62 workaround
                if (GetBoost162Workaround(options))
                {
                    runner = new BoostTest162Runner(runner);
                }

                // Force the use of a specific Boost.Test runner implementation
                Version version = GetBoostTestVersion(identifier, options);

                if (version != null)
                {
                    // Assume runner capabilities based on provided version
                    var capabilities = new BoostTestRunnerCapabilities
                    {
                        ListContent = (version >= Boost159),
                        Version     = (version >= Boost163)
                    };

                    runner = new BoostTestRunnerCapabilityOverride(runner, capabilities);
                }
            }

            return(runner);
        }
        public void ExternalBoostTestRunnerProvisioning(string source, string externalExtension, Type type)
        {
            BoostTestRunnerFactoryOptions options = new BoostTestRunnerFactoryOptions();
            options.ExternalTestRunnerSettings = new ExternalBoostTestRunnerSettings
            {
                ExtensionType = externalExtension,
                DiscoveryCommandLine = new CommandLine(),
                ExecutionCommandLine = new CommandLine()
            };

            IBoostTestRunner runner = this.Factory.GetRunner(source, options);

            if (runner == null)
            {
                Assert.That(type, Is.Null);
            }
            else
            {
                Assert.That(runner, Is.AssignableTo(type));
            }
        }
        /// <summary>
        /// Based on the provided file name, returns a suitable IBoostTestRunner
        /// instance or null if none are available.
        /// </summary>
        /// <param name="identifier">The identifier which is to be executed via the IBoostTestRunner.</param>
        /// <param name="options">test runner settings</param>
        /// <returns>A suitable IBoostTestRunner instance or null if none are available.</returns>
        public IBoostTestRunner GetRunner(string identifier, BoostTestRunnerFactoryOptions options)
        {
            IBoostTestRunner runner = null;

            if ((options != null) && (options.ExternalTestRunnerSettings != null))
            {
                // Provision an external test runner
                runner = GetExternalTestRunner(identifier, options.ExternalTestRunnerSettings);
            }

            // Provision a default internal runner
            if (runner == null)
            {
                runner = GetInternalTestRunner(identifier);
            }

            // Apply Boost 1.62 workaround
            if ((runner != null) && (options != null) && (options.UseBoost162Workaround))
            {
                runner = new BoostTest162Runner(runner);
            }

            return runner;
        }
        /// <summary>
        /// Based on the provided file name, returns a suitable IBoostTestRunner
        /// instance or null if none are available.
        /// </summary>
        /// <param name="identifier">The identifier which is to be executed via the IBoostTestRunner.</param>
        /// <param name="options">test runner settings</param>
        /// <returns>A suitable IBoostTestRunner instance or null if none are available.</returns>
        public IBoostTestRunner GetRunner(string identifier, BoostTestRunnerFactoryOptions options)
        {
            IBoostTestRunner runner = null;

            if ((options != null) && (options.ExternalTestRunnerSettings != null))
            {
                // Provision an external test runner
                runner = GetExternalTestRunner(identifier, options.ExternalTestRunnerSettings);
            }

            // Provision a default internal runner
            if (runner == null)
            {
                runner = GetInternalTestRunner(identifier);
            }

            // Apply Boost 1.62 workaround
            if ((runner != null) && (options != null) && (options.UseBoost162Workaround))
            {
                runner = new BoostTest162Runner(runner);
            }

            return(runner);
        }
        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>
 /// Determines whether or not the Boost 1.62 workaround is to be applied
 /// </summary>
 /// <param name="options">Test runner factory options</param>
 /// <returns>true if the Boost 1.62 workaround should be applied; false otherwise</returns>
 private static bool GetBoost162Workaround(BoostTestRunnerFactoryOptions options)
 {
     return((options != null) && (options.UseBoost162Workaround || (options.ForcedBoostTestVersion == Boost162)));
 }
            public IBoostTestRunner GetRunner(string source, BoostTestRunnerFactoryOptions options)
            {
                Code.Require(source, "source");
                Code.Require(options, "options");
                Code.Require(options.ExternalTestRunnerSettings, "options.ExternalTestRunnerSettings");

                return new ExternalBoostTestRunner(source, options.ExternalTestRunnerSettings);
            }
        /// <summary>
        /// Determines whether the provided source has --list_content capabilities
        /// </summary>
        /// <param name="source">The source to test</param>
        /// <param name="settings">Test adapter settings</param>
        /// <returns>true if the source has list content capabilities; false otherwise</returns>
        private bool IsListContentSupported(string source, BoostTestAdapterSettings settings)
        {
            BoostTestRunnerFactoryOptions options = new BoostTestRunnerFactoryOptions()
            {
                ExternalTestRunnerSettings = settings.ExternalTestRunner
            };

            IBoostTestRunner runner = _factory.GetRunner(source, options);
            return (runner != null) && runner.ListContentSupported;
        }
 public IBoostTestRunner GetRunner(string identifier, BoostTestRunnerFactoryOptions options)
 {
     this.ProvisionedRunners.Add(Tuple.Create(identifier, options, this.TemplateRunner));
     return this.TemplateRunner;
 }
        /// <summary>
        /// Determines whether the provided source has --list_content capabilities
        /// </summary>
        /// <param name="source">The source to test</param>
        /// <param name="settings">Test adapter settings</param>
        /// <returns>true if the source has list content capabilities; false otherwise</returns>
        private bool IsListContentSupported(string source, BoostTestAdapterSettings settings)
        {
            BoostTestRunnerFactoryOptions options = new BoostTestRunnerFactoryOptions()
            {
                ExternalTestRunnerSettings = settings.ExternalTestRunner
            };

            IBoostTestRunner runner = _factory.GetRunner(source, options);

            // Convention over configuration. Assume test runners utilising such an extension
            return (runner != null) && (runner.Source.EndsWith(ForceListContentExtension, StringComparison.OrdinalIgnoreCase) || runner.ListContentSupported);
        }