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

add label option "BeforeAndAfter" #630

Merged
merged 1 commit into from
May 28, 2019
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
112 changes: 112 additions & 0 deletions src/NUnitConsole/nunit3-console.tests/TestEventHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,42 @@ public void MultipleEvents(string[] reports, string labels, string expected)
new TestCaseData("<start-test fullname='SomeName'/>", "All", "=> SomeName\r\n"),
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'/>", "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'/>", "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"),
new TestCaseData("<test-case fullname='SomeName' result='Failed'/>", "After", "Failed => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Failed' label='Invalid'/>", "After", "Invalid => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Failed' label='Cancelled'/>", "After", "Cancelled => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Failed' label='Error'/>", "After", "Error => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Failed'/>", "BeforeAndAfter", "Failed => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Failed' label='Invalid'/>", "BeforeAndAfter", "Invalid => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Failed' label='Cancelled'/>", "BeforeAndAfter", "Cancelled => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Failed' label='Error'/>", "BeforeAndAfter", "Error => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Warning'/>", "After", "Warning => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Warning'/>", "BeforeAndAfter", "Warning => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Inconclusive'/>", "After", "Inconclusive => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Inconclusive'/>", "BeforeAndAfter", "Inconclusive => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Skipped'/>", "After", "Skipped => SomeName\r\n"),
new TestCaseData("<test-case fullname='SomeName' result='Skipped'/>", "BeforeAndAfter", "Skipped => SomeName\r\n"),
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'/>", "Before", ""),
new TestCaseData("<test-suite fullname='SomeName' result='Passed'/>", "After", ""),
new TestCaseData("<test-suite fullname='SomeName' result='Passed'/>", "BeforeAndAfter", ""),
// Finish Events - With Output
new TestCaseData(
"<test-case fullname='SomeName' result='Passed'><output>OUTPUT</output></test-case>",
Expand All @@ -125,6 +137,10 @@ public void MultipleEvents(string[] reports, string labels, string expected)
"<test-case fullname='SomeName' result='Passed'><output>OUTPUT</output></test-case>",
"After",
"=> SomeName\r\nOUTPUT\r\nPassed => SomeName\r\n"),
new TestCaseData(
"<test-case fullname='SomeName' result='Passed'><output>OUTPUT</output></test-case>",
"BeforeAndAfter",
"=> SomeName\r\nOUTPUT\r\nPassed => SomeName\r\n"),
new TestCaseData(
"<test-case fullname='SomeName' result='Failed'><output>OUTPUT</output></test-case>",
"After",
Expand Down Expand Up @@ -157,6 +173,34 @@ public void MultipleEvents(string[] reports, string labels, string expected)
"<test-case fullname='SomeName' result='Skipped' label='Ignored'><output>OUTPUT</output></test-case>",
"After",
"=> SomeName\r\nOUTPUT\r\nIgnored => SomeName\r\n"),
new TestCaseData(
"<test-case fullname='SomeName' result='Failed' label='Error'><output>OUTPUT</output></test-case>",
"BeforeAndAfter",
"=> SomeName\r\nOUTPUT\r\nError => SomeName\r\n"),
new TestCaseData(
"<test-case fullname='SomeName' result='Failed' label='Invalid'><output>OUTPUT</output></test-case>",
"BeforeAndAfter",
"=> SomeName\r\nOUTPUT\r\nInvalid => SomeName\r\n"),
new TestCaseData(
"<test-case fullname='SomeName' result='Failed' label='Cancelled'><output>OUTPUT</output></test-case>",
"BeforeAndAfter",
"=> SomeName\r\nOUTPUT\r\nCancelled => SomeName\r\n"),
new TestCaseData(
"<test-case fullname='SomeName' result='Warning'><output>OUTPUT</output></test-case>",
"BeforeAndAfter",
"=> SomeName\r\nOUTPUT\r\nWarning => SomeName\r\n"),
new TestCaseData(
"<test-case fullname='SomeName' result='Inconclusive'><output>OUTPUT</output></test-case>",
"BeforeAndAfter",
"=> SomeName\r\nOUTPUT\r\nInconclusive => SomeName\r\n"),
new TestCaseData(
"<test-case fullname='SomeName' result='Skipped'><output>OUTPUT</output></test-case>",
"BeforeAndAfter",
"=> SomeName\r\nOUTPUT\r\nSkipped => SomeName\r\n"),
new TestCaseData(
"<test-case fullname='SomeName' result='Skipped' label='Ignored'><output>OUTPUT</output></test-case>",
"BeforeAndAfter",
"=> SomeName\r\nOUTPUT\r\nIgnored => SomeName\r\n"),
new TestCaseData(
"<test-suite fullname='SomeName' result='Passed'><output>OUTPUT</output></test-suite>",
"Off",
Expand All @@ -177,6 +221,10 @@ public void MultipleEvents(string[] reports, string labels, string expected)
"<test-suite fullname='SomeName' result='Passed'><output>OUTPUT</output></test-suite>",
"After",
"=> SomeName\r\nOUTPUT"),
new TestCaseData(
"<test-suite fullname='SomeName' result='Passed'><output>OUTPUT</output></test-suite>",
"BeforeAndAfter",
"=> SomeName\r\nOUTPUT"),
// Output Events
new TestCaseData(
"<test-output testname='SomeName'>OUTPUT</test-output>",
Expand All @@ -197,6 +245,10 @@ public void MultipleEvents(string[] reports, string labels, string expected)
new TestCaseData(
"<test-output testname='SomeName'>OUTPUT</test-output>",
"After",
"=> SomeName\r\nOUTPUT"),
new TestCaseData(
"<test-output testname='SomeName'>OUTPUT</test-output>",
"BeforeAndAfter",
"=> SomeName\r\nOUTPUT")
};

