Skip to content

Commit 9a28018

Browse files
committed
Add some diagnostics with ITestOutputHelper when running the TestApp exe
1 parent a812ab1 commit 9a28018

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

test/Serilog.Settings.Configuration.Tests/PublishSingleFileTests.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
using System.Text;
1+
using System.Diagnostics;
2+
using System.Text;
23
using CliWrap;
34
using FluentAssertions;
45
using FluentAssertions.Execution;
6+
using Xunit.Abstractions;
57

68
namespace Serilog.Settings.Configuration.Tests;
79

810
public sealed class PublishSingleFileTests : IDisposable, IClassFixture<TestApp>
911
{
12+
readonly ITestOutputHelper _outputHelper;
1013
readonly TestApp _testApp;
1114
readonly AssertionScope _scope;
1215

13-
public PublishSingleFileTests(TestApp testApp)
16+
public PublishSingleFileTests(ITestOutputHelper outputHelper, TestApp testApp)
1417
{
18+
_outputHelper = outputHelper;
1519
_testApp = testApp;
1620
_scope = new AssertionScope();
1721
}
@@ -93,21 +97,34 @@ public async Task RunTestApp_ConsoleAndThread(bool singleFile, [CombinatorialVal
9397

9498
async Task<(string StdOut, string StdErr)> RunTestAppInternalAsync(bool singleExe, params string[] args)
9599
{
96-
var stdout = new StringBuilder();
97-
var stderr = new StringBuilder();
98-
var testAppPath = singleExe ? _testApp.SingleFileExe.FullName : _testApp.StandardExe.FullName;
99-
var result = await Cli.Wrap(testAppPath)
100+
var stdOutBuilder = new StringBuilder();
101+
var stdErrBuilder = new StringBuilder();
102+
103+
var command = Cli.Wrap(singleExe ? _testApp.SingleFileExe.FullName : _testApp.StandardExe.FullName)
100104
.WithArguments(args)
101105
.WithValidation(CommandResultValidation.None)
102-
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout))
103-
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stderr))
104-
.ExecuteAsync();
106+
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuilder))
107+
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuilder));
108+
109+
_outputHelper.WriteLine(command.ToString());
110+
111+
var stopwatch = Stopwatch.StartNew();
112+
var result = await command.ExecuteAsync();
113+
var executionTime = stopwatch.ElapsedMilliseconds;
114+
115+
var stdOut = stdOutBuilder.ToString().Trim();
116+
var stdErr = stdErrBuilder.ToString().Trim();
117+
118+
_outputHelper.WriteLine($"Executed in {executionTime} ms");
119+
_outputHelper.WriteLine(stdOut.Length > 0 ? $"stdout: {stdOut}" : "nothing on stdout");
120+
_outputHelper.WriteLine(stdErr.Length > 0 ? $"stderr: {stdErr}" : "nothing on stderr");
121+
_outputHelper.WriteLine("");
105122

106123
if (result.ExitCode != 0)
107124
{
108-
throw new Exception($"An unexpected exception has occurred while running {testAppPath}. {stderr}");
125+
throw new Exception($"An unexpected exception has occurred while running {command}. {stdErr}".Trim());
109126
}
110127

111-
return (stdout.ToString().Trim(), stderr.ToString().Trim());
128+
return (stdOut, stdErr);
112129
}
113130
}

0 commit comments

Comments
 (0)