Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/AutomationUtils/Matchers/GauntletEventMatcher.cs
Ben Marsh 878f74458e Horde: Use long-lived regex instances for matching patterns.
#preflight 62963a2b95336ad2bfbfe846

[CL 20438090 by Ben Marsh in ue5-main branch]
2022-05-31 12:02:25 -04:00

92 lines
2.8 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System.Text.RegularExpressions;
using EpicGames.Core;
using Microsoft.Extensions.Logging;
#nullable enable
namespace AutomationUtils.Matchers
{
/// <summary>
/// Matcher for Gauntlet unit tests
/// </summary>
class GauntletEventMatcher : ILogEventMatcher
{
static readonly Regex s_engineTestPattern = new Regex(@"^(?<indent>\s*)Error: EngineTest.RunTests Group:(?<group>[^\s]+) \(");
static readonly Regex s_mdHeadingPattern = new Regex(@"^\s*#{1,3} ");
static readonly Regex s_mdTestNamePattern = new Regex(@"^\s*#####\s+(?<friendly_name>.*):\s*(?<name>\S+)\s*");
static readonly Regex s_mdTestListPattern = new Regex(@"^\s*### The following tests failed:");
static readonly Regex s_screenshotPattern = new Regex(@"Error: Screenshot '(?<screenshot>[^']+)' test failed");
static readonly Regex s_genericPattern = new Regex("\\[ERROR\\] (.*)$");
public LogEventMatch? Match(ILogCursor cursor)
{
Match? match;
if(cursor.TryMatch(s_engineTestPattern, out match))
{
string indent = match.Groups["indent"].Value + " ";
LogEventBuilder builder = new LogEventBuilder(cursor.Hanging());
builder.Annotate(match.Groups["group"]);
string group = match.Groups["group"].Value;
bool inErrorList = false;
// List<LogEventBuilder> ChildEvents = new List<LogEventBuilder>();
// int LineCount = 1;
EventId eventId = KnownLogEvents.Gauntlet;
while (builder.Next.CurrentLine != null)
{
builder.MoveNext();
if (inErrorList)
{
Match? testNameMatch;
if (builder.Current.IsMatch(s_mdHeadingPattern))
{
inErrorList = false;
}
else if (builder.Current.TryMatch(s_mdTestNamePattern, out testNameMatch))
{
builder.AddProperty("group", group);//.Annotate().AddProperty("group", Group);
builder.Annotate(testNameMatch.Groups["name"]);
builder.Annotate(testNameMatch.Groups["friendly_name"]);
eventId = KnownLogEvents.Gauntlet_UnitTest;// ChildEvents.Add(ChildEventBuilder);
}
}
else
{
if (builder.Current.IsMatch(s_mdTestListPattern))
{
inErrorList = true;
}
}
}
return builder.ToMatch(LogEventPriority.High, LogLevel.Error, eventId);
}
if (cursor.TryMatch(s_screenshotPattern, out match))
{
LogEventBuilder builder = new LogEventBuilder(cursor);
builder.Annotate(match.Groups["screenshot"], LogEventMarkup.ScreenshotTest);//.MarkAsScreenshotTest();
return builder.ToMatch(LogEventPriority.High, LogLevel.Error, KnownLogEvents.Gauntlet_ScreenshotTest);
}
if (cursor.TryMatch(s_genericPattern, out _))
{
LogEventBuilder builder = new LogEventBuilder(cursor);
return builder.ToMatch(LogEventPriority.High, LogLevel.Error, KnownLogEvents.Generic);
}
return null;
}
}
}