Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Terminal Logger respect verbosity #9810

Merged
merged 15 commits into from
Apr 3, 2024
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;\
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
]9;4;3;\]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
emptyString
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
]9;4;3;\]9;4;0;\
142 changes: 134 additions & 8 deletions src/MSBuild.UnitTests/TerminalLogger_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()
Expand Down Expand Up @@ -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(),
};
Expand Down Expand Up @@ -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<string, string?>? extendedMetadata)
{
return new BuildMessageEventArgs(message, "keyword", null, MessageImportance.High)
return new ExtendedBuildMessageEventArgs(extendedType, message, "keyword", null, importance, _messageTime)
{
BuildEventContext = MakeBuildEventContext(),
ExtendedMetadata = extendedMetadata
};
}

Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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<string, string?>() { { "displayName", "testName1" }, { "localizedResult", "passed" } }));
MessageRaised?.Invoke(_eventSender, MakeExtendedMessageEventArgs(
"Test skipped.",
MessageImportance.High,
"TLTESTSKIPPED",
new Dictionary<string, string?>() { { "displayName", "testName2" }, { "localizedResult", "skipped" } }));
MessageRaised?.Invoke(_eventSender, MakeExtendedMessageEventArgs(
"Test results.",
MessageImportance.High,
"TLTESTFINISH",
new Dictionary<string, string?>() { { "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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/MSBuild/TerminalLogger/MessageSeverity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ namespace Microsoft.Build.Logging.TerminalLogger;
/// <summary>
/// Enumerates the supported message severities.
/// </summary>
internal enum MessageSeverity { Warning, Error }
internal enum MessageSeverity { Message, Warning, Error }
Loading