From 685b41d7ae73d5b8f315f05be0103ac862d4f214 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Thu, 8 Feb 2024 15:03:28 +0100 Subject: [PATCH 1/6] fix bug Exec task trims leading whitespace in ConsoleToMsBuild --- .../Exec_Tests.Attachments/leading-whitespace.txt | 1 + src/Tasks.UnitTests/Exec_Tests.cs | 14 ++++++++++++++ .../Microsoft.Build.Tasks.UnitTests.csproj | 3 +++ src/Tasks/Exec.cs | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/Tasks.UnitTests/Exec_Tests.Attachments/leading-whitespace.txt diff --git a/src/Tasks.UnitTests/Exec_Tests.Attachments/leading-whitespace.txt b/src/Tasks.UnitTests/Exec_Tests.Attachments/leading-whitespace.txt new file mode 100644 index 00000000000..dd86aebfa84 --- /dev/null +++ b/src/Tasks.UnitTests/Exec_Tests.Attachments/leading-whitespace.txt @@ -0,0 +1 @@ + line with some leading whitespace \ No newline at end of file diff --git a/src/Tasks.UnitTests/Exec_Tests.cs b/src/Tasks.UnitTests/Exec_Tests.cs index 088e68c81b0..dce126c5b19 100644 --- a/src/Tasks.UnitTests/Exec_Tests.cs +++ b/src/Tasks.UnitTests/Exec_Tests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Reflection; using System.Text; using Microsoft.Build.Evaluation; @@ -1033,6 +1034,19 @@ public void EndToEndMultilineExec_EscapeSpecialCharacters() } } } + + [Fact] + public void ConsoleOutputDoesNotTrimLeadingWhitespace() + { + Exec exec = PrepareExec("type .\\Exec_Tests.Attachments\\leading-whitespace.txt"); + exec.ConsoleToMSBuild = true; + + bool result = exec.Execute(); + + result.ShouldBeTrue(); + exec.ConsoleOutput.Length.ShouldBe(1); + exec.ConsoleOutput[0].ItemSpec.ShouldBe(" line with some leading whitespace"); + } } internal sealed class ExecWrapper : Exec diff --git a/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj b/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj index 6b3d539cacf..5881a46cc33 100644 --- a/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj +++ b/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj @@ -175,5 +175,8 @@ PreserveNewest + + PreserveNewest + diff --git a/src/Tasks/Exec.cs b/src/Tasks/Exec.cs index 9faaa688874..95ef57a6837 100644 --- a/src/Tasks/Exec.cs +++ b/src/Tasks/Exec.cs @@ -410,7 +410,7 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport if (ConsoleToMSBuild) { - string trimmedTextLine = singleLine.Trim(); + string trimmedTextLine = singleLine.TrimEnd(); if (trimmedTextLine.Length > 0) { // The lines read may be unescaped, so we need to escape them From d72bf0f1234c8a388584a3a26cec256a4433f82e Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Thu, 8 Feb 2024 15:08:29 +0100 Subject: [PATCH 2/6] remove unnecessary using --- src/Tasks.UnitTests/Exec_Tests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Tasks.UnitTests/Exec_Tests.cs b/src/Tasks.UnitTests/Exec_Tests.cs index dce126c5b19..82d95a53f2b 100644 --- a/src/Tasks.UnitTests/Exec_Tests.cs +++ b/src/Tasks.UnitTests/Exec_Tests.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Reflection; using System.Text; using Microsoft.Build.Evaluation; From 6b57335742911523a22f0e487660fe18a6745b3c Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Thu, 8 Feb 2024 16:42:10 +0100 Subject: [PATCH 3/6] create test file with TeestEnvironment --- .../leading-whitespace.txt | 1 - src/Tasks.UnitTests/Exec_Tests.cs | 18 ++++++++++++------ .../Microsoft.Build.Tasks.UnitTests.csproj | 6 ------ 3 files changed, 12 insertions(+), 13 deletions(-) delete mode 100644 src/Tasks.UnitTests/Exec_Tests.Attachments/leading-whitespace.txt diff --git a/src/Tasks.UnitTests/Exec_Tests.Attachments/leading-whitespace.txt b/src/Tasks.UnitTests/Exec_Tests.Attachments/leading-whitespace.txt deleted file mode 100644 index dd86aebfa84..00000000000 --- a/src/Tasks.UnitTests/Exec_Tests.Attachments/leading-whitespace.txt +++ /dev/null @@ -1 +0,0 @@ - line with some leading whitespace \ No newline at end of file diff --git a/src/Tasks.UnitTests/Exec_Tests.cs b/src/Tasks.UnitTests/Exec_Tests.cs index 82d95a53f2b..1584e9bce58 100644 --- a/src/Tasks.UnitTests/Exec_Tests.cs +++ b/src/Tasks.UnitTests/Exec_Tests.cs @@ -1037,14 +1037,20 @@ public void EndToEndMultilineExec_EscapeSpecialCharacters() [Fact] public void ConsoleOutputDoesNotTrimLeadingWhitespace() { - Exec exec = PrepareExec("type .\\Exec_Tests.Attachments\\leading-whitespace.txt"); - exec.ConsoleToMSBuild = true; + string lineWithLeadingWhitespace = " line with some leading whitespace"; - bool result = exec.Execute(); + using (var env = TestEnvironment.Create(_output)) + { + var textFilePath = env.CreateFile("leading-whitespace.txt", lineWithLeadingWhitespace).Path; + Exec exec = PrepareExec($"type {textFilePath}"); + exec.ConsoleToMSBuild = true; - result.ShouldBeTrue(); - exec.ConsoleOutput.Length.ShouldBe(1); - exec.ConsoleOutput[0].ItemSpec.ShouldBe(" line with some leading whitespace"); + bool result = exec.Execute(); + + result.ShouldBeTrue(); + exec.ConsoleOutput.Length.ShouldBe(1); + exec.ConsoleOutput[0].ItemSpec.ShouldBe(lineWithLeadingWhitespace); + } } } diff --git a/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj b/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj index 5881a46cc33..f089a95a3cf 100644 --- a/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj +++ b/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj @@ -172,11 +172,5 @@ PreserveNewest - - PreserveNewest - - - PreserveNewest - From 7c73e9bde22010aeb5662696b272aff5b3a0d587 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Thu, 8 Feb 2024 16:43:25 +0100 Subject: [PATCH 4/6] small fix --- src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj b/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj index f089a95a3cf..6b3d539cacf 100644 --- a/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj +++ b/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj @@ -172,5 +172,8 @@ PreserveNewest + + PreserveNewest + From 40b28318d4ac097f8613d4fd39628c8435b4e2a5 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Fri, 9 Feb 2024 09:50:54 +0100 Subject: [PATCH 5/6] fix test for linux and macos --- src/Tasks.UnitTests/Exec_Tests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tasks.UnitTests/Exec_Tests.cs b/src/Tasks.UnitTests/Exec_Tests.cs index 1584e9bce58..12e27c9f2de 100644 --- a/src/Tasks.UnitTests/Exec_Tests.cs +++ b/src/Tasks.UnitTests/Exec_Tests.cs @@ -1042,7 +1042,7 @@ public void ConsoleOutputDoesNotTrimLeadingWhitespace() using (var env = TestEnvironment.Create(_output)) { var textFilePath = env.CreateFile("leading-whitespace.txt", lineWithLeadingWhitespace).Path; - Exec exec = PrepareExec($"type {textFilePath}"); + Exec exec = PrepareExec(NativeMethodsShared.IsWindows ? $"type {textFilePath}" : $"cat {textFilePath}"); exec.ConsoleToMSBuild = true; bool result = exec.Execute(); From 3e3ee19d5c2afd007ce7cf2b70837b672f6bdceb Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Fri, 9 Feb 2024 14:33:23 +0100 Subject: [PATCH 6/6] apply change wave --- src/Tasks/Exec.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Tasks/Exec.cs b/src/Tasks/Exec.cs index 95ef57a6837..64dcc470f86 100644 --- a/src/Tasks/Exec.cs +++ b/src/Tasks/Exec.cs @@ -410,7 +410,10 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport if (ConsoleToMSBuild) { - string trimmedTextLine = singleLine.TrimEnd(); + 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