Skip to content

Commit 2249308

Browse files
OsirisTerjeclaude
andcommitted
Keep Progress output in results with ShowStdout=Failed
Progress output only goes live to the console, so ShowStdout=Failed lost it. Keep it in the test result for Failed, apply the reason gate to the XML converter as well, and document that None keeps NUnit's own result output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6ac534c commit 2249308

6 files changed

Lines changed: 50 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Use `.\build -t package` to create a package.
4747

4848
Agent mode only changes defaults: `ShowStdout` and `ShowStderr` become `Failed`, `StackTrace` becomes `Filtered`, and `Verbosity` becomes `-1`. A setting you set explicitly always wins.
4949

50-
- `ShowStdout`/`ShowStderr`: `All` sends test output to the console as it arrives. `Failed` keeps it only in the test result, where the VSTest console logger shows it for failed tests. `None` drops it.
50+
- `ShowStdout`/`ShowStderr`: `All` sends test output to the console as it arrives. `Failed` keeps it only in the test result, where the VSTest console logger shows it for failed tests. `None` drops the output events, but the output NUnit captures in the test result itself stays in the result, as with `ConsoleOut=0`. With `Failed`, `TestContext.Progress` output also goes to the test result instead of the console.
5151
- `StackTrace`: `Full`, `Filtered` (removes NUnit-internal and async state-machine frames) or `None`.
5252

5353
Command-line settings do not require a runsettings file:

‎src/NUnitTestAdapter/TestConverter.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,12 @@ private VSTestResult GetBasicResult(INUnitTestEvent resultNode, IEnumerable<INUn
349349
return vsResult;
350350
}
351351

