From 4d26ca1f10ddb3b1ec32424588eef42b81a7135a Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Wed, 20 Feb 2019 17:32:13 +0100 Subject: [PATCH 1/2] Ensure that all subpackages are located correctly --- .../Internal/TestPackageExtensions.cs | 41 +++++++++++++++++++ .../Runners/AggregatingTestRunner.cs | 4 -- .../nunit.engine/Runners/DirectTestRunner.cs | 19 ++++----- 3 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 src/NUnitEngine/nunit.engine/Internal/TestPackageExtensions.cs diff --git a/src/NUnitEngine/nunit.engine/Internal/TestPackageExtensions.cs b/src/NUnitEngine/nunit.engine/Internal/TestPackageExtensions.cs new file mode 100644 index 000000000..f5776b233 --- /dev/null +++ b/src/NUnitEngine/nunit.engine/Internal/TestPackageExtensions.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; + +namespace NUnit.Engine.Internal +{ + public delegate bool TestPackageSelectorDelegate(TestPackage p); + + /// + /// Extension methods for use with TestPackages + /// + 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 Select(this TestPackage package, TestPackageSelectorDelegate selector) + { + var selection = new List(); + + AccumulatePackages(package, selection, selector); + + return selection; + } + + private static void AccumulatePackages(TestPackage package, IList selection, TestPackageSelectorDelegate selector) + { + if (selector(package)) + selection.Add(package); + + foreach (var subPackage in package.SubPackages) + AccumulatePackages(subPackage, selection, selector); + } + } +} diff --git a/src/NUnitEngine/nunit.engine/Runners/AggregatingTestRunner.cs b/src/NUnitEngine/nunit.engine/Runners/AggregatingTestRunner.cs index 107ea6579..3adfe7fe9 100644 --- a/src/NUnitEngine/nunit.engine/Runners/AggregatingTestRunner.cs +++ b/src/NUnitEngine/nunit.engine/Runners/AggregatingTestRunner.cs @@ -101,10 +101,6 @@ protected override TestEngineResult LoadPackage() { var results = new List(); - var packages = new List(TestPackage.SubPackages); - if (packages.Count == 0) - packages.Add(TestPackage); - foreach (var runner in Runners) results.Add(runner.Load()); diff --git a/src/NUnitEngine/nunit.engine/Runners/DirectTestRunner.cs b/src/NUnitEngine/nunit.engine/Runners/DirectTestRunner.cs index e3b91ba5a..fc7a5dfa4 100644 --- a/src/NUnitEngine/nunit.engine/Runners/DirectTestRunner.cs +++ b/src/NUnitEngine/nunit.engine/Runners/DirectTestRunner.cs @@ -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(); - foreach (var subPackage in packages) + foreach (var subPackage in packagesToLoad) { var testFile = subPackage.FullName; @@ -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 From b5481212ba19d75d976885eb5b5450f817eb1977 Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Mon, 25 Feb 2019 07:38:45 +0100 Subject: [PATCH 2/2] Add license header to file --- .../Internal/TestPackageExtensions.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/NUnitEngine/nunit.engine/Internal/TestPackageExtensions.cs b/src/NUnitEngine/nunit.engine/Internal/TestPackageExtensions.cs index f5776b233..bbb34342b 100644 --- a/src/NUnitEngine/nunit.engine/Internal/TestPackageExtensions.cs +++ b/src/NUnitEngine/nunit.engine/Internal/TestPackageExtensions.cs @@ -1,4 +1,27 @@ -using System; +// *********************************************************************** +// Copyright (c) 2019 Charlie Poole, Rob Prouse +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// *********************************************************************** + +using System; using System.Collections.Generic; namespace NUnit.Engine.Internal