Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that all subpackages are located correctly #549

Merged
merged 2 commits into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/NUnitEngine/nunit.engine/Internal/TestPackageExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
CharliePoole marked this conversation as resolved.
Show resolved Hide resolved
using System.Collections.Generic;

namespace NUnit.Engine.Internal
{
public delegate bool TestPackageSelectorDelegate(TestPackage p);

/// <summary>
/// Extension methods for use with TestPackages
/// </summary>
public static class TestPackageExtensions
{
public static bool IsAssemblyPackage(this TestPackage package)
{
return package.FullName != null && PathUtils.IsAssemblyFileType(package.FullName);
}

public static bool HasSubPackages(this TestPackage package)
{
return package.SubPackages.Count > 0;
}

public static IList<TestPackage> Select(this TestPackage package, TestPackageSelectorDelegate selector)
{
var selection = new List<TestPackage>();

AccumulatePackages(package, selection, selector);

return selection;
}

private static void AccumulatePackages(TestPackage package, IList<TestPackage> selection, TestPackageSelectorDelegate selector)
{
if (selector(package))
selection.Add(package);

foreach (var subPackage in package.SubPackages)
AccumulatePackages(subPackage, selection, selector);
}
}
}
4 changes: 0 additions & 4 deletions src/NUnitEngine/nunit.engine/Runners/AggregatingTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ protected override TestEngineResult LoadPackage()
{
var results = new List<TestEngineResult>();

var packages = new List<TestPackage>(TestPackage.SubPackages);
if (packages.Count == 0)
packages.Add(TestPackage);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops!

foreach (var runner in Runners)
results.Add(runner.Load());

Expand Down
19 changes: 7 additions & 12 deletions src/NUnitEngine/nunit.engine/Runners/DirectTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ protected override TestEngineResult LoadPackage()
{
var result = new TestEngineResult();

// DirectRunner may be called with a single-assembly package
// or a set of assemblies as subpackages.
var packages = TestPackage.SubPackages;
if (packages.Count == 0)
packages.Add(TestPackage);
// DirectRunner may be called with a single-assembly package,
// a set of assemblies as subpackages or even an arbitrary
// hierarchy of packages and subpackages with assemblies
// found in the terminal nodes.
var packagesToLoad = TestPackage.Select(p => !p.HasSubPackages());

var driverService = Services.GetService<IDriverService>();

foreach (var subPackage in packages)
foreach (var subPackage in packagesToLoad)
{
var testFile = subPackage.FullName;

Expand Down Expand Up @@ -207,12 +207,7 @@ protected override TestEngineResult RunTests(ITestEventListener listener, TestFi
#if !NETSTANDARD1_6
if (_assemblyResolver != null)
{
var packages = TestPackage.SubPackages;

if (packages.Count == 0)
packages.Add(TestPackage);

foreach (var package in packages)
foreach (var package in TestPackage.Select(p => p.IsAssemblyPackage()))
_assemblyResolver.RemovePathFromFile(package.FullName);
}
#endif
Expand Down