Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions TUnit.Engine/Reporters/GitHubReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ or TimeoutTestNodeStateProperty
return stateProperty switch
{
FailedTestNodeStateProperty failedTestNodeStateProperty =>
failedTestNodeStateProperty.Exception?.ToString() ?? "Test failed",
GetTruncatedExceptionMessage(failedTestNodeStateProperty.Exception) ?? "Test failed",
ErrorTestNodeStateProperty errorTestNodeStateProperty =>
errorTestNodeStateProperty.Exception?.ToString() ?? "Test failed",
GetTruncatedExceptionMessage(errorTestNodeStateProperty.Exception) ?? "Test failed",
TimeoutTestNodeStateProperty timeoutTestNodeStateProperty => timeoutTestNodeStateProperty.Explanation,
#pragma warning disable CS0618 // CancelledTestNodeStateProperty is obsolete
CancelledTestNodeStateProperty => "Test was cancelled",
Expand All @@ -332,6 +332,25 @@ or TimeoutTestNodeStateProperty
};
}

private static string? GetTruncatedExceptionMessage(Exception? exception)
{
if (exception is null)
{
return null;
}

var message = exception.Message;

var firstStackTraceLine = exception.StackTrace?.Split('\n').FirstOrDefault()?.Trim();

if (string.IsNullOrWhiteSpace(firstStackTraceLine))
{
return message;
}

return $"{message}\n{firstStackTraceLine}";
}

private static string GetStatus(IProperty? stateProperty)
{
return stateProperty switch
Expand Down
Loading