Skip to content

Commit

Permalink
Merge pull request #1175 from nunit/updateanalyzer
Browse files Browse the repository at this point in the history
Update analyzer, fix coding warnings
  • Loading branch information
OsirisTerje committed May 12, 2024
2 parents a042f08 + bac6c0d commit 26a3d09
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 74 deletions.
4 changes: 1 addition & 3 deletions src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs
Expand Up @@ -3,7 +3,6 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;

using NUnit.Framework;
using NUnit.Framework.Interfaces;
Expand Down Expand Up @@ -277,7 +276,6 @@ private static string TryGetTestNupkgVersion(string directory, string packageId)

var path = selected?.FullName;

return path is null ? null :
Path.GetFileNameWithoutExtension(path).Substring(packageId.Length + 1);
return Path.GetFileNameWithoutExtension(path)?.Substring(packageId.Length + 1) ?? "";
}
}
24 changes: 12 additions & 12 deletions src/NUnit.TestAdapter.Tests.Acceptance/FilterTests.cs
Expand Up @@ -40,12 +40,12 @@ public void Bar()

[Test, Platform("Win")]
[TestCase(NoFilter, 2, 3)]
[TestCase(@"TestCategory=FooGroup", 1, 2)]
[TestCase(@"TestCategory!=BarGroup", 1, 2)]
[TestCase(@"TestCategory=IsExplicit", 1, 1)]
[TestCase(@"FullyQualifiedName=Filter.Tests.Foo", 1, 1)]
[TestCase(@"FullyQualifiedName!=Filter.Tests.Foo", 1, 1)]
[TestCase(@"TestCategory!=AllGroup", 0, 0)]
[TestCase("TestCategory=FooGroup", 1, 2)]
[TestCase("TestCategory!=BarGroup", 1, 2)]
[TestCase("TestCategory=IsExplicit", 1, 1)]
[TestCase("FullyQualifiedName=Filter.Tests.Foo", 1, 1)]
[TestCase("FullyQualifiedName!=Filter.Tests.Foo", 1, 1)]
[TestCase("TestCategory!=AllGroup", 0, 0)]
// [TestCase(@"TestThatDontExistHere", 0, 0)]
// [TestCase(@"FullyQualifiedName~Filter.Tests.Foo", 1, 1)]
// [TestCase(@"FullyQualifiedName~Foo", 1, 1)]
Expand All @@ -58,11 +58,11 @@ public void Filter_DotNetTest(string filter, int executed, int total)

[Test, Platform("Win")]
[TestCase(NoFilter, 2, 3)]
[TestCase(@"TestCategory=FooGroup", 1, 2)]
[TestCase(@"TestCategory!=BarGroup", 1, 2)]
[TestCase(@"TestCategory=IsExplicit", 1, 1)]
[TestCase(@"FullyQualifiedName=Filter.Tests.Foo", 1, 1)]
[TestCase(@"TestCategory=XXXX", 0, 0)]
[TestCase("TestCategory=FooGroup", 1, 2)]
[TestCase("TestCategory!=BarGroup", 1, 2)]
[TestCase("TestCategory=IsExplicit", 1, 1)]
[TestCase("FullyQualifiedName=Filter.Tests.Foo", 1, 1)]
[TestCase("TestCategory=XXXX", 0, 0)]
public void Filter_VSTest(string filter, int executed, int total)
{
var workspace = Build();
Expand All @@ -84,7 +84,7 @@ public void Filter_VSTest(string filter, int executed, int total)
public void Filter_DotNetTest_NUnitWhere(string filter, int executed, int total)
{
var workspace = Build();
var nunitWhere = $@"NUnit.Where={filter}";
var nunitWhere = $"NUnit.Where={filter}";
var results = workspace.DotNetTest(nunitWhere, true, true, TestContext.WriteLine);
Verify(executed, total, results);
}
Expand Down
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="nunit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.1.0">
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
14 changes: 7 additions & 7 deletions src/NUnit.TestAdapter.Tests.Acceptance/ParanthesisTests.cs
Expand Up @@ -42,13 +42,13 @@ public void VsTestNoFilter()
}

