Skip to content

Commit

Permalink
30 Error message "File type is not supported" when uses .nunit config…
Browse files Browse the repository at this point in the history
…uration file - move all logic related to .nunit config files into MasterTestRunner, ensure that TestPackage is expanded before usage
  • Loading branch information
Nikolay Pianikov authored and Nikolay Pianikov committed Sep 6, 2016
1 parent d31ebef commit 0d1f845
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 59 deletions.
16 changes: 2 additions & 14 deletions src/NUnitEngine/nunit.engine/Runners/AbstractTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public abstract class AbstractTestRunner : ITestEngineRunner
public AbstractTestRunner(IServiceLocator services, TestPackage package)
{
Services = services;
TestPackage = package;
TestRunnerFactory = Services.GetService<ITestRunnerFactory>();
ProjectService = Services.GetService<IProjectService>();
TestPackage = package;
}

#region Properties
Expand Down Expand Up @@ -214,7 +214,7 @@ public AsyncTestEngineResult RunAsync(ITestEventListener listener, TestFilter fi
{
return RunTestsAsync(listener, filter);
}

#endregion

#region IDisposable Members
Expand All @@ -239,17 +239,5 @@ protected virtual void Dispose(bool disposing)
}

#endregion

#region Helper Methods

protected bool IsProjectPackage(TestPackage package)
{
return package != null
&& ProjectService != null
&& !string.IsNullOrEmpty(package.FullName)
&& ProjectService.CanLoadFrom(package.FullName);
}

#endregion
}
}
12 changes: 2 additions & 10 deletions src/NUnitEngine/nunit.engine/Runners/AggregatingTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ public override TestEngineResult Explore(TestFilter filter)
foreach (ITestEngineRunner runner in _runners)
results.Add(runner.Explore(filter));

TestEngineResult result = ResultHelper.Merge(results);

return IsProjectPackage(TestPackage)
? result.MakePackageResult(TestPackage.Name, TestPackage.FullName)
: result;
return ResultHelper.Merge(results);
}

/// <summary>
Expand Down Expand Up @@ -159,11 +155,7 @@ protected override TestEngineResult RunTests(ITestEventListener listener, TestFi

if (disposeRunners) _runners.Clear();

TestEngineResult result = ResultHelper.Merge(results);

return IsProjectPackage(TestPackage)
? result.MakePackageResult(TestPackage.Name, TestPackage.FullName)
: result;
return ResultHelper.Merge(results);
}

/// <summary>
Expand Down
9 changes: 0 additions & 9 deletions src/NUnitEngine/nunit.engine/Runners/DirectTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ public override TestEngineResult Explore(TestFilter filter)
foreach (IFrameworkDriver driver in _drivers)
result.Add(driver.Explore(filter.Text));

if (IsProjectPackage(TestPackage))
result = result.MakePackageResult(TestPackage.Name, TestPackage.FullName);

return result;
}

Expand Down Expand Up @@ -115,9 +112,6 @@ protected override TestEngineResult LoadPackage()
_drivers.Add(driver);
}

if (IsProjectPackage(TestPackage))
result = result.MakePackageResult(TestPackage.Name, TestPackage.FullName);

return result;
}

Expand Down Expand Up @@ -159,9 +153,6 @@ protected override TestEngineResult RunTests(ITestEventListener listener, TestFi
result.Add(driver.Run(listener, filter.Text));
}

if (IsProjectPackage(TestPackage))
result = result.MakePackageResult(TestPackage.Name, TestPackage.FullName);

