Skip to content

Commit

Permalink
Add DiffReporter hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkatufus committed Mar 12, 2021
1 parent 7fb3a5e commit 5948163
Showing 1 changed file with 64 additions and 3 deletions.
67 changes: 64 additions & 3 deletions src/core/Akka.API.Tests/CoreAPISpec.cs
Expand Up @@ -26,18 +26,21 @@
using Akka.Persistence.Sql.Common.Journal;
using ApprovalTests.Core;
using ApprovalTests.Reporters;
using ApprovalTests.Reporters.Mac;
using ApprovalUtilities.Utilities;
using DiffPlex;
using DiffPlex.DiffBuilder;
using DiffPlex.DiffBuilder.Model;
using Xunit.Abstractions;
using Xunit.Sdk;
using P4MergeReporter = ApprovalTests.Reporters.P4MergeReporter;
using P4MacMergeReporter = ApprovalTests.Reporters.Mac.P4MergeReporter;

namespace Akka.API.Tests
{
#if(DEBUG)
[UseReporter(typeof(DiffPlexReporter), typeof(DiffReporter), typeof(AllFailingTestsClipboardReporter))]
[UseReporter(typeof(DiffPlexReporter), typeof(CustomDiffReporter), typeof(AllFailingTestsClipboardReporter))]
#else
[UseReporter(typeof(DiffPlexReporter))]
[UseReporter(typeof(DiffPlexReporter), typeof(CustomDiffReporter))]
#endif
public class CoreAPISpec
{
Expand Down Expand Up @@ -173,6 +176,64 @@ public ApiNotApprovedException(string message) : base($"Failed API approval. Dif
public override string StackTrace { get; } = string.Empty;
}

#region Suppress FrameworkAssertReporter hack
// The built-in FrameworkAssertReporter that is being called inside the DiffReporter class
// is buggy in a CI/CD environment because it is trying to be clever, could not distinguish
// between XUnit and XUnit2, and will throw Null Reference Exception every time it ran.
//
// This is probably fixed in latest version of ApiApprover but we couldn't switch to that
// version because the latest ApiGenerator returns a different API report format.
//
// FIX: This hack removes FrameworkAssertReporter from the possible reporter list and retains
// all of the other reporters in DiffReporter

internal class CustomDiffReporter : FirstWorkingReporter
{
public CustomDiffReporter() : base(
CustomWindowsDiffReporter.Instance,
CustomMacDiffReporter.Instance)
{ }
}

internal class CustomMacDiffReporter : FirstWorkingReporter
{
public static readonly CustomMacDiffReporter Instance = new CustomMacDiffReporter();
public CustomMacDiffReporter()
: base(

BeyondCompareMacReporter.INSTANCE,
DiffMergeReporter.INSTANCE,
KaleidoscopeDiffReporter.INSTANCE,
P4MacMergeReporter.INSTANCE,
KDiff3Reporter.INSTANCE,
TkDiffReporter.INSTANCE,
QuietReporter.INSTANCE)
{ }

public override bool IsWorkingInThisEnvironment(string forFile) => OsUtils.IsUnixOs() && base.IsWorkingInThisEnvironment(forFile);
}

internal class CustomWindowsDiffReporter : FirstWorkingReporter
{
public static readonly CustomWindowsDiffReporter Instance = new CustomWindowsDiffReporter();
public CustomWindowsDiffReporter()
: base(
CodeCompareReporter.INSTANCE,
BeyondCompareReporter.INSTANCE,
TortoiseDiffReporter.INSTANCE,
AraxisMergeReporter.INSTANCE,
P4MergeReporter.INSTANCE,
WinMergeReporter.INSTANCE,
KDiffReporter.INSTANCE,
VisualStudioReporter.INSTANCE,
QuietReporter.INSTANCE)
{ }

public override bool IsWorkingInThisEnvironment(string forFile) => OsUtils.IsWindowsOs() && base.IsWorkingInThisEnvironment(forFile);
}

#endregion

internal class DiffPlexReporter : IApprovalFailureReporter
{
public void Report(string approved, string received)
Expand Down

0 comments on commit 5948163

Please sign in to comment.