Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Labels: Add OnOutputOnly option, and deprecate On/All #721

Merged
merged 1 commit into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/NUnitConsole/nunit3-console.tests/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand Down
91 changes: 13 additions & 78 deletions src/NUnitConsole/nunit3-console.tests/TestEventHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,18 @@ public void MultipleEvents(string[] reports, string labels, string expected)
{
// Start Events
new TestCaseData("<start-test fullname='SomeName'/>", "Off", ""),
new TestCaseData("<start-test fullname='SomeName'/>", "On", ""),
new TestCaseData("<start-test fullname='SomeName'/>", "All", "=> SomeName\r\n"),
new TestCaseData("<start-test fullname='SomeName'/>", "OnOutputOnly", ""),
new TestCaseData("<start-test fullname='SomeName'/>", "Before", "=> SomeName\r\n"),
new TestCaseData("<start-test fullname='SomeName'/>", "After", ""),
new TestCaseData("<start-test fullname='SomeName'/>", "BeforeAndAfter", "=> SomeName\r\n"),
new TestCaseData("<start-suite fullname='SomeName'/>", "Off", ""),
new TestCaseData("<start-suite fullname='SomeName'/>", "On", ""),
new TestCaseData("<start-suite fullname='SomeName'/>", "All", ""),
new TestCaseData("<start-suite fullname='SomeName'/>", "OnOutputOnly", ""),
new TestCaseData("<start-suite fullname='SomeName'/>", "Before", ""),
new TestCaseData("<start-suite fullname='SomeName'/>", "After", ""),
new TestCaseData("<start-suite fullname='SomeName'/>", "BeforeAndAfter", ""),
// Finish Events - No Output
new TestCaseData("<test-case fullname='SomeName' result='Passed'/>", "Off", ""),
new TestCaseData("<test-case fullname='SomeName' result='Passed'/>", "On", ""),
new TestCaseData("<test-case fullname='SomeName' result='Passed'/>", "All", ""),
new TestCaseData("<test-case fullname='SomeName' result='Passed'/>", "OnOutputOnly", ""),
new TestCaseData("<test-case fullname='SomeName' result='Passed'/>", "Before", ""),
new TestCaseData("<test-case fullname='SomeName' result='Passed'/>", "After", "Passed => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Passed'/>", "BeforeAndAfter", "Passed => SomeName\r\n"),
Expand All @@ -111,8 +108,7 @@ public void MultipleEvents(string[] reports, string labels, string expected)
new TestCaseData("<test-case fullname='SomeName' result='Skipped' label='Ignored'/>", "After", "Ignored => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Skipped' label='Ignored'/>", "BeforeAndAfter", "Ignored => SomeName\r\n"),
new TestCaseData("<test-suite fullname='SomeName' result='Passed'/>", "Off", ""),
new TestCaseData("<test-suite fullname='SomeName' result='Passed'/>", "On", ""),
new TestCaseData("<test-suite fullname='SomeName' result='Passed'/>", "All", ""),
new TestCaseData("<test-suite fullname='SomeName' result='Passed'/>", "OnOutputOnly", ""),
new TestCaseData("<test-suite fullname='SomeName' result='Passed'/>", "Before", ""),
new TestCaseData("<test-suite fullname='SomeName' result='Passed'/>", "After", ""),
new TestCaseData("<test-suite fullname='SomeName' result='Passed'/>", "BeforeAndAfter", ""),
Expand All @@ -123,11 +119,7 @@ public void MultipleEvents(string[] reports, string labels, string expected)
"OUTPUT"),
new TestCaseData(
"<test-case fullname='SomeName' result='Passed'><output>OUTPUT</output></test-case>",
"On",
"=> SomeName\r\nOUTPUT"),
new TestCaseData(
"<test-case fullname='SomeName' result='Passed'><output>OUTPUT</output></test-case>",
"All",
"OnOutputOnly",
"=> SomeName\r\nOUTPUT"),
new TestCaseData(
"<test-case fullname='SomeName' result='Passed'><output>OUTPUT</output></test-case>",
Expand Down Expand Up @@ -207,11 +199,7 @@ public void MultipleEvents(string[] reports, string labels, string expected)
"OUTPUT"),
new TestCaseData(
"<test-suite fullname='SomeName' result='Passed'><output>OUTPUT</output></test-suite>",
"On",
"=> SomeName\r\nOUTPUT"),
new TestCaseData(
"<test-suite fullname='SomeName' result='Passed'><output>OUTPUT</output></test-suite>",
"All",
"OnOutputOnly",
"=> SomeName\r\nOUTPUT"),
new TestCaseData(
"<test-suite fullname='SomeName' result='Passed'><output>OUTPUT</output></test-suite>",
Expand All @@ -232,11 +220,7 @@ public void MultipleEvents(string[] reports, string labels, string expected)
"OUTPUT"),
new TestCaseData(
"<test-output testname='SomeName'>OUTPUT</test-output>",
"On",
"=> SomeName\r\nOUTPUT"),
new TestCaseData(
"<test-output testname='SomeName'>OUTPUT</test-output>",
"All",
"OnOutputOnly",
"=> SomeName\r\nOUTPUT"),
new TestCaseData(
"<test-output testname='SomeName'>OUTPUT</test-output>",
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -467,28 +426,14 @@ 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
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,
Expand Down Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions src/NUnitConsole/nunit3-console/ConsoleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
4 changes: 2 additions & 2 deletions src/NUnitConsole/nunit3-console/TestEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down