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);