/// <summary> /// Compares a test framework deserialised from the provided embedded resource against the expected one /// using the specified encoding to read the resource file /// </summary> /// <param name="resource">Path to an embedded resource which is to be treated as input for TestFramework deserialisation</param> /// <param name="expected">The TestFramework which the deserialised version should be compared against</param> /// <param name="encoding">The encoding by which to interpret the resource file</param> private void Compare(string resource, TestFramework expected, Encoding encoding) { Stream stream = null; try { stream = TestHelper.LoadEmbeddedResource(resource); using (var reader = new StreamReader(stream, encoding)) { stream = null; TestFrameworkDOTDeserialiser parser = new TestFrameworkDOTDeserialiser(Source); TestFramework framework = parser.Deserialise(reader); FrameworkEqualityVisitor.IsEqualTo(framework, expected, false); } } finally { if (stream != null) { stream.Dispose(); } } }
/// <summary> /// Compares a test framework deserialised from the provided embedded resource against the expected one /// </summary> /// <param name="resource">Path to an embedded resource which is to be treated as input for TestFramework deserialisation</param> /// <param name="expected">The TestFramework which the deserialised version should be compared against</param> private void Compare(string resource, TestFramework expected) { using (var stream = TestHelper.LoadEmbeddedResource(resource)) { TestFrameworkDOTDeserialiser parser = new TestFrameworkDOTDeserialiser(Source); TestFramework framework = parser.Deserialise(stream); FrameworkEqualityVisitor.IsEqualTo(framework, expected); } }
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); } } }
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> /// Compares a test framework deserialised from the provided embedded resource against the expected one /// </summary> /// <param name="resource">Path to an embedded resource which is to be treated as input for TestFramework deserialisation</param> /// <param name="expected">The TestFramework which the deserialised version should be compared against</param> private void Compare(string resource, TestFramework expected) { using (var stream = TestHelper.LoadEmbeddedResource(resource)) { TestFrameworkDOTDeserialiser parser = new TestFrameworkDOTDeserialiser(Source); TestFramework framework = parser.Deserialise(stream); FrameworkEqualityVisitor.IsEqualTo(framework, expected, false); } }
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); } } }