|
1 |
| -using System.Text; |
| 1 | +using System.Diagnostics; |
| 2 | +using System.Text; |
2 | 3 | using CliWrap;
|
3 | 4 | using FluentAssertions;
|
4 | 5 | using FluentAssertions.Execution;
|
| 6 | +using Xunit.Abstractions; |
5 | 7 |
|
6 | 8 | namespace Serilog.Settings.Configuration.Tests;
|
7 | 9 |
|
8 | 10 | public sealed class PublishSingleFileTests : IDisposable, IClassFixture<TestApp>
|
9 | 11 | {
|
| 12 | + readonly ITestOutputHelper _outputHelper; |
10 | 13 | readonly TestApp _testApp;
|
11 | 14 | readonly AssertionScope _scope;
|
12 | 15 |
|
13 |
| - public PublishSingleFileTests(TestApp testApp) |
| 16 | + public PublishSingleFileTests(ITestOutputHelper outputHelper, TestApp testApp) |
14 | 17 | {
|
| 18 | + _outputHelper = outputHelper; |
15 | 19 | _testApp = testApp;
|
16 | 20 | _scope = new AssertionScope();
|
17 | 21 | }
|
@@ -93,21 +97,34 @@ public async Task RunTestApp_ConsoleAndThread(bool singleFile, [CombinatorialVal
|
93 | 97 |
|
94 | 98 | async Task<(string StdOut, string StdErr)> RunTestAppInternalAsync(bool singleExe, params string[] args)
|
95 | 99 | {
|
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) |
100 | 104 | .WithArguments(args)
|
101 | 105 | .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(""); |
105 | 122 |
|
106 | 123 | if (result.ExitCode != 0)
|
107 | 124 | {
|
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()); |
109 | 126 | }
|
110 | 127 |
|
111 |
| - return (stdout.ToString().Trim(), stderr.ToString().Trim()); |
| 128 | + return (stdOut, stdErr); |
112 | 129 | }
|
113 | 130 | }
|
0 commit comments