From 691da8b0d262dfbd2a9f759cec5f488c5fa1d63b Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Wed, 15 Apr 2026 12:16:52 +0200 Subject: [PATCH] Re-run failed run-file tests with verbose logging --- .../CommandTests/Run/RunFileTestBase.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/dotnet.Tests/CommandTests/Run/RunFileTestBase.cs b/test/dotnet.Tests/CommandTests/Run/RunFileTestBase.cs index 4cc89bdd49a3..fe7e10525f29 100644 --- a/test/dotnet.Tests/CommandTests/Run/RunFileTestBase.cs +++ b/test/dotnet.Tests/CommandTests/Run/RunFileTestBase.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics; using Microsoft.Build.Framework; using Microsoft.Build.Logging.StructuredLogger; using Microsoft.DotNet.Cli.Commands; @@ -185,9 +186,17 @@ private protected void Build( command = customizeCommand(command); } - command.Execute() - .Should().Pass() - .And.HaveStdOut(prefix + expectedOutput); + var result = command.Execute(); + + var fullExpectedOutput = prefix + expectedOutput; + if (result.ExitCode != 0 || result.StdOut != fullExpectedOutput) + { + // Re-run with verbose logging for easier debugging of test failures. + command.WithEnvironmentVariable(CommandLoggingContext.Variables.Verbose, bool.TrueString).Execute(); + + result.Should().Pass().And.HaveStdOut(fullExpectedOutput); + throw new UnreachableException(); + } var binlogs = new DirectoryInfo(workDir ?? testInstance.Path) .EnumerateFiles("*.binlog", SearchOption.TopDirectoryOnly);