-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Log messages for Test Results #75084
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,12 @@ | |
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Immutable; | ||
using System.Collections.ObjectModel; | ||
using System.Text; | ||
using Microsoft.CodeAnalysis.LanguageServer.Handler; | ||
using Microsoft.CodeAnalysis.LanguageServer.Handler.Testing; | ||
using Microsoft.CodeAnalysis.Shared.Extensions; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; | ||
|
@@ -138,31 +141,83 @@ private static string CreateTestCaseReportMessage(TestRunChangedEventArgs? testR | |
{ | ||
var messageBuilder = new StringBuilder(); | ||
messageBuilder.Append($"[{result.Outcome}] {result.TestCase.DisplayName}"); | ||
if (result.ErrorMessage != null || result.ErrorStackTrace != null) | ||
{ | ||
messageBuilder.AppendLine(); | ||
} | ||
|
||
if (!string.IsNullOrWhiteSpace(result.ErrorMessage)) | ||
{ | ||
messageBuilder.AppendLine(); | ||
messageBuilder.AppendLine(IndentString($"{LanguageServerResources.Message}:", 4)); | ||
messageBuilder.AppendLine(IndentString(result.ErrorMessage, 8)); | ||
} | ||
|
||
if (!string.IsNullOrWhiteSpace(result.ErrorStackTrace)) | ||
{ | ||
messageBuilder.AppendLine(); | ||
messageBuilder.AppendLine(value: IndentString($"{LanguageServerResources.Stack_Trace}:", 4)); | ||
messageBuilder.AppendLine(IndentString(result.ErrorStackTrace, 8)); | ||
} | ||
|
||
var standardOutputMessages = GetTestMessages(result.Messages, TestResultMessage.StandardOutCategory); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you have a screenshot of what it looks like? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the description with some output. Let me see if I can get output and error messages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, ok. So just one new line at the top and we squish everything together.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lgtm! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
if (standardOutputMessages.Length > 0) | ||
{ | ||
messageBuilder.AppendLine(); | ||
messageBuilder.AppendLine(value: IndentString($"{LanguageServerResources.Standard_Output_Messages}:", 4)); | ||
messageBuilder.AppendLine(FormatMessages(standardOutputMessages, 8)); | ||
} | ||
|
||
var standardErrorMessages = GetTestMessages(result.Messages, TestResultMessage.StandardErrorCategory); | ||
if (standardErrorMessages.Length > 0) | ||
{ | ||
messageBuilder.AppendLine(); | ||
messageBuilder.AppendLine(value: IndentString($"{LanguageServerResources.Standard_Error_Messages}:", 4)); | ||
messageBuilder.AppendLine(FormatMessages(standardErrorMessages, 8)); | ||
} | ||
|
||
var debugTraceMessages = GetTestMessages(result.Messages, TestResultMessage.DebugTraceCategory); | ||
if (debugTraceMessages.Length > 0) | ||
{ | ||
messageBuilder.AppendLine(); | ||
messageBuilder.AppendLine(value: IndentString($"{LanguageServerResources.Debug_Trace_Messages}:", 4)); | ||
messageBuilder.AppendLine(FormatMessages(debugTraceMessages, 8)); | ||
} | ||
|
||
var additionalInfoMessages = GetTestMessages(result.Messages, TestResultMessage.AdditionalInfoCategory); | ||
if (additionalInfoMessages.Length > 0) | ||
{ | ||
messageBuilder.AppendLine(); | ||
messageBuilder.AppendLine(value: IndentString($"{LanguageServerResources.Additional_Info_Messages}:", 4)); | ||
messageBuilder.AppendLine(FormatMessages(additionalInfoMessages, 8)); | ||
} | ||
|
||
return messageBuilder.ToString(); | ||
}); | ||
|
||
return string.Join(Environment.NewLine, results); | ||
|
||
static string IndentString(string text, int count) | ||
{ | ||
return text.Replace(Environment.NewLine, $"{Environment.NewLine} ").TrimEnd().Insert(0, new string(' ', count)); | ||
var indentation = new string(' ', count); | ||
return text.Replace(Environment.NewLine, $"{Environment.NewLine}{indentation}").TrimEnd().Insert(0, indentation); | ||
} | ||
|
||
static ImmutableArray<TestResultMessage> GetTestMessages(Collection<TestResultMessage> messages, string requiredCategory) | ||
{ | ||
return messages.WhereAsArray(static (msg, category) => msg.Category.Equals(category, StringComparison.OrdinalIgnoreCase), requiredCategory); | ||
} | ||
|
||
static string FormatMessages(ImmutableArray<TestResultMessage> messages, int indentation) | ||
{ | ||
var builder = new StringBuilder(); | ||
foreach (var message in messages) | ||
{ | ||
if (message.Text is null) | ||
continue; | ||
|
||
var indentedMessage = IndentString(message.Text, indentation); | ||
if (!string.IsNullOrWhiteSpace(indentedMessage)) | ||
builder.Append(indentedMessage); | ||
} | ||
|
||
return builder.ToString(); | ||
} | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will append an empty line between the msg and stack trace, which IIRC is why I appended only once above. Maybe not the biggest issue but I believe that was why it was written that way