Skip to content

Commit

Permalink
Make second reporter resolution more strict (#412)
Browse files Browse the repository at this point in the history
Now, it only considers assemblies with names matching the
*reporters* pattern.
  • Loading branch information
delatrie committed Mar 27, 2024
1 parent f03b633 commit c4f8f08
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Allure.XUnit/AllureXunitFacade.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -11,6 +11,7 @@ namespace Allure.Xunit
{
static class AllureXunitFacade
{
static readonly Regex REPORTER_ASSEMBLY_PATTERN = new(@".*reporters.*");
internal static IMessageSink CreateAllureXunitMessageHandler(
IRunnerLogger logger
)
Expand Down Expand Up @@ -89,7 +90,9 @@ select reporter

static IEnumerable<IRunnerReporter> 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;
Expand All @@ -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.
/// </summary>
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
)
Expand Down

0 comments on commit c4f8f08

Please sign in to comment.