From 0e24b77b99aff4bbe8a9c6d77413205a2b41c882 Mon Sep 17 00:00:00 2001 From: Brian Gatt Date: Thu, 9 Mar 2017 16:58:27 +0100 Subject: [PATCH] 'CatchSystemErrors' is defined based on whether a test is being debugged or running - Change default configuration value of 'CatchSystemErrors' -- Default value of '--catch_system_errors' changed from 'yes' to 'no' from Boost 1.59 to Boost 1.60 -- Necessary to `#define BOOST_TEST_DEFAULTS_TO_CORE_DUMP` (http://www.boost.org/doc/libs/1_60_0/libs/test/doc/html/boost_test/utf_reference/rt_param_reference/catch_system.html) --- .../Runner/BoostTestRunnerCommandLineArgs.cs | 16 +++-- BoostTestAdapter/BoostTestExecutor.cs | 60 ++++++++++--------- .../Settings/BoostTestAdapterSettings.cs | 6 +- .../BoostTestExecutorTest.cs | 10 ++++ .../BoostTestRunnerCommandLineArgsTest.cs | 5 +- .../BoostTestSettingsTest.cs | 22 ++++++- 6 files changed, 79 insertions(+), 40 deletions(-) diff --git a/BoostTestAdapter/Boost/Runner/BoostTestRunnerCommandLineArgs.cs b/BoostTestAdapter/Boost/Runner/BoostTestRunnerCommandLineArgs.cs index c978f55..b89369c 100644 --- a/BoostTestAdapter/Boost/Runner/BoostTestRunnerCommandLineArgs.cs +++ b/BoostTestAdapter/Boost/Runner/BoostTestRunnerCommandLineArgs.cs @@ -220,7 +220,7 @@ public BoostTestRunnerCommandLineArgs() this.ShowProgress = false; this.BuildInfo = false; this.AutoStartDebug = "no"; - this.CatchSystemErrors = true; + this.CatchSystemErrors = null; this.ColorOutput = false; this.ResultCode = true; this.Random = 0; @@ -358,7 +358,13 @@ public string ReportFile /// /// Determines whether system errors should be caught. /// - public bool CatchSystemErrors { get; set; } + /// + /// Since the default value of '--catch_system_errors' is dependent on Boost.Test's + /// '#define BOOST_TEST_DEFAULTS_TO_CORE_DUMP', this value has been set to a optional type + /// + /// Reference: http://www.boost.org/doc/libs/1_60_0/libs/test/doc/html/boost_test/utf_reference/rt_param_reference/catch_system.html + /// + public bool? CatchSystemErrors { get; set; } /// /// States whether standard output text is colour coded. @@ -485,10 +491,10 @@ public override string ToString() AddArgument(AutoStartDebugArg, this.AutoStartDebug, args); } - // --catch_system_errors=no - if (!this.CatchSystemErrors) + // --catch_system_errors=yes + if (this.CatchSystemErrors.HasValue) { - AddArgument(CatchSystemErrorsArg, No, args); + AddArgument(CatchSystemErrorsArg, (this.CatchSystemErrors.Value ? Yes : No), args); } // --color_output=yes diff --git a/BoostTestAdapter/BoostTestExecutor.cs b/BoostTestAdapter/BoostTestExecutor.cs index 9db7369..c13182b 100644 --- a/BoostTestAdapter/BoostTestExecutor.cs +++ b/BoostTestAdapter/BoostTestExecutor.cs @@ -187,7 +187,7 @@ public void RunTests(IEnumerable sources, Logger.Debug("IRunContext.RunSettings.SettingsXml: {0}", runContext.RunSettings.SettingsXml); BoostTestAdapterSettings settings = BoostTestAdapterSettingsProvider.GetSettings(runContext); - + foreach (string source in sources) { if (_cancelled) @@ -219,7 +219,7 @@ public void RunTests(IEnumerable sources, // NOTE For code-coverage speed is given preference over adapter responsiveness. TestBatch.Strategy strategy = ((runContext.IsDataCollectionEnabled) ? TestBatch.Strategy.Source : settings.TestBatchStrategy); - ITestBatchingStrategy batchStrategy = GetBatchStrategy(strategy, settings); + ITestBatchingStrategy batchStrategy = GetBatchStrategy(strategy, settings, runContext); if (batchStrategy == null) { Logger.Error(Resources.BatchStrategyNotFoundFor, source); @@ -274,7 +274,7 @@ public void RunTests(IEnumerable tests, IRunContext runContext, IFra strategy = Strategy.TestSuite; } - ITestBatchingStrategy batchStrategy = GetBatchStrategy(strategy, settings); + ITestBatchingStrategy batchStrategy = GetBatchStrategy(strategy, settings, runContext); if (batchStrategy == null) { Logger.Error(Resources.BatchStrategyNotFound); @@ -306,13 +306,32 @@ public void Cancel() /// /// The base strategy to provide /// Adapter settings currently in use + /// The RunContext for this TestCase. Determines whether the test should be debugged or not. /// An ITestBatchingStrategy instance or null if one cannot be provided - private ITestBatchingStrategy GetBatchStrategy(TestBatch.Strategy strategy, BoostTestAdapterSettings settings) + private ITestBatchingStrategy GetBatchStrategy(TestBatch.Strategy strategy, BoostTestAdapterSettings settings, IRunContext runContext) { - TestBatch.CommandLineArgsBuilder argsBuilder = GetDefaultArguments; + TestBatch.CommandLineArgsBuilder argsBuilder = (string _source, BoostTestAdapterSettings _settings) => + { + return GetDefaultArguments(_source, _settings, runContext.IsBeingDebugged); + }; + if (strategy != Strategy.TestCase) { - argsBuilder = GetBatchedTestRunsArguments; + // Disable stdout, stderr and memory leak detection since it is difficult + // to distinguish from which test does portions of the output map to + argsBuilder = (string _source, BoostTestAdapterSettings _settings) => + { + var args = GetDefaultArguments(_source, _settings, runContext.IsBeingDebugged); + + // Disable standard error/standard output capture + args.StandardOutFile = null; + args.StandardErrorFile = null; + + // Disable memory leak detection + args.DetectMemoryLeaks = 0; + + return args; + }; } switch (strategy) @@ -449,11 +468,12 @@ private void GetDebugConfigurationProperties(string source, BoostTestAdapterSett /// /// The TestCases source /// The Boost Test adapter settings currently in use + /// Determines whether the test should be debugged or not. /// A BoostTestRunnerCommandLineArgs structure for the provided source - private BoostTestRunnerCommandLineArgs GetDefaultArguments(string source, BoostTestAdapterSettings settings) + private BoostTestRunnerCommandLineArgs GetDefaultArguments(string source, BoostTestAdapterSettings settings, bool debugMode) { BoostTestRunnerCommandLineArgs args = settings.CommandLineArgs.Clone(); - + GetDebugConfigurationProperties(source, settings, args); // Specify log and report file information @@ -468,26 +488,10 @@ private BoostTestRunnerCommandLineArgs GetDefaultArguments(string source, BoostT args.StandardOutFile = ((settings.EnableStdOutRedirection) ? TestPathGenerator.Generate(source, FileExtensions.StdOutFile) : null); args.StandardErrorFile = ((settings.EnableStdErrRedirection) ? TestPathGenerator.Generate(source, FileExtensions.StdErrFile) : null); - return args; - } - - /// - /// Factory function which returns an appropriate BoostTestRunnerCommandLineArgs structure for batched test runs - /// - /// The TestCases source - /// The Boost Test adapter settings currently in use - /// A BoostTestRunnerCommandLineArgs structure for the provided source - private BoostTestRunnerCommandLineArgs GetBatchedTestRunsArguments(string source, BoostTestAdapterSettings settings) - { - BoostTestRunnerCommandLineArgs args = GetDefaultArguments(source, settings); - - // Disable standard error/standard output capture - args.StandardOutFile = null; - args.StandardErrorFile = null; - - // Disable memory leak detection - args.DetectMemoryLeaks = 0; - + // Set '--catch_system_errors' to 'yes' if the test is not being debugged + // or if this value was not overridden via configuration before-hand + args.CatchSystemErrors = args.CatchSystemErrors.GetValueOrDefault(false) || !debugMode; + return args; } diff --git a/BoostTestAdapter/Settings/BoostTestAdapterSettings.cs b/BoostTestAdapter/Settings/BoostTestAdapterSettings.cs index 1205873..143e72e 100644 --- a/BoostTestAdapter/Settings/BoostTestAdapterSettings.cs +++ b/BoostTestAdapter/Settings/BoostTestAdapterSettings.cs @@ -40,7 +40,7 @@ public BoostTestAdapterSettings() : this.LogLevel = LogLevel.TestSuite; - this.CatchSystemErrors = true; + this.CatchSystemErrors = null; this.DetectFloatingPointExceptions = false; @@ -107,8 +107,8 @@ public int ExecutionTimeoutMilliseconds /// /// Set to 'true'|'1' to enable Boost Test's catch_system_errors. /// - [DefaultValue(true)] - public bool CatchSystemErrors + [DefaultValue(null)] + public bool? CatchSystemErrors { get { diff --git a/BoostTestAdapterNunit/BoostTestExecutorTest.cs b/BoostTestAdapterNunit/BoostTestExecutorTest.cs index bfba22b..bcd3941 100644 --- a/BoostTestAdapterNunit/BoostTestExecutorTest.cs +++ b/BoostTestAdapterNunit/BoostTestExecutorTest.cs @@ -543,6 +543,11 @@ public void RunTestsFromSource() ); AssertDefaultTestResultProperties(this.FrameworkHandle.Results); + + MockBoostTestRunner runner = this.RunnerFactory.LastTestRunner as MockBoostTestRunner; + + Assert.That(runner, Is.Not.Null); + Assert.That(runner.ExecutionArgs.All(args => (!args.Arguments.CatchSystemErrors.HasValue || args.Arguments.CatchSystemErrors.Value)), Is.True); } /// @@ -579,6 +584,10 @@ public void RunTestSelection() ); AssertDefaultTestResultProperties(this.FrameworkHandle.Results); + MockBoostTestRunner runner = this.RunnerFactory.LastTestRunner as MockBoostTestRunner; + + Assert.That(runner, Is.Not.Null); + Assert.That(runner.ExecutionArgs.All(args => (!args.Arguments.CatchSystemErrors.HasValue || args.Arguments.CatchSystemErrors.Value)), Is.True); } /// @@ -602,6 +611,7 @@ public void DebugTestSelection() Assert.That(runner, Is.Not.Null); Assert.That(runner.ExecutionArgs.First().Context, Is.TypeOf()); + Assert.That(runner.ExecutionArgs.All(args => (args.Arguments.CatchSystemErrors.HasValue && !args.Arguments.CatchSystemErrors.Value)), Is.True); AssertDefaultTestResultProperties(this.FrameworkHandle.Results); } diff --git a/BoostTestAdapterNunit/BoostTestRunnerCommandLineArgsTest.cs b/BoostTestAdapterNunit/BoostTestRunnerCommandLineArgsTest.cs index ca84329..461308a 100644 --- a/BoostTestAdapterNunit/BoostTestRunnerCommandLineArgsTest.cs +++ b/BoostTestAdapterNunit/BoostTestRunnerCommandLineArgsTest.cs @@ -5,7 +5,6 @@ using BoostTestAdapter.Boost.Runner; using NUnit.Framework; -using System.IO; namespace BoostTestAdapterNunit { @@ -45,7 +44,7 @@ private static BoostTestRunnerCommandLineArgs GenerateCommandLineArgs() args.DetectMemoryLeaks = 0; - args.CatchSystemErrors = false; + args.CatchSystemErrors = true; args.DetectFPExceptions = true; args.StandardOutFile = GenerateFullyQualifiedPath("stdout.log"); @@ -82,7 +81,7 @@ public void SampleCommandLineArgs() { BoostTestRunnerCommandLineArgs args = GenerateCommandLineArgs(); // serge: boost 1.60 requires uppercase input - Assert.That(args.ToString(), Is.EqualTo("\"--run_test=test,suite/*\" \"--catch_system_errors=no\" \"--log_format=XML\" \"--log_level=test_suite\" \"--log_sink=" + Assert.That(args.ToString(), Is.EqualTo("\"--run_test=test,suite/*\" \"--catch_system_errors=yes\" \"--log_format=XML\" \"--log_level=test_suite\" \"--log_sink=" + GenerateFullyQualifiedPath("log.xml") + "\" \"--report_format=XML\" \"--report_level=detailed\" \"--report_sink=" + GenerateFullyQualifiedPath("report.xml") + "\" \"--detect_memory_leak=0\" \"--detect_fp_exceptions=yes\" > \"" + GenerateFullyQualifiedPath("stdout.log") + "\" 2> \"" diff --git a/BoostTestAdapterNunit/BoostTestSettingsTest.cs b/BoostTestAdapterNunit/BoostTestSettingsTest.cs index 250408e..ab037d4 100644 --- a/BoostTestAdapterNunit/BoostTestSettingsTest.cs +++ b/BoostTestAdapterNunit/BoostTestSettingsTest.cs @@ -62,7 +62,7 @@ private void AssertDefaultSettings(BoostTestAdapterSettings settings) Assert.That(settings.LogLevel, Is.EqualTo(LogLevel.TestSuite)); Assert.That(settings.ExternalTestRunner, Is.Null); Assert.That(settings.DetectFloatingPointExceptions, Is.False); - Assert.That(settings.CatchSystemErrors, Is.True); + Assert.That(settings.CatchSystemErrors, Is.Null); Assert.That(settings.TestBatchStrategy, Is.EqualTo(Strategy.TestCase)); Assert.That(settings.ForceListContent, Is.False); Assert.That(settings.WorkingDirectory, Is.Null); @@ -171,7 +171,10 @@ public void ParseComplexSettings() /// - Assert that: the Boost 1.62 workaround option can be parsed /// [TestCase("true", Result = true)] + [TestCase("1", Result = true)] [TestCase("false", Result = false)] + [TestCase("0", Result = false)] + [TestCase("", Result = false)] [TestCase("", Result = false)] public bool ParseWorkaroundOption(string settingsXml) { @@ -195,6 +198,23 @@ public int ParsePostTestDelayOption(string settingsXml) return settings.PostTestDelay; } + /// + /// The 'CatchSystemErrors' option can be properly parsed + /// + /// Test aims: + /// - Assert that: the 'CatchSystemErrors' option can be properly parsed + /// + [TestCase("true", Result = true)] + [TestCase("1", Result = true)] + [TestCase("false", Result = false)] + [TestCase("0", Result = false)] + [TestCase("", Result = null)] + public bool? ParseCatchSystemErrorsOption(string settingsXml) + { + BoostTestAdapterSettings settings = ParseXml(settingsXml); + return settings.CatchSystemErrors; + } + #endregion Tests } }