From e9b1b2804218fe3925a12c30c0466c0d14939162 Mon Sep 17 00:00:00 2001 From: Chris Maddock Date: Wed, 1 Jan 2020 18:32:11 +0000 Subject: [PATCH] Labels: Add OnOutputOnly option, and deprecate On/All --- .../nunit3-console.tests/CommandLineTests.cs | 31 ++++++- .../TestEventHandlerTests.cs | 91 +++---------------- .../nunit3-console/ConsoleOptions.cs | 22 ++++- .../nunit3-console/TestEventHandler.cs | 4 +- 4 files changed, 64 insertions(+), 84 deletions(-) diff --git a/src/NUnitConsole/nunit3-console.tests/CommandLineTests.cs b/src/NUnitConsole/nunit3-console.tests/CommandLineTests.cs index eb6eccbe0..e221f39e3 100644 --- a/src/NUnitConsole/nunit3-console.tests/CommandLineTests.cs +++ b/src/NUnitConsole/nunit3-console.tests/CommandLineTests.cs @@ -212,7 +212,7 @@ public void CanRecognizeBooleanOptions(string propertyName, string pattern) [TestCase("ActiveConfig", "config", new string[] { "Debug" }, new string[0])] [TestCase("OutFile", "output|out", new string[] { "output.txt" }, new string[0])] [TestCase("WorkDirectory", "work", new string[] { "results" }, new string[0])] - [TestCase("DisplayTestLabels", "labels", new string[] { "Off", "On", "Before", "After", "All" }, new string[] { "JUNK" })] + [TestCase("DisplayTestLabels", "labels", new string[] { "Off", "OnOutputOnly", "Before", "After", "BeforeAndAfter" }, new string[] { "JUNK" })] [TestCase("InternalTraceLevel", "trace", new string[] { "Off", "Error", "Warning", "Info", "Debug", "Verbose" }, new string[] { "JUNK" })] [TestCase("DefaultTestNamePattern", "test-name-format", new string[] { "{m}{a}" }, new string[0])] [TestCase("ConsoleEncoding", "encoding", new string[] { "utf-8", "ascii", "unicode" }, new string[0])] @@ -263,7 +263,7 @@ public void CanRecognizeInProcessOption() [TestCase("ProcessModel", "process", new string[] { "InProcess", "Separate", "Multiple" })] [TestCase("DomainUsage", "domain", new string[] { "None", "Single", "Multiple" })] #endif - [TestCase("DisplayTestLabels", "labels", new string[] { "Off", "On", "Before", "After", "All" })] + [TestCase("DisplayTestLabels", "labels", new string[] { "Off", "OnOutputOnly", "Before", "After", "BeforeAndAfter" })] [TestCase("InternalTraceLevel", "trace", new string[] { "Off", "Error", "Warning", "Info", "Debug", "Verbose" })] public void CanRecognizeLowerCaseOptionValues(string propertyName, string optionName, string[] canonicalValues) { @@ -853,6 +853,33 @@ public void DisplayTestParameters() Console.WriteLine(" Name: {0} Value: {1}", name, TestContext.Parameters[name]); } + [TestCase("On", true)] + [TestCase("All", true)] + [TestCase("Off", false)] + [TestCase("OnOutputOnly", false)] + [TestCase("Before", false)] + [TestCase("After", false)] + [TestCase("BeforeAndAfter", false)] + public void DeprecatedLabelsOptionsWarnCorrectly(string labelOption, bool shouldWarn) + { + var options = ConsoleMocks.Options("--labels=" + labelOption); + options.Validate(); + var countWarningsExpected = shouldWarn ? 1 : 0; + Assert.Multiple(() => { + Assert.That(options.ErrorMessages, Is.Empty); + Assert.That(options.WarningMessages, Has.Exactly(countWarningsExpected).Contains("deprecated")); + }); + } + + [TestCase("On", "OnOutputOnly")] + [TestCase("All", "Before")] + public void DeprecatedLabelsOptionsAreReplacedCorrectly(string oldOption, string newOption) + { + var options = ConsoleMocks.Options("--labels=" + oldOption); + options.Validate(); + Assert.That(options.DisplayTestLabels, Is.EqualTo(newOption)); + } + private static IFileSystem GetFileSystemContainingFile(string fileName) { var fileSystem = new VirtualFileSystem(); diff --git a/src/NUnitConsole/nunit3-console.tests/TestEventHandlerTests.cs b/src/NUnitConsole/nunit3-console.tests/TestEventHandlerTests.cs index 983984fdd..4b56b7655 100644 --- a/src/NUnitConsole/nunit3-console.tests/TestEventHandlerTests.cs +++ b/src/NUnitConsole/nunit3-console.tests/TestEventHandlerTests.cs @@ -76,21 +76,18 @@ public void MultipleEvents(string[] reports, string labels, string expected) { // Start Events new TestCaseData("", "Off", ""), - new TestCaseData("", "On", ""), - new TestCaseData("", "All", "=> SomeName\r\n"), + new TestCaseData("", "OnOutputOnly", ""), new TestCaseData("", "Before", "=> SomeName\r\n"), new TestCaseData("", "After", ""), new TestCaseData("", "BeforeAndAfter", "=> SomeName\r\n"), new TestCaseData("", "Off", ""), - new TestCaseData("", "On", ""), - new TestCaseData("", "All", ""), + new TestCaseData("", "OnOutputOnly", ""), new TestCaseData("", "Before", ""), new TestCaseData("", "After", ""), new TestCaseData("", "BeforeAndAfter", ""), // Finish Events - No Output new TestCaseData("", "Off", ""), - new TestCaseData("", "On", ""), - new TestCaseData("", "All", ""), + new TestCaseData("", "OnOutputOnly", ""), new TestCaseData("", "Before", ""), new TestCaseData("", "After", "Passed => SomeName\r\n"), new TestCaseData("", "BeforeAndAfter", "Passed => SomeName\r\n"), @@ -111,8 +108,7 @@ public void MultipleEvents(string[] reports, string labels, string expected) new TestCaseData("", "After", "Ignored => SomeName\r\n"), new TestCaseData("", "BeforeAndAfter", "Ignored => SomeName\r\n"), new TestCaseData("", "Off", ""), - new TestCaseData("", "On", ""), - new TestCaseData("", "All", ""), + new TestCaseData("", "OnOutputOnly", ""), new TestCaseData("", "Before", ""), new TestCaseData("", "After", ""), new TestCaseData("", "BeforeAndAfter", ""), @@ -123,11 +119,7 @@ public void MultipleEvents(string[] reports, string labels, string expected) "OUTPUT"), new TestCaseData( "OUTPUT", - "On", - "=> SomeName\r\nOUTPUT"), - new TestCaseData( - "OUTPUT", - "All", + "OnOutputOnly", "=> SomeName\r\nOUTPUT"), new TestCaseData( "OUTPUT", @@ -207,11 +199,7 @@ public void MultipleEvents(string[] reports, string labels, string expected) "OUTPUT"), new TestCaseData( "OUTPUT", - "On", - "=> SomeName\r\nOUTPUT"), - new TestCaseData( - "OUTPUT", - "All", + "OnOutputOnly", "=> SomeName\r\nOUTPUT"), new TestCaseData( "OUTPUT", @@ -232,11 +220,7 @@ public void MultipleEvents(string[] reports, string labels, string expected) "OUTPUT"), new TestCaseData( "OUTPUT", - "On", - "=> SomeName\r\nOUTPUT"), - new TestCaseData( - "OUTPUT", - "All", + "OnOutputOnly", "=> SomeName\r\nOUTPUT"), new TestCaseData( "OUTPUT", @@ -308,11 +292,7 @@ public void MultipleEvents(string[] reports, string labels, string expected) "OUTPUT"), new TestCaseData( SingleTest_StartAndFinish, - "On", - "=> TestName\r\nOUTPUT"), - new TestCaseData( - SingleTest_StartAndFinish, - "All", + "OnOutputOnly", "=> TestName\r\nOUTPUT"), new TestCaseData( SingleTest_StartAndFinish, @@ -335,15 +315,7 @@ public void MultipleEvents(string[] reports, string labels, string expected) TEST1"), new TestCaseData( SingleTest_ImmediateOutput, - "On", -@"=> TEST1 -Immediate output from TEST1 -Output -from -TEST1"), - new TestCaseData( - SingleTest_ImmediateOutput, - "All", + "OnOutputOnly", @"=> TEST1 Immediate output from TEST1 Output @@ -384,13 +356,7 @@ Immediate output from TEST1 Output from Suite TEST1"), new TestCaseData( SingleTest_SuiteFinish, - "On", -@"=> TEST1 -Immediate output from TEST1 -Output from Suite TEST1"), - new TestCaseData( - SingleTest_SuiteFinish, - "All", + "OnOutputOnly", @"=> TEST1 Immediate output from TEST1 Output from Suite TEST1"), @@ -419,14 +385,7 @@ Immediate output from TEST1 Output from second test"), new TestCaseData( TwoTests_SequentialExecution, - "On", -@"=> TEST1 -Output from first test -=> TEST2 -Output from second test"), - new TestCaseData( - TwoTests_SequentialExecution, - "All", + "OnOutputOnly", @"=> TEST1 Output from first test => TEST2 @@ -467,7 +426,7 @@ Output from first test Output from second test"), new TestCaseData( TwoTests_InterleavedExecution, - "On", + "OnOutputOnly", @"=> TEST1 Immediate output from first testAnother immediate output from first test => TEST2 @@ -475,20 +434,6 @@ Immediate output from second test => TEST1 Output from first test => TEST2 -Output from second test"), - new TestCaseData( - TwoTests_InterleavedExecution, - "All", -@"=> TEST1 -Immediate output from first test -=> TEST2 -=> TEST1 -Another immediate output from first test -=> TEST2 -Immediate output from second test -=> TEST1 -Output from first test -=> TEST2 Output from second test"), new TestCaseData( TwoTests_InterleavedExecution, @@ -544,17 +489,7 @@ Output from second test Output from first test"), new TestCaseData( TwoTests_NestedExecution, - "On", -@"=> TEST1 -Immediate output from first test -=> TEST2 -Immediate output from second test -Output from second test -=> TEST1 -Output from first test"), - new TestCaseData( - TwoTests_NestedExecution, - "All", + "OnOutputOnly", @"=> TEST1 Immediate output from first test => TEST2 diff --git a/src/NUnitConsole/nunit3-console/ConsoleOptions.cs b/src/NUnitConsole/nunit3-console/ConsoleOptions.cs index 5d7fd1f60..485fbe7dd 100644 --- a/src/NUnitConsole/nunit3-console/ConsoleOptions.cs +++ b/src/NUnitConsole/nunit3-console/ConsoleOptions.cs @@ -296,8 +296,26 @@ private void ConfigureOptions() this.Add("noresult", "Don't save any test results.", v => noresult = v != null); - this.Add("labels=", "Specify whether to write test case names to the output. Values: Off, On, Before, After, BeforeAndAfter, All", - v => DisplayTestLabels = parser.RequiredValue(v, "--labels", "Off", "On", "Before", "After", "BeforeAndAfter", "All")); + this.Add("labels=", "Specify whether to write test case names to the output. Values: Off, OnOutputOnly, Before, After, BeforeAndAfter", + v => { + string deprecationWarning = null; + + if (v.Equals("On", StringComparison.OrdinalIgnoreCase)) + { + deprecationWarning = "labels=On is deprecated and will be removed in a future release. Please use labels=OnOutputOnly instead."; + v = "OnOutputOnly"; + } + else if (v.Equals("All", StringComparison.OrdinalIgnoreCase)) + { + deprecationWarning = "labels=All is deprecated and will be removed in a future release. Please use labels=Before instead."; + v = "Before"; + } + + if (deprecationWarning != null && !WarningMessages.Contains(deprecationWarning)) + WarningMessages.Add(deprecationWarning); + + DisplayTestLabels = parser.RequiredValue(v, "--labels", "Off", "OnOutputOnly", "Before", "After", "BeforeAndAfter"); + }); this.Add("test-name-format=", "Non-standard naming pattern to use in generating test names.", v => DefaultTestNamePattern = parser.RequiredValue(v, "--test-name-format")); diff --git a/src/NUnitConsole/nunit3-console/TestEventHandler.cs b/src/NUnitConsole/nunit3-console/TestEventHandler.cs index 2c28c96d1..b82451f54 100644 --- a/src/NUnitConsole/nunit3-console/TestEventHandler.cs +++ b/src/NUnitConsole/nunit3-console/TestEventHandler.cs @@ -51,9 +51,9 @@ public TestEventHandler(ExtendedTextWriter outWriter, string labelsOption) _outWriter = outWriter; labelsOption = labelsOption.ToUpperInvariant(); - _displayBeforeTest = labelsOption == "ALL" || labelsOption == "BEFORE" || labelsOption == "BEFOREANDAFTER"; + _displayBeforeTest = labelsOption == "BEFORE" || labelsOption == "BEFOREANDAFTER"; _displayAfterTest = labelsOption == "AFTER" || labelsOption == "BEFOREANDAFTER"; - _displayBeforeOutput = _displayBeforeTest || _displayAfterTest || labelsOption == "ON"; + _displayBeforeOutput = _displayBeforeTest || _displayAfterTest || labelsOption == "ONOUTPUTONLY"; } public void OnTestEvent(string report)