Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -154,18 +153,6 @@ public AndConstraint<CommandResultAssertions> NotFileContains(string path, strin
return new AndConstraint<CommandResultAssertions>(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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using FluentAssertions;
using FluentAssertions.Execution;
using Microsoft.DotNet.Cli.Build.Framework;
using System;

namespace Microsoft.DotNet.CoreSetup.Test
{
Expand All @@ -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);
Expand Down
17 changes: 16 additions & 1 deletion src/installer/tests/TestUtils/CommandResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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_")).Select(i => $" {i.Key} = {i.Value}"))}
Exit Code: 0x{ExitCode:x}
StdOut:
{StdOut}
StdErr:
{StdErr}
""";
}
}
Loading