Skip to content

Restore the original console writer after benchmarks run - #196

Merged
si618 merged 1 commit into
mainfrom
fix/restore-console-out
Oct 18, 2026
Merged

si618 merged 1 commit into
mainfrom
fix/restore-console-out

Conversation

@si618

@si618 si618 commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Summary

BenchmarkRunner.BuildSummaries mutes the console with Console.SetOut(TextWriter.Null) while the spinner runs. It then called Console.SetOut(Console.Out), but Console.Out was already the null writer at that point, so plain Console output stayed muted afterwards.

The method now saves the original writer and restores it in a finally block, so a benchmark that throws doesn't leave the console muted either. Spectre.Console output wasn't affected, because it keeps its own writer.

Test plan

  • dotnet build -c Release and dotnet format --verify-no-changes pass.
  • benchmark FizzBuzz --csharp prints its summary table, and BenchmarkDotNet's log stays hidden while the spinner runs.

Console.SetOut(Console.Out) ran after Console.Out was already TextWriter.Null, so it
restored nothing. Save the writer first, and restore it in a finally block.
@si618
si618 merged commit 1c30307 into main Oct 18, 2026
2 checks passed
@si618
si618 deleted the fix/restore-console-out branch October 18, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant