Skip to content

Commit

Permalink
Update for net core (#670)
Browse files Browse the repository at this point in the history
* Updated dumpxml to work with .net core.  Added debug logging of which method is being called when starting execution. Updated version to 3.16.0

* Fix for sdk version

* Fixed comments
  • Loading branch information
OsirisTerje authored Oct 30, 2019
1 parent 78300b4 commit c3a617c
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 43 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ indent_size = 2
[*.vsixmanifest]
indent_style = space
indent_size = 2

[*.cs]


1 change: 1 addition & 0 deletions NUnit3TestAdapter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ VisualStudioVersion = 16.0.28606.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7CE30108-5D81-4850-BE6B-C8BCA35D3592}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
appveyor.yml = appveyor.yml
build.cake = build.cake
build.cmd = build.cmd
Expand Down
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var configuration = Argument("configuration", "Release");
// SET PACKAGE VERSION
//////////////////////////////////////////////////////////////////////

var version = "3.15.1";
var version = "3.16.0";
var modifier = "";

var dbgSuffix = configuration.ToLower() == "debug" ? "-dbg" : "";
Expand Down
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ $CAKE_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) {
}

# Build Cake arguments
$cakeArguments = ""
$cakeArguments = @()
If ($Script) {
$cakeArguments += @("`"$Script`"");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<ItemGroup>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.14.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3" />
</ItemGroup>

</Project>
3 changes: 1 addition & 2 deletions src/NUnitTestAdapter/DumpXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public void AddString(string text)

}

#if NET35
public static class XmlNodeExtension
{
public static string AsString(this System.Xml.XmlNode node)
Expand All @@ -132,5 +131,5 @@ public static string AsString(this System.Xml.XmlNode node)
}
}
}
#endif

}
17 changes: 5 additions & 12 deletions src/NUnitTestAdapter/NUnit3TestDiscoverer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ***********************************************************************
// Copyright (c) 2011-2017 Charlie Poole, Terje Sandstrom
// Copyright (c) 2011-2019 Charlie Poole, Terje Sandstrom
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -62,9 +62,6 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove
Debugger.Launch();
#endif
Initialize(discoveryContext, messageLogger);



TestLog.Info($"NUnit Adapter {AdapterVersion}: Test discovery starting");

// Ensure any channels registered by other adapters are unregistered
Expand All @@ -86,17 +83,14 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove
if (Settings.DumpXmlTestDiscovery)
{
dumpXml = new DumpXml(sourceAssemblyPath);

}

try
{
runner = GetRunnerFor(sourceAssemblyPath, null);

XmlNode topNode = runner.Explore(TestFilter.Empty);
#if NET35
var topNode = runner.Explore(TestFilter.Empty);
dumpXml?.AddString(topNode.AsString());
#endif

// Currently, this will always be the case but it might change
if (topNode.Name == "test-run")
topNode = topNode.FirstChild;
Expand All @@ -120,7 +114,7 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove
{
var msgNode = topNode.SelectSingleNode("properties/property[@name='_SKIPREASON']");
if (msgNode != null &&
(new[] {"contains no tests", "Has no TestFixtures"}).Any(msgNode.GetAttribute("value")
(new[] { "contains no tests", "Has no TestFixtures" }).Any(msgNode.GetAttribute("value")
.Contains))
{
if (Settings.Verbosity > 0)
Expand Down Expand Up @@ -172,9 +166,8 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove
}
finally
{
#if NET35
dumpXml?.Dump4Discovery();
#endif

if (runner != null)
{
if (runner.IsTestRunning)
Expand Down
40 changes: 18 additions & 22 deletions src/NUnitTestAdapter/NUnit3TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@

// #define LAUNCHDEBUGGER

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using NUnit.Engine;
using NUnit.Engine.Services;
using NUnit.VisualStudio.TestAdapter.Dump;
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using NUnit.Engine;
using NUnit.Engine.Services;
using NUnit.VisualStudio.TestAdapter.Dump;

namespace NUnit.VisualStudio.TestAdapter
{
Expand Down Expand Up @@ -79,11 +79,13 @@ public NUnit3TestExecutor()
/// <param name="frameworkHandle">Test log to send results and messages through</param>
public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
{
#if LAUNCHDEBUGGER
#if LAUNCHDEBUGGER
if (!Debugger.IsAttached)
Debugger.Launch();
#endif
Initialize(runContext, frameworkHandle);
TestLog.Debug("RunTests by IEnumerable<string>");
InitializeForExecution(runContext, frameworkHandle);

if (Settings.InProcDataCollectorsAvailable && sources.Count() > 1)
{
Expand All @@ -92,8 +94,6 @@ public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrame
return;
}



foreach (var assemblyName in sources)
{
try
Expand Down Expand Up @@ -125,7 +125,9 @@ public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrame
if (!Debugger.IsAttached)
Debugger.Launch();
#endif
Initialize(runContext, frameworkHandle);
base.Initialize(runContext, frameworkHandle);
TestLog.Debug("RunTests by IEnumerable<TestCase>");
InitializeForExecution(runContext, frameworkHandle);

var assemblyGroups = tests.GroupBy(tc => tc.Source);
if (Settings.InProcDataCollectorsAvailable && assemblyGroups.Count() > 1)
Expand Down Expand Up @@ -176,11 +178,9 @@ public void Dispose()

#region Helper Methods

public void Initialize(IRunContext runContext, IFrameworkHandle frameworkHandle)
public void InitializeForExecution(IRunContext runContext, IFrameworkHandle frameworkHandle)
{
base.Initialize(runContext, frameworkHandle);

TestLog.Info(string.Format("NUnit Adapter {0}: Test execution started", AdapterVersion));
TestLog.Info($"NUnit Adapter {AdapterVersion}: Test execution started");

RunContext = runContext;
FrameworkHandle = frameworkHandle;
Expand Down Expand Up @@ -233,9 +233,7 @@ private void RunAssembly(string assemblyPath, IGrouping<string, TestCase> testCa
_activeRunner = GetRunnerFor(assemblyPath, testCases);
CreateTestOutputFolder();
var loadResult = _activeRunner.Explore(filter);
#if NET35
dumpXml?.AddString(loadResult.AsString());
#endif
if (loadResult.Name == "test-run")
loadResult = loadResult.FirstChild;

Expand Down Expand Up @@ -300,12 +298,12 @@ private void RunAssembly(string assemblyPath, IGrouping<string, TestCase> testCa
// we skip the native c++ binaries that we don't support.
TestLog.Warning(" Assembly not supported: " + assemblyPath);
}
catch( NUnitEngineException e )
catch (NUnitEngineException e)
{
if( e.InnerException is BadImageFormatException )
if (e.InnerException is BadImageFormatException)
{
// we skip the native c++ binaries that we don't support.
TestLog.Warning( " Assembly not supported: " + assemblyPath );
TestLog.Warning(" Assembly not supported: " + assemblyPath);
}
throw;
}
Expand All @@ -322,9 +320,7 @@ private void RunAssembly(string assemblyPath, IGrouping<string, TestCase> testCa
}
finally
{
#if NET35
dumpXml?.Dump4Execution();
#endif
try
{
_activeRunner?.Dispose();
Expand All @@ -335,7 +331,7 @@ private void RunAssembly(string assemblyPath, IGrouping<string, TestCase> testCa
// can happen if CLR throws CannotUnloadAppDomainException, for example
// due to a long-lasting operation in a protected region (catch/finally clause).
if (ex is TargetInvocationException) { ex = ex.InnerException; }
TestLog.Warning(" Exception thrown unloading tests from " + assemblyPath, ex);
TestLog.Warning($" Exception thrown unloading tests from {assemblyPath}", ex);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/NUnitTestAdapter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ****************************************************************
// Copyright (c) 2011-2018 Charlie Poole, Terje Sandstrom.
// Copyright (c) 2011-2019 Charlie Poole, Terje Sandstrom.
// ****************************************************************

using System;
Expand All @@ -21,7 +21,7 @@
[assembly: ComVisible(false)]

[assembly: Guid("c0aad5e4-b486-49bc-b3e8-31e01be6fefe")]
[assembly: AssemblyVersion("3.15.1.0")]
[assembly: AssemblyFileVersion("3.15.1.0")]
[assembly: AssemblyVersion("3.16.0.0")]
[assembly: AssemblyFileVersion("3.16.0.0")]

[assembly: InternalsVisibleTo("NUnit.VisualStudio.TestAdapter.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010029b97dea816272cc4ea44cf3cf666f8150d6dfe1274b6c2e6c4d54259b756888ec08ad6dd3ea0f540b30408b948ae5f39cf0c7b210abdec267b367ce1eccab97d5c6c02ee67090827ffd699544fa2add4849b45a1901eac08495bfee0397fba3946ff3912ce0b9a497818e418a77a0c8db4ca1780e7b6f6dd6911395fcc0faba")]

0 comments on commit c3a617c

Please sign in to comment.