|
16 | 16 | using Xunit;
|
17 | 17 | using Xunit.Abstractions;
|
18 | 18 | using Xunit.Sdk;
|
| 19 | +using Microsoft.Build.Logging.StructuredLogger; |
19 | 20 |
|
20 | 21 | #nullable enable
|
21 | 22 |
|
@@ -176,9 +177,48 @@ public BuildTestBase(ProjectProviderBase providerBase, ITestOutputHelper output,
|
176 | 177 | else if (res.ExitCode == 0)
|
177 | 178 | throw new XunitException($"Build should have failed, but it didn't. Process exited with exitCode : {res.ExitCode}");
|
178 | 179 |
|
| 180 | + // Ensure we got all output. |
| 181 | + string[] successMessages = ["Build succeeded"]; |
| 182 | + string[] errorMessages = ["Build failed", "Build FAILED", "Restore failed", "Stopping the build"]; |
| 183 | + if ((res.ExitCode == 0 && successMessages.All(m => !res.Output.Contains(m))) || (res.ExitCode != 0 && errorMessages.All(m => !res.Output.Contains(m)))) |
| 184 | + { |
| 185 | + _testOutput.WriteLine("Replacing dotnet process output with messages from binlog"); |
| 186 | + |
| 187 | + var outputBuilder = new StringBuilder(); |
| 188 | + var buildRoot = BinaryLog.ReadBuild(logFilePath); |
| 189 | + buildRoot.VisitAllChildren<TextNode>(m => |
| 190 | + { |
| 191 | + if (m is Message || m is Error || m is Warning) |
| 192 | + { |
| 193 | + var context = GetBinlogMessageContext(m); |
| 194 | + outputBuilder.AppendLine($"{context}{m.Title}"); |
| 195 | + } |
| 196 | + }); |
| 197 | + |
| 198 | + res = new CommandResult(res.StartInfo, res.ExitCode, outputBuilder.ToString()); |
| 199 | + } |
| 200 | + |
179 | 201 | return (res, logFilePath);
|
180 | 202 | }
|
181 | 203 |
|
| 204 | + private string GetBinlogMessageContext(TextNode node) |
| 205 | + { |
| 206 | + var currentNode = node; |
| 207 | + while (currentNode != null) |
| 208 | + { |
| 209 | + if (currentNode is Error error) |
| 210 | + { |
| 211 | + return $"{error.File}({error.LineNumber},{error.ColumnNumber}): error {error.Code}: "; |
| 212 | + } |
| 213 | + else if (currentNode is Warning warning) |
| 214 | + { |
| 215 | + return $"{warning.File}({warning.LineNumber},{warning.ColumnNumber}): warning {warning.Code}: "; |
| 216 | + } |
| 217 | + currentNode = currentNode.Parent as TextNode; |
| 218 | + } |
| 219 | + return string.Empty; |
| 220 | + } |
| 221 | + |
182 | 222 | protected string RunAndTestWasmApp(BuildArgs buildArgs,
|
183 | 223 | RunHost host,
|
184 | 224 | string id,
|
|
0 commit comments