-
Notifications
You must be signed in to change notification settings - Fork 359
[fix] Fix tilde/exclamation characters corrupted in TerminalLogger test output #16046
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b857494
Fix tilde/exclamation characters corrupted in TerminalLogger output
nohwnd 667f4e7
test: add encoder/decoder round-trip tests for MSBuildLogger
nohwnd 4ad352f
Address review: add sync warning to Decode helper and cross-reference…
nohwnd 772650a
Use %-escaping instead of control chars for MSBuild logger encoding
nohwnd b0c0741
test: add e2e test for special char encoding in TerminalLogger output
nohwnd 269271b
Fix review comments: doc, boxing in Unescape
nohwnd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
106 changes: 106 additions & 0 deletions
106
test/vstest.console.UnitTests/Internal/MSBuildLoggerEncoderTests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using Microsoft.VisualStudio.TestPlatform.CommandLine.Internal; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| namespace vstest.console.UnitTests.Internal; | ||
|
|
||
| /// <summary> | ||
| /// Round-trip tests for MSBuildLogger Escape/Unescape. | ||
| /// </summary> | ||
| [TestClass] | ||
| public class MSBuildLoggerEncoderTests | ||
| { | ||
| [TestMethod] | ||
| public void FormatMessage_TildeCharsInMessage_SurviveRoundTrip() | ||
| { | ||
| var rawMessage = new string('~', 5); | ||
|
|
||
| var encoded = MSBuildLogger.FormatMessage("test-failed", rawMessage, "TestFile.cs", "42"); | ||
| var decoded = DecodeFirstField(encoded); | ||
|
|
||
| Assert.AreEqual(rawMessage, decoded); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FormatMessage_ExclamationCharsInMessage_SurviveRoundTrip() | ||
| { | ||
| var rawMessage = new string('!', 4); | ||
|
|
||
| var encoded = MSBuildLogger.FormatMessage("test-failed", rawMessage, "TestFile.cs", "42"); | ||
| var decoded = DecodeFirstField(encoded); | ||
|
|
||
| Assert.AreEqual(rawMessage, decoded); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FormatMessage_NewlinesInMessage_SurviveRoundTrip() | ||
| { | ||
| var rawMessage = "Assert failed.\r\n at MyTest()"; | ||
|
|
||
| var encoded = MSBuildLogger.FormatMessage("test-failed", rawMessage, "TestFile.cs", "42"); | ||
| var decoded = DecodeFirstField(encoded); | ||
|
|
||
| Assert.AreEqual(rawMessage, decoded); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FormatMessage_PipesInMessage_SurviveRoundTrip() | ||
| { | ||
| // 4 pipes would have been eaten by the old ||||→____ replacement. | ||
| var rawMessage = "expected: a]||||[b"; | ||
|
|
||
| var encoded = MSBuildLogger.FormatMessage("test-failed", rawMessage, "TestFile.cs", "42"); | ||
| var decoded = DecodeFirstField(encoded); | ||
|
|
||
| Assert.AreEqual(rawMessage, decoded); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FormatMessage_PercentInMessage_SurviveRoundTrip() | ||
| { | ||
| // The escape char itself must round-trip. | ||
| var rawMessage = "100% done"; | ||
|
|
||
| var encoded = MSBuildLogger.FormatMessage("test-failed", rawMessage, "TestFile.cs", "42"); | ||
| var decoded = DecodeFirstField(encoded); | ||
|
|
||
| Assert.AreEqual(rawMessage, decoded); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FormatMessage_PercentN_NotConfusedWithNewline() | ||
| { | ||
| // "%n" in user data must not become a newline after round-trip. | ||
| var rawMessage = "url-encoded: %n %r %p"; | ||
|
|
||
| var encoded = MSBuildLogger.FormatMessage("test-failed", rawMessage, "TestFile.cs", "42"); | ||
| var decoded = DecodeFirstField(encoded); | ||
|
|
||
| Assert.AreEqual(rawMessage, decoded); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FormatMessage_MultipleFields_AllFieldsSurviveRoundTrip() | ||
| { | ||
| var rawMessage = "Assert failed.\r\n at MyTest()"; | ||
| var rawFile = @"C:\src\TestFile.cs"; | ||
| var rawLine = "42"; | ||
|
|
||
| var encoded = MSBuildLogger.FormatMessage("test-failed", rawMessage, rawFile, rawLine); | ||
| var parts = encoded.Split(new[] { "||||" }, System.StringSplitOptions.None); | ||
| // parts[0] = empty, parts[1] = name, parts[2..] = fields | ||
| var decoded = new[] { MSBuildLogger.Unescape(parts[2]), MSBuildLogger.Unescape(parts[3]), MSBuildLogger.Unescape(parts[4]) }; | ||
|
|
||
| Assert.AreEqual(rawMessage, decoded[0]); | ||
| Assert.AreEqual(rawFile, decoded[1]); | ||
| Assert.AreEqual(rawLine, decoded[2]); | ||
| } | ||
|
|
||
| private static string? DecodeFirstField(string encoded) | ||
| { | ||
| var parts = encoded.Split(new[] { "||||" }, System.StringSplitOptions.None); | ||
| return MSBuildLogger.Unescape(parts[2]); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.