[Test, Platform("Win")]
[TestCase(@"FullyQualifiedName=Issue919.Foo.Bzzt", 1, 1)] // Sanity check
[TestCase("FullyQualifiedName=Issue919.Foo.Bzzt", 1, 1)] // Sanity check
[TestCase(@"FullyQualifiedName=Issue919.Foo.Bar\(1\)", 0, 0)]
[TestCase(@"FullyQualifiedName=Issue919.Foo.Baz\(1\)", 1, 1)]
[TestCase(@"Name=Bzzt", 1, 1)] // Sanity check
[TestCase("Name=Bzzt", 1, 1)] // Sanity check
[TestCase(@"Name=Bar\(1\)", 0, 0)]
[TestCase(@"Name=Baz\(1\)", 1, 1)]
[TestCase(@"", 2, 2)]
[TestCase("", 2, 2)]
public void VsTestTestCases(string filter, int executed, int total)
{
var workspace = Build();
Expand All @@ -58,7 +58,7 @@ public void VsTestTestCases(string filter, int executed, int total)
}

[Test, Platform("Win")]
[TestCase(@"Bzzt", 1, 1)] // Sanity check
[TestCase("Bzzt", 1, 1)] // Sanity check
[TestCase(@"Bar\(1\)", 0, 0)]
[TestCase(@"Baz\(1\)", 1, 1)]
public void VsTestTests(string filter, int executed, int total)
Expand All @@ -69,13 +69,13 @@ public void VsTestTests(string filter, int executed, int total)
}

[Test, Platform("Win")]
[TestCase(@"FullyQualifiedName=Issue919.Foo.Bzzt", 1, 1)] // Sanity check
[TestCase("FullyQualifiedName=Issue919.Foo.Bzzt", 1, 1)] // Sanity check
[TestCase(@"FullyQualifiedName=Issue919.Foo.Bar\(1\)", 0, 0)]
[TestCase(@"FullyQualifiedName=Issue919.Foo.Baz\(1\)", 1, 1)]
[TestCase(@"Name=Bzzt", 1, 1)] // Sanity check
[TestCase("Name=Bzzt", 1, 1)] // Sanity check
[TestCase(@"Name=Bar\(1\)", 0, 0)]
[TestCase(@"Name=Baz\(1\)", 1, 1)]
[TestCase(@"", 2, 2)]
[TestCase("", 2, 2)]
public void DotnetTestCases(string filter, int executed, int total)
{
var workspace = Build();
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapterTests/AdapterSettingsTests.cs
Expand Up @@ -209,7 +209,7 @@ public void TestOutputSetting()
_settings.Load(@"<RunSettings><NUnit><WorkDirectory>C:\Whatever</WorkDirectory><TestOutputXml>/my/work/dir</TestOutputXml></NUnit></RunSettings>");
Assert.That(_settings.UseTestOutputXml);
_settings.SetTestOutputFolder(_settings.WorkDirectory);
Assert.That(_settings.TestOutputFolder, Does.Contain(@"/my/work/dir"));
Assert.That(_settings.TestOutputFolder, Does.Contain("/my/work/dir"));
}

/// <summary>
Expand Down
5 changes: 1 addition & 4 deletions src/NUnitTestAdapterTests/AsyncTests.cs
Expand Up @@ -49,9 +49,6 @@ private static Task<int> ReturnOne()

private static Task ThrowException()
{
return Task.Run(() =>
{
throw new InvalidOperationException();
});
return Task.Run(() => throw new InvalidOperationException());
}
}
6 changes: 3 additions & 3 deletions src/NUnitTestAdapterTests/DumpXmlTests.cs
Expand Up @@ -75,9 +75,9 @@ public void ThatPathIsCorrectlyParsedInDiscoveryPhase(string path, string expect
file.Received().WriteAllText(Arg.Is<string>(o => o.StartsWith(expected, StringComparison.OrdinalIgnoreCase)), Arg.Any<string>());
}

