Add --ansi option to force Ansi output
Summary
Add the complement to --no-ansi, that forces --ansi output, even if output is redirected.
Background and Motivation
When running the tests from a PowerShell script, I may want to display the test output but not have it as output from the PowerShell function.
mytest.exe | Out-Host
if ($LASTEXITCODE){
throw "test failed"
}
This removes all coloring from the output, even though it's logically equivalent to passing it directly to the terminal for display.
Proposed Feature
Add --ansi parameter that forces ansi output, regardless of redirection. Let the user decide.
Alternative Designs
Always output ansi unless the user explicitly uses --no-ansi.
That has the drawback of potentially breaking existing scripts.
It's probably a quick and easy update so I don't see why not! Thanks for the suggestion @powercode.
cc @mariam-abdulla as it might require some porting to dotnet test.
Forcing ANSI should only be done if you know if you're running inside of a terminal that can handle it. The standard console host (CONHOST), for example, does not support ANSI:
@bradwilson I agree and that's why this is not the default behavior. The default is trying to auto-detect if we can use ansi or not. We then have flags to force using or not using ANSI.
moving to 3.10, I think we need a better design for this, having --ansi and --no-ansi, leads to many combinations with similar options like --no-color and so on.
@nohwnd what about --ansi <auto|enable|disable>, --color <enable|disable> (this one may need some deps on ansi?).
I think gradle (java) had something interesting where cli has only part of the commands, for extra granularity you needed the config file. Maybe a similar design could help so we don't have to support it all as CLI.
FWIW, xUnit.net uses on and off for switches in MTP. https://github.com/xunit/xunit/blob/main/src/xunit.v3.runner.inproc.console/TestingPlatform/CommandLineOptionsProvider.cs
yes those are all good options, terminal logger does something similar with handling auto, and on/off true/false 0/1.
Then it is just question of deprecating no-ansi no-color or not, but we cannot do that right away anyway.
@nohwnd I moved to "Future" milestone. But feel free to move to "2.0.0" as a breaking change (and if you did, please add it to https://github.com/microsoft/testfx/issues/5762 and add the "Breaking !!" label)
Given the v2 was missed, what about introducing the new API and deprecating the old ones (but keeping them working)? It feels like something we can implement quickly.