From 14d1a7bed548f4c61fa2a91f42dbf102daf2fa6c Mon Sep 17 00:00:00 2001 From: Jonas Nyrup Date: Mon, 9 Nov 2026 16:45:56 +0100 Subject: [PATCH] Replace Verify with plain DiffPlex This PR replaces the use of Verify.XunitV3 and Verify.DiffPlex with just DiffPlex --- .editorconfig | 2 +- .gitattributes | 2 +- .github/dependabot.yml | 1 - CONTRIBUTING.md | 2 +- README.md | 4 +- Tests/Approval.Tests/ApiApproval.cs | 58 ++++++++++++++----- Tests/Approval.Tests/Approval.Tests.csproj | 6 +- .../net47.verified.txt | 3 +- .../net6.0.verified.txt | 3 +- 9 files changed, 56 insertions(+), 25 deletions(-) diff --git a/.editorconfig b/.editorconfig index ad2fa2a..8857e2e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -393,7 +393,7 @@ dotnet_diagnostic.MA0047.severity = none # Use an overload of 'GetHashCode' that has a StringComparison parameter dotnet_diagnostic.MA0074.severity = none -# Verify settings +# Approval.Tests settings [*.{received,verified}.txt] charset = utf-8-bom end_of_line = lf diff --git a/.gitattributes b/.gitattributes index a0f2e69..7dc4292 100644 --- a/.gitattributes +++ b/.gitattributes @@ -64,5 +64,5 @@ #*.rtf diff=astextplain #*.RTF diff=astextplain -# Verify settings +# Approval.Tests settings *.verified.txt text eol=lf working-tree-encoding=UTF-8 diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9966f65..d4e1647 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -19,7 +19,6 @@ updates: xunit: patterns: - "xunit*" - - "Verify*" nuke: patterns: - "Nuke*" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2ae028a..f352eac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -72,7 +72,7 @@ Please do: * Ensure that changes are covered by a new or existing set of unit tests which follow the Arrange-Act-Assert syntax such as is used [in this example](https://github.com/fluentassertions/fluentassertions/blob/daaf35b9b59b622c96d0c034e8972a020b2bee55/Tests/FluentAssertions.Shared.Specs/BasicEquivalencySpecs.cs#L33). * Also the code coverage reported by the coveralls must be non-decreasing unless accepted by the authors. * If the contribution adds a feature or fixes a bug, please update the [**release notes**](https://github.com/fluentassertions/fluentassertions/blob/develop/docs/_pages/releases.md), which is published on the [website](https://fluentassertions.com/releases). -* If the contribution changes the public API, the changes needs to be included by running [`AcceptApiChanges.ps1`](https://github.com/fluentassertions/fluentassertions/tree/develop/AcceptApiChanges.ps1)/[`AcceptApiChanges.sh`](https://github.com/fluentassertions/fluentassertions/tree/develop/AcceptApiChanges.sh) or using Rider's [Verify Support](https://plugins.jetbrains.com/plugin/17240-verify-support) plug-in. +* If the contribution changes the public API, the changes needs to be included by running [`AcceptApiChanges.ps1`](https://github.com/fluentassertions/fluentassertions/tree/develop/AcceptApiChanges.ps1)/[`AcceptApiChanges.sh`](https://github.com/fluentassertions/fluentassertions/tree/develop/AcceptApiChanges.sh). Please do not: diff --git a/README.md b/README.md index d8b5a9e..5e1a9fc 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,9 @@ This package is shipped as a [NuGet package](https://www.nuget.org/packages/Flue You can either build the solution using Visual Studio or Rider, or use the `build.ps1` script to kick-off the [Nuke](https://nuke.build/) build process. This will build the package and run all tests. ## Approval Tests -This is a special set of tests that use the [Verify](https://github.com/VerifyTests/Verify) project to verify whether you've introduced any breaking changes in the public API of the library. +This is a special set of tests that use the [PublicApiGenerator](https://github.com/PublicApiGenerator/PublicApiGenerator) and [DiffPlex](https://github.com/mmanela/diffplex) projects to verify whether you've introduced any breaking changes in the public API of the library. -If you've verified the changes and decided they are valid, you can accept them using `AcceptApiChanges.ps1` or `AcceptApiChanges.sh`. Alternatively, you can use the [Verify Support](https://plugins.jetbrains.com/plugin/17240-verify-support) plug-in to compare the changes and accept them right from inside Rider. See also the [Contribution Guidelines](CONTRIBUTING.md). +If you've verified the changes and decided they are valid, you can accept them using `AcceptApiChanges.ps1` or `AcceptApiChanges.sh`. See also the [Contribution Guidelines](CONTRIBUTING.md). # Usage diff --git a/Tests/Approval.Tests/ApiApproval.cs b/Tests/Approval.Tests/ApiApproval.cs index 2bed357..fb84f0f 100644 --- a/Tests/Approval.Tests/ApiApproval.cs +++ b/Tests/Approval.Tests/ApiApproval.cs @@ -2,36 +2,31 @@ using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using System.Threading.Tasks; +using System.Text; using System.Xml.Linq; using System.Xml.XPath; +using DiffPlex.DiffBuilder; +using DiffPlex.DiffBuilder.Model; using PublicApiGenerator; -using VerifyTests; -using VerifyTests.DiffPlex; -using VerifyXunit; using Xunit; namespace Approval.Tests; public class ApiApproval { - static ApiApproval() => VerifyDiffPlex.Initialize(OutputType.Minimal); - [Theory] [ClassData(typeof(TargetFrameworksTheoryData))] - public Task ApproveApi(string framework) + public void ApproveApi(string framework) { var configuration = typeof(ApiApproval).Assembly.GetCustomAttribute()!.Configuration; var assemblyFile = CombinedPaths("Src", "FluentAssertions.DataSets", "bin", configuration, framework, "FluentAssertions.DataSets.dll"); var assembly = Assembly.LoadFile(assemblyFile); var publicApi = assembly.GeneratePublicApi(options: null); + var expected = GetExpected(publicApi, framework); + + var diff = InlineDiffBuilder.Diff(expected, publicApi); - return Verifier - .Verify(publicApi) - .ScrubLinesContaining("FrameworkDisplayName") - .UseDirectory(Path.Combine("ApprovedApi", "FluentAssertions.DataSets")) - .UseFileName(framework) - .DisableDiff(); + Assert.False(diff.HasDifferences, StringifyDiff(diff)); } private class TargetFrameworksTheoryData : TheoryData @@ -50,4 +45,41 @@ private static string GetSolutionDirectory([CallerFilePath] string path = "") => private static string CombinedPaths(params string[] paths) => Path.GetFullPath(Path.Combine(paths.Prepend(GetSolutionDirectory()).ToArray())); + + private string GetExpected(string publicApi, string targetFramework, [CallerFilePath] string path = "") + { + var projectPath = Path.Combine(Path.GetDirectoryName(path)!, "ApprovedApi", "FluentAssertions.DataSets"); + var receivedPath = Path.Combine(projectPath, $"{targetFramework}.received.txt"); + var verifiedPath = Path.Combine(projectPath, $"{targetFramework}.verified.txt"); + + File.WriteAllText(receivedPath, publicApi); + return File.Exists(verifiedPath) ? File.ReadAllText(verifiedPath) : string.Empty; + } + + private static string StringifyDiff(DiffPaneModel diff) + { + var builder = new StringBuilder(); + if (diff.HasDifferences) + { + foreach (var line in diff.Lines) + { + switch (line.Type) + { + case ChangeType.Inserted: + builder.Append("+ "); + break; + case ChangeType.Deleted: + builder.Append("- "); + break; + default: + // omit unchanged files + continue; + } + + builder.AppendLine(line.Text); + } + } + + return builder.ToString(); + } } diff --git a/Tests/Approval.Tests/Approval.Tests.csproj b/Tests/Approval.Tests/Approval.Tests.csproj index 845f3ad..f2df45d 100644 --- a/Tests/Approval.Tests/Approval.Tests.csproj +++ b/Tests/Approval.Tests/Approval.Tests.csproj @@ -6,13 +6,11 @@ + - - - - + diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions.DataSets/net47.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions.DataSets/net47.verified.txt index be63c21..bf02983 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions.DataSets/net47.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions.DataSets/net47.verified.txt @@ -1,7 +1,8 @@ -[assembly: FluentAssertions.CustomAssertionsAssembly] +[assembly: FluentAssertions.CustomAssertionsAssembly] [assembly: FluentAssertions.Extensibility.AssertionEngineInitializer(typeof(FluentAssertions.DataSets.InitializeDataSetSupport), "Initialize")] [assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/fluentassertions/fluentassertions.datasets")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"FluentAssertions.DataSets.Specs, PublicKey=00240000048000009400000006020000002400005253413100040000010001002d25ff515c85b13ba08f61d466cff5d80a7f28ba197bbf8796085213e7a3406f970d2a4874932fed35db546e89af2da88c194bf1b7f7ac70de7988c78406f7629c547283061282a825616eb7eb48a9514a7570942936020a9bb37dca9ff60b778309900851575614491c6d25018fadb75828f4c7a17bf2d7dc86e7b6eafc5d8f")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.7", FrameworkDisplayName=".NET Framework 4.7")] namespace FluentAssertions { public static class AssertionExtensions diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions.DataSets/net6.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions.DataSets/net6.0.verified.txt index be63c21..33d9fc4 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions.DataSets/net6.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions.DataSets/net6.0.verified.txt @@ -1,7 +1,8 @@ -[assembly: FluentAssertions.CustomAssertionsAssembly] +[assembly: FluentAssertions.CustomAssertionsAssembly] [assembly: FluentAssertions.Extensibility.AssertionEngineInitializer(typeof(FluentAssertions.DataSets.InitializeDataSetSupport), "Initialize")] [assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/fluentassertions/fluentassertions.datasets")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"FluentAssertions.DataSets.Specs, PublicKey=00240000048000009400000006020000002400005253413100040000010001002d25ff515c85b13ba08f61d466cff5d80a7f28ba197bbf8796085213e7a3406f970d2a4874932fed35db546e89af2da88c194bf1b7f7ac70de7988c78406f7629c547283061282a825616eb7eb48a9514a7570942936020a9bb37dca9ff60b778309900851575614491c6d25018fadb75828f4c7a17bf2d7dc86e7b6eafc5d8f")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName=".NET 6.0")] namespace FluentAssertions { public static class AssertionExtensions