[TestCase(@"/some/Folder/Whatever.dll", @"/some/Folder/Dump/D_Whatever.dll.dump")]
[TestCase(@"/some/Folder/Whatever.dll", @"/some/Folder/Dump")]
[TestCase(@"/some/Folder/Whatever.dll", @"/some/Folder")]
[TestCase("/some/Folder/Whatever.dll", "/some/Folder/Dump/D_Whatever.dll.dump")]
[TestCase("/some/Folder/Whatever.dll", "/some/Folder/Dump")]
[TestCase("/some/Folder/Whatever.dll", "/some/Folder")]
[Platform("Unix")]
public void ThatPathIsCorrectlyParsedInDiscoveryPhaseOnUnix(string path, string expected)
{
Expand Down
4 changes: 1 addition & 3 deletions src/NUnitTestAdapterTests/ExecutionTests.cs
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using NSubstitute;
using NUnit.Engine;
Expand Down
4 changes: 2 additions & 2 deletions src/NUnitTestAdapterTests/ExtensionsTests.cs
Expand Up @@ -36,7 +36,7 @@ public class ExtensionsTests
[TestCase("\r\n")]
public void ThatIsNullOrWhiteSpaceHandlesTabs(string value)
{
var res = StringExtensions.IsNullOrWhiteSpace(value);
var res = value.IsNullOrWhiteSpace();
Assert.That(res);
}

Expand All @@ -45,7 +45,7 @@ public void ThatIsNullOrWhiteSpaceHandlesTabs(string value)
[TestCase("42\n\r")]
public void ThatIsNullOrWhiteSpaceHandlesNonWhiteSpace(string value)
{
var res = StringExtensions.IsNullOrWhiteSpace(value);
var res = value.IsNullOrWhiteSpace();
Assert.That(res, Is.False);
}
}
4 changes: 2 additions & 2 deletions src/NUnitTestAdapterTests/Filtering/FilteringTestUtils.cs
Expand Up @@ -41,11 +41,11 @@ public static ITestCaseFilterExpression CreateVSTestFilterExpression(string filt
var filterExpressionWrapper =
filterExpressionWrapperType.GetTypeInfo()
.GetConstructor(new[] { typeof(string) })
.Invoke(new object[] { filter });
.Invoke([filter]);

return (ITestCaseFilterExpression)Type.GetType("Microsoft.VisualStudio.TestPlatform.Common.Filtering.TestCaseFilterExpression, Microsoft.VisualStudio.TestPlatform.Common", throwOnError: true).GetTypeInfo()
.GetConstructor(new[] { filterExpressionWrapperType })
.Invoke(new[] { filterExpressionWrapper });
.Invoke([filterExpressionWrapper]);
}

public static VsTestFilter CreateTestFilter(ITestCaseFilterExpression filterExpression)
Expand Down
13 changes: 3 additions & 10 deletions src/NUnitTestAdapterTests/Filtering/TestDoubleFilterExpression.cs
Expand Up @@ -29,17 +29,10 @@

namespace NUnit.VisualStudio.TestAdapter.Tests.Filtering;

