Skip to content

Commit 73189d3

Browse files
committed
Port changes from #1613 to V4
1 parent 6e95b01 commit 73189d3

17 files changed

+292
-289
lines changed

NuGet.config

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
<packageSources>
44
<clear/>
55
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
6+
<add key="NUnit MyGet Feed" value="https://www.myget.org/F/nunit/api/v3/index.json" />
67
</packageSources>
78
</configuration>

package-tests.cake

+114-114
Original file line numberDiff line numberDiff line change
@@ -296,120 +296,120 @@ AddToBothLists(new PackageTest(1, "Net80WPFTest")
296296
// TODO: Add back extension tests after latest changes to ExtensionManager
297297
// are ported. Most extensions will require an update to work under V4.
298298

299-
// NUnit Project Loader Tests
300-
StandardRunnerTests.Add(new PackageTest(1, "NUnitProjectTest")
301-
{
302-
Description = "Run NUnit project with mock-assembly.dll built for .NET 4.6.2 and 6.0",
303-
Arguments = "../../MixedTests.nunit --config=Release",
304-
ExpectedResult = new MockAssemblyExpectedResult("net-4.6.2", "net-6.0"),
305-
ExtensionsNeeded = new[] { KnownExtensions.NUnitProjectLoader }
306-
});
307-
308-
NetCoreRunnerTests.Add(new PackageTest(1, "NUnitProjectTest")
309-
{
310-
Description = "Run NUnit project with mock-assembly.dll built for .NET 6.0 and 8.0",
311-
Arguments = "../../NetCoreTests.nunit --config=Release",
312-
ExpectedResult = new MockAssemblyExpectedResult("netcore-6.0", "netcore-8.0"),
313-
ExtensionsNeeded = new[] { KnownExtensions.NUnitProjectLoader }
314-
});
315-
316-
// V2 Result Writer Test
317-
StandardRunnerTests.Add(new PackageTest(1, "V2ResultWriterTest")
318-
{
319-
Description = "Run mock-assembly under .NET 4.6.2 and produce V2 output",
320-
Arguments = "testdata/net462/mock-assembly.dll --result=TestResult.xml --result=NUnit2TestResult.xml;format=nunit2",
321-
ExpectedResult = new MockAssemblyExpectedResult("net-4.6.2"),
322-
ExtensionsNeeded = new[] { KnownExtensions.NUnitV2ResultWriter }
323-
});
324-
325-
StandardRunnerTests.Add(new PackageTest(1, "V2ResultWriterTest")
326-
{
327-
Description = "Run mock-assembly under .NET 6.0 and produce V2 output",
328-
Arguments = "testdata/net6.0/mock-assembly.dll --result=TestResult.xml --result=NUnit2TestResult.xml;format=nunit2",
329-
ExpectedResult = new MockAssemblyExpectedResult("netcore-6.0"),
330-
ExtensionsNeeded = new[] { KnownExtensions.NUnitV2ResultWriter }
331-
});
332-
333-
// VS Project Loader Tests
334-
StandardRunnerTests.Add(new PackageTest(1, "VSProjectLoaderTest_Project")
335-
{
336-
Description = "Run mock-assembly using the .csproj file",
337-
Arguments = "../../src/TestData/mock-assembly/mock-assembly.csproj --config=Release",
338-
ExpectedResult = new MockAssemblyExpectedResult("net462", "netcore-3.1", "netcore-6.0", "netcore-7.0", "netcore-8.0"),
339-
ExtensionsNeeded = new[] { KnownExtensions.VSProjectLoader }
340-
});
341-
342-
StandardRunnerTests.Add(new PackageTest(1, "VSProjectLoaderTest_Solution")
343-
{
344-
Description = "Run mock-assembly using the .sln file",
345-
Arguments = "../../src/TestData/TestData.sln --config=Release --trace=Debug",
346-
ExpectedResult = new ExpectedResult("Failed")
347-
{
348-
Total = 37 * 5,
349-
Passed = 23 * 5,
350-
Failed = 5 * 5,
351-
Warnings = 1 * 5,
352-
Inconclusive = 1 * 5,
353-
Skipped = 7 * 5,
354-
Assemblies = new ExpectedAssemblyResult[]
355-
{
356-
new ExpectedAssemblyResult("mock-assembly.dll", "net-4.6.2"),
357-
new ExpectedAssemblyResult("mock-assembly.dll", "netcore-3.1"),
358-
new ExpectedAssemblyResult("mock-assembly.dll", "netcore-6.0"),
359-
new ExpectedAssemblyResult("mock-assembly.dll", "netcore-7.0"),
360-
new ExpectedAssemblyResult("mock-assembly.dll", "netcore-8.0"),
361-
new ExpectedAssemblyResult("notest-assembly.dll", "net-4.6.2"),
362-
new ExpectedAssemblyResult("notest-assembly.dll", "netcore-3.1"),
363-
new ExpectedAssemblyResult("notest-assembly.dll", "netstandard-2.0"),
364-
new ExpectedAssemblyResult("WpfApp.exe")
365-
}
366-
},
367-
ExtensionsNeeded = new[] { KnownExtensions.VSProjectLoader }
368-
});
369-
370-
// TeamCity Event Listener Test
371-
StandardRunnerTests.Add(new PackageTest(1, "TeamCityListenerTest")
372-
{
373-
Description = "Run mock-assembly with --teamcity enabled",
374-
Arguments = "testdata/net462/mock-assembly.dll --teamcity",
375-
ExpectedResult = new MockAssemblyExpectedResult("net-4.6.2"),
376-
ExtensionsNeeded = new[] { KnownExtensions.TeamCityEventListener }
377-
});
378-
379-
// V2 Framework Driver Tests
380-
StandardRunnerTests.Add(new PackageTest(1, "V2FrameworkDriverTest")
381-
{
382-
Description = "Run mock-assembly-v2 using the V2 Driver in process",
383-
Arguments = "v2-tests/net462/mock-assembly-v2.dll",
384-
ExpectedResult = new ExpectedResult("Failed")
385-
{
386-
Total = 28,
387-
Passed = 18,
388-
Failed = 5,
389-
Warnings = 0,
390-
Inconclusive = 1,
391-
Skipped = 4,
392-
Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly-v2.dll", "net-4.6.2") }
393-
},
394-
ExtensionsNeeded = new[] { KnownExtensions.NUnitV2Driver }
395-
});
396-
397-
StandardRunnerTests.Add(new PackageTest(1, "V2FrameworkDriverTest")
398-
{
399-
Description = "Run mock-assembly-v2 using the V2 Driver out of process",
400-
Arguments = "v2-tests/net462/mock-assembly-v2.dll --list-extensions",
401-
ExpectedResult = new ExpectedResult("Failed")
402-
{
403-
Total = 28,
404-
Passed = 18,
405-
Failed = 5,
406-
Warnings = 0,
407-
Inconclusive = 1,
408-
Skipped = 4,
409-
Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly-v2.dll", "net-4.6.2") }
410-
},
411-
ExtensionsNeeded = new[] { KnownExtensions.NUnitV2Driver }
412-
});
299+
//// NUnit Project Loader Tests
300+
//StandardRunnerTests.Add(new PackageTest(1, "NUnitProjectTest")
301+
//{
302+
// Description = "Run NUnit project with mock-assembly.dll built for .NET 4.6.2 and 6.0",
303+
// Arguments = "../../MixedTests.nunit --config=Release",
304+
// ExpectedResult = new MockAssemblyExpectedResult("net-4.6.2", "net-6.0"),
305+
// ExtensionsNeeded = new[] { KnownExtensions.NUnitProjectLoader }
306+
//});
307+
308+
//NetCoreRunnerTests.Add(new PackageTest(1, "NUnitProjectTest")
309+
//{
310+
// Description = "Run NUnit project with mock-assembly.dll built for .NET 6.0 and 8.0",
311+
// Arguments = "../../NetCoreTests.nunit --config=Release",
312+
// ExpectedResult = new MockAssemblyExpectedResult("netcore-6.0", "netcore-8.0"),
313+
// ExtensionsNeeded = new[] { KnownExtensions.NUnitProjectLoader }
314+
//});
315+
316+
//// V2 Result Writer Test
317+
//StandardRunnerTests.Add(new PackageTest(1, "V2ResultWriterTest_Net462")
318+
//{
319+
// Description = "Run mock-assembly under .NET 4.6.2 and produce V2 output",
320+
// Arguments = "testdata/net462/mock-assembly.dll --result=TestResult.xml --result=NUnit2TestResult.xml;format=nunit2 --trace:Debug",
321+
// ExpectedResult = new MockAssemblyExpectedResult("net-4.6.2"),
322+
// ExtensionsNeeded = new[] { KnownExtensions.NUnitV2ResultWriter }
323+
//});
324+
325+
//StandardRunnerTests.Add(new PackageTest(1, "V2ResultWriterTest_Net60")
326+
//{
327+
// Description = "Run mock-assembly under .NET 6.0 and produce V2 output",
328+
// Arguments = "testdata/net6.0/mock-assembly.dll --result=TestResult.xml --result=NUnit2TestResult.xml;format=nunit2 --trace:Debug",
329+
// ExpectedResult = new MockAssemblyExpectedResult("netcore-6.0"),
330+
// ExtensionsNeeded = new[] { KnownExtensions.NUnitV2ResultWriter }
331+
//});
332+
333+
//// VS Project Loader Tests
334+
//StandardRunnerTests.Add(new PackageTest(1, "VSProjectLoaderTest_Project")
335+
//{
336+
// Description = "Run mock-assembly using the .csproj file",
337+
// Arguments = "../../src/TestData/mock-assembly/mock-assembly.csproj --config=Release",
338+
// ExpectedResult = new MockAssemblyExpectedResult("net462", "netcore-3.1", "netcore-6.0", "netcore-7.0", "netcore-8.0"),
339+
// ExtensionsNeeded = new[] { KnownExtensions.VSProjectLoader }
340+
//});
341+
342+
//StandardRunnerTests.Add(new PackageTest(1, "VSProjectLoaderTest_Solution")
343+
//{
344+
// Description = "Run mock-assembly using the .sln file",
345+
// Arguments = "../../src/TestData/TestData.sln --config=Release --trace=Debug",
346+
// ExpectedResult = new ExpectedResult("Failed")
347+
// {
348+
// Total = 37 * 5,
349+
// Passed = 23 * 5,
350+
// Failed = 5 * 5,
351+
// Warnings = 1 * 5,
352+
// Inconclusive = 1 * 5,
353+
// Skipped = 7 * 5,
354+
// Assemblies = new ExpectedAssemblyResult[]
355+
// {
356+
// new ExpectedAssemblyResult("mock-assembly.dll", "net-4.6.2"),
357+
// new ExpectedAssemblyResult("mock-assembly.dll", "netcore-3.1"),
358+
// new ExpectedAssemblyResult("mock-assembly.dll", "netcore-6.0"),
359+
// new ExpectedAssemblyResult("mock-assembly.dll", "netcore-7.0"),
360+
// new ExpectedAssemblyResult("mock-assembly.dll", "netcore-8.0"),
361+
// new ExpectedAssemblyResult("notest-assembly.dll", "net-4.6.2"),
362+
// new ExpectedAssemblyResult("notest-assembly.dll", "netcore-3.1"),
363+
// new ExpectedAssemblyResult("notest-assembly.dll", "netstandard-2.0"),
364+
// new ExpectedAssemblyResult("WpfApp.exe")
365+
// }
366+
// },
367+
// ExtensionsNeeded = new[] { KnownExtensions.VSProjectLoader }
368+
//});
369+
370+
//// TeamCity Event Listener Test
371+
//StandardRunnerTests.Add(new PackageTest(1, "TeamCityListenerTest")
372+
//{
373+
// Description = "Run mock-assembly with --teamcity enabled",
374+
// Arguments = "testdata/net462/mock-assembly.dll --teamcity",
375+
// ExpectedResult = new MockAssemblyExpectedResult("net-4.6.2"),
376+
// ExtensionsNeeded = new[] { KnownExtensions.TeamCityEventListener }
377+
//});
378+
379+
//// V2 Framework Driver Tests
380+
//StandardRunnerTests.Add(new PackageTest(1, "V2FrameworkDriverTest")
381+
//{
382+
// Description = "Run mock-assembly-v2 using the V2 Driver in process",
383+
// Arguments = "v2-tests/net462/mock-assembly-v2.dll",
384+
// ExpectedResult = new ExpectedResult("Failed")
385+
// {
386+
// Total = 28,
387+
// Passed = 18,
388+
// Failed = 5,
389+
// Warnings = 0,
390+
// Inconclusive = 1,
391+
// Skipped = 4,
392+
// Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly-v2.dll", "net-4.6.2") }
393+
// },
394+
// ExtensionsNeeded = new[] { KnownExtensions.NUnitV2Driver }
395+
//});
396+
397+
//StandardRunnerTests.Add(new PackageTest(1, "V2FrameworkDriverTest")
398+
//{
399+
// Description = "Run mock-assembly-v2 using the V2 Driver out of process",
400+
// Arguments = "v2-tests/net462/mock-assembly-v2.dll --list-extensions",
401+
// ExpectedResult = new ExpectedResult("Failed")
402+
// {
403+
// Total = 28,
404+
// Passed = 18,
405+
// Failed = 5,
406+
// Warnings = 0,
407+
// Inconclusive = 1,
408+
// Skipped = 4,
409+
// Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly-v2.dll", "net-4.6.2") }
410+
// },
411+
// ExtensionsNeeded = new[] { KnownExtensions.NUnitV2Driver }
412+
//});
413413

414414
//////////////////////////////////////////////////////////////////////
415415
// SPECIAL CASES

src/NUnitCommon/nunit.extensibility/ExtensionManager.cs

+39-18
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
using System;
44
using System.Collections.Generic;
5+
using System.Diagnostics;
56
using System.IO;
67
using System.Linq;
78
using System.Reflection;
9+
using NUnit.Engine;
810
using NUnit.FileSystemAccess;
911
using TestCentric.Metadata;
1012

@@ -15,6 +17,8 @@ public class ExtensionManager
1517
static readonly Version CURRENT_ENGINE_VERSION = Assembly.GetExecutingAssembly().GetName().Version ?? new Version();
1618
static readonly string EXTENSION_ATTRIBUTE = typeof(ExtensionAttribute).FullName.ShouldNotBeNull();
1719
static readonly string EXTENSION_PROPERTY_ATTRIBUTE = typeof(ExtensionPropertyAttribute).FullName.ShouldNotBeNull();
20+
static readonly string V3_EXTENSION_ATTRIBUTE = "NUnit.Engine.Extensibility.ExtensionAttribute";
21+
static readonly string V3_EXTENSION_PROPERTY_ATTRIBUTE = "NUnit.Engine.Extensibility.ExtensionPropertyAttribute";
1822

1923
static readonly Logger log = InternalTrace.GetLogger(typeof(ExtensionManager));
2024

@@ -372,6 +376,7 @@ private void ProcessAddinsFile(IFile addinsFile, bool fromWildCard)
372376
string entryDir = entry.DirectoryName;
373377
string entryFile = entry.FileName;
374378

379+
log.Debug($"Processing entry {entry.Text}");
375380
if (entry.IsDirectory)
376381
{
377382
if (entry.IsFullyQualified)
@@ -400,9 +405,13 @@ private void ProcessAddinsFile(IFile addinsFile, bool fromWildCard)
400405

401406
private void ProcessCandidateAssembly(string filePath, bool fromWildCard)
402407
{
408+
log.Debug($"Processing candidate assembly {filePath}");
403409
// Did we already process this file?
404410
if (_assemblies.ByPath.ContainsKey(filePath))
411+
{
412+
log.Debug(" Skipping assembly already processed");
405413
return;
414+
}
406415

407416
try
408417
{
@@ -411,7 +420,10 @@ private void ProcessCandidateAssembly(string filePath, bool fromWildCard)
411420

412421
// We never add assemblies unless the host can load them
413422
if (!CanLoadTargetFramework(Assembly.GetEntryAssembly(), candidateAssembly))
423+
{
424+
log.Debug(" Unable to load this assembly");
414425
return;
426+
}
415427

416428
// Do we already have a copy of the same assembly at a different path?
417429
//if (_assemblies.ByName.ContainsKey(assemblyName))
@@ -423,6 +435,7 @@ private void ProcessCandidateAssembly(string filePath, bool fromWildCard)
423435
return;
424436
}
425437

438+
log.Debug(" Adding this assembly");
426439
_assemblies.Add(candidateAssembly);
427440
}
428441
catch (Exception) when(fromWildCard)
@@ -461,29 +474,33 @@ public void FindExtensionsInAssembly(ExtensionAssembly extensionAssembly)
461474
}
462475

463476
#if NETFRAMEWORK
464-
#if FIXED
465-
// Use special properties provided by our backport of RuntimeInformation
466-
Version currentVersion = RuntimeInformation.FrameworkVersion;
467-
var frameworkName = extensionAssembly.FrameworkName;
477+
//// Use special properties provided by our backport of RuntimeInformation
478+
//Version currentVersion = RuntimeInformation.FrameworkVersion;
479+
//var frameworkName = extensionAssembly.FrameworkName;
468480

469-
if (frameworkName.Identifier != FrameworkIdentifiers.NetFramework || frameworkName.Version > currentVersion)
470-
{
471-
if (!extensionAssembly.FromWildCard)
472-
{
473-
throw new NUnitEngineException($"Extension {extensionAssembly.FilePath} targets {assemblyTargetFramework.DisplayName}, which is not available.");
474-
}
475-
else
476-
{
477-
log.Info($"Assembly {extensionAssembly.FilePath} targets {assemblyTargetFramework.DisplayName}, which is not available. Assembly found via wildcard.");
478-
return;
479-
}
480-
}
481-
#endif
481+
//if (frameworkName.Identifier != FrameworkIdentifiers.NetFramework || frameworkName.Version > currentVersion)
482+
//{
483+
// if (!extensionAssembly.FromWildCard)
484+
// {
485+
// throw new NUnitEngineException($"Extension {extensionAssembly.FilePath} targets {assemblyTargetFramework.DisplayName}, which is not available.");
486+
// }
487+
// else
488+
// {
489+
// log.Info($"Assembly {extensionAssembly.FilePath} targets {assemblyTargetFramework.DisplayName}, which is not available. Assembly found via wildcard.");
490+
// return;
491+
// }
492+
//}
482493
#endif
483494

484495
foreach (var extensionType in extensionAssembly.Assembly.MainModule.GetTypes())
485496
{
497+
bool useV3Attribute = false;
486498
CustomAttribute extensionAttr = extensionType.GetAttribute(EXTENSION_ATTRIBUTE);
499+
if (extensionAttr == null)
500+
{
501+
extensionAttr = extensionType.GetAttribute(V3_EXTENSION_ATTRIBUTE);
502+
useV3Attribute = true;
503+
}
487504

488505
if (extensionAttr == null)
489506
continue;
@@ -512,7 +529,11 @@ public void FindExtensionsInAssembly(ExtensionAssembly extensionAssembly)
512529

513530
log.Info(" Found ExtensionAttribute on Type " + extensionType.Name);
514531

515-
foreach (var attr in extensionType.GetAttributes(EXTENSION_PROPERTY_ATTRIBUTE))
532+
var propertyAttributes = useV3Attribute
533+
? extensionType.GetAttributes(V3_EXTENSION_PROPERTY_ATTRIBUTE)
534+
: extensionType.GetAttributes(EXTENSION_PROPERTY_ATTRIBUTE);
535+
536+
foreach (var attr in propertyAttributes)
516537
{
517538
string? name = attr.ConstructorArguments[0].Value as string;
518539
string? value = attr.ConstructorArguments[1].Value as string;

0 commit comments

Comments
 (0)