in src/extensions/testframework/YamlTestFrameworkConsoleHost.cs [131:190]
private void PrintResult(TestResult testResult)
{
lock (this)
{
Console.ForegroundColor = ColorHelpers.MapColor(ConsoleColor.DarkGray);
if (testResult.Outcome == TestOutcome.Passed) Console.ForegroundColor = ConsoleColor.Green;
if (testResult.Outcome == TestOutcome.Skipped) Console.ForegroundColor = ConsoleColor.Yellow;
if (testResult.Outcome == TestOutcome.Failed) Console.ForegroundColor = ConsoleColor.Red;
var duration = TimeSpanFormatter.FormatMsOrSeconds(testResult.Duration);
Console.WriteLine($"{testResult.Outcome} ({duration}): {testResult.TestCase.FullyQualifiedName}");
Console.ResetColor();
if (testResult.Outcome == TestOutcome.Failed)
{
var codeFilePath = testResult.TestCase.CodeFilePath;
var hasCodeFilePath = !string.IsNullOrEmpty(codeFilePath);
if (hasCodeFilePath)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"at {codeFilePath}({testResult.TestCase.LineNumber})");
}
var stack = testResult.ErrorStackTrace;
var hasStack = !string.IsNullOrEmpty(stack);
if (hasStack)
{
Console.ForegroundColor = ColorHelpers.MapColor(ConsoleColor.DarkGray);
Console.WriteLine(stack.TrimEnd('\r', '\n', ' '));
}
var stdErr = testResult.Messages.FirstOrDefault(x => x.Category == TestResultMessage.StandardErrorCategory)?.Text;
var hasStdErr = !string.IsNullOrEmpty(stdErr);
if (hasStdErr)
{
var lines = stdErr!.Split('\n');
if (lines.Length > 10)
{
var first5 = lines.Take(5);
var last5 = lines.Skip(lines.Length - 5);
lines = first5.Concat(new[] { $"[ ******* ------- TRIMMED +{lines.Length - 10} LINE(s) ------- ******* ]" }).Concat(last5).ToArray();
stdErr = string.Join("\n", lines) + "\n...";
}
Console.ForegroundColor = ColorHelpers.MapColor(ConsoleColor.DarkGray);
Console.WriteLine(stdErr.TrimEnd('\r', '\n', ' '));
}
var err = testResult.ErrorMessage;
var hasErr = !string.IsNullOrEmpty(err);
if (hasErr)
{
Console.ResetColor();
Console.WriteLine(err.TrimEnd('\r', '\n', ' '));
}
Console.ResetColor();
if (hasStack || hasStdErr || hasErr || hasCodeFilePath) Console.WriteLine();
}
}
}