Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -76,7 +76,7 @@ internal static string GetDotNetSdkVersion()
}

internal static ProcessStartInfo BuildStartInfo(string customDotNetCliPath, string workingDirectory, string arguments,
IReadOnlyList<EnvironmentVariable> environmentVariables = null, bool redirectStandardInput = false)
IReadOnlyList<EnvironmentVariable> environmentVariables = null, bool redirectStandardInput = false, bool redirectStandardError = true)
{
const string dotnetMultiLevelLookupEnvVarName = "DOTNET_MULTILEVEL_LOOKUP";

Expand All @@ -88,12 +88,16 @@ internal static ProcessStartInfo BuildStartInfo(string customDotNetCliPath, stri
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardError = redirectStandardError,
RedirectStandardInput = redirectStandardInput,
StandardErrorEncoding = Encoding.UTF8,
StandardOutputEncoding = Encoding.UTF8,
};

if (redirectStandardError) // StandardErrorEncoding is only supported when standard error is redirected
{
startInfo.StandardErrorEncoding = Encoding.UTF8;
}

if (environmentVariables != null)
foreach (var environmentVariable in environmentVariables)
startInfo.EnvironmentVariables[environmentVariable.Key] = environmentVariable.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ private ExecuteResult Execute(BenchmarkCase benchmarkCase,
CustomDotNetCliPath,
artifactsPaths.BinariesDirectoryPath,
$"{executableName.Escape()} {benchmarkId.ToArguments()}",
redirectStandardInput: true);
redirectStandardInput: true,
redirectStandardError: false); // #1629

startInfo.SetEnvironmentVariables(benchmarkCase, resolver);

Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Toolchains/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private ProcessStartInfo CreateStartInfo(BenchmarkCase benchmarkCase, ArtifactsP
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true,
RedirectStandardError = true,
RedirectStandardError = false, // #1629
CreateNoWindow = true,
WorkingDirectory = null // by default it's null
};
Expand Down
43 changes: 43 additions & 0 deletions tests/BenchmarkDotNet.IntegrationTests/StandardErrorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Tests.Loggers;
using System;
using Xunit;
using Xunit.Abstractions;

namespace BenchmarkDotNet.IntegrationTests
{
public class StandardErrorTests : BenchmarkTestExecutor
{
private const string ErrorMessage = "ErrorMessage";

public StandardErrorTests(ITestOutputHelper output) : base(output)
{
}

[Fact]
public void BenchmarkCanWriteToStandardError() => CanExecute<WritingToStandardError>();

public class WritingToStandardError
{
[Benchmark]
public void Write() => Console.Error.Write(new string('a', 10_000)); // the text needs to be big enough to hit the deadlock
}

[Fact]
public void ExceptionMessageIsNotLost()
{
var logger = new OutputLogger(Output);
var config = CreateSimpleConfig(logger);

CanExecute<ThrowingException>(config, fullValidation: false);

Assert.Contains(ErrorMessage, logger.GetLog());
}

public class ThrowingException
{
[Benchmark]
public void Write() => throw new Exception(ErrorMessage);
}
}
}