Skip to content

Commit 444432a

Browse files
Merge pull request #4848 from Arkatufus/Fix_APIApprover_NRE_bug
Fix Akka.API.Tests spec always throws NRE when failed in CI/CD pipeline
2 parents 7fb3a5e + 5948163 commit 444432a

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

src/core/Akka.API.Tests/CoreAPISpec.cs

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@
2626
using Akka.Persistence.Sql.Common.Journal;
2727
using ApprovalTests.Core;
2828
using ApprovalTests.Reporters;
29+
using ApprovalTests.Reporters.Mac;
30+
using ApprovalUtilities.Utilities;
2931
using DiffPlex;
3032
using DiffPlex.DiffBuilder;
3133
using DiffPlex.DiffBuilder.Model;
32-
using Xunit.Abstractions;
3334
using Xunit.Sdk;
35+
using P4MergeReporter = ApprovalTests.Reporters.P4MergeReporter;
36+
using P4MacMergeReporter = ApprovalTests.Reporters.Mac.P4MergeReporter;
3437

3538
namespace Akka.API.Tests
3639
{
3740
#if(DEBUG)
38-
[UseReporter(typeof(DiffPlexReporter), typeof(DiffReporter), typeof(AllFailingTestsClipboardReporter))]
41+
[UseReporter(typeof(DiffPlexReporter), typeof(CustomDiffReporter), typeof(AllFailingTestsClipboardReporter))]
3942
#else
40-
[UseReporter(typeof(DiffPlexReporter))]
43+
[UseReporter(typeof(DiffPlexReporter), typeof(CustomDiffReporter))]
4144
#endif
4245
public class CoreAPISpec
4346
{
@@ -173,6 +176,64 @@ public ApiNotApprovedException(string message) : base($"Failed API approval. Dif
173176
public override string StackTrace { get; } = string.Empty;
174177
}
175178

179+
#region Suppress FrameworkAssertReporter hack
180+
// The built-in FrameworkAssertReporter that is being called inside the DiffReporter class
181+
// is buggy in a CI/CD environment because it is trying to be clever, could not distinguish
182+
// between XUnit and XUnit2, and will throw Null Reference Exception every time it ran.
183+
//
184+
// This is probably fixed in latest version of ApiApprover but we couldn't switch to that
185+
// version because the latest ApiGenerator returns a different API report format.
186+
//
187+
// FIX: This hack removes FrameworkAssertReporter from the possible reporter list and retains
188+
// all of the other reporters in DiffReporter
189+
190+
internal class CustomDiffReporter : FirstWorkingReporter
191+
{
192+
public CustomDiffReporter() : base(
193+
CustomWindowsDiffReporter.Instance,
194+
CustomMacDiffReporter.Instance)
195+
{ }
196+
}
197+
198+
internal class CustomMacDiffReporter : FirstWorkingReporter
199+
{
200+
public static readonly CustomMacDiffReporter Instance = new CustomMacDiffReporter();
201+
public CustomMacDiffReporter()
202+
: base(
203+
204+
BeyondCompareMacReporter.INSTANCE,
205+
DiffMergeReporter.INSTANCE,
206+
KaleidoscopeDiffReporter.INSTANCE,
207+
P4MacMergeReporter.INSTANCE,
208+
KDiff3Reporter.INSTANCE,
209+
TkDiffReporter.INSTANCE,
210+
QuietReporter.INSTANCE)
211+
{ }
212+
213+
public override bool IsWorkingInThisEnvironment(string forFile) => OsUtils.IsUnixOs() && base.IsWorkingInThisEnvironment(forFile);
214+
}
215+
216+
internal class CustomWindowsDiffReporter : FirstWorkingReporter
217+
{
218+
public static readonly CustomWindowsDiffReporter Instance = new CustomWindowsDiffReporter();
219+
public CustomWindowsDiffReporter()
220+
: base(
221+
CodeCompareReporter.INSTANCE,
222+
BeyondCompareReporter.INSTANCE,
223+
TortoiseDiffReporter.INSTANCE,
224+
AraxisMergeReporter.INSTANCE,
225+
P4MergeReporter.INSTANCE,
226+
WinMergeReporter.INSTANCE,
227+
KDiffReporter.INSTANCE,
228+
VisualStudioReporter.INSTANCE,
229+
QuietReporter.INSTANCE)
230+
{ }
231+
232+
public override bool IsWorkingInThisEnvironment(string forFile) => OsUtils.IsWindowsOs() && base.IsWorkingInThisEnvironment(forFile);
233+
}
234+
235+
#endregion
236+
176237
internal class DiffPlexReporter : IApprovalFailureReporter
177238
{
178239
public void Report(string approved, string received)

0 commit comments

Comments
 (0)