public sealed class TestDoubleFilterExpression : ITestCaseFilterExpression
public sealed class TestDoubleFilterExpression(string testCaseFilterValue, Func<Func<string, object>, bool> predicate)
: ITestCaseFilterExpression
{
private readonly Func<Func<string, object>, bool> predicate;

public TestDoubleFilterExpression(string testCaseFilterValue, Func<Func<string, object>, bool> predicate)
{
TestCaseFilterValue = testCaseFilterValue;
this.predicate = predicate;
}

public string TestCaseFilterValue { get; }
public string TestCaseFilterValue { get; } = testCaseFilterValue;

public bool MatchTestCase(TestCase testCase, Func<string, object> propertyValueProvider)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.1.0">
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Expand Up @@ -980,8 +980,8 @@ public void ThatDotNetTestWorks()
var sut = new DiscoveryConverter(logger, settings);
var ndr = sut.ConvertXml(
new NUnitResults(XmlHelper.CreateXmlNode(DotnetXml)));
var fixtures = ndr.TestAssembly.TestFixtures;
Assert.That(fixtures.Count(), Is.EqualTo(3), "Didnt find all fixtures");
var fixtures = ndr.TestAssembly.TestFixtures.ToList();
Assert.That(fixtures.Count, Is.EqualTo(3), "Didnt find all fixtures");
foreach (var fixture in fixtures)
{
Assert.That(fixture.TestCases.Count, Is.EqualTo(3),
Expand Down Expand Up @@ -1010,7 +1010,7 @@ public void ThatDotNetTestWorks()
</test-run>";

/// <summary>
/// See issue 1041 at https://github.com/nunit/nunit3-vs-adapter/issues/1044
/// See issue 1041 at https://github.com/nunit/nunit3-vs-adapter/issues/1044.
/// </summary>
private const string MixedExplicitTestSourceXmlForIssue1041 =
@"<test-run id='0' name='Issue1044.dll' fullname='d:\repos\NUnit\nunit3-vs-adapter.issues\Issue1044\bin\Debug\net7.0\Issue1044.dll' runstate='Runnable' testcasecount='4'>
Expand Down
Expand Up @@ -21,12 +21,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NUnit.VisualStudio.TestAdapter.Tests.NUnitEngineTests;

public class NUnitResultsTests
Expand Down
Expand Up @@ -28,11 +28,11 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.NUnitEngineTests;

public class NUnitTestCaseTests
{
private const string XmlRunnable = @"<test-case id='0-1007' name='Test2M' fullname='TestWarnings.Test4.Test2M' methodname='Test2M' classname='TestWarnings.Test4' runstate='Runnable' seed='882017471' />";
private const string XmlRunnable = "<test-case id='0-1007' name='Test2M' fullname='TestWarnings.Test4.Test2M' methodname='Test2M' classname='TestWarnings.Test4' runstate='Runnable' seed='882017471' />";

private const string XmlExplicit = @"<test-case id='0-1007' name='Test2M' fullname='TestWarnings.Test4.Test2M' methodname='Test2M' classname='TestWarnings.Test4' runstate='Explicit' seed='882017471' />";
private const string XmlExplicit = "<test-case id='0-1007' name='Test2M' fullname='TestWarnings.Test4.Test2M' methodname='Test2M' classname='TestWarnings.Test4' runstate='Explicit' seed='882017471' />";

private const string XmlNone = @"<test-case id='0-1007' name='Test2M' fullname='TestWarnings.Test4.Test2M' methodname='Test2M' classname='TestWarnings.Test4' seed='882017471' />";
private const string XmlNone = "<test-case id='0-1007' name='Test2M' fullname='TestWarnings.Test4.Test2M' methodname='Test2M' classname='TestWarnings.Test4' seed='882017471' />";


[Test]
Expand Down
Expand Up @@ -6,16 +6,16 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.NUnitEngineTests;
public class NUnitTestEventTestOutputTests
{
private const string OutputProgress =
@"<test-output stream='Progress' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[Whatever]]></test-output>";
"<test-output stream='Progress' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[Whatever]]></test-output>";

private const string OutputOut =
@"<test-output stream='Out' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[Whatever]]></test-output>";
"<test-output stream='Out' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[Whatever]]></test-output>";

private const string OutputError =
@"<test-output stream='Error' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[Whatever]]></test-output>";
"<test-output stream='Error' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[Whatever]]></test-output>";

private const string BlankTestOutput =
@"<test-output stream='Progress' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[ ]]></test-output>";
"<test-output stream='Progress' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[ ]]></test-output>";



Expand Down
Expand Up @@ -21,7 +21,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************

using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using NUnit.VisualStudio.TestAdapter.NUnitEngine;
Expand All @@ -30,7 +29,7 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.NUnitEngineTests;

public class NUnitTestEventsTests
{
private const string StartSuite = @"<start-suite id = '0-1073' parentId='0-1141' name='SimpleTests' fullname='NUnitTestDemo.SimpleTests' type='TestFixture' />";
private const string StartSuite = "<start-suite id = '0-1073' parentId='0-1141' name='SimpleTests' fullname='NUnitTestDemo.SimpleTests' type='TestFixture' />";
private readonly string testSuite = @"<test-suite type='TestFixture' id='0-1073' name='SimpleTests' fullname='NUnitTestDemo.SimpleTests' classname='NUnitTestDemo.SimpleTests' runstate='Runnable' testcasecount='20' result='Failed' site='Child' start-time='2020-01-24 13:02:55Z' end-time='2020-01-24 13:02:55Z' duration='0.032827' total='15' passed='6' failed='8' warnings='0' inconclusive='1' skipped='0' asserts='11' parentId='0-1141'>
<failure>
<message><![CDATA[One or more child tests had errors]]></message>
Expand All @@ -53,7 +52,7 @@ public void ThatTestEventIsParsedForTestSuite()
Assert.That(sut.FailureMessage, Is.EqualTo("One or more child tests had errors"));
}

private readonly string startTest = @"<start-test id='0-1139' parentId='0-1138' name='Test2' fullname='NUnitTestDemo.SetUpFixture.TestFixture2.Test2' type='TestMethod' />";
private readonly string startTest = "<start-test id='0-1139' parentId='0-1138' name='Test2' fullname='NUnitTestDemo.SetUpFixture.TestFixture2.Test2' type='TestMethod' />";

[Test]
public void ThatTestEventIsParsedForStartTest()
Expand Down Expand Up @@ -224,7 +223,7 @@ public void ThatTestEventIsParsedForFinishSuiteWithFailure()
}

/// <summary>
/// Exception in OneTimeSetUp
/// Exception in OneTimeSetUp.
/// </summary>
private readonly string testSuiteFinishedWithFailureAndStackTrace = @"<test-suite type='TestFixture' id='0-1000' name='Tests' fullname='Issue671.Tests' classname='Issue671.Tests' runstate='Runnable' testcasecount='2' result='Failed' label='Error' site='SetUp' start-time='2021-05-29T09:34:10.2386869Z' end-time='2021-05-29T09:34:10.2532435Z' duration='0.014557' total='2' passed='0' failed='2' warnings='0' inconclusive='0' skipped='0' asserts='0'>
<failure>
Expand Down Expand Up @@ -330,7 +329,7 @@ public void ThatTestCaseFailsCanBeParsedWithReason()
}

private readonly string testCaseExplicitFixtureTime =
@"<test-case id='0-1001' name='ExplicitTest' fullname='NUnit3VSIssue811.Explicit.ExplicitTest' methodname='ExplicitTest' classname='NUnit3VSIssue811.Explicit' runstate='Runnable' seed='1980958818' result='Skipped' label='Explicit' site='Parent' start-time='0001-01-01T00:00:00.0000000' end-time='0001-01-01T00:00:00.0000000' duration='0.000000' asserts='0' parentId='0-1000'/>";
"<test-case id='0-1001' name='ExplicitTest' fullname='NUnit3VSIssue811.Explicit.ExplicitTest' methodname='ExplicitTest' classname='NUnit3VSIssue811.Explicit' runstate='Runnable' seed='1980958818' result='Skipped' label='Explicit' site='Parent' start-time='0001-01-01T00:00:00.0000000' end-time='0001-01-01T00:00:00.0000000' duration='0.000000' asserts='0' parentId='0-1000'/>";

/// <summary>
/// Issue 811.
Expand Down
7 changes: 3 additions & 4 deletions src/NUnitTestAdapterTests/NUnitEventListenerOutputTests.cs
Expand Up @@ -3,7 +3,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using NSubstitute;
using NUnit.Framework;
using NUnit.VisualStudio.TestAdapter.Dump;
using NUnit.VisualStudio.TestAdapter.NUnitEngine;

namespace NUnit.VisualStudio.TestAdapter.Tests;
Expand Down Expand Up @@ -32,16 +31,16 @@ public class NUnitEventListenerOutputTests
]]></test-output>";

private const string BlankTestOutput =
@"<test-output stream='Progress' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[ ]]></test-output>";
"<test-output stream='Progress' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[ ]]></test-output>";

private const string TestFinish =
@"<test-case id='0-1001' name='Test1' fullname='UnitTests.Test1' methodname='Test1' classname='UnitTests' runstate='Runnable' seed='108294034' result='Passed' start-time='2018-10-15 09:41:24Z' end-time='2018-10-15 09:41:24Z' duration='0.000203' asserts='0' parentId='0-1000' />";
"<test-case id='0-1001' name='Test1' fullname='UnitTests.Test1' methodname='Test1' classname='UnitTests' runstate='Runnable' seed='108294034' result='Passed' start-time='2018-10-15 09:41:24Z' end-time='2018-10-15 09:41:24Z' duration='0.000203' asserts='0' parentId='0-1000' />";

/// <summary>
/// For Issue 811.
/// </summary>
private const string TestFinishWithExplicitFixture =
@"<test-case id='0-1001' name='ExplicitTest' fullname='NUnit3VSIssue811.Explicit.ExplicitTest' methodname='ExplicitTest' classname='NUnit3VSIssue811.Explicit' runstate='Runnable' seed='1980958818' result='Skipped' label='Explicit' site='Parent' start-time='0001-01-01T00:00:00.0000000' end-time='0001-01-01T00:00:00.0000000' duration='0.000000' asserts='0' parentId='0-1000'/>";
"<test-case id='0-1001' name='ExplicitTest' fullname='NUnit3VSIssue811.Explicit.ExplicitTest' methodname='ExplicitTest' classname='NUnit3VSIssue811.Explicit' runstate='Runnable' seed='1980958818' result='Skipped' label='Explicit' site='Parent' start-time='0001-01-01T00:00:00.0000000' end-time='0001-01-01T00:00:00.0000000' duration='0.000000' asserts='0' parentId='0-1000'/>";

[SetUp]
public void Setup()
Expand Down

0 comments on commit 26a3d09

Please sign in to comment.