if (_assemblyResolver != null)
{
var packages = TestPackage.SubPackages;
Expand Down
99 changes: 74 additions & 25 deletions src/NUnitEngine/nunit.engine/Runners/MasterTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
Expand All @@ -36,25 +35,25 @@ namespace NUnit.Engine.Runners
public class MasterTestRunner : ITestRunner
{
private const string TEST_RUN_ELEMENT = "test-run";

private ITestEngineRunner _engineRunner;

private IServiceLocator _services;
private IRuntimeFrameworkService _runtimeService;
private ExtensionService _extensionService;
private IProjectService _projectService;
private ITestRunnerFactory _testRunnerFactory;
private readonly ITestEngineRunner _engineRunner;
private readonly IServiceLocator _services;
private readonly IRuntimeFrameworkService _runtimeService;
private readonly ExtensionService _extensionService;
private readonly IProjectService _projectService;
private bool _disposed;

public MasterTestRunner(IServiceLocator services, TestPackage package)
{
if (services == null) throw new ArgumentNullException("services");
if (package == null) throw new ArgumentNullException("package");

_services = services;
TestPackage = package;

_testRunnerFactory = _services.GetService<ITestRunnerFactory>();
_projectService = _services.GetService<IProjectService>();
_runtimeService = _services.GetService<IRuntimeFrameworkService>();
_extensionService = _services.GetService<ExtensionService>();
_engineRunner = _testRunnerFactory.MakeTestRunner(package);
_engineRunner = _services.GetService<ITestRunnerFactory>().MakeTestRunner(package);
}

#region Properties
Expand Down Expand Up @@ -139,7 +138,8 @@ public int CountTestCases(TestFilter filter)
/// <returns>An XmlNode giving the result of the test execution</returns>
public XmlNode Run(ITestEventListener listener, TestFilter filter)
{
return RunTests(listener, filter).Xml;
LoadPackage();
return PrepareResult(RunTests(listener, filter)).Xml;
}

/// <summary>
Expand All @@ -151,6 +151,7 @@ public XmlNode Run(ITestEventListener listener, TestFilter filter)
/// <returns></returns>
public ITestRun RunAsync(ITestEventListener listener, TestFilter filter)
{
LoadPackage();
return _engineRunner.RunAsync(listener, filter);
}

Expand All @@ -171,7 +172,8 @@ public void StopRun(bool force)
/// <returns>An XmlNode representing the tests found.</returns>
public XmlNode Explore(TestFilter filter)
{
return _engineRunner.Explore(filter)
LoadPackage();
return PrepareResult(_engineRunner.Explore(filter))
.Aggregate(TEST_RUN_ELEMENT, TestPackage.Name, TestPackage.FullName).Xml;
}

Expand All @@ -185,8 +187,6 @@ public void Dispose()
GC.SuppressFinalize(this);
}

private bool _disposed = false;

/// <summary>
/// Dispose of this object.
/// </summary>
Expand Down Expand Up @@ -218,7 +218,7 @@ private void LoadPackage()
// Some files in the top level package may be projects.
// Expand them so that they contain subprojects for
// each contained assembly.
ExpandProjects();
EnsurePackagesAreExpanded(TestPackage);

// Use SelectRuntimeFramework for its side effects.
// Info will be left behind in the package about
Expand All @@ -236,14 +236,51 @@ private void LoadPackage()
LoadResult = _engineRunner.Load().Aggregate(TEST_RUN_ELEMENT, TestPackage.Name, TestPackage.FullName);
}

private void ExpandProjects()
private TestEngineResult PrepareResult(TestEngineResult result)
{
if (result == null) throw new ArgumentNullException("result");

if (!IsProjectPackage(TestPackage))
{
return result;
}

return result.MakePackageResult(TestPackage.Name, TestPackage.FullName);
}

private void EnsurePackagesAreExpanded(TestPackage package)
{
foreach (var package in TestPackage.SubPackages)
if (package == null) throw new ArgumentNullException("package");

foreach (var subPackage in package.SubPackages)
{
string packageName = package.FullName;
EnsurePackagesAreExpanded(subPackage);
}

if (package.SubPackages.Count == 0 && IsProjectPackage(package))
{
ExpandProjects(package);
}
}

private bool IsProjectPackage(TestPackage package)
{
if (package == null) throw new ArgumentNullException("package");

return
_projectService != null
&& !string.IsNullOrEmpty(package.FullName)
&& _projectService.CanLoadFrom(package.FullName);
}

private void ExpandProjects(TestPackage package)
{
if (package == null) throw new ArgumentNullException("package");

if (File.Exists(packageName) && _projectService.CanLoadFrom(packageName))
_projectService.ExpandProjectPackage(package);
string packageName = package.FullName;
if (File.Exists(packageName) && _projectService.CanLoadFrom(packageName))
{
_projectService.ExpandProjectPackage(package);
}
}

Expand Down Expand Up @@ -343,6 +380,11 @@ private static void InsertCommandLineElement(XmlNode resultNode)
{
var doc = resultNode.OwnerDocument;

if (doc == null)
{
return;
}

XmlNode cmd = doc.CreateElement("command-line");
resultNode.InsertAfter(cmd, null);

Expand All @@ -356,12 +398,19 @@ private static void InsertFilterElement(XmlNode resultNode, TestFilter filter)
var tempNode = XmlHelper.CreateXmlNode(filter.Text);

// Don't include it if it's an empty filter
if (tempNode.ChildNodes.Count > 0)
if (tempNode.ChildNodes.Count <= 0)
{
return;
}

var doc = resultNode.OwnerDocument;
if (doc == null)
{
var doc = resultNode.OwnerDocument;
var filterElement = doc.ImportNode(tempNode, true);
resultNode.InsertAfter(filterElement, null);
return;
}

var filterElement = doc.ImportNode(tempNode, true);
resultNode.InsertAfter(filterElement, null);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitEngine/nunit.engine/Services/DriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace NUnit.Engine.Services
/// </summary>
public class DriverService : Service, IDriverService
{
IList<IDriverFactory> _factories = new List<IDriverFactory>();
readonly IList<IDriverFactory> _factories = new List<IDriverFactory>();

#region IDriverService Members

Expand Down

0 comments on commit 0d1f845

Please sign in to comment.