From fbc9a4f72412a26f1e609d035d7355f675727ee2 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:26:08 +0100 Subject: [PATCH 01/12] make TL respect verbosity --- .../TerminalLoggerConfiguration_Tests.cs | 15 +- ...bosity_FailedWithErrors.Linux.verified.txt | 9 + ...erbosity_FailedWithErrors.OSX.verified.txt | 8 + ...sity_FailedWithErrors.Windows.verified.txt | 9 + ...bosity_FailedWithErrors.Linux.verified.txt | 9 + ...erbosity_FailedWithErrors.OSX.verified.txt | 8 + ...sity_FailedWithErrors.Windows.verified.txt | 9 + ...bosity_FailedWithErrors.Linux.verified.txt | 8 + ...erbosity_FailedWithErrors.OSX.verified.txt | 7 + ...sity_FailedWithErrors.Windows.verified.txt | 8 + ...bosity_FailedWithErrors.Linux.verified.txt | 8 + ...erbosity_FailedWithErrors.OSX.verified.txt | 7 + ...sity_FailedWithErrors.Windows.verified.txt | 8 + ...bosity_FailedWithErrors.Linux.verified.txt | 3 + ...erbosity_FailedWithErrors.OSX.verified.txt | 2 + ...sity_FailedWithErrors.Windows.verified.txt | 3 + ...ormalVerbosity_Succeded.Linux.verified.txt | 6 + ...yNormalVerbosity_Succeded.OSX.verified.txt | 5 + ...malVerbosity_Succeded.Windows.verified.txt | 6 + ...QuietVerbosity_Succeded.Linux.verified.txt | 1 + ...ryQuietVerbosity_Succeded.OSX.verified.txt | 1 + ...ietVerbosity_Succeded.Windows.verified.txt | 1 + src/MSBuild.UnitTests/TerminalLogger_Tests.cs | 142 +++++- src/MSBuild/TerminalLogger/MessageSeverity.cs | 2 +- src/MSBuild/TerminalLogger/TerminalLogger.cs | 415 ++++++++++-------- src/MSBuild/XMake.cs | 5 +- 26 files changed, 512 insertions(+), 193 deletions(-) create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Linux.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.OSX.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Windows.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Linux.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.OSX.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Windows.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Linux.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.OSX.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Windows.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Linux.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.OSX.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Windows.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.Linux.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.OSX.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.Windows.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Linux.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.OSX.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Windows.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Linux.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Windows.verified.txt diff --git a/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs b/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs index 6266cb6e4c7..3860daa0f5a 100644 --- a/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs +++ b/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs @@ -23,6 +23,7 @@ public class TerminalLoggerConfiguration_Tests : IDisposable private readonly TestEnvironment _env; private readonly string _cmd; + private readonly string _cmd2; public TerminalLoggerConfiguration_Tests(ITestOutputHelper output) { @@ -40,7 +41,19 @@ public TerminalLoggerConfiguration_Tests(ITestOutputHelper output) """); - _cmd = $"{projectFile.Path} -target:Hello -logger:{typeof(MockLogger).FullName},{typeof(MockLogger).Assembly.Location};ReportTelemetry"; + TransientTestFile projectFile2 = _env.CreateFile(logFolder, "myProj2.proj", $""" + + + + + + + + + + """); + + _cmd2 = $"{projectFile2.Path} -target:Hello2 -logger:{typeof(MockLogger).FullName},{typeof(MockLogger).Assembly.Location};ReportTelemetry"; } /// diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Linux.verified.txt new file mode 100644 index 00000000000..d2a02edc803 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Linux.verified.txt @@ -0,0 +1,9 @@ +]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + High importance message! + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.OSX.verified.txt new file mode 100644 index 00000000000..6d379050835 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.OSX.verified.txt @@ -0,0 +1,8 @@ +The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + High importance message! + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Windows.verified.txt new file mode 100644 index 00000000000..d2a02edc803 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Windows.verified.txt @@ -0,0 +1,9 @@ +]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + High importance message! + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Linux.verified.txt new file mode 100644 index 00000000000..d2a02edc803 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Linux.verified.txt @@ -0,0 +1,9 @@ +]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + High importance message! + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.OSX.verified.txt new file mode 100644 index 00000000000..6d379050835 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.OSX.verified.txt @@ -0,0 +1,8 @@ +The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + High importance message! + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Windows.verified.txt new file mode 100644 index 00000000000..d2a02edc803 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Windows.verified.txt @@ -0,0 +1,9 @@ +]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + High importance message! + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Linux.verified.txt new file mode 100644 index 00000000000..78887aa5bf3 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Linux.verified.txt @@ -0,0 +1,8 @@ +]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.OSX.verified.txt new file mode 100644 index 00000000000..1127e52e995 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.OSX.verified.txt @@ -0,0 +1,7 @@ +The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Windows.verified.txt new file mode 100644 index 00000000000..78887aa5bf3 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Windows.verified.txt @@ -0,0 +1,8 @@ +]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Linux.verified.txt new file mode 100644 index 00000000000..78887aa5bf3 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Linux.verified.txt @@ -0,0 +1,8 @@ +]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.OSX.verified.txt new file mode 100644 index 00000000000..1127e52e995 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.OSX.verified.txt @@ -0,0 +1,7 @@ +The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Windows.verified.txt new file mode 100644 index 00000000000..78887aa5bf3 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Windows.verified.txt @@ -0,0 +1,8 @@ +]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.Linux.verified.txt new file mode 100644 index 00000000000..ed7d3ade9de --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.Linux.verified.txt @@ -0,0 +1,3 @@ +]9;4;3;\directory/file(1,2,3,4): warning AA0000: Warning! +directory/file(1,2,3,4): error AA0000: Error! +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.OSX.verified.txt new file mode 100644 index 00000000000..b52d4bf957f --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.OSX.verified.txt @@ -0,0 +1,2 @@ +directory/file(1,2,3,4): warning AA0000: Warning! +directory/file(1,2,3,4): error AA0000: Error! diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.Windows.verified.txt new file mode 100644 index 00000000000..ed7d3ade9de --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.Windows.verified.txt @@ -0,0 +1,3 @@ +]9;4;3;\directory/file(1,2,3,4): warning AA0000: Warning! +directory/file(1,2,3,4): error AA0000: Error! +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Linux.verified.txt new file mode 100644 index 00000000000..34897dfd415 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Linux.verified.txt @@ -0,0 +1,6 @@ +]9;4;3;\ project test succeeded (0.2s) +[?25l +[?25h +Build succeeded in 5.0s +Test run failed. Total: 10 Failed: 1 Passed: 7 Skipped: 2, Duration: 1.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.OSX.verified.txt new file mode 100644 index 00000000000..6615c0644e7 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.OSX.verified.txt @@ -0,0 +1,5 @@ + project test succeeded (0.2s) +[?25l +[?25h +Build succeeded in 5.0s +Test run failed. Total: 10 Failed: 1 Passed: 7 Skipped: 2, Duration: 1.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Windows.verified.txt new file mode 100644 index 00000000000..34897dfd415 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Windows.verified.txt @@ -0,0 +1,6 @@ +]9;4;3;\ project test succeeded (0.2s) +[?25l +[?25h +Build succeeded in 5.0s +Test run failed. Total: 10 Failed: 1 Passed: 7 Skipped: 2, Duration: 1.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Linux.verified.txt new file mode 100644 index 00000000000..1631c824d25 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Linux.verified.txt @@ -0,0 +1 @@ +]9;4;3;\]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt new file mode 100644 index 00000000000..5f282702bb0 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Windows.verified.txt new file mode 100644 index 00000000000..1631c824d25 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Windows.verified.txt @@ -0,0 +1 @@ +]9;4;3;\]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/TerminalLogger_Tests.cs b/src/MSBuild.UnitTests/TerminalLogger_Tests.cs index 75749517b55..2fef5495c10 100644 --- a/src/MSBuild.UnitTests/TerminalLogger_Tests.cs +++ b/src/MSBuild.UnitTests/TerminalLogger_Tests.cs @@ -30,6 +30,12 @@ public class TerminalLogger_Tests : IEventSource, IDisposable { private const int _nodeCount = 8; private const string _eventSender = "Test"; + + private const string _immediateMessageString = + "The plugin credential provider could not acquire credentials." + + "Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, " + + "/p:NuGetInteractive=\"true\" for MSBuild or removing the -NonInteractive switch for `NuGet`"; + private readonly string _projectFile = NativeMethods.IsUnixLike ? "/src/project.proj" : @"C:\src\project.proj"; private StringWriter _outputWriter = new(); @@ -38,8 +44,11 @@ public class TerminalLogger_Tests : IEventSource, IDisposable private readonly TerminalLogger _terminallogger; private readonly DateTime _buildStartTime = new DateTime(2023, 3, 30, 16, 30, 0); + private readonly DateTime _targetStartTime = new DateTime(2023, 3, 30, 16, 30, 1); + private readonly DateTime _messageTime = new DateTime(2023, 3, 30, 16, 30, 2); private readonly DateTime _buildFinishTime = new DateTime(2023, 3, 30, 16, 30, 5); + private VerifySettings _settings = new(); public TerminalLogger_Tests() @@ -132,7 +141,7 @@ private ProjectFinishedEventArgs MakeProjectFinishedEventArgs(string projectFile private TargetStartedEventArgs MakeTargetStartedEventArgs(string projectFile, string targetName) { - return new TargetStartedEventArgs("", "", targetName, projectFile, targetFile: projectFile) + return new TargetStartedEventArgs("", "", targetName, projectFile, targetFile: projectFile, String.Empty, TargetBuiltReason.None, _targetStartTime) { BuildEventContext = MakeBuildEventContext(), }; @@ -170,11 +179,20 @@ private BuildWarningEventArgs MakeWarningEventArgs(string warning) }; } - private BuildMessageEventArgs MakeMessageEventArgs(string message) + private BuildMessageEventArgs MakeMessageEventArgs(string message, MessageImportance importance) + { + return new BuildMessageEventArgs(message, "keyword", null, importance) + { + BuildEventContext = MakeBuildEventContext(), + }; + } + + private BuildMessageEventArgs MakeExtendedMessageEventArgs(string message, MessageImportance importance, string extendedType, Dictionary? extendedMetadata) { - return new BuildMessageEventArgs(message, "keyword", null, MessageImportance.High) + return new ExtendedBuildMessageEventArgs(extendedType, message, "keyword", null, importance, _messageTime) { BuildEventContext = MakeBuildEventContext(), + ExtendedMetadata = extendedMetadata }; } @@ -207,6 +225,23 @@ private void InvokeLoggerCallbacksForSimpleProject(bool succeeded, Action additi BuildFinished?.Invoke(_eventSender, MakeBuildFinishedEventArgs(succeeded)); } + private void InvokeLoggerCallbacksForTestProject(bool succeeded, Action additionalCallbacks) + { + BuildStarted?.Invoke(_eventSender, MakeBuildStartedEventArgs()); + ProjectStarted?.Invoke(_eventSender, MakeProjectStartedEventArgs(_projectFile)); + + TargetStarted?.Invoke(_eventSender, MakeTargetStartedEventArgs(_projectFile, "_TestRunStart")); + TaskStarted?.Invoke(_eventSender, MakeTaskStartedEventArgs(_projectFile, "Task")); + + additionalCallbacks(); + + TaskFinished?.Invoke(_eventSender, MakeTaskFinishedEventArgs(_projectFile, "Task", succeeded)); + TargetFinished?.Invoke(_eventSender, MakeTargetFinishedEventArgs(_projectFile, "_TestRunStart", succeeded)); + + ProjectFinished?.Invoke(_eventSender, MakeProjectFinishedEventArgs(_projectFile, succeeded)); + BuildFinished?.Invoke(_eventSender, MakeBuildFinishedEventArgs(succeeded)); + } + [Fact] public Task PrintsBuildSummary_Succeeded() { @@ -247,10 +282,7 @@ public Task PrintImmediateMessage_Success() { InvokeLoggerCallbacksForSimpleProject(succeeded: true, () => { - MessageRaised?.Invoke(_eventSender, MakeMessageEventArgs( - "The plugin credential provider could not acquire credentials." + - "Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, " + - "/p:NuGetInteractive=\"true\" for MSBuild or removing the -NonInteractive switch for `NuGet`")); + MessageRaised?.Invoke(_eventSender, MakeMessageEventArgs(_immediateMessageString, MessageImportance.High)); }); return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); @@ -261,7 +293,7 @@ public Task PrintImmediateMessage_Skipped() { InvokeLoggerCallbacksForSimpleProject(succeeded: true, () => { - MessageRaised?.Invoke(_eventSender, MakeMessageEventArgs("--anycustomarg")); + MessageRaised?.Invoke(_eventSender, MakeMessageEventArgs("--anycustomarg", MessageImportance.High)); }); return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); @@ -315,6 +347,100 @@ public Task PrintBuildSummary_FailedWithErrors() #endregion + private void CallAllTypesOfMessagesWarningAndError() + { + MessageRaised?.Invoke(_eventSender, MakeMessageEventArgs(_immediateMessageString, MessageImportance.High)); + MessageRaised?.Invoke(_eventSender, MakeMessageEventArgs("High importance message!", MessageImportance.High)); + MessageRaised?.Invoke(_eventSender, MakeMessageEventArgs("Normal importance message!", MessageImportance.Normal)); + MessageRaised?.Invoke(_eventSender, MakeMessageEventArgs("Low importance message!", MessageImportance.Low)); + WarningRaised?.Invoke(_eventSender, MakeWarningEventArgs("Warning!")); + ErrorRaised?.Invoke(_eventSender, MakeErrorEventArgs("Error!")); + } + + private void CallAllTypesOfTestMessages() + { + MessageRaised?.Invoke(_eventSender, MakeExtendedMessageEventArgs( + "Test passed.", + MessageImportance.High, + "TLTESTPASSED", + new Dictionary() { { "displayName", "testName1" }, { "localizedResult", "passed" } })); + MessageRaised?.Invoke(_eventSender, MakeExtendedMessageEventArgs( + "Test skipped.", + MessageImportance.High, + "TLTESTSKIPPED", + new Dictionary() { { "displayName", "testName2" }, { "localizedResult", "skipped" } })); + MessageRaised?.Invoke(_eventSender, MakeExtendedMessageEventArgs( + "Test results.", + MessageImportance.High, + "TLTESTFINISH", + new Dictionary() { { "total", "10" }, { "passed", "7" }, { "skipped", "2" }, { "failed", "1" } })); + } + + [Fact] + public Task PrintBuildSummaryQuietVerbosity_FailedWithErrors() + { + _terminallogger.Verbosity = LoggerVerbosity.Quiet; + InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError); + + return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); + } + + + [Fact] + public Task PrintBuildSummaryMinimalVerbosity_FailedWithErrors() + { + _terminallogger.Verbosity = LoggerVerbosity.Minimal; + InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError); + + return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); + } + + [Fact] + public Task PrintBuildSummaryNormalVerbosity_FailedWithErrors() + { + _terminallogger.Verbosity = LoggerVerbosity.Normal; + InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError); + + return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); + } + + [Fact] + public Task PrintBuildSummaryDetailedVerbosity_FailedWithErrors() + { + _terminallogger.Verbosity = LoggerVerbosity.Detailed; + InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError); + + return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); + } + + + [Fact] + public Task PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors() + { + _terminallogger.Verbosity = LoggerVerbosity.Diagnostic; + InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError); + + return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); + } + + [Fact] + public Task PrintTestSummaryNormalVerbosity_Succeded() + { + _terminallogger.Verbosity = LoggerVerbosity.Normal; + InvokeLoggerCallbacksForTestProject(succeeded: true, CallAllTypesOfTestMessages); + + return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); + } + + [Fact] + public Task PrintTestSummaryQuietVerbosity_Succeded() + { + _terminallogger.Verbosity = LoggerVerbosity.Quiet; + InvokeLoggerCallbacksForTestProject(succeeded: true, CallAllTypesOfTestMessages); + + return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); + } + [Fact] public void DisplayNodesShowsCurrent() { diff --git a/src/MSBuild/TerminalLogger/MessageSeverity.cs b/src/MSBuild/TerminalLogger/MessageSeverity.cs index 07aa9058be3..9f374e292dd 100644 --- a/src/MSBuild/TerminalLogger/MessageSeverity.cs +++ b/src/MSBuild/TerminalLogger/MessageSeverity.cs @@ -6,4 +6,4 @@ namespace Microsoft.Build.Logging.TerminalLogger; /// /// Enumerates the supported message severities. /// -internal enum MessageSeverity { Warning, Error } +internal enum MessageSeverity { Message, Warning, Error } diff --git a/src/MSBuild/TerminalLogger/TerminalLogger.cs b/src/MSBuild/TerminalLogger/TerminalLogger.cs index 195ebb95789..7ba0330387c 100644 --- a/src/MSBuild/TerminalLogger/TerminalLogger.cs +++ b/src/MSBuild/TerminalLogger/TerminalLogger.cs @@ -10,8 +10,10 @@ using System.Text.RegularExpressions; using System.Diagnostics; + #if NET7_0_OR_GREATER using System.Diagnostics.CodeAnalysis; + #endif #if NETFRAMEWORK using Microsoft.IO; @@ -201,6 +203,12 @@ public TerminalLogger() Terminal = new Terminal(); } + public TerminalLogger(LoggerVerbosity verbosity) + : this() + { + Verbosity = verbosity; + } + /// /// Internal constructor accepting a custom for testing. /// @@ -212,8 +220,14 @@ internal TerminalLogger(ITerminal terminal) #region INodeLogger implementation + private LoggerVerbosity _verbosity = LoggerVerbosity.Minimal; + /// - public LoggerVerbosity Verbosity { get => LoggerVerbosity.Minimal; set { } } + public LoggerVerbosity Verbosity + { + get { return _verbosity; } + set { _verbosity = value; } + } /// public string Parameters @@ -295,43 +309,46 @@ private void BuildFinished(object sender, BuildFinishedEventArgs e) Terminal.BeginUpdate(); try - { - string duration = (e.Timestamp - _buildStartTime).TotalSeconds.ToString("F1"); - string buildResult = RenderBuildResult(e.Succeeded, _buildHasErrors, _buildHasWarnings); - - Terminal.WriteLine(""); - if (_restoreFailed) + { + if (Verbosity > LoggerVerbosity.Quiet) { - Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("RestoreCompleteWithMessage", - buildResult, - duration)); - } - else - { - Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("BuildFinished", - buildResult, - duration)); - } + string duration = (e.Timestamp - _buildStartTime).TotalSeconds.ToString("F1"); + string buildResult = RenderBuildResult(e.Succeeded, _buildHasErrors, _buildHasWarnings); - if (_testRunSummaries.Any()) - { - var total = _testRunSummaries.Sum(t => t.Total); - var failed = _testRunSummaries.Sum(t => t.Failed); - var passed = _testRunSummaries.Sum(t => t.Passed); - var skipped = _testRunSummaries.Sum(t => t.Skipped); - var testDuration = (_testStartTime != null && _testEndTime != null ? (_testEndTime - _testStartTime).Value.TotalSeconds : 0).ToString("F1"); - - var colorizedResult = _testRunSummaries.Any(t => t.Failed > 0) || _buildHasErrors - ? AnsiCodes.Colorize(ResourceUtilities.GetResourceString("BuildResult_Failed"), TerminalColor.Red) - : AnsiCodes.Colorize(ResourceUtilities.GetResourceString("BuildResult_Succeeded"), TerminalColor.Green); - - Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("TestSummary", - colorizedResult, - total, - failed, - passed, - skipped, - testDuration)); + Terminal.WriteLine(""); + if (_restoreFailed) + { + Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("RestoreCompleteWithMessage", + buildResult, + duration)); + } + else + { + Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("BuildFinished", + buildResult, + duration)); + } + + if (_testRunSummaries.Any()) + { + var total = _testRunSummaries.Sum(t => t.Total); + var failed = _testRunSummaries.Sum(t => t.Failed); + var passed = _testRunSummaries.Sum(t => t.Passed); + var skipped = _testRunSummaries.Sum(t => t.Skipped); + var testDuration = (_testStartTime != null && _testEndTime != null ? (_testEndTime - _testStartTime).Value.TotalSeconds : 0).ToString("F1"); + + var colorizedResult = _testRunSummaries.Any(t => t.Failed > 0) || _buildHasErrors + ? AnsiCodes.Colorize(ResourceUtilities.GetResourceString("BuildResult_Failed"), TerminalColor.Red) + : AnsiCodes.Colorize(ResourceUtilities.GetResourceString("BuildResult_Succeeded"), TerminalColor.Green); + + Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("TestSummary", + colorizedResult, + total, + failed, + passed, + skipped, + testDuration)); + } } } finally @@ -400,166 +417,170 @@ private void ProjectFinished(object sender, ProjectFinishedEventArgs e) UpdateNodeStatus(buildEventContext, null); } - ProjectContext c = new(buildEventContext); - - if (_projects.TryGetValue(c, out Project? project)) + // Add project summary to the static part of the Console only if verbosity is higher than Quiet. + if (Verbosity > LoggerVerbosity.Quiet) { - lock (_lock) + ProjectContext c = new(buildEventContext); + + if (_projects.TryGetValue(c, out Project? project)) { - Terminal.BeginUpdate(); - try + lock (_lock) { - EraseNodes(); + Terminal.BeginUpdate(); + try + { + EraseNodes(); - string duration = project.Stopwatch.ElapsedSeconds.ToString("F1"); - ReadOnlyMemory? outputPath = project.OutputPath; + string duration = project.Stopwatch.ElapsedSeconds.ToString("F1"); + ReadOnlyMemory? outputPath = project.OutputPath; - string projectFile = e.ProjectFile is not null ? - Path.GetFileNameWithoutExtension(e.ProjectFile) : - string.Empty; + string projectFile = e.ProjectFile is not null ? + Path.GetFileNameWithoutExtension(e.ProjectFile) : + string.Empty; - // Build result. One of 'failed', 'succeeded with warnings', or 'succeeded' depending on the build result and diagnostic messages - // reported during build. - bool haveErrors = project.BuildMessages?.Exists(m => m.Severity == MessageSeverity.Error) == true; - bool haveWarnings = project.BuildMessages?.Exists(m => m.Severity == MessageSeverity.Warning) == true; + // Build result. One of 'failed', 'succeeded with warnings', or 'succeeded' depending on the build result and diagnostic messages + // reported during build. + bool haveErrors = project.BuildMessages?.Exists(m => m.Severity == MessageSeverity.Error) == true; + bool haveWarnings = project.BuildMessages?.Exists(m => m.Severity == MessageSeverity.Warning) == true; - string buildResult = RenderBuildResult(e.Succeeded, haveErrors, haveWarnings); + string buildResult = RenderBuildResult(e.Succeeded, haveErrors, haveWarnings); - // Check if we're done restoring. - if (c == _restoreContext) - { - if (e.Succeeded) + // Check if we're done restoring. + if (c == _restoreContext) { - if (haveErrors || haveWarnings) + if (e.Succeeded) { - Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("RestoreCompleteWithMessage", - buildResult, - duration)); + if (haveErrors || haveWarnings) + { + Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("RestoreCompleteWithMessage", + buildResult, + duration)); + } + else + { + Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("RestoreComplete", + duration)); + } } else { - Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("RestoreComplete", - duration)); + // It will be reported after build finishes. + _restoreFailed = true; } - } - else - { - // It will be reported after build finishes. - _restoreFailed = true; - } - _restoreContext = null; - _restoreFinished = true; - } - // If this was a notable project build, we print it as completed only if it's produced an output or warnings/error. - // If this is a test project, print it always, so user can see either a success or failure, otherwise success is hidden - // and it is hard to see if project finished, or did not run at all. - else if (project.OutputPath is not null || project.BuildMessages is not null || project.IsTestProject) - { - // Show project build complete and its output - if (project.IsTestProject) + _restoreContext = null; + _restoreFinished = true; + } + // If this was a notable project build, we print it as completed only if it's produced an output or warnings/error. + // If this is a test project, print it always, so user can see either a success or failure, otherwise success is hidden + // and it is hard to see if project finished, or did not run at all. + else if (project.OutputPath is not null || project.BuildMessages is not null || project.IsTestProject) { - if (string.IsNullOrEmpty(project.TargetFramework)) + // Show project build complete and its output + if (project.IsTestProject) { - Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("TestProjectFinished_NoTF", - Indentation, - projectFile, - buildResult, - duration)); + if (string.IsNullOrEmpty(project.TargetFramework)) + { + Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("TestProjectFinished_NoTF", + Indentation, + projectFile, + buildResult, + duration)); + } + else + { + Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("TestProjectFinished_WithTF", + Indentation, + projectFile, + AnsiCodes.Colorize(project.TargetFramework, TargetFrameworkColor), + buildResult, + duration)); + } } else { - Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("TestProjectFinished_WithTF", - Indentation, - projectFile, - AnsiCodes.Colorize(project.TargetFramework, TargetFrameworkColor), - buildResult, - duration)); + if (string.IsNullOrEmpty(project.TargetFramework)) + { + Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_NoTF", + Indentation, + projectFile, + buildResult, + duration)); + } + else + { + Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_WithTF", + Indentation, + projectFile, + AnsiCodes.Colorize(project.TargetFramework, TargetFrameworkColor), + buildResult, + duration)); + } } - } - else - { - if (string.IsNullOrEmpty(project.TargetFramework)) + + // Print the output path as a link if we have it. + if (outputPath is not null) { - Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_NoTF", - Indentation, - projectFile, - buildResult, - duration)); + ReadOnlySpan outputPathSpan = outputPath.Value.Span; + ReadOnlySpan url = outputPathSpan; + try + { + // If possible, make the link point to the containing directory of the output. + url = Path.GetDirectoryName(url); + } + catch + { + // Ignore any GetDirectoryName exceptions. + } + + // Generates file:// schema url string which is better handled by various Terminal clients than raw folder name. + string urlString = url.ToString(); + if (Uri.TryCreate(urlString, UriKind.Absolute, out Uri? uri)) + { + urlString = uri.AbsoluteUri; + } + + // If the output path is under the initial working directory, make the console output relative to that to save space. + if (outputPathSpan.StartsWith(_initialWorkingDirectory.AsSpan(), FileUtilities.PathComparison)) + { + if (outputPathSpan.Length > _initialWorkingDirectory.Length + && (outputPathSpan[_initialWorkingDirectory.Length] == Path.DirectorySeparatorChar + || outputPathSpan[_initialWorkingDirectory.Length] == Path.AltDirectorySeparatorChar)) + { + outputPathSpan = outputPathSpan.Slice(_initialWorkingDirectory.Length + 1); + } + } + + Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_OutputPath", + $"{AnsiCodes.LinkPrefix}{urlString}{AnsiCodes.LinkInfix}{outputPathSpan.ToString()}{AnsiCodes.LinkSuffix}")); } else { - Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_WithTF", - Indentation, - projectFile, - AnsiCodes.Colorize(project.TargetFramework, TargetFrameworkColor), - buildResult, - duration)); + Terminal.WriteLine(string.Empty); } } - // Print the output path as a link if we have it. - if (outputPath is not null) + // Print diagnostic output under the Project -> Output line. + if (project.BuildMessages is not null) { - ReadOnlySpan outputPathSpan = outputPath.Value.Span; - ReadOnlySpan url = outputPathSpan; - try - { - // If possible, make the link point to the containing directory of the output. - url = Path.GetDirectoryName(url); - } - catch - { - // Ignore any GetDirectoryName exceptions. - } - - // Generates file:// schema url string which is better handled by various Terminal clients than raw folder name. - string urlString = url.ToString(); - if (Uri.TryCreate(urlString, UriKind.Absolute, out Uri? uri)) + foreach (BuildMessage buildMessage in project.BuildMessages) { - urlString = uri.AbsoluteUri; + Terminal.WriteLine($"{Indentation}{Indentation}{buildMessage.Message}"); } + } - // If the output path is under the initial working directory, make the console output relative to that to save space. - if (outputPathSpan.StartsWith(_initialWorkingDirectory.AsSpan(), FileUtilities.PathComparison)) - { - if (outputPathSpan.Length > _initialWorkingDirectory.Length - && (outputPathSpan[_initialWorkingDirectory.Length] == Path.DirectorySeparatorChar - || outputPathSpan[_initialWorkingDirectory.Length] == Path.AltDirectorySeparatorChar)) - { - outputPathSpan = outputPathSpan.Slice(_initialWorkingDirectory.Length + 1); - } - } + _buildHasErrors |= haveErrors; + _buildHasWarnings |= haveWarnings; - Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_OutputPath", - $"{AnsiCodes.LinkPrefix}{urlString}{AnsiCodes.LinkInfix}{outputPathSpan.ToString()}{AnsiCodes.LinkSuffix}")); - } - else - { - Terminal.WriteLine(string.Empty); - } + DisplayNodes(); } - - // Print diagnostic output under the Project -> Output line. - if (project.BuildMessages is not null) + finally { - foreach (BuildMessage buildMessage in project.BuildMessages) - { - Terminal.WriteLine($"{Indentation}{Indentation}{buildMessage.Message}"); - } + Terminal.EndUpdate(); } - - _buildHasErrors |= haveErrors; - _buildHasWarnings |= haveWarnings; - - DisplayNodes(); - } - finally - { - Terminal.EndUpdate(); } } - } + } } /// @@ -642,6 +663,7 @@ private void MessageRaised(object sender, BuildMessageEventArgs e) if (message is not null && e.Importance == MessageImportance.High) { var hasProject = _projects.TryGetValue(new ProjectContext(buildEventContext), out Project? project); + // Detect project output path by matching high-importance messages against the "$(MSBuildProjectName) -> ..." // pattern used by the CopyFilesToOutputDirectory target. int index = message.IndexOf(FilePathPattern, StringComparison.Ordinal); @@ -653,14 +675,31 @@ private void MessageRaised(object sender, BuildMessageEventArgs e) { ReadOnlyMemory outputPath = e.Message.AsMemory().Slice(index + 4); project!.OutputPath = outputPath; + return; } } - if (IsImmediateMessage(message)) + if (Verbosity > LoggerVerbosity.Quiet) { - RenderImmediateMessage(message); + // Show immediate messages to the user. + if (IsImmediateMessage(message)) + { + RenderImmediateMessage(message); + return; + } + if (e.Code == "NETSDK1057" && !_loggedPreviewMessage) + { + // The SDK will log the high-pri "not-a-warning" message NETSDK1057 + // when it's a preview version up to MaxCPUCount times, but that's + // an implementation detail--the user cares about at most one. + + RenderImmediateMessage(message); + _loggedPreviewMessage = true; + return; + } } - else if (hasProject && project!.IsTestProject) + + if (hasProject && project!.IsTestProject) { var node = _nodes[NodeIndexForContext(buildEventContext)]; @@ -691,30 +730,40 @@ private void MessageRaised(object sender, BuildMessageEventArgs e) case "TLTESTFINISH": { - _ = int.TryParse(extendedMessage.ExtendedMetadata!["total"]!, out int total); - _ = int.TryParse(extendedMessage.ExtendedMetadata!["passed"]!, out int passed); - _ = int.TryParse(extendedMessage.ExtendedMetadata!["skipped"]!, out int skipped); - _ = int.TryParse(extendedMessage.ExtendedMetadata!["failed"]!, out int failed); + // Collect test run summary. + if (Verbosity > LoggerVerbosity.Quiet) + { + _ = int.TryParse(extendedMessage.ExtendedMetadata!["total"]!, out int total); + _ = int.TryParse(extendedMessage.ExtendedMetadata!["passed"]!, out int passed); + _ = int.TryParse(extendedMessage.ExtendedMetadata!["skipped"]!, out int skipped); + _ = int.TryParse(extendedMessage.ExtendedMetadata!["failed"]!, out int failed); - _testRunSummaries.Add(new TestSummary(total, passed, skipped, failed)); + _testRunSummaries.Add(new TestSummary(total, passed, skipped, failed)); - _testEndTime = _testEndTime == null - ? e.Timestamp - : e.Timestamp > _testEndTime - ? e.Timestamp : _testEndTime; + _testEndTime = _testEndTime == null + ? e.Timestamp + : e.Timestamp > _testEndTime + ? e.Timestamp : _testEndTime; + } + break; } } + return; } } - else if (e.Code == "NETSDK1057" && !_loggedPreviewMessage) - { - // The SDK will log the high-pri "not-a-warning" message NETSDK1057 - // when it's a preview version up to MaxCPUCount times, but that's - // an implementation detail--the user cares about at most one. - RenderImmediateMessage(message); - _loggedPreviewMessage = true; + if (Verbosity > LoggerVerbosity.Normal) + { + if (hasProject) + { + project!.AddBuildMessage(MessageSeverity.Message, message); + } + else + { + // Display messages reported by MSBuild, even if it's not tracked in _projects collection. + RenderImmediateMessage(message); + } } } } @@ -739,7 +788,9 @@ private void WarningRaised(object sender, BuildWarningEventArgs e) threadId: e.ThreadId, logOutputProperties: null); - if (buildEventContext is not null && _projects.TryGetValue(new ProjectContext(buildEventContext), out Project? project)) + if (buildEventContext is not null + && _projects.TryGetValue(new ProjectContext(buildEventContext), out Project? project) + && Verbosity > LoggerVerbosity.Quiet) { if (IsImmediateMessage(message)) { @@ -750,7 +801,7 @@ private void WarningRaised(object sender, BuildWarningEventArgs e) } else { - // It is necessary to display warning messages reported by MSBuild, even if it's not tracked in _projects collection. + // It is necessary to display warning messages reported by MSBuild, even if it's not tracked in _projects collection or the verbosity is Quiet. RenderImmediateMessage(message); _buildHasWarnings = true; } @@ -788,13 +839,15 @@ private void ErrorRaised(object sender, BuildErrorEventArgs e) threadId: e.ThreadId, logOutputProperties: null); - if (buildEventContext is not null && _projects.TryGetValue(new ProjectContext(buildEventContext), out Project? project)) + if (buildEventContext is not null + && _projects.TryGetValue(new ProjectContext(buildEventContext), out Project? project) + && Verbosity > LoggerVerbosity.Quiet) { project.AddBuildMessage(MessageSeverity.Error, message); } else { - // It is necessary to display error messages reported by MSBuild, even if it's not tracked in _projects collection. + // It is necessary to display error messages reported by MSBuild, even if it's not tracked in _projects collection or the verbosity is Quiet. RenderImmediateMessage(message); _buildHasErrors = true; } diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 545fdbc9844..424db887f2d 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -3735,7 +3735,7 @@ private static ILogger[] ProcessLoggingSwitches( } else if (terminalloggerOptIn) { - ProcessTerminalLogger(noConsoleLogger, aggregatedTerminalLoggerParameters, distributedLoggerRecords, cpuCount, loggers); + ProcessTerminalLogger(noConsoleLogger, aggregatedTerminalLoggerParameters, distributedLoggerRecords, verbosity, cpuCount, loggers); } else { @@ -3914,13 +3914,14 @@ internal static void ProcessConsoleLoggerSwitch( private static void ProcessTerminalLogger(bool noConsoleLogger, string aggregatedLoggerParameters, List distributedLoggerRecords, + LoggerVerbosity verbosity, int cpuCount, List loggers) { if (!noConsoleLogger) { // A central logger will be created for both single proc and multiproc. - TerminalLogger logger = new TerminalLogger() + TerminalLogger logger = new TerminalLogger(verbosity) { Parameters = aggregatedLoggerParameters }; From 896d0acc3b49529952c1b2a99de49569db0c4b04 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:11:18 +0100 Subject: [PATCH 02/12] Remove unused variables --- .../TerminalLoggerConfiguration_Tests.cs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs b/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs index 3860daa0f5a..83cd6c15d3b 100644 --- a/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs +++ b/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs @@ -23,7 +23,6 @@ public class TerminalLoggerConfiguration_Tests : IDisposable private readonly TestEnvironment _env; private readonly string _cmd; - private readonly string _cmd2; public TerminalLoggerConfiguration_Tests(ITestOutputHelper output) { @@ -41,19 +40,6 @@ public TerminalLoggerConfiguration_Tests(ITestOutputHelper output) """); - TransientTestFile projectFile2 = _env.CreateFile(logFolder, "myProj2.proj", $""" - - - - - - - - - - """); - - _cmd2 = $"{projectFile2.Path} -target:Hello2 -logger:{typeof(MockLogger).FullName},{typeof(MockLogger).Assembly.Location};ReportTelemetry"; } /// From e275441d54ecea8c7eae3e15513df85fc40a93b7 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:15:43 +0100 Subject: [PATCH 03/12] Fix accidentally removed line --- src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs b/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs index 83cd6c15d3b..6266cb6e4c7 100644 --- a/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs +++ b/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs @@ -40,6 +40,7 @@ public TerminalLoggerConfiguration_Tests(ITestOutputHelper output) """); + _cmd = $"{projectFile.Path} -target:Hello -logger:{typeof(MockLogger).FullName},{typeof(MockLogger).Assembly.Location};ReportTelemetry"; } /// From 582d6db85066deaae4de49ac1ed6f4272366804e Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Mon, 4 Mar 2024 14:26:52 +0100 Subject: [PATCH 04/12] Try to fix OSX test. --- ...sts.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt index 5f282702bb0..e02abfc9b0e 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt @@ -1 +1 @@ - \ No newline at end of file + From e725dd468b686a3faa0b460cd4ee875164df1e45 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Thu, 14 Mar 2024 14:34:13 +0100 Subject: [PATCH 05/12] Try to fix OSX test - 2 --- ...sts.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt index e02abfc9b0e..c1b8d743e34 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt @@ -1 +1 @@ - +emptyString \ No newline at end of file From 1b202b3f7240fa126049ffec6c639f683a5c37ce Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Fri, 15 Mar 2024 14:43:36 +0100 Subject: [PATCH 06/12] Address comments --- src/MSBuild/TerminalLogger/TerminalLogger.cs | 260 +++++++++---------- 1 file changed, 128 insertions(+), 132 deletions(-) diff --git a/src/MSBuild/TerminalLogger/TerminalLogger.cs b/src/MSBuild/TerminalLogger/TerminalLogger.cs index 7ba0330387c..cdedde8e551 100644 --- a/src/MSBuild/TerminalLogger/TerminalLogger.cs +++ b/src/MSBuild/TerminalLogger/TerminalLogger.cs @@ -220,14 +220,8 @@ internal TerminalLogger(ITerminal terminal) #region INodeLogger implementation - private LoggerVerbosity _verbosity = LoggerVerbosity.Minimal; - /// - public LoggerVerbosity Verbosity - { - get { return _verbosity; } - set { _verbosity = value; } - } + public LoggerVerbosity Verbosity { get; set; } = LoggerVerbosity.Minimal; /// public string Parameters @@ -417,170 +411,172 @@ private void ProjectFinished(object sender, ProjectFinishedEventArgs e) UpdateNodeStatus(buildEventContext, null); } - // Add project summary to the static part of the Console only if verbosity is higher than Quiet. - if (Verbosity > LoggerVerbosity.Quiet) + // Continue execution and add project summary to the static part of the Console only if verbosity is higher than Quiet. + if (Verbosity <= LoggerVerbosity.Quiet) { - ProjectContext c = new(buildEventContext); + return; + } + + ProjectContext c = new(buildEventContext); - if (_projects.TryGetValue(c, out Project? project)) + if (_projects.TryGetValue(c, out Project? project)) + { + lock (_lock) { - lock (_lock) + Terminal.BeginUpdate(); + try { - Terminal.BeginUpdate(); - try - { - EraseNodes(); + EraseNodes(); - string duration = project.Stopwatch.ElapsedSeconds.ToString("F1"); - ReadOnlyMemory? outputPath = project.OutputPath; + string duration = project.Stopwatch.ElapsedSeconds.ToString("F1"); + ReadOnlyMemory? outputPath = project.OutputPath; - string projectFile = e.ProjectFile is not null ? - Path.GetFileNameWithoutExtension(e.ProjectFile) : - string.Empty; + string projectFile = e.ProjectFile is not null ? + Path.GetFileNameWithoutExtension(e.ProjectFile) : + string.Empty; - // Build result. One of 'failed', 'succeeded with warnings', or 'succeeded' depending on the build result and diagnostic messages - // reported during build. - bool haveErrors = project.BuildMessages?.Exists(m => m.Severity == MessageSeverity.Error) == true; - bool haveWarnings = project.BuildMessages?.Exists(m => m.Severity == MessageSeverity.Warning) == true; + // Build result. One of 'failed', 'succeeded with warnings', or 'succeeded' depending on the build result and diagnostic messages + // reported during build. + bool haveErrors = project.BuildMessages?.Exists(m => m.Severity == MessageSeverity.Error) == true; + bool haveWarnings = project.BuildMessages?.Exists(m => m.Severity == MessageSeverity.Warning) == true; - string buildResult = RenderBuildResult(e.Succeeded, haveErrors, haveWarnings); + string buildResult = RenderBuildResult(e.Succeeded, haveErrors, haveWarnings); - // Check if we're done restoring. - if (c == _restoreContext) + // Check if we're done restoring. + if (c == _restoreContext) + { + if (e.Succeeded) { - if (e.Succeeded) + if (haveErrors || haveWarnings) { - if (haveErrors || haveWarnings) - { - Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("RestoreCompleteWithMessage", - buildResult, - duration)); - } - else - { - Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("RestoreComplete", - duration)); - } + Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("RestoreCompleteWithMessage", + buildResult, + duration)); } else { - // It will be reported after build finishes. - _restoreFailed = true; + Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("RestoreComplete", + duration)); } - - _restoreContext = null; - _restoreFinished = true; } - // If this was a notable project build, we print it as completed only if it's produced an output or warnings/error. - // If this is a test project, print it always, so user can see either a success or failure, otherwise success is hidden - // and it is hard to see if project finished, or did not run at all. - else if (project.OutputPath is not null || project.BuildMessages is not null || project.IsTestProject) + else + { + // It will be reported after build finishes. + _restoreFailed = true; + } + + _restoreContext = null; + _restoreFinished = true; + } + // If this was a notable project build, we print it as completed only if it's produced an output or warnings/error. + // If this is a test project, print it always, so user can see either a success or failure, otherwise success is hidden + // and it is hard to see if project finished, or did not run at all. + else if (project.OutputPath is not null || project.BuildMessages is not null || project.IsTestProject) + { + // Show project build complete and its output + if (project.IsTestProject) { - // Show project build complete and its output - if (project.IsTestProject) + if (string.IsNullOrEmpty(project.TargetFramework)) { - if (string.IsNullOrEmpty(project.TargetFramework)) - { - Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("TestProjectFinished_NoTF", - Indentation, - projectFile, - buildResult, - duration)); - } - else - { - Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("TestProjectFinished_WithTF", - Indentation, - projectFile, - AnsiCodes.Colorize(project.TargetFramework, TargetFrameworkColor), - buildResult, - duration)); - } + Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("TestProjectFinished_NoTF", + Indentation, + projectFile, + buildResult, + duration)); } else { - if (string.IsNullOrEmpty(project.TargetFramework)) - { - Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_NoTF", - Indentation, - projectFile, - buildResult, - duration)); - } - else - { - Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_WithTF", - Indentation, - projectFile, - AnsiCodes.Colorize(project.TargetFramework, TargetFrameworkColor), - buildResult, - duration)); - } + Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("TestProjectFinished_WithTF", + Indentation, + projectFile, + AnsiCodes.Colorize(project.TargetFramework, TargetFrameworkColor), + buildResult, + duration)); } - - // Print the output path as a link if we have it. - if (outputPath is not null) + } + else + { + if (string.IsNullOrEmpty(project.TargetFramework)) { - ReadOnlySpan outputPathSpan = outputPath.Value.Span; - ReadOnlySpan url = outputPathSpan; - try - { - // If possible, make the link point to the containing directory of the output. - url = Path.GetDirectoryName(url); - } - catch - { - // Ignore any GetDirectoryName exceptions. - } - - // Generates file:// schema url string which is better handled by various Terminal clients than raw folder name. - string urlString = url.ToString(); - if (Uri.TryCreate(urlString, UriKind.Absolute, out Uri? uri)) - { - urlString = uri.AbsoluteUri; - } - - // If the output path is under the initial working directory, make the console output relative to that to save space. - if (outputPathSpan.StartsWith(_initialWorkingDirectory.AsSpan(), FileUtilities.PathComparison)) - { - if (outputPathSpan.Length > _initialWorkingDirectory.Length - && (outputPathSpan[_initialWorkingDirectory.Length] == Path.DirectorySeparatorChar - || outputPathSpan[_initialWorkingDirectory.Length] == Path.AltDirectorySeparatorChar)) - { - outputPathSpan = outputPathSpan.Slice(_initialWorkingDirectory.Length + 1); - } - } - - Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_OutputPath", - $"{AnsiCodes.LinkPrefix}{urlString}{AnsiCodes.LinkInfix}{outputPathSpan.ToString()}{AnsiCodes.LinkSuffix}")); + Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_NoTF", + Indentation, + projectFile, + buildResult, + duration)); } else { - Terminal.WriteLine(string.Empty); + Terminal.Write(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_WithTF", + Indentation, + projectFile, + AnsiCodes.Colorize(project.TargetFramework, TargetFrameworkColor), + buildResult, + duration)); } } - // Print diagnostic output under the Project -> Output line. - if (project.BuildMessages is not null) + // Print the output path as a link if we have it. + if (outputPath is not null) { - foreach (BuildMessage buildMessage in project.BuildMessages) + ReadOnlySpan outputPathSpan = outputPath.Value.Span; + ReadOnlySpan url = outputPathSpan; + try { - Terminal.WriteLine($"{Indentation}{Indentation}{buildMessage.Message}"); + // If possible, make the link point to the containing directory of the output. + url = Path.GetDirectoryName(url); + } + catch + { + // Ignore any GetDirectoryName exceptions. } - } - _buildHasErrors |= haveErrors; - _buildHasWarnings |= haveWarnings; + // Generates file:// schema url string which is better handled by various Terminal clients than raw folder name. + string urlString = url.ToString(); + if (Uri.TryCreate(urlString, UriKind.Absolute, out Uri? uri)) + { + urlString = uri.AbsoluteUri; + } - DisplayNodes(); + // If the output path is under the initial working directory, make the console output relative to that to save space. + if (outputPathSpan.StartsWith(_initialWorkingDirectory.AsSpan(), FileUtilities.PathComparison)) + { + if (outputPathSpan.Length > _initialWorkingDirectory.Length + && (outputPathSpan[_initialWorkingDirectory.Length] == Path.DirectorySeparatorChar + || outputPathSpan[_initialWorkingDirectory.Length] == Path.AltDirectorySeparatorChar)) + { + outputPathSpan = outputPathSpan.Slice(_initialWorkingDirectory.Length + 1); + } + } + + Terminal.WriteLine(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ProjectFinished_OutputPath", + $"{AnsiCodes.LinkPrefix}{urlString}{AnsiCodes.LinkInfix}{outputPathSpan.ToString()}{AnsiCodes.LinkSuffix}")); + } + else + { + Terminal.WriteLine(string.Empty); + } } - finally + + // Print diagnostic output under the Project -> Output line. + if (project.BuildMessages is not null) { - Terminal.EndUpdate(); + foreach (BuildMessage buildMessage in project.BuildMessages) + { + Terminal.WriteLine($"{Indentation}{Indentation}{buildMessage.Message}"); + } } + + _buildHasErrors |= haveErrors; + _buildHasWarnings |= haveWarnings; + + DisplayNodes(); + } + finally + { + Terminal.EndUpdate(); } } - } + } } /// From efb5cf78d5ac5abd4d8a786896afa07a3785b729 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:00:50 +0100 Subject: [PATCH 07/12] Fix merge error --- src/MSBuild/TerminalLogger/TerminalLogger.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/MSBuild/TerminalLogger/TerminalLogger.cs b/src/MSBuild/TerminalLogger/TerminalLogger.cs index 94f5b3b0be8..98419a4b8f3 100644 --- a/src/MSBuild/TerminalLogger/TerminalLogger.cs +++ b/src/MSBuild/TerminalLogger/TerminalLogger.cs @@ -14,11 +14,8 @@ #if NET7_0_OR_GREATER using System.Diagnostics.CodeAnalysis; -<<<<<<< HEAD - -======= using System.Globalization; ->>>>>>> main + #endif #if NETFRAMEWORK using Microsoft.IO; From 0e34e8459ecd33b5d8a0091f1eb28136311985ed Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:20:17 +0100 Subject: [PATCH 08/12] Add parameters parsing --- src/Build/Logging/BaseConsoleLogger.cs | 62 +++--------- src/Build/Logging/ConsoleLogger.cs | 3 +- .../Logging/LoggerParametersHelper.cs | 73 ++++++++++++++ ...dLineEventArgs_Succeded.Linux.verified.txt | 6 ++ ...andLineEventArgs_Succeded.OSX.verified.txt | 5 + ...ineEventArgs_Succeded.Windows.verified.txt | 6 ++ ...dLineEventArgs_Succeded.Linux.verified.txt | 4 + ...andLineEventArgs_Succeded.OSX.verified.txt | 3 + ...ineEventArgs_Succeded.Windows.verified.txt | 4 + src/MSBuild.UnitTests/TerminalLogger_Tests.cs | 38 ++++++++ src/MSBuild/MSBuild.csproj | 1 + src/MSBuild/TerminalLogger/TerminalLogger.cs | 97 ++++++++++++++++++- 12 files changed, 248 insertions(+), 54 deletions(-) create mode 100644 src/Framework/Logging/LoggerParametersHelper.cs create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Linux.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.OSX.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Windows.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Linux.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.OSX.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Windows.verified.txt diff --git a/src/Build/Logging/BaseConsoleLogger.cs b/src/Build/Logging/BaseConsoleLogger.cs index 96942d03d55..598837e60e1 100644 --- a/src/Build/Logging/BaseConsoleLogger.cs +++ b/src/Build/Logging/BaseConsoleLogger.cs @@ -12,6 +12,7 @@ using System.Threading; using Microsoft.Build.Evaluation; using Microsoft.Build.Framework; +using Microsoft.Build.Framework.Logging; using Microsoft.Build.Internal; using Microsoft.Build.Shared; using ColorResetter = Microsoft.Build.Logging.ColorResetter; @@ -75,20 +76,11 @@ internal abstract class BaseConsoleLogger : INodeLogger, IStringBuilderProvider /// public void ParseParameters() { - if (Parameters == null) - { - return; - } + var parameters = LoggerParametersHelper.ParseParameters(Parameters); - foreach (string parameter in Parameters.Split(parameterDelimiters)) + foreach (var parameter in parameters) { - if (string.IsNullOrWhiteSpace(parameter)) - { - continue; - } - - string[] parameterAndValue = parameter.Split(s_parameterValueSplitCharacter); - ApplyParameter(parameterAndValue[0], parameterAndValue.Length > 1 ? parameterAndValue[1] : null); + ApplyParameter(parameter.Key, parameter.Value); } } @@ -1038,33 +1030,17 @@ internal virtual bool ApplyParameter(string parameterName, string parameterValue /// private bool ApplyVerbosityParameter(string parameterValue) { - switch (parameterValue.ToUpperInvariant()) + if (LoggerParametersHelper.TryParseVerbosityParameter(parameterValue, out LoggerVerbosity? verbosity)) { - case "Q": - case "QUIET": - Verbosity = LoggerVerbosity.Quiet; - return true; - case "M": - case "MINIMAL": - Verbosity = LoggerVerbosity.Minimal; - return true; - case "N": - case "NORMAL": - Verbosity = LoggerVerbosity.Normal; - return true; - case "D": - case "DETAILED": - Verbosity = LoggerVerbosity.Detailed; - return true; - case "DIAG": - case "DIAGNOSTIC": - Verbosity = LoggerVerbosity.Diagnostic; - return true; - default: - string errorCode; - string helpKeyword; - string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out errorCode, out helpKeyword, "InvalidVerbosity", parameterValue); - throw new LoggerException(message, null, errorCode, helpKeyword); + Verbosity = (LoggerVerbosity)verbosity; + return true; + } + else + { + string errorCode; + string helpKeyword; + string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out errorCode, out helpKeyword, "InvalidVerbosity", parameterValue); + throw new LoggerException(message, null, errorCode, helpKeyword); } } @@ -1135,16 +1111,6 @@ private bool ApplyVerbosityParameter(string parameterValue) internal const string projectSeparatorLine = "__________________________________________________"; - /// - /// Console logger parameters delimiters. - /// - internal static readonly char[] parameterDelimiters = MSBuildConstants.SemicolonChar; - - /// - /// Console logger parameter value split character. - /// - private static readonly char[] s_parameterValueSplitCharacter = MSBuildConstants.EqualsChar; - /// /// When true, accumulate performance numbers. /// diff --git a/src/Build/Logging/ConsoleLogger.cs b/src/Build/Logging/ConsoleLogger.cs index 35886babcca..41bfaf94f50 100644 --- a/src/Build/Logging/ConsoleLogger.cs +++ b/src/Build/Logging/ConsoleLogger.cs @@ -4,6 +4,7 @@ using System; using Microsoft.Build.BackEnd.Logging; using Microsoft.Build.Framework; +using Microsoft.Build.Framework.Logging; using Microsoft.Build.Framework.Telemetry; using Microsoft.Build.Shared; using BaseConsoleLogger = Microsoft.Build.BackEnd.Logging.BaseConsoleLogger; @@ -113,7 +114,7 @@ private void InitializeBaseConsoleLogger() bool preferConsoleColor = false; if (!string.IsNullOrEmpty(_parameters)) { - string[] parameterComponents = _parameters.Split(BaseConsoleLogger.parameterDelimiters); + string[] parameterComponents = _parameters.Split(LoggerParametersHelper.s_parameterDelimiters); foreach (string param in parameterComponents) { if (param.Length <= 0) diff --git a/src/Framework/Logging/LoggerParametersHelper.cs b/src/Framework/Logging/LoggerParametersHelper.cs new file mode 100644 index 00000000000..2dd27bed0b3 --- /dev/null +++ b/src/Framework/Logging/LoggerParametersHelper.cs @@ -0,0 +1,73 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Build.Shared; + +namespace Microsoft.Build.Framework.Logging +{ + internal static class LoggerParametersHelper + { + // Logger parameters delimiters. + public static readonly char[] s_parameterDelimiters = MSBuildConstants.SemicolonChar; + + // Logger parameter value split character. + public static readonly char[] s_parameterValueSplitCharacter = MSBuildConstants.EqualsChar; + + public static bool TryParseVerbosityParameter(string parameterValue, out LoggerVerbosity? verbosity) + { + switch (parameterValue.ToUpperInvariant()) + { + case "Q": + case "QUIET": + verbosity = LoggerVerbosity.Quiet; + return true; + case "M": + case "MINIMAL": + verbosity = LoggerVerbosity.Minimal; + return true; + case "N": + case "NORMAL": + verbosity = LoggerVerbosity.Normal; + return true; + case "D": + case "DETAILED": + verbosity = LoggerVerbosity.Detailed; + return true; + case "DIAG": + case "DIAGNOSTIC": + verbosity = LoggerVerbosity.Diagnostic; + return true; + default: + verbosity = null; + return false; + } + } + + public static IEnumerable> ParseParameters(string? parametersString) + { + List> parameters = new(); + if (parametersString == null) + { + return parameters; + } + + foreach (string parameter in parametersString.Split(s_parameterDelimiters)) + { + if (string.IsNullOrWhiteSpace(parameter)) + { + continue; + } + + string[] parameterAndValue = parameter.Split(s_parameterValueSplitCharacter); + parameters.Add(new KeyValuePair(parameterAndValue[0], parameterAndValue.Length > 1 ? parameterAndValue[1] : null )); + } + + return parameters; + } + } +} diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Linux.verified.txt new file mode 100644 index 00000000000..ea19717537f --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Linux.verified.txt @@ -0,0 +1,6 @@ +]9;4;3;\ project succeeded (0.2s) + Task Command Line. +[?25l +[?25h +Build succeeded in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.OSX.verified.txt new file mode 100644 index 00000000000..809a4f0a0eb --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.OSX.verified.txt @@ -0,0 +1,5 @@ + project succeeded (0.2s) + Task Command Line. +[?25l +[?25h +Build succeeded in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Windows.verified.txt new file mode 100644 index 00000000000..ea19717537f --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Windows.verified.txt @@ -0,0 +1,6 @@ +]9;4;3;\ project succeeded (0.2s) + Task Command Line. +[?25l +[?25h +Build succeeded in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Linux.verified.txt new file mode 100644 index 00000000000..d5e6b72e894 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Linux.verified.txt @@ -0,0 +1,4 @@ +]9;4;3;\[?25l +[?25h +Build succeeded in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.OSX.verified.txt new file mode 100644 index 00000000000..4d414bf90bf --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.OSX.verified.txt @@ -0,0 +1,3 @@ +[?25l +[?25h +Build succeeded in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Windows.verified.txt new file mode 100644 index 00000000000..d5e6b72e894 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Windows.verified.txt @@ -0,0 +1,4 @@ +]9;4;3;\[?25l +[?25h +Build succeeded in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/TerminalLogger_Tests.cs b/src/MSBuild.UnitTests/TerminalLogger_Tests.cs index 5e97d38f1af..c695cd64f1d 100644 --- a/src/MSBuild.UnitTests/TerminalLogger_Tests.cs +++ b/src/MSBuild.UnitTests/TerminalLogger_Tests.cs @@ -193,6 +193,14 @@ private BuildMessageEventArgs MakeMessageEventArgs(string message, MessageImport }; } + private BuildMessageEventArgs MakeTaskCommandLineEventArgs(string message, MessageImportance importance) + { + return new TaskCommandLineEventArgs(message, "Task", importance) + { + BuildEventContext = MakeBuildEventContext(), + }; + } + private BuildMessageEventArgs MakeExtendedMessageEventArgs(string message, MessageImportance importance, string extendedType, Dictionary? extendedMetadata) { return new ExtendedBuildMessageEventArgs(extendedType, message, "keyword", null, importance, _messageTime) @@ -447,6 +455,36 @@ public Task PrintTestSummaryQuietVerbosity_Succeded() return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); } + [Fact] + public Task PrintSummaryWithTaskCommandLineEventArgs_Succeded() + { + _terminallogger.Verbosity = LoggerVerbosity.Detailed; + _terminallogger.Parameters = "SHOWCOMMANDLINE=on"; + _terminallogger.ParseParameters(); + + InvokeLoggerCallbacksForSimpleProject(succeeded: true, () => + { + MessageRaised?.Invoke(_eventSender, MakeTaskCommandLineEventArgs("Task Command Line.", MessageImportance.High)); + }); + + return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); + } + + [Fact] + public Task PrintSummaryWithoutTaskCommandLineEventArgs_Succeded() + { + _terminallogger.Verbosity = LoggerVerbosity.Detailed; + _terminallogger.Parameters = "SHOWCOMMANDLINE=off"; + _terminallogger.ParseParameters(); + + InvokeLoggerCallbacksForSimpleProject(succeeded: true, () => + { + MessageRaised?.Invoke(_eventSender, MakeTaskCommandLineEventArgs("Task Command Line.", MessageImportance.High)); + }); + + return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); + } + [Fact] public void DisplayNodesShowsCurrent() { diff --git a/src/MSBuild/MSBuild.csproj b/src/MSBuild/MSBuild.csproj index 0415842c6b7..f396ca22cfe 100644 --- a/src/MSBuild/MSBuild.csproj +++ b/src/MSBuild/MSBuild.csproj @@ -128,6 +128,7 @@ + diff --git a/src/MSBuild/TerminalLogger/TerminalLogger.cs b/src/MSBuild/TerminalLogger/TerminalLogger.cs index 98419a4b8f3..f4ceb444366 100644 --- a/src/MSBuild/TerminalLogger/TerminalLogger.cs +++ b/src/MSBuild/TerminalLogger/TerminalLogger.cs @@ -10,12 +10,13 @@ using Microsoft.Build.Shared; using System.Text.RegularExpressions; using System.Diagnostics; - +using Microsoft.Build.Framework.Logging; #if NET7_0_OR_GREATER using System.Diagnostics.CodeAnalysis; using System.Globalization; + #endif #if NETFRAMEWORK using Microsoft.IO; @@ -199,6 +200,11 @@ public ProjectContext(BuildEventContext context) /// private DateTime? _testEndTime; + /// + /// Whether to show TaskCommandLineEventArgs high-priority messages. + /// + private bool _showCommandLine = false; + /// /// Default constructor, used by the MSBuild logger infra. /// @@ -228,10 +234,7 @@ internal TerminalLogger(ITerminal terminal) public LoggerVerbosity Verbosity { get; set; } = LoggerVerbosity.Minimal; /// - public string Parameters - { - get => ""; set { } - } + public string? Parameters { get; set; } = null; /// public void Initialize(IEventSource eventSource, int nodeCount) @@ -245,6 +248,8 @@ public void Initialize(IEventSource eventSource, int nodeCount) /// public void Initialize(IEventSource eventSource) { + ParseParameters(); + eventSource.BuildStarted += BuildStarted; eventSource.BuildFinished += BuildFinished; eventSource.ProjectStarted += ProjectStarted; @@ -263,6 +268,83 @@ public void Initialize(IEventSource eventSource) } } + /// + /// Parses out the logger parameters from the Parameters string. + /// + public void ParseParameters() + { + var parameters = LoggerParametersHelper.ParseParameters(Parameters); + + foreach (var parameter in parameters) + { + ApplyParameter(parameter.Key, parameter.Value); + } + } + + /// + /// Apply a terminal logger parameter. + /// parameterValue may be null, if there is no parameter value. + /// + private bool ApplyParameter(string parameterName, string? parameterValue) + { + ErrorUtilities.VerifyThrowArgumentNull(parameterName, nameof(parameterName)); + + switch (parameterName.ToUpperInvariant()) + { + case "V": + case "VERBOSITY": + return ApplyVerbosityParameter(parameterValue); + case "SHOWCOMMANDLINE": + return ApplyShowCommandLineParameter(parameterValue); + } + + return false; + } + + /// + /// Apply the verbosity value + /// + private bool ApplyVerbosityParameter(string? parameterValue) + { + if (parameterValue is not null && LoggerParametersHelper.TryParseVerbosityParameter(parameterValue, out LoggerVerbosity? verbosity)) + { + Verbosity = (LoggerVerbosity)verbosity!; + return true; + } + else + { + string errorCode; + string helpKeyword; + string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out errorCode, out helpKeyword, "InvalidVerbosity", parameterValue); + throw new LoggerException(message, null, errorCode, helpKeyword); + } + } + + /// + /// Apply the show command Line value + /// + private bool ApplyShowCommandLineParameter(string? parameterValue) + { + if (String.IsNullOrEmpty(parameterValue)) + { + _showCommandLine = true; + } + else + { + try + { + _showCommandLine = ConversionUtilities.ConvertStringToBool(parameterValue); + } + catch (ArgumentException) + { + return false; + } + } + + return true; + } + + /// public void Shutdown() { @@ -756,6 +838,11 @@ private void MessageRaised(object sender, BuildMessageEventArgs e) if (Verbosity > LoggerVerbosity.Normal) { + if (e is TaskCommandLineEventArgs && !_showCommandLine) + { + return; + } + if (hasProject) { project!.AddBuildMessage(MessageSeverity.Message, message); From 7dd402f3c0678607683b495a762fcfbdfac7f092 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:55:04 +0100 Subject: [PATCH 09/12] Add a test, fix typo --- ...bosity_FailedWithErrors.Linux.verified.txt | 9 +++++++++ ...erbosity_FailedWithErrors.OSX.verified.txt | 8 ++++++++ ...sity_FailedWithErrors.Windows.verified.txt | 9 +++++++++ ...ineEventArgs_Succeeded.Linux.verified.txt} | 0 ...dLineEventArgs_Succeeded.OSX.verified.txt} | 0 ...eEventArgs_Succeeded.Windows.verified.txt} | 0 ...ineEventArgs_Succeeded.Linux.verified.txt} | 0 ...dLineEventArgs_Succeeded.OSX.verified.txt} | 0 ...eEventArgs_Succeeded.Windows.verified.txt} | 0 ...malVerbosity_Succeeded.Linux.verified.txt} | 0 ...ormalVerbosity_Succeeded.OSX.verified.txt} | 0 ...lVerbosity_Succeeded.Windows.verified.txt} | 0 ...ietVerbosity_Succeeded.Linux.verified.txt} | 0 ...QuietVerbosity_Succeeded.OSX.verified.txt} | 0 ...tVerbosity_Succeeded.Windows.verified.txt} | 0 src/MSBuild.UnitTests/TerminalLogger_Tests.cs | 20 +++++++++++++++---- 16 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Linux.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.OSX.verified.txt create mode 100644 src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Windows.verified.txt rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Linux.verified.txt => TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeeded.Linux.verified.txt} (100%) rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.OSX.verified.txt => TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeeded.OSX.verified.txt} (100%) rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Windows.verified.txt => TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeeded.Windows.verified.txt} (100%) rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Linux.verified.txt => TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeeded.Linux.verified.txt} (100%) rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.OSX.verified.txt => TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeeded.OSX.verified.txt} (100%) rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Windows.verified.txt => TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeeded.Windows.verified.txt} (100%) rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Linux.verified.txt => TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeeded.Linux.verified.txt} (100%) rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.OSX.verified.txt => TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeeded.OSX.verified.txt} (100%) rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Windows.verified.txt => TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeeded.Windows.verified.txt} (100%) rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Linux.verified.txt => TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeeded.Linux.verified.txt} (100%) rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt => TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeeded.OSX.verified.txt} (100%) rename src/MSBuild.UnitTests/Snapshots/{TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Windows.verified.txt => TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeeded.Windows.verified.txt} (100%) diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Linux.verified.txt new file mode 100644 index 00000000000..d2a02edc803 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Linux.verified.txt @@ -0,0 +1,9 @@ +]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + High importance message! + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.OSX.verified.txt new file mode 100644 index 00000000000..6d379050835 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.OSX.verified.txt @@ -0,0 +1,8 @@ +The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + High importance message! + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Windows.verified.txt new file mode 100644 index 00000000000..d2a02edc803 --- /dev/null +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Windows.verified.txt @@ -0,0 +1,9 @@ +]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` + project failed with errors (0.2s) + High importance message! + directory/file(1,2,3,4): warning AA0000: Warning! + directory/file(1,2,3,4): error AA0000: Error! +[?25l +[?25h +Build failed with errors in 5.0s +]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeeded.Linux.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Linux.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeeded.Linux.verified.txt diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeeded.OSX.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.OSX.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeeded.OSX.verified.txt diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeeded.Windows.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeded.Windows.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithTaskCommandLineEventArgs_Succeeded.Windows.verified.txt diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeeded.Linux.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Linux.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeeded.Linux.verified.txt diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeeded.OSX.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.OSX.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeeded.OSX.verified.txt diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeeded.Windows.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeded.Windows.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithoutTaskCommandLineEventArgs_Succeeded.Windows.verified.txt diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeeded.Linux.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Linux.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeeded.Linux.verified.txt diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeeded.OSX.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.OSX.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeeded.OSX.verified.txt diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeeded.Windows.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeded.Windows.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryNormalVerbosity_Succeeded.Windows.verified.txt diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeeded.Linux.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Linux.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeeded.Linux.verified.txt diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeeded.OSX.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.OSX.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeeded.OSX.verified.txt diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeeded.Windows.verified.txt similarity index 100% rename from src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeded.Windows.verified.txt rename to src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintTestSummaryQuietVerbosity_Succeeded.Windows.verified.txt diff --git a/src/MSBuild.UnitTests/TerminalLogger_Tests.cs b/src/MSBuild.UnitTests/TerminalLogger_Tests.cs index c695cd64f1d..c7580aaf035 100644 --- a/src/MSBuild.UnitTests/TerminalLogger_Tests.cs +++ b/src/MSBuild.UnitTests/TerminalLogger_Tests.cs @@ -438,7 +438,7 @@ public Task PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors() } [Fact] - public Task PrintTestSummaryNormalVerbosity_Succeded() + public Task PrintTestSummaryNormalVerbosity_Succeeded() { _terminallogger.Verbosity = LoggerVerbosity.Normal; InvokeLoggerCallbacksForTestProject(succeeded: true, CallAllTypesOfTestMessages); @@ -447,7 +447,7 @@ public Task PrintTestSummaryNormalVerbosity_Succeded() } [Fact] - public Task PrintTestSummaryQuietVerbosity_Succeded() + public Task PrintTestSummaryQuietVerbosity_Succeeded() { _terminallogger.Verbosity = LoggerVerbosity.Quiet; InvokeLoggerCallbacksForTestProject(succeeded: true, CallAllTypesOfTestMessages); @@ -456,7 +456,19 @@ public Task PrintTestSummaryQuietVerbosity_Succeded() } [Fact] - public Task PrintSummaryWithTaskCommandLineEventArgs_Succeded() + public Task PrintSummaryWithOverwrittenVerbosity_FailedWithErrors() + { + _terminallogger.Verbosity = LoggerVerbosity.Minimal; + _terminallogger.Parameters = "v=diag"; + _terminallogger.ParseParameters(); + + InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError); + + return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform(); + } + + [Fact] + public Task PrintSummaryWithTaskCommandLineEventArgs_Succeeded() { _terminallogger.Verbosity = LoggerVerbosity.Detailed; _terminallogger.Parameters = "SHOWCOMMANDLINE=on"; @@ -471,7 +483,7 @@ public Task PrintSummaryWithTaskCommandLineEventArgs_Succeded() } [Fact] - public Task PrintSummaryWithoutTaskCommandLineEventArgs_Succeded() + public Task PrintSummaryWithoutTaskCommandLineEventArgs_Succeeded() { _terminallogger.Verbosity = LoggerVerbosity.Detailed; _terminallogger.Parameters = "SHOWCOMMANDLINE=off"; From 7df23fd6678d357e65ceb207f221c8255d51d50f Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:17:15 +0100 Subject: [PATCH 10/12] fix merge bugs --- ...mmaryDetailedVerbosity_FailedWithErrors.Linux.verified.txt | 4 ++-- ...SummaryDetailedVerbosity_FailedWithErrors.OSX.verified.txt | 4 ++-- ...aryDetailedVerbosity_FailedWithErrors.Windows.verified.txt | 4 ++-- ...aryDiagnosticVerbosity_FailedWithErrors.Linux.verified.txt | 4 ++-- ...mmaryDiagnosticVerbosity_FailedWithErrors.OSX.verified.txt | 4 ++-- ...yDiagnosticVerbosity_FailedWithErrors.Windows.verified.txt | 4 ++-- ...ummaryMinimalVerbosity_FailedWithErrors.Linux.verified.txt | 4 ++-- ...dSummaryMinimalVerbosity_FailedWithErrors.OSX.verified.txt | 4 ++-- ...maryMinimalVerbosity_FailedWithErrors.Windows.verified.txt | 4 ++-- ...SummaryNormalVerbosity_FailedWithErrors.Linux.verified.txt | 4 ++-- ...ldSummaryNormalVerbosity_FailedWithErrors.OSX.verified.txt | 4 ++-- ...mmaryNormalVerbosity_FailedWithErrors.Windows.verified.txt | 4 ++-- ...thOverwrittenVerbosity_FailedWithErrors.Linux.verified.txt | 4 ++-- ...WithOverwrittenVerbosity_FailedWithErrors.OSX.verified.txt | 4 ++-- ...OverwrittenVerbosity_FailedWithErrors.Windows.verified.txt | 4 ++-- src/MSBuild/TerminalLogger/TerminalLogger.cs | 2 +- 16 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Linux.verified.txt index d2a02edc803..2a011fd87a4 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Linux.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Linux.verified.txt @@ -1,9 +1,9 @@ ]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) High importance message! directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s ]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.OSX.verified.txt index 6d379050835..94c8f8666eb 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.OSX.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.OSX.verified.txt @@ -1,8 +1,8 @@ The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) High importance message! directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Windows.verified.txt index d2a02edc803..2a011fd87a4 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Windows.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDetailedVerbosity_FailedWithErrors.Windows.verified.txt @@ -1,9 +1,9 @@ ]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) High importance message! directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s ]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Linux.verified.txt index d2a02edc803..2a011fd87a4 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Linux.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Linux.verified.txt @@ -1,9 +1,9 @@ ]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) High importance message! directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s ]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.OSX.verified.txt index 6d379050835..94c8f8666eb 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.OSX.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.OSX.verified.txt @@ -1,8 +1,8 @@ The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) High importance message! directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Windows.verified.txt index d2a02edc803..2a011fd87a4 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Windows.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors.Windows.verified.txt @@ -1,9 +1,9 @@ ]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) High importance message! directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s ]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Linux.verified.txt index 78887aa5bf3..c0b5f816a67 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Linux.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Linux.verified.txt @@ -1,8 +1,8 @@ ]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s ]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.OSX.verified.txt index 1127e52e995..f2c3daca5c7 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.OSX.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.OSX.verified.txt @@ -1,7 +1,7 @@ The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Windows.verified.txt index 78887aa5bf3..c0b5f816a67 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Windows.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryMinimalVerbosity_FailedWithErrors.Windows.verified.txt @@ -1,8 +1,8 @@ ]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s ]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Linux.verified.txt index 78887aa5bf3..c0b5f816a67 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Linux.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Linux.verified.txt @@ -1,8 +1,8 @@ ]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s ]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.OSX.verified.txt index 1127e52e995..f2c3daca5c7 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.OSX.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.OSX.verified.txt @@ -1,7 +1,7 @@ The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Windows.verified.txt index 78887aa5bf3..c0b5f816a67 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Windows.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryNormalVerbosity_FailedWithErrors.Windows.verified.txt @@ -1,8 +1,8 @@ ]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s ]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Linux.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Linux.verified.txt index d2a02edc803..2a011fd87a4 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Linux.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Linux.verified.txt @@ -1,9 +1,9 @@ ]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) High importance message! directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s ]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.OSX.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.OSX.verified.txt index 6d379050835..94c8f8666eb 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.OSX.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.OSX.verified.txt @@ -1,8 +1,8 @@ The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) High importance message! directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s diff --git a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Windows.verified.txt b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Windows.verified.txt index d2a02edc803..2a011fd87a4 100644 --- a/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Windows.verified.txt +++ b/src/MSBuild.UnitTests/Snapshots/TerminalLogger_Tests.PrintSummaryWithOverwrittenVerbosity_FailedWithErrors.Windows.verified.txt @@ -1,9 +1,9 @@ ]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet` - project failed with errors (0.2s) + project failed with 1 error(s) and 1 warning(s) (0.2s) High importance message! directory/file(1,2,3,4): warning AA0000: Warning! directory/file(1,2,3,4): error AA0000: Error! [?25l [?25h -Build failed with errors in 5.0s +Build failed with 1 error(s) and 1 warning(s) in 5.0s ]9;4;0;\ \ No newline at end of file diff --git a/src/MSBuild/TerminalLogger/TerminalLogger.cs b/src/MSBuild/TerminalLogger/TerminalLogger.cs index 8df24bf5de7..f7e5bed1511 100644 --- a/src/MSBuild/TerminalLogger/TerminalLogger.cs +++ b/src/MSBuild/TerminalLogger/TerminalLogger.cs @@ -417,7 +417,7 @@ private void BuildFinished(object sender, BuildFinishedEventArgs e) var skipped = _testRunSummaries.Sum(t => t.Skipped); var testDuration = (_testStartTime != null && _testEndTime != null ? (_testEndTime - _testStartTime).Value.TotalSeconds : 0).ToString("F1"); - var colorizedResult = _testRunSummaries.Any(t => t.Failed > 0) || || (_buildErrorsCount > 0) + var colorizedResult = _testRunSummaries.Any(t => t.Failed > 0) || (_buildErrorsCount > 0) ? AnsiCodes.Colorize(ResourceUtilities.GetResourceString("BuildResult_Failed"), TerminalColor.Red) : AnsiCodes.Colorize(ResourceUtilities.GetResourceString("BuildResult_Succeeded"), TerminalColor.Green); From ed9d5eedccb9f1f581e7476fd21fe9e591742bd0 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Thu, 28 Mar 2024 10:54:30 +0100 Subject: [PATCH 11/12] Address PR comments --- src/MSBuild/TerminalLogger/TerminalLogger.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/MSBuild/TerminalLogger/TerminalLogger.cs b/src/MSBuild/TerminalLogger/TerminalLogger.cs index f7e5bed1511..8687642f2ce 100644 --- a/src/MSBuild/TerminalLogger/TerminalLogger.cs +++ b/src/MSBuild/TerminalLogger/TerminalLogger.cs @@ -331,14 +331,7 @@ private bool ApplyShowCommandLineParameter(string? parameterValue) } else { - try - { - _showCommandLine = ConversionUtilities.ConvertStringToBool(parameterValue); - } - catch (ArgumentException) - { - return false; - } + return ConversionUtilities.TryConvertStringToBool(parameterValue, out _showCommandLine); } return true; From 015c200a635b4becbba28a26f95b262af0f0f394 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Tue, 2 Apr 2024 18:34:45 +0200 Subject: [PATCH 12/12] Address PR comments --- src/Build/Logging/BaseConsoleLogger.cs | 6 ++-- .../Logging/LoggerParametersHelper.cs | 28 ++++++++----------- src/MSBuild/TerminalLogger/TerminalLogger.cs | 26 ++++++++--------- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/Build/Logging/BaseConsoleLogger.cs b/src/Build/Logging/BaseConsoleLogger.cs index 598837e60e1..7dc448e6fb5 100644 --- a/src/Build/Logging/BaseConsoleLogger.cs +++ b/src/Build/Logging/BaseConsoleLogger.cs @@ -76,11 +76,9 @@ internal abstract class BaseConsoleLogger : INodeLogger, IStringBuilderProvider /// public void ParseParameters() { - var parameters = LoggerParametersHelper.ParseParameters(Parameters); - - foreach (var parameter in parameters) + foreach (var parameter in LoggerParametersHelper.ParseParameters(Parameters)) { - ApplyParameter(parameter.Key, parameter.Value); + ApplyParameter(parameter.Item1, parameter.Item2); } } diff --git a/src/Framework/Logging/LoggerParametersHelper.cs b/src/Framework/Logging/LoggerParametersHelper.cs index 2dd27bed0b3..b4f7a843d4f 100644 --- a/src/Framework/Logging/LoggerParametersHelper.cs +++ b/src/Framework/Logging/LoggerParametersHelper.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -18,7 +19,7 @@ internal static class LoggerParametersHelper // Logger parameter value split character. public static readonly char[] s_parameterValueSplitCharacter = MSBuildConstants.EqualsChar; - public static bool TryParseVerbosityParameter(string parameterValue, out LoggerVerbosity? verbosity) + public static bool TryParseVerbosityParameter(string parameterValue, [NotNullWhen(true)] out LoggerVerbosity? verbosity) { switch (parameterValue.ToUpperInvariant()) { @@ -48,26 +49,21 @@ public static bool TryParseVerbosityParameter(string parameterValue, out LoggerV } } - public static IEnumerable> ParseParameters(string? parametersString) + public static IEnumerable> ParseParameters(string? parametersString) { - List> parameters = new(); - if (parametersString == null) + if (parametersString is not null) { - return parameters; - } - - foreach (string parameter in parametersString.Split(s_parameterDelimiters)) - { - if (string.IsNullOrWhiteSpace(parameter)) + foreach (string parameter in parametersString.Split(s_parameterDelimiters)) { - continue; - } + if (string.IsNullOrWhiteSpace(parameter)) + { + continue; + } - string[] parameterAndValue = parameter.Split(s_parameterValueSplitCharacter); - parameters.Add(new KeyValuePair(parameterAndValue[0], parameterAndValue.Length > 1 ? parameterAndValue[1] : null )); + string[] parameterAndValue = parameter.Split(s_parameterValueSplitCharacter); + yield return new Tuple(parameterAndValue[0], parameterAndValue.Length > 1 ? parameterAndValue[1] : null); + } } - - return parameters; } } } diff --git a/src/MSBuild/TerminalLogger/TerminalLogger.cs b/src/MSBuild/TerminalLogger/TerminalLogger.cs index 8687642f2ce..dd13fbe28aa 100644 --- a/src/MSBuild/TerminalLogger/TerminalLogger.cs +++ b/src/MSBuild/TerminalLogger/TerminalLogger.cs @@ -273,11 +273,9 @@ public void Initialize(IEventSource eventSource) /// public void ParseParameters() { - var parameters = LoggerParametersHelper.ParseParameters(Parameters); - - foreach (var parameter in parameters) + foreach (var parameter in LoggerParametersHelper.ParseParameters(Parameters)) { - ApplyParameter(parameter.Key, parameter.Value); + ApplyParameter(parameter.Item1, parameter.Item2); } } @@ -285,7 +283,10 @@ public void ParseParameters() /// Apply a terminal logger parameter. /// parameterValue may be null, if there is no parameter value. /// - private bool ApplyParameter(string parameterName, string? parameterValue) + /// + /// If verbosity parameter value is not correct, throws an exception. Other incorrect parameter values are disregarded. + /// + private void ApplyParameter(string parameterName, string? parameterValue) { ErrorUtilities.VerifyThrowArgumentNull(parameterName, nameof(parameterName)); @@ -293,23 +294,22 @@ private bool ApplyParameter(string parameterName, string? parameterValue) { case "V": case "VERBOSITY": - return ApplyVerbosityParameter(parameterValue); + ApplyVerbosityParameter(parameterValue); + break; case "SHOWCOMMANDLINE": - return ApplyShowCommandLineParameter(parameterValue); + TryApplyShowCommandLineParameter(parameterValue); + break; } - - return false; } /// /// Apply the verbosity value /// - private bool ApplyVerbosityParameter(string? parameterValue) + private void ApplyVerbosityParameter(string? parameterValue) { if (parameterValue is not null && LoggerParametersHelper.TryParseVerbosityParameter(parameterValue, out LoggerVerbosity? verbosity)) { - Verbosity = (LoggerVerbosity)verbosity!; - return true; + Verbosity = (LoggerVerbosity)verbosity; } else { @@ -323,7 +323,7 @@ private bool ApplyVerbosityParameter(string? parameterValue) /// /// Apply the show command Line value /// - private bool ApplyShowCommandLineParameter(string? parameterValue) + private bool TryApplyShowCommandLineParameter(string? parameterValue) { if (String.IsNullOrEmpty(parameterValue)) {