Expand Down Expand Up @@ -270,6 +322,10 @@ public void MultipleEvents(string[] reports, string labels, string expected)
SingleTest_StartAndFinish,
"After",
"=> TestName\r\nOUTPUT\r\nPassed => TestName\r\n"),
new TestCaseData(
SingleTest_StartAndFinish,
"BeforeAndAfter",
"=> TestName\r\nOUTPUT\r\nPassed => TestName\r\n"),
new TestCaseData(
SingleTest_ImmediateOutput,
"Off",
Expand Down Expand Up @@ -310,6 +366,16 @@ Immediate output from TEST1
from
TEST1
Passed => TEST1
"),
new TestCaseData(
SingleTest_ImmediateOutput,
"BeforeAndAfter",
@"=> TEST1
Immediate output from TEST1
Output
from
TEST1
Passed => TEST1
"),
new TestCaseData(
SingleTest_SuiteFinish,
Expand Down Expand Up @@ -339,6 +405,12 @@ Immediate output from TEST1
"After",
@"=> TEST1
Immediate output from TEST1
Output from Suite TEST1"),
new TestCaseData(
SingleTest_SuiteFinish,
"BeforeAndAfter",
@"=> TEST1
Immediate output from TEST1
Output from Suite TEST1"),
new TestCaseData(
TwoTests_SequentialExecution,
Expand Down Expand Up @@ -375,6 +447,16 @@ Output from first test
=> TEST2
Output from second test
Passed => TEST2
"),
new TestCaseData(
TwoTests_SequentialExecution,
"BeforeAndAfter",
@"=> TEST1
Output from first test
Failed => TEST1
=> TEST2
Output from second test
Passed => TEST2
"),
new TestCaseData(
TwoTests_InterleavedExecution,
Expand Down Expand Up @@ -435,6 +517,23 @@ Output from first test
=> TEST2
Output from second test
Passed => TEST2
"),
new TestCaseData(
TwoTests_InterleavedExecution,
"BeforeAndAfter",
@"=> 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
Failed => TEST1
=> TEST2
Output from second test
Passed => TEST2
"),
new TestCaseData(
TwoTests_NestedExecution,
Expand Down Expand Up @@ -485,6 +584,19 @@ Output from second test
=> TEST1
Output from first test
Failed => TEST1
"),
new TestCaseData(
TwoTests_NestedExecution,
"BeforeAndAfter",
@"=> TEST1
Immediate output from first test
=> TEST2
Immediate output from second test
Output from second test
Passed => TEST2
=> TEST1
Output from first test
Failed => TEST1
")
};
#pragma warning restore 414
Expand Down
14 changes: 7 additions & 7 deletions src/NUnitConsole/nunit3-console/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class CommandLineOptions : OptionSet
/// </summary>
protected readonly IFileSystem _fileSystem;

#region Constructor
#region Constructor

internal CommandLineOptions(IDefaultOptionsProvider defaultOptionsProvider, IFileSystem fileSystem, params string[] args)
{
Expand All @@ -72,9 +72,9 @@ public CommandLineOptions(params string[] args)
Parse(args);
}

#endregion
#endregion

#region Properties
#region Properties

// Action to Perform

Expand Down Expand Up @@ -174,9 +174,9 @@ public bool Validate()
return ErrorMessages.Count == 0;
}

#endregion
#endregion

#region Helper Methods
#region Helper Methods

protected virtual void CheckOptionCombinations()
{
Expand Down Expand Up @@ -338,8 +338,8 @@ protected virtual 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, All",
v => DisplayTestLabels = RequiredValue(v, "--labels", "Off", "On", "Before", "After", "All"));
this.Add("labels=", "Specify whether to write test case names to the output. Values: Off, On, Before, After, BeforeAndAfter, All",
v => DisplayTestLabels = RequiredValue(v, "--labels", "Off", "On", "Before", "After", "BeforeAndAfter", "All"));

this.Add("test-name-format=", "Non-standard naming pattern to use in generating test names.",
v => DefaultTestNamePattern = RequiredValue(v, "--test-name-format"));
Expand Down
6 changes: 3 additions & 3 deletions src/NUnitConsole/nunit3-console/TestEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using NUnit.Engine;

namespace NUnit.ConsoleRunner
{
{
/// <summary>
/// TestEventHandler processes events from the running
/// test for the console runner.
Expand All @@ -47,8 +47,8 @@ public TestEventHandler(ExtendedTextWriter outWriter, string labelsOption)
_outWriter = outWriter;

labelsOption = labelsOption.ToUpper(System.Globalization.CultureInfo.InvariantCulture);
_displayBeforeTest = labelsOption == "ALL" || labelsOption == "BEFORE";
_displayAfterTest = labelsOption == "AFTER";
_displayBeforeTest = labelsOption == "ALL" || labelsOption == "BEFORE" || labelsOption == "BEFOREANDAFTER";
_displayAfterTest = labelsOption == "AFTER" || labelsOption == "BEFOREANDAFTER";
_displayBeforeOutput = _displayBeforeTest || _displayAfterTest || labelsOption == "ON";
}

Expand Down