public IEnumerable <FactoryResult> GetDiscoverers(IReadOnlyCollection <string> sources, BoostTestAdapterSettings settings) { var tmpSources = new List <string>(sources); var discoverers = new List <FactoryResult>(); // sources that can be run on the external runner if (settings.ExternalTestRunner != null) { var extSources = tmpSources .Where(s => settings.ExternalTestRunner.ExtensionType.IsMatch(Path.GetExtension(s))) .ToList(); discoverers.Add(new FactoryResult() { Discoverer = new ExternalDiscoverer(settings.ExternalTestRunner, _dummySolution.Provider), Sources = extSources }); tmpSources.RemoveAll(s => extSources.Contains(s)); } // sources that support list-content parameter var listContentSources = tmpSources .Where(s => (s == ("ListContentSupport" + BoostTestDiscoverer.ExeExtension))) .ToList(); if (listContentSources.Count > 0) { IBoostTestRunnerFactory factory = A.Fake <IBoostTestRunnerFactory>(); A.CallTo(() => factory.GetRunner(A <string> ._, A <BoostTestRunnerFactoryOptions> ._)).ReturnsLazily((string source, BoostTestRunnerFactoryOptions options) => new StubListContentRunner(source)); discoverers.Add(new FactoryResult() { Discoverer = new ListContentDiscoverer(factory, _dummySolution.Provider), Sources = listContentSources }); tmpSources.RemoveAll(s => listContentSources.Contains(s)); } // sources that NOT support the list-content parameter var sourceCodeSources = tmpSources .Where(s => Path.GetExtension(s) == BoostTestDiscoverer.ExeExtension) .ToList(); if (sourceCodeSources.Count > 0) { discoverers.Add(new FactoryResult() { Discoverer = new SourceCodeDiscoverer(_dummySolution.Provider), Sources = sourceCodeSources }); } return(discoverers); }
/// <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); }
/// <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)); }
/// <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 static bool IsListContentSupported(IBoostTestRunnerFactory factory, string source, BoostTestAdapterSettings settings) { var runner = factory.GetRunner(source, settings.TestRunnerFactoryOptions); return((runner != null) && (runner.Capabilities.ListContent)); }
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); BoostTestRunnerSettings runnerSettings = new BoostTestRunnerSettings() { Timeout = settings.DiscoveryTimeoutMilliseconds }; BoostTestRunnerCommandLineArgs args = new BoostTestRunnerCommandLineArgs() { ListContent = ListContentFormat.DOT }; foreach (var source in sources) { try { var vs = _vsProvider?.Instance; if (vs != null) { Logger.Debug("Connected to Visual Studio {0} instance", vs.Version); } args.SetWorkingEnvironment(source, settings, vs); } catch (ROTException ex) { Logger.Exception(ex, "Could not retrieve WorkingDirectory from Visual Studio Configuration"); } catch (COMException ex) { Logger.Exception(ex, "Could not retrieve WorkingDirectory from Visual Studio Configuration"); } try { IBoostTestRunner runner = _factory.GetRunner(source, settings.TestRunnerFactoryOptions); 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); int resultCode = EXIT_SUCCESS; using (var context = new DefaultProcessExecutionContext()) { resultCode = runner.Execute(args, runnerSettings, context); } // Skip sources for which the --list_content file is not available if (!File.Exists(args.StandardErrorFile)) { Logger.Error("--list_content=DOT output for {0} is not available. Skipping.", source); continue; } // If the executable failed to exit with an EXIT_SUCCESS code, skip source and notify user accordingly if (resultCode != EXIT_SUCCESS) { Logger.Error("--list_content=DOT for {0} failed with exit code {1}. Skipping.", source, resultCode); continue; } // Parse --list_content=DOT output using (FileStream stream = File.OpenRead(args.StandardErrorFile)) { TestFrameworkDOTDeserialiser deserialiser = new TestFrameworkDOTDeserialiser(source); TestFramework framework = deserialiser.Deserialise(stream); if ((framework != null) && (framework.MasterTestSuite != null)) { framework.MasterTestSuite.Apply(new VSDiscoveryVisitor(source, GetVersion(runner), discoverySink)); } } } } catch (Exception ex) { Logger.Exception(ex, "Exception caught while discovering tests for {0} ({1} - {2})", source, ex.Message, ex.HResult); } } }