diff --git a/.github/workflows/NUnit3TestAdapter.CI.yml b/.github/workflows/NUnit3TestAdapter.CI.yml
index 96119f9b..f84f1f7d 100644
--- a/.github/workflows/NUnit3TestAdapter.CI.yml
+++ b/.github/workflows/NUnit3TestAdapter.CI.yml
@@ -9,7 +9,7 @@ jobs:
runs-on: windows-latest
steps:
- - uses: actions/checkout@v4.1.7
+ - uses: actions/checkout@v4.2.0
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
diff --git a/Directory.Packages.props b/Directory.Packages.props
new file mode 100644
index 00000000..e2f16d50
--- /dev/null
+++ b/Directory.Packages.props
@@ -0,0 +1,34 @@
+
+
+ true
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
diff --git a/NUnit3TestAdapter.sln b/NUnit3TestAdapter.sln
index 7717a16a..273d2545 100644
--- a/NUnit3TestAdapter.sln
+++ b/NUnit3TestAdapter.sln
@@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
build.cmd = build.cmd
build.ps1 = build.ps1
src\Directory.Build.props = src\Directory.Build.props
+ Directory.Packages.props = Directory.Packages.props
DisableAppDomain.runsettings = DisableAppDomain.runsettings
LICENSE = LICENSE
src\native-assembly\NativeTests.dll = src\native-assembly\NativeTests.dll
diff --git a/build.cake b/build.cake
index 532564e0..59e0aa3b 100644
--- a/build.cake
+++ b/build.cake
@@ -15,7 +15,7 @@ var configuration = Argument("configuration", "Release");
var version = "5.0.0";
-var modifier = "-beta.10";
+var modifier = "-beta.20";
var dbgSuffix = configuration.ToLower() == "debug" ? "-dbg" : "";
var packageVersion = version + modifier + dbgSuffix;
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index 8bbc8c51..4ac08f7a 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -9,11 +9,4 @@
true
-
-
-
-
-
-
-
diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs
index 2f778d32..fd22f1a7 100644
--- a/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs
+++ b/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs
@@ -29,26 +29,26 @@ public abstract class AcceptanceTests
public const string LowestNetfxTarget = "net462";
public const string LegacyProjectTargetFrameworkVersion = "v4.6.2";
- protected static IEnumerable TargetFrameworks => new[]
- {
+ protected static IEnumerable TargetFrameworks =>
+ [
LowestNetfxTarget,
Frameworks.NetCoreApp31
- };
+ ];
- protected static IEnumerable DotNetCliTargetFrameworks => new[]
- {
+ protected static IEnumerable DotNetCliTargetFrameworks =>
+ [
Frameworks.NetCoreApp31,
Frameworks.Net50,
Frameworks.Net60,
Frameworks.Net70
- };
+ ];
- protected static IEnumerable ModernDotNetCliTargetFrameworks => new[]
- {
+ protected static IEnumerable ModernDotNetCliTargetFrameworks =>
+ [
Frameworks.Net60,
Frameworks.Net70,
Frameworks.Net80
- };
+ ];
protected static string NUnit3 => "3.*";
protected static string NUnit4 => "4.*";
@@ -58,25 +58,25 @@ public class MultiFrameworkSource
public IEnumerable Frameworks { get; set; } = DotNetCliTargetFrameworks;
public string NUnitVersion { get; set; } = NUnit3;
- public static IEnumerable LegacyDotNetFrameworks => new List { new() };
+ public static IEnumerable LegacyDotNetFrameworks => [new()];
- public static IEnumerable ModernDotNetFrameworks => new List
- {
+ public static IEnumerable ModernDotNetFrameworks =>
+ [
new ()
{
Frameworks = ModernDotNetCliTargetFrameworks,
NUnitVersion = NUnit4
}
- };
+ ];
- public static IEnumerable NetFxFrameworks => new List
- {
+ public static IEnumerable NetFxFrameworks =>
+ [
new ()
{
- Frameworks = new List { LowestNetfxTarget },
+ Frameworks = [LowestNetfxTarget],
NUnitVersion = NUnit4
}
- };
+ ];
public static IEnumerable AllFrameworks => LegacyDotNetFrameworks.Concat(ModernDotNetFrameworks).Concat(NetFxFrameworks);
}
@@ -86,10 +86,10 @@ public class SingleFrameworkSource
public string Framework { get; set; } = LowestNetfxTarget;
public string NUnitVersion { get; set; } = NUnit4;
- public static IEnumerable NetFxFramework => new List { new() };
+ public static IEnumerable NetFxFramework => [new()];
- public static IEnumerable LegacyDotNetFramework => new List
- {
+ public static IEnumerable LegacyDotNetFramework =>
+ [
new ()
{
Framework = Frameworks.NetCoreApp31,
@@ -100,10 +100,10 @@ public class SingleFrameworkSource
Framework = Frameworks.Net50,
NUnitVersion = NUnit3
}
- };
+ ];
- public static IEnumerable ModernDotNetFramework => new List
- {
+ public static IEnumerable ModernDotNetFramework =>
+ [
new ()
{
Framework = Frameworks.Net60,
@@ -119,7 +119,7 @@ public class SingleFrameworkSource
Framework = Frameworks.Net80,
NUnitVersion = NUnit4
}
- };
+ ];
public static IEnumerable AllFrameworks => NetFxFramework.Concat(LegacyDotNetFramework).Concat(ModernDotNetFramework);
public static IEnumerable AllFrameworksExceptNetFx => LegacyDotNetFramework.Concat(ModernDotNetFramework);
@@ -136,12 +136,12 @@ protected string NUnitVersion(string targetFramework) =>
private static readonly Lazy<(IsolatedWorkspaceManager Manager, string NupkgVersion, bool KeepWorkspaces)> Initialization = new(() =>
{
var directory = TestContext.Parameters["ProjectWorkspaceDirectory"]
- ?? TryAutoDetectProjectWorkspaceDirectory()
- ?? throw new InvalidOperationException("The test parameter ProjectWorkspaceDirectory must be set in order to run this test.");
+ ?? TryAutoDetectProjectWorkspaceDirectory() // Walks the directory tree up to find the project workspace directory, named ".acceptance"
+ ?? throw new InvalidOperationException("Either The test parameter ProjectWorkspaceDirectory must be set in order to run this test, or the `.acceptance` folder has not been found. Run cmd line `build -t acceptance` first");
var nupkgDirectory = TestContext.Parameters["TestNupkgDirectory"]
- ?? TryAutoDetectTestNupkgDirectory(NuGetPackageId)
- ?? throw new InvalidOperationException("The test parameter TestNupkgDirectory must be set in order to run this test.");
+ ?? TryAutoDetectTestNupkgDirectory(NuGetPackageId) // Walks the directory tree up to find the test nupkg directory, named "package"
+ ?? throw new InvalidOperationException("The test parameter TestNupkgDirectory must be set in order to run this test, or the packages have not been created, run cmdline `build -t package` first");
var nupkgVersion = TryGetTestNupkgVersion(nupkgDirectory, packageId: NuGetPackageId)
?? throw new InvalidOperationException($"No NuGet package with the ID {NuGetPackageId} was found in {nupkgDirectory}.");
@@ -162,7 +162,7 @@ protected string NUnitVersion(string targetFramework) =>
downloadCachePath: Path.Combine(directory, ".toolcache"));
if (keepWorkspaces) manager.PreserveDirectory("The KeepWorkspaces test parameter was set to true.");
- TestContext.WriteLine($"Directory: {directory}, NugetPackageDirectory {nupkgDirectory},NugetPackageVersion: {nupkgVersion}");
+ TestContext.Out.WriteLine($"Directory: {directory}, NugetPackageDirectory {nupkgDirectory},NugetPackageVersion: {nupkgVersion}");
return (manager, nupkgVersion, keepWorkspaces);
});
@@ -224,7 +224,9 @@ public static void TearDown()
}
}
+#pragma warning disable NUnit1028 // The non-test method is public
internal static void OnGlobalTeardown()
+#pragma warning restore NUnit1028 // The non-test method is public
{
if (!Initialization.IsValueCreated) return;
diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/BundledDependencyTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/BundledDependencyTests.cs
index 968c07eb..78838197 100644
--- a/src/NUnit.TestAdapter.Tests.Acceptance/BundledDependencyTests.cs
+++ b/src/NUnit.TestAdapter.Tests.Acceptance/BundledDependencyTests.cs
@@ -14,6 +14,7 @@ public static void User_tests_get_the_version_of_Mono_Cecil_referenced_from_the_
{string.Join(";", TargetFrameworks)}
+ falsefalse
@@ -67,6 +68,7 @@ public static void Engine_uses_its_bundled_version_of_Mono_Cecil_instead_of_the_
{string.Join(";", TargetFrameworks)}
+ falsefalse
diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs
index d3c1af7b..153cba9b 100644
--- a/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs
+++ b/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs
@@ -17,6 +17,7 @@ protected IsolatedWorkspace CreateTestWorkspace(string framework)
{framework}
+ falsefalse
@@ -39,9 +40,9 @@ protected IsolatedWorkspace Build()
protected void Verify(int executed, int total, VSTestResult results)
{
- TestContext.WriteLine(" ");
+ TestContext.Out.WriteLine(" ");
foreach (var error in results.RunErrors)
- TestContext.WriteLine(error);
+ TestContext.Out.WriteLine(error);
Assert.Multiple(() =>
{
Assert.That(results.Counters.Total, Is.EqualTo(total),
diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj b/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj
index 788486e0..3742586f 100644
--- a/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj
+++ b/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj
@@ -10,13 +10,9 @@
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
+
+
diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/README.md b/src/NUnit.TestAdapter.Tests.Acceptance/README.md
new file mode 100644
index 00000000..c3fd0b63
--- /dev/null
+++ b/src/NUnit.TestAdapter.Tests.Acceptance/README.md
@@ -0,0 +1,18 @@
+# How to run the acceptance tests
+
+## Running the tests by command line
+
+```cmd
+build -t acceptance
+```
+
+This will build and package the test adapter and run the acceptance tests.
+
+## Running the tests in Visual Studio
+
+You can also run the acceptance tests in Visual Studio.
+To do this, open the solution in Visual Studio and run the `NUnit.TestAdapter.Tests.Acceptance` Tests from the Test Explorer.
+
+Note: Running the acceptance tests in Visual Studio require that the package are built and packaged on commandline before running the tests.
+This will create the `.acceptance` directory and add the package to the `package` directory.
+
diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/SinglePassingTestResultTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/SinglePassingTestResultTests.cs
index 9fb8f010..a22a2838 100644
--- a/src/NUnit.TestAdapter.Tests.Acceptance/SinglePassingTestResultTests.cs
+++ b/src/NUnit.TestAdapter.Tests.Acceptance/SinglePassingTestResultTests.cs
@@ -47,6 +47,7 @@ private IsolatedWorkspace CreateSingleTargetWorkspace(string fileName, SingleFra
{source.Framework}
+ false
@@ -105,6 +106,7 @@ private IsolatedWorkspace CreateMultiTargetWorkspace(string fileName, MultiFrame
{string.Join(";", source.Frameworks)}
+ false
@@ -181,6 +183,7 @@ public void Legacy_csproj_with_PackageReference()
{LegacyProjectTargetFrameworkVersion}
512
true
+ falsefalse
true
@@ -251,6 +254,7 @@ public void Legacy_vbproj_with_PackageReference()
Windows
{LegacyProjectTargetFrameworkVersion}
true
+ falsefalse
true
diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs b/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs
index 6caf161a..fd2d1ad6 100644
--- a/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs
+++ b/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs
@@ -89,13 +89,14 @@ public static void Single_target_csproj(SingleFrameworkSource source)
" : "";
- TestContext.WriteLine($"Testing {source.Framework}");
+ TestContext.Out.WriteLine($"Testing {source.Framework}");
var workspace = CreateWorkspace()
.AddProject("Test.csproj", $@"
{source.Framework}
+ falsefalse
diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/Utils.cs b/src/NUnit.TestAdapter.Tests.Acceptance/Utils.cs
index ab9e1dc0..b5bfe7e5 100644
--- a/src/NUnit.TestAdapter.Tests.Acceptance/Utils.cs
+++ b/src/NUnit.TestAdapter.Tests.Acceptance/Utils.cs
@@ -104,7 +104,7 @@ public static void DeleteDirectoryRobust(string directory)
}
catch (IOException ex) when (attempt < 3 && (WinErrorCode)ex.HResult == WinErrorCode.DirNotEmpty)
{
- TestContext.WriteLine("Another process added files to the directory while its contents were being deleted. Retrying...");
+ TestContext.Out.WriteLine("Another process added files to the directory while its contents were being deleted. Retrying...");
}
}
}
diff --git a/src/NUnit3AdapterExternalTests/NUnit3AdapterExternalTests.csproj b/src/NUnit3AdapterExternalTests/NUnit3AdapterExternalTests.csproj
index 4726d338..33edc844 100644
--- a/src/NUnit3AdapterExternalTests/NUnit3AdapterExternalTests.csproj
+++ b/src/NUnit3AdapterExternalTests/NUnit3AdapterExternalTests.csproj
@@ -8,11 +8,11 @@
-
+
-
+
\ No newline at end of file
diff --git a/src/NUnitTestAdapter/CategoryList.cs b/src/NUnitTestAdapter/CategoryList.cs
index 7e31107a..b7224cf0 100644
--- a/src/NUnitTestAdapter/CategoryList.cs
+++ b/src/NUnitTestAdapter/CategoryList.cs
@@ -57,7 +57,7 @@ public class CategoryList
private readonly NUnitProperty explicitTrait = new (ExplicitTraitName, ExplicitTraitValue);
- private readonly List categorylist = new ();
+ private readonly List categorylist = [];
private readonly TestCase testCase;
private readonly IAdapterSettings settings;
private readonly bool showInternalProperties;
diff --git a/src/NUnitTestAdapter/NUnit.TestAdapter.csproj b/src/NUnitTestAdapter/NUnit.TestAdapter.csproj
index 713f9bff..78a05b3e 100644
--- a/src/NUnitTestAdapter/NUnit.TestAdapter.csproj
+++ b/src/NUnitTestAdapter/NUnit.TestAdapter.csproj
@@ -10,8 +10,8 @@
true
https://github.com/nunit/nunit3-vs-adapter
true
- 4.6.0.0
- 4.6.0.0
+ 5.0.0.0
+ 5.0.0.0
en
NUnit3 Test Adapter for Visual Studio
Copyright © 2011-2021 Charlie Poole, 2014-2024 Terje Sandstrom
@@ -32,10 +32,10 @@
-
-
-
-
+
+
+
+
diff --git a/src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs b/src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs
index 65ae6940..25bddff6 100644
--- a/src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs
+++ b/src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs
@@ -100,7 +100,7 @@ internal static class NUnitXmlAttributeNames
public bool HasExplicitTests => NoOfExplicitTestCases > 0;
- private readonly List loadedTestCases = new();
+ private readonly List loadedTestCases = [];
public IList LoadedTestCases => loadedTestCases;
public int NoOfLoadedTestCases => loadedTestCases.Count;
@@ -134,7 +134,7 @@ public IEnumerable GetExplicitTestCases(IEnumerable filtered
public IList Convert(NUnitResults discoveryResults, string assemblyPath)
{
if (discoveryResults == null)
- return new List();
+ return [];
AssemblyPath = assemblyPath;
var timing = new TimingLogger(Settings, TestLog);
if (Settings.DiscoveryMethod != DiscoveryMethod.Legacy)
diff --git a/src/NUnitTestAdapter/NUnitEngine/NUnitDiscoveryTestClasses.cs b/src/NUnitTestAdapter/NUnitEngine/NUnitDiscoveryTestClasses.cs
index ee41abb7..3ba82567 100644
--- a/src/NUnitTestAdapter/NUnitEngine/NUnitDiscoveryTestClasses.cs
+++ b/src/NUnitTestAdapter/NUnitEngine/NUnitDiscoveryTestClasses.cs
@@ -105,7 +105,7 @@ public void AddTestAssembly(NUnitDiscoveryTestAssembly testAssembly)
public class NUnitDiscoveryProperties
{
- private List TheProperties { get; } = new();
+ private List TheProperties { get; } = [];
public IEnumerable Properties => TheProperties;
public void Add(NUnitProperty p) => TheProperties.Add(p);
@@ -124,7 +124,7 @@ public class NUnitDiscoveryTestSuite(BaseProperties theBase, INUnitDiscoverySuit
public sealed class NUnitDiscoveryTestAssembly(BaseProperties theBase, NUnitDiscoveryTestRun parent)
: NUnitDiscoveryTestSuite(theBase, parent)
{
- private readonly List allTestCases = new();
+ private readonly List allTestCases = [];
///
/// If all testcases are Explicit, we can run this one.
@@ -152,12 +152,12 @@ public override void AddToAllTestCases(NUnitDiscoveryTestCase tc)
public sealed class NUnitDiscoveryTestFixture(BaseProperties theBase, string classname, INUnitDiscoverySuiteBase parent)
: NUnitDiscoveryCanHaveTestCases(theBase, parent, classname)
{
- private readonly List parameterizedMethods = new();
+ private readonly List parameterizedMethods = [];
public IEnumerable ParameterizedMethods => parameterizedMethods;
- private readonly List theories = new();
+ private readonly List theories = [];
- private readonly List genericMethods = new();
+ private readonly List genericMethods = [];
public IEnumerable Theories => theories;
public override int NoOfActualTestCases =>
@@ -257,7 +257,7 @@ public abstract class NUnitDiscoveryCanHaveTestCases(
string classname)
: NUnitDiscoverySuiteBase(theBase, parent), INUnitDiscoveryCanHaveTestCases
{
- private readonly List testCases = new();
+ private readonly List testCases = [];
public IEnumerable TestCases => testCases;
public virtual int NoOfActualTestCases => testCases.Count;
@@ -284,7 +284,7 @@ public interface INUnitDiscoveryCanHaveTestFixture : INUnitDiscoverySuiteBase
public abstract class NUnitDiscoveryCanHaveTestFixture(BaseProperties theBase, INUnitDiscoverySuiteBase parent)
: NUnitDiscoverySuiteBase(theBase, parent), INUnitDiscoveryCanHaveTestFixture
{
- private readonly List testFixtures = new();
+ private readonly List testFixtures = [];
public IEnumerable TestFixtures => testFixtures;
@@ -294,11 +294,11 @@ public void AddTestFixture(NUnitDiscoveryTestFixture tf)
}
- private readonly List testSuites = new();
+ private readonly List testSuites = [];
- private readonly List genericFixtures = new();
- private readonly List setUpFixtures = new();
- private readonly List parameterizedFixtures = new();
+ private readonly List genericFixtures = [];
+ private readonly List setUpFixtures = [];
+ private readonly List parameterizedFixtures = [];
public IEnumerable TestSuites => testSuites;
diff --git a/src/NUnitTestAdapter/NUnitEngine/NUnitTestEvent.cs b/src/NUnitTestAdapter/NUnitEngine/NUnitTestEvent.cs
index f95da627..af6798eb 100644
--- a/src/NUnitTestAdapter/NUnitEngine/NUnitTestEvent.cs
+++ b/src/NUnitTestAdapter/NUnitEngine/NUnitTestEvent.cs
@@ -127,7 +127,7 @@ protected NUnitTestEvent(XmlNode node) : base(node)
public string MethodName => Node.GetAttribute("methodname");
public string ClassName => Node.GetAttribute("classname");
- public string Output => Node.SelectSingleNode("output")?.InnerText.UnEscapeUnicodeCharacters();
+ public string Output => Node.SelectSingleNode("output")?.InnerText.UnEscapeUnicodeColorCodesCharacters();
public CheckedTime StartTime()
@@ -161,11 +161,11 @@ public IEnumerable NUnitAttachments
{
if (nUnitAttachments != null)
return nUnitAttachments;
- nUnitAttachments = new List();
+ nUnitAttachments = [];
foreach (XmlNode attachment in Node.SelectNodes("attachments/attachment"))
{
var path = attachment.SelectSingleNode("filePath")?.InnerText ?? string.Empty;
- var description = attachment.SelectSingleNode("description")?.InnerText.UnEscapeUnicodeCharacters();
+ var description = attachment.SelectSingleNode("description")?.InnerText.UnEscapeUnicodeColorCodesCharacters();
nUnitAttachments.Add(new NUnitAttachment(path, description));
}
return nUnitAttachments;
diff --git a/src/NUnitTestAdapter/NUnitEngine/NUnitTestEventSuiteFinished.cs b/src/NUnitTestAdapter/NUnitEngine/NUnitTestEventSuiteFinished.cs
index 6f0a900f..dbc941c5 100644
--- a/src/NUnitTestAdapter/NUnitEngine/NUnitTestEventSuiteFinished.cs
+++ b/src/NUnitTestAdapter/NUnitEngine/NUnitTestEventSuiteFinished.cs
@@ -28,10 +28,10 @@ public NUnitTestEventSuiteFinished(XmlNode node) : base(node)
var failureNode = Node.SelectSingleNode("failure");
if (failureNode != null)
{
- FailureMessage = failureNode.SelectSingleNode("message")?.InnerText.UnEscapeUnicodeCharacters();
- StackTrace = failureNode.SelectSingleNode("stack-trace")?.InnerText.UnEscapeUnicodeCharacters();
+ FailureMessage = failureNode.SelectSingleNode("message")?.InnerText.UnEscapeUnicodeColorCodesCharacters();
+ StackTrace = failureNode.SelectSingleNode("stack-trace")?.InnerText.UnEscapeUnicodeColorCodesCharacters();
}
- ReasonMessage = Node.SelectSingleNode("reason/message")?.InnerText.UnEscapeUnicodeCharacters();
+ ReasonMessage = Node.SelectSingleNode("reason/message")?.InnerText.UnEscapeUnicodeColorCodesCharacters();
}
public string ReasonMessage { get; }
diff --git a/src/NUnitTestAdapter/NUnitEngine/NUnitTestEventTestCase.cs b/src/NUnitTestAdapter/NUnitEngine/NUnitTestEventTestCase.cs
index 4b079cf5..c5f7438b 100644
--- a/src/NUnitTestAdapter/NUnitEngine/NUnitTestEventTestCase.cs
+++ b/src/NUnitTestAdapter/NUnitEngine/NUnitTestEventTestCase.cs
@@ -48,11 +48,11 @@ public NUnitTestEventTestCase(XmlNode node)
if (failureNode != null)
{
Failure = new NUnitFailure(
- failureNode.SelectSingleNode("message")?.InnerText.UnEscapeUnicodeCharacters(),
- failureNode.SelectSingleNode("stack-trace")?.InnerText.UnEscapeUnicodeCharacters());
+ failureNode.SelectSingleNode("message")?.InnerText.UnEscapeUnicodeColorCodesCharacters(),
+ failureNode.SelectSingleNode("stack-trace")?.InnerText.UnEscapeUnicodeColorCodesCharacters());
}
- ReasonMessage = Node.SelectSingleNode("reason/message")?.InnerText.UnEscapeUnicodeCharacters();
+ ReasonMessage = Node.SelectSingleNode("reason/message")?.InnerText.UnEscapeUnicodeColorCodesCharacters();
}
public string ReasonMessage { get; }
@@ -73,7 +73,7 @@ public string StackTrace
int i = 1;
foreach (XmlNode assertionStacktraceNode in Node.SelectNodes("assertions/assertion/stack-trace"))
{
- stackTrace += $"{i++}) " + assertionStacktraceNode.InnerText.UnEscapeUnicodeCharacters();
+ stackTrace += $"{i++}) " + assertionStacktraceNode.InnerText.UnEscapeUnicodeColorCodesCharacters();
stackTrace += "\n";
}
diff --git a/src/NUnitTestAdapter/NUnitEngine/NUnitTestNode.cs b/src/NUnitTestAdapter/NUnitEngine/NUnitTestNode.cs
index a2cd0bc1..48dad9e0 100644
--- a/src/NUnitTestAdapter/NUnitEngine/NUnitTestNode.cs
+++ b/src/NUnitTestAdapter/NUnitEngine/NUnitTestNode.cs
@@ -21,7 +21,7 @@ public abstract class NUnitTestNode : INUnitTestNode
public bool IsNull => Node == null;
- private readonly List properties = new ();
+ private readonly List properties = [];
public IEnumerable Properties => properties;
public string Seed => Node.GetAttribute("seed");
diff --git a/src/NUnitTestAdapter/NUnitEngine/UnicodeEscapeHelper.cs b/src/NUnitTestAdapter/NUnitEngine/UnicodeEscapeHelper.cs
index 5949e930..616813bf 100644
--- a/src/NUnitTestAdapter/NUnitEngine/UnicodeEscapeHelper.cs
+++ b/src/NUnitTestAdapter/NUnitEngine/UnicodeEscapeHelper.cs
@@ -6,50 +6,90 @@ namespace NUnit.VisualStudio.TestAdapter.NUnitEngine;
internal static class UnicodeEscapeHelper
{
- public static string UnEscapeUnicodeCharacters(this string text)
+ private const int EscapeAsciiValue = 0x1B;
+
+ public static string UnEscapeUnicodeColorCodesCharacters(this string text)
{
- if (text == null)
- return null;
+ if (text == null)
+ return null;
- // Small optimization, if there are no "\u", then there is no need to rewrite the string
- var firstEscapeIndex = text.IndexOf("\\u", StringComparison.Ordinal);
- if (firstEscapeIndex == -1)
- return text;
+ // Small optimization, if there are no "\u", then there is no need to rewrite the string
+ var firstEscapeIndex = text.IndexOf("\\u", StringComparison.Ordinal);
+ if (firstEscapeIndex == -1)
+ return text;
- var stringBuilder = new StringBuilder(text.Substring(0, firstEscapeIndex));
- for (var position = firstEscapeIndex; position < text.Length; position++)
+ var stringBuilder = new StringBuilder(text.Substring(0, firstEscapeIndex));
+ for (var position = firstEscapeIndex; position < text.Length; position++)
+ {
+ char c = text[position];
+ if (c == '\\' && TryUnEscapeOneCharacter(text, position, out var escapedChar, out var extraCharacterRead))
{
- char c = text[position];
- if (c == '\\' && TryUnEscapeOneCharacter(text, position, out var escapedChar, out var extraCharacterRead))
- {
- stringBuilder.Append(escapedChar);
- position += extraCharacterRead;
- }
- else
- {
- stringBuilder.Append(c);
- }
+ stringBuilder.Append(escapedChar);
+ position += extraCharacterRead;
+ }
+ else
+ {
+ stringBuilder.Append(c);
}
-
- return stringBuilder.ToString();
}
+ return stringBuilder.ToString();
+ }
+
private static bool TryUnEscapeOneCharacter(string text, int position, out char escapedChar, out int extraCharacterRead)
{
- const string unicodeEscapeSample = "u0000";
+ const string unicodeEscapeSample = "u0000";
- extraCharacterRead = 0;
- escapedChar = '\0';
- if (position + unicodeEscapeSample.Length >= text.Length)
- return false;
+ extraCharacterRead = 0;
+ escapedChar = '\0';
+ if (position + unicodeEscapeSample.Length >= text.Length)
+ return false;
+ extraCharacterRead = unicodeEscapeSample.Length;
+ if (!int.TryParse(text.Substring(position + 2, unicodeEscapeSample.Length - 1), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var escapeValue))
+ return false;
- extraCharacterRead = unicodeEscapeSample.Length;
- if (!int.TryParse(text.Substring(position + 2, unicodeEscapeSample.Length - 1), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var escapeValue))
- return false;
+ // Here we only want to escape color escape character when used in a context of a ANSI color code
+ // See https://github.com/nunit/nunit3-vs-adapter/issues/1124 for more information.
+ if (escapeValue != EscapeAsciiValue)
+ return false;
+
+ if (!IsAnsiColorCodeSequence(text, position + extraCharacterRead + 1))
+ return false;
+
+ escapedChar = (char)escapeValue;
- escapedChar = (char)escapeValue;
+ return true;
+ }
- return true;
+ private static bool IsAnsiColorCodeSequence(string text, int position)
+ {
+ var start = false;
+ while (position < text.Length)
+ {
+ var c = text[position++];
+ // Look for the begining [
+ if (c == '[' && !start)
+ {
+ start = true;
+ continue;
+ }
+
+ // Found the 'm' at the end
+ if (c == 'm' && start)
+ return true;
+
+ // [ was not found
+ if (!start)
+ return false;
+
+ // Ignore all number and ;
+ var isDigit = c is >= '0' and <= '9';
+ if (!isDigit && c != ';')
+ return false;
}
+
+ // At the end without the ending 'm'
+ return false;
+ }
}
\ No newline at end of file
diff --git a/src/NUnitTestAdapter/NUnitEventListener.cs b/src/NUnitTestAdapter/NUnitEventListener.cs
index 0e07de39..7ae01f61 100644
--- a/src/NUnitTestAdapter/NUnitEventListener.cs
+++ b/src/NUnitTestAdapter/NUnitEventListener.cs
@@ -48,7 +48,7 @@ public class NUnitEventListener(ITestConverterCommon testConverter, INUnit3TestE
#endif
ITestEventListener, IDisposable // Public for testing
{
- private static readonly ICollection EmptyNodes = new List();
+ private static readonly ICollection EmptyNodes = [];
private ITestExecutionRecorder Recorder { get; } = executor.FrameworkHandle;
private ITestConverterCommon TestConverter { get; } = testConverter;
private IAdapterSettings Settings { get; } = executor.Settings;
@@ -235,7 +235,7 @@ public void TestOutput(INUnitTestEventTestOutput outputNodeEvent)
{
if (!OutputNodes.TryGetValue(testId, out var outputNodes))
{
- outputNodes = new List();
+ outputNodes = [];
OutputNodes.Add(testId, outputNodes);
}
diff --git a/src/NUnitTestAdapter/TraitsFeature.cs b/src/NUnitTestAdapter/TraitsFeature.cs
index bcfb4e87..bc1bb083 100644
--- a/src/NUnitTestAdapter/TraitsFeature.cs
+++ b/src/NUnitTestAdapter/TraitsFeature.cs
@@ -49,7 +49,7 @@ public sealed class CachedTestCaseInfo
/// Currently, the only effect this has is to add a Test Explorer grouping header
/// for each trait with the name “Name [Value]”, or for an empty value, “Name”.
///
- public List Traits { get; } = new ();
+ public List Traits { get; } = [];
///
/// Used by ; does not affect the Test Explorer UI.
diff --git a/src/NUnitTestAdapterTests/ExecutionTests.cs b/src/NUnitTestAdapterTests/ExecutionTests.cs
index b56de2f5..533f6796 100644
--- a/src/NUnitTestAdapterTests/ExecutionTests.cs
+++ b/src/NUnitTestAdapterTests/ExecutionTests.cs
@@ -30,10 +30,10 @@ public void Setup()
discovery.NoOfLoadedTestCases.Returns(1);
discovery.IsDiscoveryMethodCurrent.Returns(true);
- discovery.LoadedTestCases.Returns(new List
- {
+ discovery.LoadedTestCases.Returns(
+ [
new ("A", new Uri(NUnitTestAdapter.ExecutorUri), "line 23")
- });
+ ]);
filter = new TestFilter("AB");
}
diff --git a/src/NUnitTestAdapterTests/Fakes/FakeFrameworkHandle.cs b/src/NUnitTestAdapterTests/Fakes/FakeFrameworkHandle.cs
index 07608dff..eb3875af 100644
--- a/src/NUnitTestAdapterTests/Fakes/FakeFrameworkHandle.cs
+++ b/src/NUnitTestAdapterTests/Fakes/FakeFrameworkHandle.cs
@@ -16,7 +16,7 @@ class FakeFrameworkHandle : IFrameworkHandle
public FakeFrameworkHandle()
{
- Events = new List();
+ Events = [];
}
#endregion
diff --git a/src/NUnitTestAdapterTests/Fakes/MessageLoggerStub.cs b/src/NUnitTestAdapterTests/Fakes/MessageLoggerStub.cs
index 391aa7ac..733969f6 100644
--- a/src/NUnitTestAdapterTests/Fakes/MessageLoggerStub.cs
+++ b/src/NUnitTestAdapterTests/Fakes/MessageLoggerStub.cs
@@ -30,7 +30,7 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.Fakes;
public class MessageLoggerStub : IMessageLogger
{
- private readonly List> messages = new ();
+ private readonly List> messages = [];
public void SendMessage(TestMessageLevel testMessageLevel, string message)
{
messages.Add(new Tuple(testMessageLevel, message));
diff --git a/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj b/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj
index 4212d4bb..afba9ac3 100644
--- a/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj
+++ b/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj
@@ -5,37 +5,33 @@
NUnit.VisualStudio.TestAdapter.Tests
NUnit.VisualStudio.TestAdapter.Tests
net462;netcoreapp3.1
-
+
+
true
true
latest
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
+
+
-
+
-
-
+
+
-
-
+
-
-
-
-
+
diff --git a/src/NUnitTestAdapterTests/NUnit3TestDiscovererTests.cs b/src/NUnitTestAdapterTests/NUnit3TestDiscovererTests.cs
index dcc67002..51befe1b 100644
--- a/src/NUnitTestAdapterTests/NUnit3TestDiscovererTests.cs
+++ b/src/NUnitTestAdapterTests/NUnit3TestDiscovererTests.cs
@@ -49,7 +49,7 @@ public void ThatDiscovererNUnitEngineAdapterIsInitialized()
var sut = new NUnit3TestDiscoverer();
Assert.That(sut.NUnitEngineAdapter, Is.Not.Null);
var dc = Substitute.For();
- sut.DiscoverTests(new List(), dc, null, null);
+ sut.DiscoverTests([], dc, null, null);
Assert.That(sut.NUnitEngineAdapter, Is.Not.Null);
}
}
\ No newline at end of file
diff --git a/src/NUnitTestAdapterTests/NUnitEngineTests/UnicodeEscapeHelperTests.cs b/src/NUnitTestAdapterTests/NUnitEngineTests/UnicodeEscapeHelperTests.cs
index e13ea6b6..f8d37df6 100644
--- a/src/NUnitTestAdapterTests/NUnitEngineTests/UnicodeEscapeHelperTests.cs
+++ b/src/NUnitTestAdapterTests/NUnitEngineTests/UnicodeEscapeHelperTests.cs
@@ -5,14 +5,17 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.NUnitEngineTests;
public class UnicodeEscapeHelperTests
{
- [TestCase("\\u001b", "\u001b")]
+ [TestCase("\\u001b", "\\u001b")]
[TestCase("\\u001", "\\u001")]
[TestCase("\\u01", "\\u01")]
[TestCase("\\u1", "\\u1")]
- [TestCase("\\u001b6", "\u001b6")]
+ [TestCase("\\u001b6", "\\u001b6")]
+ [TestCase("\\u001b[0m", "\u001b[0m")]
+ [TestCase("\\u001b[36m", "\u001b[36m")]
+ [TestCase("\\u001b[48;5;122mTest", "\u001b[48;5;122mTest")]
[TestCase("some-text", "some-text")]
- public void UnEscapeUnicodeCharacters_ShouldReplaceBackslashU(string value, string expected)
+ public void UnEscapeUnicodeColorCodesCharactersShouldReplaceBackslashU(string value, string expected)
{
- Assert.That(value.UnEscapeUnicodeCharacters(), Is.EqualTo(expected));
+ Assert.That(value.UnEscapeUnicodeColorCodesCharacters(), Is.EqualTo(expected));
}
}
\ No newline at end of file
diff --git a/src/NUnitTestAdapterTests/TestDiscoveryTests.cs b/src/NUnitTestAdapterTests/TestDiscoveryTests.cs
index f32d713b..e1b6a31c 100644
--- a/src/NUnitTestAdapterTests/TestDiscoveryTests.cs
+++ b/src/NUnitTestAdapterTests/TestDiscoveryTests.cs
@@ -53,7 +53,7 @@ public class TestDiscoveryTests : ITestCaseDiscoverySink
static readonly string MockAssemblyPath =
Path.Combine(TestContext.CurrentContext.TestDirectory, "mock-assembly.dll");
- private readonly List testCases = new();
+ private readonly List testCases = [];
private readonly IDiscoveryContext _context;
diff --git a/src/NUnitTestAdapterTests/TestExecutionTests.cs b/src/NUnitTestAdapterTests/TestExecutionTests.cs
index 552eeea0..e78f434d 100644
--- a/src/NUnitTestAdapterTests/TestExecutionTests.cs
+++ b/src/NUnitTestAdapterTests/TestExecutionTests.cs
@@ -45,7 +45,7 @@ public class ResultSummary
public ResultSummary(IEnumerable results)
{
- summary = new Dictionary();
+ summary = [];
foreach (TestResult result in results)
{
@@ -103,10 +103,10 @@ public void TestsWhereShouldFilter(string filter, int expectedCount, int noOfSki
executor.RunTests(new[] { mockAssemblyPath }, context, fakeFramework);
var completedRuns = fakeFramework.Events.Where(e => e.EventType == FakeFrameworkHandle.EventType.RecordEnd).ToList();
- TestContext.WriteLine(" ");
+ TestContext.Out.WriteLine(" ");
foreach (var test in completedRuns)
{
- TestContext.WriteLine($"{test.TestCase.DisplayName}:{test.TestOutcome}");
+ TestContext.Out.WriteLine($"{test.TestCase.DisplayName}:{test.TestOutcome}");
}
Assert.Multiple(() =>
@@ -155,15 +155,15 @@ public void DumpEvents()
{
foreach (var ev in testLog.Events)
{
- TestContext.Write(ev.EventType + ": ");
+ TestContext.Out.Write(ev.EventType + ": ");
if (ev.TestResult != null)
- TestContext.WriteLine("{0} {1}", ev.TestResult.TestCase.FullyQualifiedName, ev.TestResult.Outcome);
+ TestContext.Out.WriteLine("{0} {1}", ev.TestResult.TestCase.FullyQualifiedName, ev.TestResult.Outcome);
else if (ev.TestCase != null)
- TestContext.WriteLine(ev.TestCase.FullyQualifiedName);
+ TestContext.Out.WriteLine(ev.TestCase.FullyQualifiedName);
else if (ev.Message.Text != null)
- TestContext.WriteLine(ev.Message.Text);
+ TestContext.Out.WriteLine(ev.Message.Text);
else
- TestContext.WriteLine();
+ TestContext.Out.WriteLine();
}
}
@@ -210,8 +210,8 @@ public void CorrectNumberOfResultsWereReceived()
[TestCaseSource(nameof(Outcomes))]
public int TestOutcomeTotalsAreCorrect(TestOutcome outcome)
{
- TestContext.WriteLine(" ");
- TestContext.WriteLine($"Looking for outcome: {outcome}");
+ TestContext.Out.WriteLine(" ");
+ TestContext.Out.WriteLine($"Looking for outcome: {outcome}");
return testLog.Events
.Count(e => e.EventType == FakeFrameworkHandle.EventType.RecordResult && e.TestResult.Outcome == outcome);
}
diff --git a/src/NUnitTestAdapterTests/TraitsTests.cs b/src/NUnitTestAdapterTests/TraitsTests.cs
index 63ea129c..07745c65 100644
--- a/src/NUnitTestAdapterTests/TraitsTests.cs
+++ b/src/NUnitTestAdapterTests/TraitsTests.cs
@@ -386,7 +386,7 @@ public void SetUp()
var settings = Substitute.For();
settings.CollectSourceInformation.Returns(false);
testconverter = new TestConverterForXml(testlogger, "whatever", settings);
- testcaselist = new List();
+ testcaselist = [];
}
[TearDown]
diff --git a/src/NUnitTestAdapterTests/Utils.cs b/src/NUnitTestAdapterTests/Utils.cs
index 34f4b313..8891cb0a 100644
--- a/src/NUnitTestAdapterTests/Utils.cs
+++ b/src/NUnitTestAdapterTests/Utils.cs
@@ -20,7 +20,7 @@ public static void DeleteDirectoryRobust(string directory)
}
catch (IOException ex) when (attempt < 3 && (WinErrorCode)ex.HResult == WinErrorCode.DirNotEmpty)
{
- TestContext.WriteLine("Another process added files to the directory while its contents were being deleted. Retrying...");
+ TestContext.Out.WriteLine("Another process added files to the directory while its contents were being deleted. Retrying...");
}
}
}
diff --git a/src/NUnitTestAdapterTests/VsExperimentalTests.cs b/src/NUnitTestAdapterTests/VsExperimentalTests.cs
index d21ed0c0..98c58b6c 100644
--- a/src/NUnitTestAdapterTests/VsExperimentalTests.cs
+++ b/src/NUnitTestAdapterTests/VsExperimentalTests.cs
@@ -50,7 +50,7 @@ public void ThatCategoriesAreDistinct()
var settings = Substitute.For();
settings.VsTestCategoryType.Returns(VsTestCategoryType.NUnit);
var cl = new CategoryList(testCase, settings);
- cl.AddRange(new List { "one", "one", "two", "two" });
+ cl.AddRange(["one", "one", "two", "two"]);
cl.UpdateCategoriesToVs();
var returnedCategoryList = testCase.GetCategories();
diff --git a/src/empty-assembly/empty-assembly.csproj b/src/empty-assembly/empty-assembly.csproj
index cd29ed19..40fc46d2 100644
--- a/src/empty-assembly/empty-assembly.csproj
+++ b/src/empty-assembly/empty-assembly.csproj
@@ -8,11 +8,11 @@
-
+
-
+
\ No newline at end of file
diff --git a/src/mock-assembly/MockAssembly.cs b/src/mock-assembly/MockAssembly.cs
index 28fc1258..a6ff3c25 100644
--- a/src/mock-assembly/MockAssembly.cs
+++ b/src/mock-assembly/MockAssembly.cs
@@ -130,7 +130,9 @@ public void MockTest3()
{ Assert.Pass("Succeeded!"); }
[Test]
+#pragma warning disable NUnit1026 // The test or setup/teardown method is not public
protected static void MockTest5()
+#pragma warning restore NUnit1026 // The test or setup/teardown method is not public
{ }
[Test]
@@ -153,12 +155,14 @@ public void MockTest4()
[Category("Special")]
public void ExplicitlyRunTest()
{ }
+ // ReSharper disable once NUnit.MethodWithParametersAndTestAttribute
+#pragma warning disable NUnit1027 // Remove unused parameter
[Test]
- // ReSharper disable once NUnit.MethodWithParametersAndTestAttribute
#pragma warning disable IDE0060 // Remove unused parameter
public void NotRunnableTest(int a, int b)
#pragma warning restore IDE0060 // Remove unused parameter
+#pragma warning restore NUnit1027
{
}
@@ -246,7 +250,11 @@ public class BadFixture
public const int Tests = 1;
public const int Suites = 1;
+#pragma warning disable IDE0290 // Use primary constructor
+#pragma warning disable IDE0060 // Remove unused parameter
public BadFixture(int val) { }
+#pragma warning restore IDE0060 // Remove unused parameter
+#pragma warning restore IDE0290 // Use primary constructor
[Test]
public void SomeTest() { }
@@ -267,7 +275,9 @@ public int MethodWithParameters(int x, int y)
[TestCase(2, 4)]
[TestCase(9.2, 11.7)]
+#pragma warning disable IDE0060 // Remove unused parameter
public void GenericMethod(T x, T y)
+#pragma warning restore IDE0060 // Remove unused parameter
{
}
}
@@ -279,7 +289,11 @@ public class ParameterizedFixture
public const int Tests = 4;
public const int Suites = 3;
+#pragma warning disable IDE0290 // Use primary constructor
+#pragma warning disable IDE0060 // Remove unused parameter
public ParameterizedFixture(int num) { }
+#pragma warning restore IDE0060 // Remove unused parameter
+#pragma warning restore IDE0290 // Use primary constructor
[Test]
public void Test1() { }
@@ -298,7 +312,11 @@ public class GenericFixtureConstants
[TestFixture(11.5)]
public class GenericFixture
{
+#pragma warning disable IDE0290 // Use primary constructor
+#pragma warning disable IDE0060 // Remove unused parameter
public GenericFixture(T num) { }
+#pragma warning restore IDE0060 // Remove unused parameter
+#pragma warning restore IDE0290 // Use primary constructor
[Test]
public void Test1() { }
diff --git a/src/mock-assembly/mock-assembly.csproj b/src/mock-assembly/mock-assembly.csproj
index 9feaf8e5..ad03465e 100644
--- a/src/mock-assembly/mock-assembly.csproj
+++ b/src/mock-assembly/mock-assembly.csproj
@@ -8,11 +8,11 @@
-
+
-
+
\ No newline at end of file