diff --git a/src/installer/tests/TestUtils/Assertions/CommandResultAssertions.cs b/src/installer/tests/TestUtils/Assertions/CommandResultAssertions.cs index b2195ce1973772..f2331aec6d69a2 100644 --- a/src/installer/tests/TestUtils/Assertions/CommandResultAssertions.cs +++ b/src/installer/tests/TestUtils/Assertions/CommandResultAssertions.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Linq; using System.Text.RegularExpressions; using FluentAssertions; using FluentAssertions.Execution; @@ -154,18 +153,6 @@ public AndConstraint NotFileContains(string path, strin return new AndConstraint(this); } - public string GetDiagnosticsInfo() - => $""" - - File Name: {Result.StartInfo.FileName} - Arguments: {Result.StartInfo.Arguments} - Environment: - {string.Join(Environment.NewLine, Result.StartInfo.Environment.Where(i => i.Key.StartsWith(Constants.DotnetRoot.EnvironmentVariable)).Select(i => $" {i.Key} = {i.Value}"))} - Exit Code: 0x{Result.ExitCode:x} - StdOut: - {Result.StdOut} - StdErr: - {Result.StdErr} - """; + public string GetDiagnosticsInfo() => Result.GetDiagnosticsInfo(); } } diff --git a/src/installer/tests/TestUtils/Assertions/CommandResultExtensions.cs b/src/installer/tests/TestUtils/Assertions/CommandResultExtensions.cs index d0e0175060b893..7ca15639b7dc2d 100644 --- a/src/installer/tests/TestUtils/Assertions/CommandResultExtensions.cs +++ b/src/installer/tests/TestUtils/Assertions/CommandResultExtensions.cs @@ -4,7 +4,6 @@ using FluentAssertions; using FluentAssertions.Execution; using Microsoft.DotNet.Cli.Build.Framework; -using System; namespace Microsoft.DotNet.CoreSetup.Test { @@ -20,10 +19,7 @@ public static CommandResult StdErrAfter(this CommandResult commandResult, string int i = commandResult.StdErr.IndexOf(pattern); i.Should().BeGreaterThanOrEqualTo( 0, - "Trying to filter StdErr after '{0}', but such string can't be found in the StdErr.{1}{2}", - pattern, - Environment.NewLine, - commandResult.StdErr); + $"'{pattern}' should be in StdErr - cannot filter StdErr to after expected string.{commandResult.GetDiagnosticsInfo()}"); string filteredStdErr = commandResult.StdErr.Substring(i); return new CommandResult(commandResult.StartInfo, commandResult.ProcessId, commandResult.ExitCode, commandResult.StdOut, filteredStdErr); diff --git a/src/installer/tests/TestUtils/CommandResult.cs b/src/installer/tests/TestUtils/CommandResult.cs index ac2f959835fca0..5e850ab4220fa2 100644 --- a/src/installer/tests/TestUtils/CommandResult.cs +++ b/src/installer/tests/TestUtils/CommandResult.cs @@ -2,8 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Text; using System.Diagnostics; +using System.Linq; +using System.Text; namespace Microsoft.DotNet.Cli.Build.Framework { @@ -23,5 +24,19 @@ public CommandResult(ProcessStartInfo startInfo, int pid, int exitCode, string s StdOut = stdOut; StdErr = stdErr; } + + internal string GetDiagnosticsInfo() + => $""" + + File Name: {StartInfo.FileName} + Arguments: {StartInfo.Arguments} + Environment: + {string.Join(Environment.NewLine, StartInfo.Environment.Where(i => i.Key.StartsWith("DOTNET_", OperatingSystem.IsWindows() ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)).Select(i => $" {i.Key} = {i.Value}"))} + Exit Code: 0x{ExitCode:x} + StdOut: + {StdOut} + StdErr: + {StdErr} + """; } }