Skip to content

Commit

Permalink
Support for NUnit 4 classic asserts (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
jairbubbles authored Dec 5, 2023
1 parent af216ac commit 67d22fd
Show file tree
Hide file tree
Showing 8 changed files with 1,330 additions and 756 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Meziantou.DotNet.CodingStandard" Version="1.0.16">
<PackageReference Include="Meziantou.DotNet.CodingStandard" Version="1.0.96">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ private async Task VerifyDiagnostics(DiagnosticAnalyzer analyzer, IList<Diagnost
}

[DebuggerStepThrough]
private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResults, DiagnosticAnalyzer analyzer, IList<DiagnosticResult> expectedResults)
private static void VerifyDiagnosticResults(IReadOnlyCollection<Diagnostic> actualResults, DiagnosticAnalyzer analyzer, IList<DiagnosticResult> expectedResults)
{
var expectedCount = expectedResults.Count;
var actualCount = actualResults.Count();
var actualCount = actualResults.Count;

if (expectedCount != actualCount)
{
Expand Down Expand Up @@ -238,7 +238,9 @@ private async Task<Diagnostic[]> GetSortedDiagnosticsFromDocuments(DiagnosticAna
// Enable diagnostic
options = options.WithSpecificDiagnosticOptions(analyzer.SupportedDiagnostics.Select(diag => new KeyValuePair<string, ReportDiagnostic>(diag.Id, GetReportDiagnostic(diag))));

var compilation = (await project.GetCompilationAsync().ConfigureAwait(false)).WithOptions(options);
var compilation = await project.GetCompilationAsync().ConfigureAwait(false);
Assert.NotNull(compilation);
compilation = compilation.WithOptions(options);
if (compileSolution)
{
using var ms = new MemoryStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ private ProjectBuilder AddNuGetReference(string packageName, string version, str

public ProjectBuilder AddMSTestApi() => AddNuGetReference("MSTest.TestFramework", "2.2.10", "lib/netstandard1.0/");

public ProjectBuilder AddNUnitApi() => AddNuGetReference("NUnit", "3.13.3", "lib/netstandard2.0/");
public ProjectBuilder AddNUnit3Api() => AddNuGetReference("NUnit", "3.13.3", "lib/netstandard2.0/");

public ProjectBuilder AddNUnit4Api() => AddNuGetReference("NUnit", "4.0.1", "lib/net6.0/");

public ProjectBuilder AddXUnitApi() =>
AddNuGetReference("xunit.extensibility.core", "2.4.1", "lib/netstandard1.1/")
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Meziantou.FluentAssertionsAnalyzers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
README.md = README.md
global.json = global.json
EndProjectSection
EndProject
Global
Expand Down
3 changes: 2 additions & 1 deletion Meziantou.FluentAssertionsAnalyzers/AssertAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private static bool IsNunitAssertClass(Compilation compilation, ITypeSymbol type
|| typeSymbol.Equals(compilation.GetTypeByMetadataName("NUnit.Framework.CollectionAssert"), SymbolEqualityComparer.Default)
|| typeSymbol.Equals(compilation.GetTypeByMetadataName("NUnit.Framework.DirectoryAssert"), SymbolEqualityComparer.Default)
|| typeSymbol.Equals(compilation.GetTypeByMetadataName("NUnit.Framework.FileAssert"), SymbolEqualityComparer.Default)
|| typeSymbol.Equals(compilation.GetTypeByMetadataName("NUnit.Framework.StringAssert"), SymbolEqualityComparer.Default);
|| typeSymbol.Equals(compilation.GetTypeByMetadataName("NUnit.Framework.StringAssert"), SymbolEqualityComparer.Default)
|| typeSymbol.Equals(compilation.GetTypeByMetadataName("NUnit.Framework.Legacy.ClassicAssert"), SymbolEqualityComparer.Default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ private static async Task<Document> Rewrite(Document document, SyntaxNode nodeTo

SyntaxNode result = null;
var addImports = true;
if (method.ContainingType.Equals(compilation.GetTypeByMetadataName("NUnit.Framework.Assert"), SymbolEqualityComparer.Default))
if (method.ContainingType.Equals(compilation.GetTypeByMetadataName("NUnit.Framework.Assert"), SymbolEqualityComparer.Default)
|| method.ContainingType.Equals(compilation.GetTypeByMetadataName("NUnit.Framework.Legacy.ClassicAssert"), SymbolEqualityComparer.Default))
{
if (methodName is "AreEqual")
{
Expand Down Expand Up @@ -881,7 +882,7 @@ private static IEnumerable<ArgumentSyntax> ArgumentList(ExpressionSyntax express
return list;
}

private class Rewriter
private sealed class Rewriter
{
private readonly bool _isDynamic;

Expand Down

0 comments on commit 67d22fd

Please sign in to comment.