Skip to content

Commit

Permalink
#331: DisableAppDomain switch is not fully respected for Discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Jul 1, 2023
1 parent 1aa409d commit 671542c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/xunit.runner.visualstudio/VsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#if NETCOREAPP
using System.Text;
using Internal.Microsoft.Extensions.DependencyModel;
using InternalRuntimeEnvironment = Internal.Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;
#endif

namespace Xunit.Runner.VisualStudio
Expand Down Expand Up @@ -251,9 +250,13 @@ void DiscoverTests<TVisitor>(
var fileName = Path.GetFileNameWithoutExtension(assemblyFileName);
var shadowCopy = configuration.ShadowCopyOrDefault;
var diagnosticSink = DiagnosticMessageSink.ForDiagnostics(logger, fileName, configuration.DiagnosticMessagesOrDefault);
var appDomain = configuration.AppDomain ?? AppDomainDefaultBehavior;

using var framework = new XunitFrontController(AppDomainDefaultBehavior, assemblyFileName, shadowCopy: shadowCopy, diagnosticMessageSink: MessageSinkAdapter.Wrap(diagnosticSink));
if (!DiscoverTestsInSource(framework, logger, testPlatformContext, runSettings, visitorFactory, visitComplete, assemblyFileName, shadowCopy, configuration))
if (runSettings.DisableAppDomain)
appDomain = AppDomainSupport.Denied;

using var framework = new XunitFrontController(appDomain, assemblyFileName, shadowCopy: shadowCopy, diagnosticMessageSink: MessageSinkAdapter.Wrap(diagnosticSink));
if (!DiscoverTestsInSource(framework, logger, testPlatformContext, runSettings, visitorFactory, visitComplete, assemblyFileName, shadowCopy, configuration, appDomain))
break;
}
}
Expand All @@ -272,7 +275,8 @@ bool DiscoverTestsInSource<TVisitor>(
Action<string, ITestFrameworkDiscoverer, ITestFrameworkDiscoveryOptions, TVisitor>? visitComplete,
string assemblyFileName,
bool shadowCopy,
TestAssemblyConfiguration configuration)
TestAssemblyConfiguration configuration,
AppDomainSupport appDomain)
where TVisitor : IVsDiscoverySink, IDisposable
{
if (cancelled)
Expand All @@ -297,7 +301,7 @@ bool DiscoverTestsInSource<TVisitor>(

using var visitor = visitorFactory(assemblyFileName, framework, discoveryOptions);
var totalTests = 0;
var usingAppDomains = framework.CanUseAppDomains && AppDomainDefaultBehavior != AppDomainSupport.Denied;
var usingAppDomains = framework.CanUseAppDomains && appDomain != AppDomainSupport.Denied;
reporterMessageHandler.OnMessage(new TestAssemblyDiscoveryStarting(assembly, usingAppDomains, shadowCopy, discoveryOptions));

try
Expand Down Expand Up @@ -469,7 +473,8 @@ void RunTestsInAssembly(
},
assemblyFileName,
shadowCopy,
configuration
configuration,
appDomain
);

if (assemblyDiscoveredInfo == null || assemblyDiscoveredInfo.DiscoveredTestCases == null || !assemblyDiscoveredInfo.DiscoveredTestCases.Any())
Expand Down

0 comments on commit 671542c

Please sign in to comment.