Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ updates:
xunit:
patterns:
- "xunit*"
- "Verify*"
nuke:
patterns:
- "Nuke*"
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 45 additions & 13 deletions Tests/Approval.Tests/ApiApproval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AssemblyConfigurationAttribute>()!.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<string>
Expand All @@ -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();
}
}
6 changes: 2 additions & 4 deletions Tests/Approval.Tests/Approval.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DiffPlex" Version="1.9.0" />
<PackageReference Include="FluentAssertions" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="xunit.v3.core" Version="4.0.1" />
<PackageReference Include="PublicApiGenerator" Version="11.5.4" />
<PackageReference Include="Verify.DiffPlex" Version="[3.3.1]" />
<!-- See OSMF terms before upgrading: https://github.com/VerifyTests/Verify#open-source-maintenance-fee -->
<PackageReference Include="Verify.XunitV3" Version="[32.0.1,33.0.0)" />
<PackageReference Include="xunit.v3" Version="4.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading