From 1bef219ab6ef56c37a980eddf12a37605101cad9 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Fri, 10 Jan 2025 12:48:01 +0000 Subject: [PATCH] Fix --- .../TestApplicationBuilderExtensions.cs | 4 +-- TUnit.Engine/Framework/IFilterReceiver.cs | 6 ++++ TUnit.Engine/Framework/TUnitTestFramework.cs | 10 +++++- TUnit.Engine/Reporters/GitHubReporter.cs | 36 +++++++++++-------- 4 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 TUnit.Engine/Framework/IFilterReceiver.cs diff --git a/TUnit.Engine/Extensions/TestApplicationBuilderExtensions.cs b/TUnit.Engine/Extensions/TestApplicationBuilderExtensions.cs index 3bb64d32ad..69ce73f36c 100644 --- a/TUnit.Engine/Extensions/TestApplicationBuilderExtensions.cs +++ b/TUnit.Engine/Extensions/TestApplicationBuilderExtensions.cs @@ -23,7 +23,7 @@ public static void AddTUnit(this ITestApplicationBuilder testApplicationBuilder) testApplicationBuilder.RegisterTestFramework( serviceProvider => new TestFrameworkCapabilities(new TrxReportCapability(), new BannerCapability(serviceProvider.GetRequiredService(), serviceProvider.GetCommandLineOptions())), - (capabilities, serviceProvider) => new TUnitTestFramework(extension, serviceProvider, capabilities)); + (capabilities, serviceProvider) => new TUnitTestFramework(extension, serviceProvider, capabilities, [githubReporter])); testApplicationBuilder.AddTreeNodeFilterService(extension); // TODO: testApplicationBuilder.CommandLine.AddProvider(() => new JsonOutputCommandProvider(extension)); @@ -34,6 +34,6 @@ public static void AddTUnit(this ITestApplicationBuilder testApplicationBuilder) testApplicationBuilder.CommandLine.AddProvider(() => new DisableLogoCommandProvider(extension)); testApplicationBuilder.TestHost.AddDataConsumer(_ => githubReporter); - testApplicationBuilder.TestHost.AddTestApplicationLifecycleCallbacks(sp => githubReporter.WithFilter(FilterParser.StringifyFilter(sp.GetRequiredService()))); + testApplicationBuilder.TestHost.AddTestApplicationLifecycleCallbacks(_ => githubReporter); } } \ No newline at end of file diff --git a/TUnit.Engine/Framework/IFilterReceiver.cs b/TUnit.Engine/Framework/IFilterReceiver.cs new file mode 100644 index 0000000000..9875519a71 --- /dev/null +++ b/TUnit.Engine/Framework/IFilterReceiver.cs @@ -0,0 +1,6 @@ +namespace TUnit.Engine.Framework; + +public interface IFilterReceiver +{ + string? Filter { set; } +} \ No newline at end of file diff --git a/TUnit.Engine/Framework/TUnitTestFramework.cs b/TUnit.Engine/Framework/TUnitTestFramework.cs index 002c49249a..fe7d5ddf62 100644 --- a/TUnit.Engine/Framework/TUnitTestFramework.cs +++ b/TUnit.Engine/Framework/TUnitTestFramework.cs @@ -14,15 +14,18 @@ internal sealed class TUnitTestFramework : ITestFramework, IDataProducer private readonly IExtension _extension; private readonly IServiceProvider _frameworkServiceProvider; private readonly ITestFrameworkCapabilities _capabilities; + private readonly IEnumerable _filterReceivers; private static readonly ConcurrentDictionary ServiceProvidersPerSession = []; public TUnitTestFramework(IExtension extension, IServiceProvider frameworkServiceProvider, - ITestFrameworkCapabilities capabilities) + ITestFrameworkCapabilities capabilities, + IEnumerable filterReceivers) { _extension = extension; _frameworkServiceProvider = frameworkServiceProvider; _capabilities = capabilities; + _filterReceivers = filterReceivers; } public Task IsEnabledAsync() => _extension.IsEnabledAsync(); @@ -51,6 +54,11 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context) ); var stringFilter = serviceProvider.FilterParser.GetTestFilter(context); + + foreach (var filterReceiver in _filterReceivers) + { + filterReceiver.Filter = stringFilter; + } var logger = serviceProvider.Logger; diff --git a/TUnit.Engine/Reporters/GitHubReporter.cs b/TUnit.Engine/Reporters/GitHubReporter.cs index 4752aec1c0..ab564d9038 100644 --- a/TUnit.Engine/Reporters/GitHubReporter.cs +++ b/TUnit.Engine/Reporters/GitHubReporter.cs @@ -4,10 +4,11 @@ using Microsoft.Testing.Platform.Extensions; using Microsoft.Testing.Platform.Extensions.Messages; using Microsoft.Testing.Platform.Extensions.TestHost; +using TUnit.Engine.Framework; namespace TUnit.Engine.Reporters; -public class GitHubReporter(IExtension extension) : IDataConsumer, ITestApplicationLifecycleCallbacks +public class GitHubReporter(IExtension extension) : IDataConsumer, ITestApplicationLifecycleCallbacks, IFilterReceiver { private const long MaxFileSizeInBytes = 1 * 1024 * 1024; // 1MB private string _outputSummaryFilePath = null!; @@ -62,22 +63,33 @@ public Task AfterRunAsync(int exitCode, CancellationToken cancellation) { return Task.CompletedTask; } - + var last = _updates.ToDictionary(x => x.Key, x => x.Value.Last()); - - var passedCount = last.Count(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is PassedTestNodeStateProperty)); - var failed = last.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is FailedTestNodeStateProperty or ErrorTestNodeStateProperty)).ToArray(); - var cancelled = last.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is CancelledTestNodeStateProperty)).ToArray(); - var timeout = last.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is TimeoutTestNodeStateProperty)).ToArray(); - var skipped = last.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is SkippedTestNodeStateProperty)).ToArray(); - var inProgress = last.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is InProgressTestNodeStateProperty)).ToArray(); + + var passedCount = last.Count(x => + x.Value.TestNode.Properties.AsEnumerable().Any(p => p is PassedTestNodeStateProperty)); + var failed = last.Where(x => + x.Value.TestNode.Properties.AsEnumerable() + .Any(p => p is FailedTestNodeStateProperty or ErrorTestNodeStateProperty)).ToArray(); + var cancelled = last.Where(x => + x.Value.TestNode.Properties.AsEnumerable().Any(p => p is CancelledTestNodeStateProperty)).ToArray(); + var timeout = last + .Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is TimeoutTestNodeStateProperty)) + .ToArray(); + var skipped = last + .Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is SkippedTestNodeStateProperty)) + .ToArray(); + var inProgress = last.Where(x => + x.Value.TestNode.Properties.AsEnumerable().Any(p => p is InProgressTestNodeStateProperty)).ToArray(); var stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"## {Assembly.GetEntryAssembly()?.GetName().Name}"); + if (!string.IsNullOrEmpty(Filter)) { stringBuilder.AppendLine($"### Filter: {Filter}"); } + stringBuilder.AppendLine(); stringBuilder.AppendLine("| Test Count | Status |"); stringBuilder.AppendLine("| --- | --- |"); @@ -220,11 +232,5 @@ private static string GetStatus(TestNodeStateProperty? stateProperty) }; } - public ITestApplicationLifecycleCallbacks WithFilter(string? filter) - { - Filter = filter; - return this; - } - public string? Filter { get; set; } } \ No newline at end of file