Add --ansi <auto|on|off> CLI option for explicit ANSI control (#5081)#8493
Merged
Conversation
Implements the user-facing --ansi option with auto/on/off values (plus true|enable|1 / false|disable|0 aliases). The new option fulfils issue #5081 by mapping --ansi on to the existing internal AnsiMode.ForceAnsi, which emits ANSI escape codes (including cursor movement) even when stdout is redirected (for example, in 'mytest.exe | Out-Host' pipelines). - New internal CommandLineOptionArgumentValidator helper exposes IsValidBooleanArgument / IsValidBooleanAutoArgument / IsOnValue / IsOffValue / IsAutoValue for reuse by future on|off|auto options. - --no-ansi continues to work unchanged. When both --ansi and --no-ansi are specified, --ansi wins (documented in the help text). - Updated MTP and MSTest acceptance test --help and --info expectations to include the new option. - Added unit tests for the validator and the provider plus integration tests verifying the on/off/auto behavior, alias handling, and invalid argument rejection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an explicit --ansi <auto|on|off> CLI option to the Terminal test reporter (Microsoft.Testing.Platform), including parsing/validation helpers, localized help/error strings, and updated acceptance/unit tests to cover the new behavior and help output.
Changes:
- Introduces
--ansi <auto|on|off>(withtrue|enable|1andfalse|disable|0aliases) and wires it toAnsiMode.ForceAnsi/NoAnsi/auto detection. - Adds
CommandLineOptionArgumentValidatorhelper for reusable boolean/boolean+auto argument validation. - Updates localized resources and
--help/--infoacceptance expectations; adds new unit + acceptance coverage for the new option.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterCommandLineOptionsProviderTests.cs | Unit tests for --ansi option arity/visibility and accepted/rejected argument values. |
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineOptionArgumentValidatorTests.cs | Unit tests for shared on/off/auto argument validation helper. |
| test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs | Updates MSTest host --help expectations to include --ansi. |
| test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs | Updates MTP host --help/--info expectations to include --ansi option details. |
| test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoAllExtensionsTests.cs | Updates “all extensions” --help/--info expectations to include --ansi. |
| test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/AnsiOptionTests.cs | New acceptance tests covering --ansi on/off/auto behavior, precedence, and invalid argument handling. |
| src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx | Adds localized resource strings for --ansi description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf | Regenerated localization entry for new --ansi strings (Czech). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf | Regenerated localization entry for new --ansi strings (German). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf | Regenerated localization entry for new --ansi strings (Spanish). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf | Regenerated localization entry for new --ansi strings (French). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf | Regenerated localization entry for new --ansi strings (Italian). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf | Regenerated localization entry for new --ansi strings (Japanese). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf | Regenerated localization entry for new --ansi strings (Korean). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf | Regenerated localization entry for new --ansi strings (Polish). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf | Regenerated localization entry for new --ansi strings (Portuguese - Brazil). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf | Regenerated localization entry for new --ansi strings (Russian). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf | Regenerated localization entry for new --ansi strings (Turkish). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf | Regenerated localization entry for new --ansi strings (Chinese - Simplified). |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf | Regenerated localization entry for new --ansi strings (Chinese - Traditional). |
| src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporterCommandLineOptionsProvider.cs | Adds --ansi option definition + argument validation using the shared validator helper. |
| src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs | Implements --ansi precedence rules and maps values to AnsiMode selection. |
| src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionArgumentValidator.cs | New shared helper for on/off/auto argument validation and alias handling. |
Copilot's findings
- Files reviewed: 23/23 changed files
- Comments generated: 2
- AnsiOption_MissingArgument_FailsCommandLineValidation: assert the actual arity-validation message (CommandLineOptionsValidator rejects --ansi without a value before per-occurrence validation runs, so the custom TerminalAnsiOptionInvalidArgument text is not used here). - AnsiOption_Auto_OverridesNoAnsi_AndFollowsEnvironmentDetection: rewrite to prove the override deterministically by forcing GITHUB_ACTIONS=true and clearing known LLM env vars so '--ansi auto' maps to SimpleAnsi and emits ESC, demonstrating it won over the auto-injected --no-ansi. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the user-facing
--ansioption withauto/on/offvalues (plustrue|enable|1/false|disable|0aliases). The new option fulfils issue #5081 by mapping--ansi onto the existing internalAnsiMode.ForceAnsi, which emits ANSI escape codes (including cursor movement) even when stdout is redirected (for example, inmytest.exe | Out-Hostpipelines).Closes #5081.
What
--ansi <auto|on|off>option on the Terminal test reporter extension.on/true/enable/1andoff/false/disable/0; case-insensitive; invalid values are rejected with a localized message.--ansiand--no-ansiare specified,--ansiwins (documented in the help text and verified by integration tests).--ansi autoexplicitly opts back into auto-detection and overrides a sibling--no-ansi.CommandLineOptionArgumentValidatorhelper exposesIsValidBooleanArgument/IsValidBooleanAutoArgument/IsOnValue/IsOffValue/IsAutoValueso futureon|off|autooptions can share the same parsing.Tests
CommandLineOptionArgumentValidatorTests,TerminalTestReporterCommandLineOptionsProviderTests).AnsiOptionTestsexercising on/off/auto behavior, alias handling, precedence vs--no-ansi, and invalid-argument rejection.--help/--infoexpectations to include the new option.Notes
This was previously bundled into #8461 (TestRun.Current / PlannedTests). Split out per code-review request.