Skip to content
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

Fix bug: Exec task trims leading whitespace in ConsoleToMsBuild #9722

Merged
merged 6 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Tasks.UnitTests/Exec_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,25 @@ public void EndToEndMultilineExec_EscapeSpecialCharacters()
}
}
}

[Fact]
public void ConsoleOutputDoesNotTrimLeadingWhitespace()
{
string lineWithLeadingWhitespace = " line with some leading whitespace";

using (var env = TestEnvironment.Create(_output))
{
var textFilePath = env.CreateFile("leading-whitespace.txt", lineWithLeadingWhitespace).Path;
Exec exec = PrepareExec(NativeMethodsShared.IsWindows ? $"type {textFilePath}" : $"cat {textFilePath}");
exec.ConsoleToMSBuild = true;

bool result = exec.Execute();

result.ShouldBeTrue();
exec.ConsoleOutput.Length.ShouldBe(1);
exec.ConsoleOutput[0].ItemSpec.ShouldBe(lineWithLeadingWhitespace);
}
}
}

internal sealed class ExecWrapper : Exec
Expand Down
5 changes: 4 additions & 1 deletion src/Tasks/Exec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport

if (ConsoleToMSBuild)
{
string trimmedTextLine = singleLine.Trim();
string trimmedTextLine = ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10) ?
singleLine.TrimEnd() :
singleLine.Trim();

if (trimmedTextLine.Length > 0)
{
// The lines read may be unescaped, so we need to escape them
Expand Down