/// <summary> /// Attempts to match the line with each regex specified by the current state /// </summary> /// <param name="state">Current state</param> /// <param name="logData">Input line</param> /// <returns>True if a match occurs</returns> private bool AttemptMatch(ITestResultParserState state, LogData logData) { foreach (var regexActionPair in state.RegexesToMatch) { try { var match = regexActionPair.Regex.Match(logData.Line); if (match.Success) { // Reset this value on a match _stateContext.LinesWithinWhichMatchIsExpected = -1; _currentState = (MochaParserStates)regexActionPair.MatchAction(match, _stateContext); return(true); } } catch (RegexMatchTimeoutException) { Logger.Warning($"MochaTestResultParser : AttemptMatch : failed due to timeout while trying to match { regexActionPair.Regex.ToString() } at line {logData.LineNumber}"); Telemetry.AddAndAggregate("RegexTimeout", new List <string> { regexActionPair.Regex.ToString() }, MochaTelemetryConstants.EventArea); } } state.PeformNoPatternMatchedAction(logData.Line, _stateContext); return(false); }
/// <summary> /// Detailed constructor where specified logger and telemetry data collector are initialized along with test run manager /// </summary> /// <param name="testRunPublisher"></param> /// <param name="diagnosticDataCollector"></param> /// <param name="telemetryDataCollector"></param> public MochaTestResultParser(ITestRunManager testRunManager, ITraceLogger logger, ITelemetryDataCollector telemetryDataCollector) : base(testRunManager, logger, telemetryDataCollector) { Logger.Info("MochaTestResultParser : Starting mocha test result parser."); Telemetry.AddOrUpdate(MochaTelemetryConstants.Initialize, true, MochaTelemetryConstants.EventArea); // Initialize the starting state of the parser var testRun = new TestRun($"{Name}/{Version}", "Mocha", 1); _stateContext = new MochaParserStateContext(testRun); _currentState = MochaParserStates.ExpectingTestResults; }
/// <summary> /// Used to reset the parser inluding the test run and context /// </summary> private void ResetParser() { // Start a new TestRun var newTestRun = new TestRun($"{Name}/{Version}", this.stateContext.TestRun.TestRunId + 1); // Set state to ExpectingTestResults this.currentState = MochaParserStates.ExpectingTestResults; // Refresh the context this.stateContext.Initialize(newTestRun); this.logger.Info("MochaTestResultParser : Successfully reset the parser."); }
/// <summary> /// Attempts to match the line with each regex specified by the current state /// </summary> /// <param name="state">Current state</param> /// <param name="testResultsLine">Input line</param> /// <returns>True if a match occurs</returns> private bool AttemptMatch(ITestResultParserState state, LogData testResultsLine) { foreach (var regexActionPair in state.RegexsToMatch) { var match = regexActionPair.Regex.Match(testResultsLine.Message); if (match.Success) { this.currentState = (MochaParserStates)regexActionPair.MatchAction(match, this.stateContext); return(true); } } return(false); }
/// <summary> /// Detailed constructor where specified logger and telemetry data collector are initialized along with test run manager /// </summary> /// <param name="testRunPublisher"></param> /// <param name="diagnosticDataCollector"></param> /// <param name="telemetryDataCollector"></param> public MochaTestResultParser(ITestRunManager testRunManager, ITraceLogger logger, ITelemetryDataCollector telemetryDataCollector) : base(testRunManager, logger, telemetryDataCollector) { logger.Info("MochaTestResultParser : Starting mocha test result parser."); telemetryDataCollector.AddToCumulativeTelemetry(MochaTelemetryConstants.EventArea, MochaTelemetryConstants.Initialize, true); // Initialize the starting state of the parser var testRun = new TestRun($"{Name}/{Version}", 1); this.stateContext = new MochaParserStateContext(testRun); this.currentState = MochaParserStates.ExpectingTestResults; this.expectingTestResults = new MochaExpectingTestResults(AttemptPublishAndResetParser, logger, telemetryDataCollector); this.expectingTestRunSummary = new MochaExpectingTestRunSummary(AttemptPublishAndResetParser, logger, telemetryDataCollector); this.expectingStackTraces = new MochaExpectingStackTraces(AttemptPublishAndResetParser, logger, telemetryDataCollector); }