private void HandleTestResult(TestResult testResult) { // We only care about tests with negative outcomes if (testResult.Outcome <= TestOutcome.Passed) { return; } var stackFrame = TryGetTestStackFrame(testResult); var filePath = TryGetSourceFilePath(testResult, stackFrame); var line = TryGetSourceLine(testResult, stackFrame); var message = !string.IsNullOrWhiteSpace(testResult.ErrorMessage) ? $"{testResult.TestCase.DisplayName}: {testResult.ErrorMessage}" : $"{testResult.TestCase.DisplayName}: {testResult.Outcome}"; if (testResult.Outcome == TestOutcome.Failed) { GitHubActions.ReportError(message, filePath, line); } else if (_reportWarnings) { GitHubActions.ReportWarning(message, filePath, line); } }
private void Initialize(TestLoggerEvents events, TestLoggerOptions options) { if (!GitHubActions.IsRunningInsideWorkflow()) { Console.WriteLine("WARN: Not running inside GitHub Actions, but using GitHub Actions Test Logger."); } Context = new TestLoggerContext(Console.Out, options); events.TestResult += (_, args) => Context.ProcessTestResult(args.Result); }
public void ProcessTestResult(TestResult testResult) { if (testResult.Outcome <= TestOutcome.Passed) { return; } var stackFrame = TryGetTestStackFrame(testResult); var filePath = TryGetSourceFilePath(testResult, stackFrame); var line = TryGetSourceLine(testResult, stackFrame); var message = Options.MessageFormat.Apply(testResult); if (testResult.Outcome == TestOutcome.Failed) { Output.WriteLine(GitHubActions.FormatError(message, filePath, line)); } else if (Options.ReportWarnings) { Output.WriteLine(GitHubActions.FormatWarning(message, filePath, line)); } }