-
Notifications
You must be signed in to change notification settings - Fork 285
Fix escape character handling in test display names with multi-target framework optimization #6174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the added tests to be parameterized and test all the special characters we handle
Updated the tests to be parameterized with all 32 C0 control characters (U+0000-U+001F) that are handled by the |
- Enhanced NormalizeSpecialCharacters to handle all C0 control characters (U+0000-U+001F) - Added NormalizeTestDisplayName method to apply normalization to test names - Updated RenderTestCompleted to normalize display names when showing test results - Updated TestDiscovered and TestInProgress to normalize display names when storing - Added comprehensive tests for escape character normalization - Control characters like \n, \t, \r, ESC are now displayed as Unicode control pictures (␊, ␉, ␍, ␛) This prevents escape characters in test display names from breaking console output formatting. Co-authored-by: Evangelink <[email protected]>
Co-authored-by: Evangelink <[email protected]>
b4acefb
to
1913168
Compare
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Outdated
Show resolved
Hide resolved
...ests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jakub Jareš <[email protected]>
Co-authored-by: Jakub Jareš <[email protected]>
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: nohwnd <[email protected]>
Co-authored-by: nohwnd <[email protected]>
# Conflicts: # src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
Outdated
Show resolved
Hide resolved
… use char.IsControl Co-authored-by: nohwnd <[email protected]>
This PR fixes the issue where test display names containing escape characters (like
\n
,\t
, etc.) are interpreted as actual control characters in console output instead of being displayed literally, and includes performance optimization with multi-targeting framework support.Problem
When test display names contain escape characters, they break the console output formatting. As shown in the original issue, a test framework publishing test nodes with display names like
"Hello(\nWorld {i})"
causes the console output to be malformed:The newlines in test names are interpreted as actual line breaks, making the output difficult to read and potentially interfering with terminal functionality.
Solution
The fix replaces all C0 control characters (U+0000-U+001F) with their Unicode control picture equivalents:
\n
(newline) →␊
(U+240A)\t
(tab) →␉
(U+2409)\r
(carriage return) →␍
(U+240D)\x001B
(escape) →␛
(U+241B)\0
(null) →␀
(U+2400)After the fix, test names like
"Hello(\nWorld 0)"
display cleanly as"Hello(␊World 0)"
where the control character is visible but doesn't break the console layout.Multi-Targeting Framework Optimization
The
NormalizeSpecialCharacters
method has been optimized with conditional compilation to support the project's multi-targeting requirements (netstandard2.0, net6.0, net7.0, net8.0, net9.0):For .NET 8.0 and later:
SearchValues<char>
for O(1) detection of control charactersAsSpan().IndexOfAny()
for optimal performanceFor earlier frameworks (netstandard2.0, net6.0, net7.0):
char[]
arrays withIndexOfAny()
Both implementations provide:
StringBuilder
Implementation
Enhanced
NormalizeSpecialCharacters
method:Applied normalization in key locations:
RenderTestCompleted
- for test execution results outputTestDiscovered
- when storing discovered test namesTestInProgress
- when tracking active testsFiles Modified
src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs
test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs
Testing
✅ Added comprehensive parameterized unit tests covering all 32 C0 control characters (U+0000-U+001F)
✅ Manual verification confirms the fix resolves console formatting issues
✅ Existing tests preserved - simple test names without special characters remain unchanged
✅ Multi-targeting validation - optimization works across all supported framework versions
✅ Performance optimized - normalization only occurs when special characters are present with minimal overhead
Impact
Fixes #5133.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.