Skip to content

Commit f2b2ba5

Browse files
committed
Add a FluentAssertions approval failure reporter
So that we have a clear error to investigate in case `ApprovePublicApi` fails on the continuous integration server.
1 parent fd54d11 commit f2b2ba5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/PublicApi.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System.IO;
22
using System.Reflection;
33
using ApprovalTests;
4+
using ApprovalTests.Core;
45
using ApprovalTests.Namers;
56
using ApprovalTests.Reporters;
7+
using FluentAssertions;
68
using PublicApiGenerator;
79
using Xunit;
810

@@ -16,7 +18,7 @@ public void ApprovePublicApi()
1618
var assembly = typeof(Log4NetTextFormatter).Assembly;
1719
var publicApi = assembly.GeneratePublicApi();
1820
var writer = new ApprovalTextWriter(publicApi);
19-
Approvals.Verify(writer, new AssemblyNamer(assembly), new DiffReporter());
21+
Approvals.Verify(writer, new AssemblyNamer(assembly), new MultiReporter(DiffReporter.INSTANCE, new FluentAssertionReporter()));
2022
}
2123

2224
private class AssemblyNamer : UnitTestFrameworkNamer
@@ -27,5 +29,12 @@ private class AssemblyNamer : UnitTestFrameworkNamer
2729

2830
public override string Name => nameof(PublicApi) + "." + Path.GetFileNameWithoutExtension(_assembly.Location);
2931
}
32+
33+
// So that we have the full approved + received text written on the console in case it fails on continuous integration server
34+
// where the DiffEngine used by `DiffReporter` is [automatically disabled](https://github.com/VerifyTests/DiffEngine/blob/6.4.5/src/DiffEngine/DisabledChecker.cs#L10).
35+
private class FluentAssertionReporter : IApprovalFailureReporter
36+
{
37+
public void Report(string approved, string received) => File.ReadAllText(received).Should().Be(File.ReadAllText(approved));
38+
}
3039
}
3140
}

0 commit comments

Comments
 (0)