From c4f8f08953f70cc1ba5a249937f8f9861b98eaed Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Thu, 28 Mar 2024 02:13:22 +0700 Subject: [PATCH] Make second reporter resolution more strict (#412) Now, it only considers assemblies with names matching the *reporters* pattern. --- Allure.XUnit/AllureXunitFacade.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Allure.XUnit/AllureXunitFacade.cs b/Allure.XUnit/AllureXunitFacade.cs index 3a4a6518..2c82bdb0 100644 --- a/Allure.XUnit/AllureXunitFacade.cs +++ b/Allure.XUnit/AllureXunitFacade.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; +using System.Text.RegularExpressions; using Xunit; using Xunit.Abstractions; @@ -11,6 +11,7 @@ namespace Allure.Xunit { static class AllureXunitFacade { + static readonly Regex REPORTER_ASSEMBLY_PATTERN = new(@".*reporters.*"); internal static IMessageSink CreateAllureXunitMessageHandler( IRunnerLogger logger ) @@ -89,7 +90,9 @@ select reporter static IEnumerable GetReporters() => from assembly in AppDomain.CurrentDomain.GetAssemblies() - where IsPotentialReporterAssembly(assembly) + where IsPotentialReporterAssembly( + assembly.GetName()?.Name + ) from type in assembly.GetTypes() where IsReporterType(type) select Activator.CreateInstance(type) as IRunnerReporter; @@ -99,11 +102,13 @@ where IsReporterType(type) /// skipped as well, because there is only one reporter there and it /// has already been picked at the time this code is run. /// - static bool IsPotentialReporterAssembly(Assembly assembly) => - assembly?.FullName is not null + static bool IsPotentialReporterAssembly(string? name) => + name is not null + && + REPORTER_ASSEMBLY_PATTERN.IsMatch(name) && ASSEMBLY_PREFIXES_TO_SKIP.All( - a => !assembly.FullName.StartsWith( + a => !name.StartsWith( a, StringComparison.OrdinalIgnoreCase )