352-
private static void FillResultFromOutputNodes(IEnumerable<INUnitTestEventTestOutput> outputNodes, VSTestResult vsResult)
352+
private void FillResultFromOutputNodes(IEnumerable<INUnitTestEventTestOutput> outputNodes, VSTestResult vsResult)
353353
{
354354
foreach (var output in outputNodes)
355355
{
356-
if (output.IsNullOrEmptyStream || output.IsProgressStream) // Don't add progress streams as output
356+
// Progress goes live to the console, unless the policy keeps it in the result
357+
if (output.IsNullOrEmptyStream || (output.IsProgressStream && !outputPolicy.KeepsProgressInResult))
357358
{
358359
continue;
359360
}

‎src/NUnitTestAdapter/TestConverterForXml.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ public TestResultSet GetVsTestResults(INUnitTestEventTestCase resultNode, IColle
146146
break;
147147
default:
148148
{
149-
if (adapterSettings.AgentMode == AgentMode.Off &&
150-
adapterSettings.ConsoleOut > 0 &&
149+
if (outputPolicy.ShowsReason(testCaseResult.Outcome) &&
151150
!string.IsNullOrEmpty(resultNode.ReasonMessage))
152151
testCaseResult.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, resultNode.ReasonMessage));
153152
break;
@@ -355,11 +354,12 @@ private VSTestResult GetBasicResult(INUnitTestEvent resultNode, IEnumerable<INUn
355354
return vsResult;
356355
}
357356

358-
private static void FillResultFromOutputNodes(IEnumerable<INUnitTestEventTestOutput> outputNodes, VSTestResult vsResult)
357+
private void FillResultFromOutputNodes(IEnumerable<INUnitTestEventTestOutput> outputNodes, VSTestResult vsResult)
359358
{
360359
foreach (var output in outputNodes)
361360
{
362-
if (output.IsNullOrEmptyStream || output.IsProgressStream) // Don't add progress streams as output
361+
// Progress goes live to the console, unless the policy keeps it in the result
362+
if (output.IsNullOrEmptyStream || (output.IsProgressStream && !outputPolicy.KeepsProgressInResult))
363363
{
364364
continue;
365365
}

‎src/NUnitTestAdapter/TestOutputPolicy.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ public bool ShowsLiveOutput(bool isErrorStream) =>
3333
ModeFor(isErrorStream) == CapturedOutputMode.All;
3434

3535
/// <summary>
36-
/// Output is buffered per test, and attached to its result, unless it is turned off.
36+
/// Output events are buffered per test, and attached to its result, unless they are turned off.
37+
/// None only drops these events. The output NUnit puts in the test result itself
38+
/// is always attached, as before (ConsoleOut=0 maps to None).
3739
/// </summary>
3840
public bool CollectsOutput(bool isErrorStream) =>
3941
ModeFor(isErrorStream) != CapturedOutputMode.None;
4042

43+
/// <summary>
44+
/// Progress output normally goes live to the console only. With Failed it is kept in the result instead.
45+
/// </summary>
46+
public bool KeepsProgressInResult => settings.ShowStdout == CapturedOutputMode.Failed;
47+
4148
public TestMessageLevel ConsoleOutputLevel =>
4249
settings.ConsoleOut >= 2 ? TestMessageLevel.Warning : TestMessageLevel.Informational;
4350

‎src/NUnitTestAdapterTests/TestConverterForXmlTests.cs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ public class TestConverterForXmlTests
4040
{
4141
private NUnitEventTestCase fakeTestNode;
4242
private TestConverterForXml testConverterForXml;
43+
private IAdapterSettings settings;
4344

4445
[SetUp]
4546
public void SetUp()
4647
{
4748
fakeTestNode = new NUnitEventTestCase(FakeTestData.GetTestNode());
48-
var settings = Substitute.For<IAdapterSettings>();
49+
settings = Substitute.For<IAdapterSettings>();
4950
settings.ConsoleOut.Returns(0);
51+
settings.ShowStdout.Returns(CapturedOutputMode.None); // What ConsoleOut=0 maps to
5052
settings.UseTestNameInConsoleOutput.Returns(false);
5153
settings.CollectSourceInformation.Returns(true);
5254
testConverterForXml = new TestConverterForXml(new TestLogger(new MessageLoggerStub()), FakeTestData.AssemblyPath, settings);
@@ -181,6 +183,20 @@ public void CanMakeTestResultFromNUnitTestResult2(string output, string expected
181183
Assert.That(actualMessages, Is.EqualTo(expectedMessages));
182184
}
183185

186+
[Test]
187+
public void ProgressOutputIsKeptInResultWhenLiveOutputIsOff()
188+
{
189+
settings.ShowStdout.Returns(CapturedOutputMode.Failed);
190+
testConverterForXml.ConvertTestCase(fakeTestNode);
191+
var fakeResultNode = new NUnitTestEventTestCase(FakeTestData.GetResultNode());
192+
var progress = new NUnitTestEventTestOutput(XmlHelper.CreateXmlNode(
193+
"<test-output stream=\"Progress\" testid=\"0-1001\" testname=\"UnitTests.Test1\"><![CDATA[some text]]></test-output>"));
194+
195+
var testResult = testConverterForXml.GetVsTestResults(fakeResultNode, [progress]).TestResults[0];
196+
197+
Assert.That(testResult.Messages.Select(i => i.Category + ":" + i.Text), Is.EqualTo(new[] { "StdOutMsgs:some text" }));
198+
}
199+
184200
#region IncludeStackTraceForSuites tests
185201

186202
[Test]

‎src/NUnitTestAdapterTests/TestConverterTests.cs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class TestConverterTests
4141
{
4242
private NUnitDiscoveryTestCase fakeTestNode;
4343
private TestConverter testConverter;
44+
private IAdapterSettings settings;
4445

4546
[SetUp]
4647
public void SetUp()
@@ -53,8 +54,9 @@ public void SetUp()
5354
var tcs = DiscoveryConverter.ExtractTestCases(tf, xDoc.Root);
5455
Assert.That(tcs.Count(), Is.EqualTo(1), "Setup: More than one test case in fake data");
5556
fakeTestNode = tcs.Single();
56-
var settings = Substitute.For<IAdapterSettings>();
57+
settings = Substitute.For<IAdapterSettings>();
5758
settings.ConsoleOut.Returns(0);
59+
settings.ShowStdout.Returns(CapturedOutputMode.None); // What ConsoleOut=0 maps to
5860
settings.UseTestNameInConsoleOutput.Returns(false);
5961
settings.CollectSourceInformation.Returns(true);
6062
var discoveryConverter = Substitute.For<IDiscoveryConverter>();
@@ -198,6 +200,20 @@ public void CanMakeTestResultFromNUnitTestResult2(string output, string expected
198200
Assert.That(actualMessages, Is.EqualTo(expectedMessages));
199201
}
200202

203+
[Test]
204+
public void ProgressOutputIsKeptInResultWhenLiveOutputIsOff()
205+
{
206+
settings.ShowStdout.Returns(CapturedOutputMode.Failed);
207+
testConverter.ConvertTestCase(fakeTestNode);
208+
var fakeResultNode = new NUnitTestEventTestCase(FakeTestData.GetResultNode());
209+
var progress = new NUnitTestEventTestOutput(XmlHelper.CreateXmlNode(
210+
"<test-output stream=\"Progress\" testid=\"0-1001\" testname=\"UnitTests.Test1\"><![CDATA[some text]]></test-output>"));
211+
212+
var testResult = testConverter.GetVsTestResults(fakeResultNode, [progress]).TestResults[0];
213+
214+
Assert.That(testResult.Messages.Select(i => i.Category + ":" + i.Text), Is.EqualTo(new[] { "StdOutMsgs:some text" }));
215+
}
216+
201217
#region IncludeStackTraceForSuites tests
202218

203219
[Test]

0 commit comments

Comments
 (0)