diff --git a/src/Humanizer.Tests/ApiApprover/DiffPlexReporter.cs b/src/Humanizer.Tests/ApiApprover/DiffPlexReporter.cs new file mode 100644 index 000000000..a07c7680e --- /dev/null +++ b/src/Humanizer.Tests/ApiApprover/DiffPlexReporter.cs @@ -0,0 +1,49 @@ +#if NET46 +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using ApprovalTests.Core; +using DiffPlex; +using DiffPlex.DiffBuilder; +using DiffPlex.DiffBuilder.Model; +using System.IO; +using Xunit.Abstractions; + +namespace Humanizer.Tests.ApiApprover +{ + public class DiffPlexReporter : IApprovalFailureReporter + { + public static readonly DiffPlexReporter Instance = new DiffPlexReporter(); + + public ITestOutputHelper Output { get; set; } + + public void Report(string approved, string received) + { + var approvedText = File.Exists(approved) ? File.ReadAllText(approved) : string.Empty; + var receivedText = File.ReadAllText(received); + + var diffBuilder = new InlineDiffBuilder(new Differ()); + var diff = diffBuilder.BuildDiffModel(approvedText, receivedText); + + foreach (var line in diff.Lines) + { + if (line.Type == ChangeType.Unchanged) continue; + + var prefix = " "; + switch (line.Type) + { + case ChangeType.Inserted: + prefix = "+ "; + break; + case ChangeType.Deleted: + prefix = "- "; + break; + } + + Output.WriteLine("{0}{1}", prefix, line.Text); + } + } + } +} +#endif diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.cs b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.cs index d970355e9..9d97ae4f9 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.cs +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.cs @@ -5,15 +5,25 @@ using ApprovalTests.Reporters; using PublicApiGenerator; using Xunit; +using Xunit.Abstractions; namespace Humanizer.Tests.ApiApprover { public class PublicApiApprovalTest { + public PublicApiApprovalTest(ITestOutputHelper output) + { + DiffPlexReporter.Instance.Output = output; + } + [Fact] [UseCulture("en-US")] - [UseReporter(typeof(DiffReporter))] +#if DEBUG + [UseReporter(typeof(DiffReporter))] +#else + [UseReporter(typeof(DiffPlexReporter))] +#endif [IgnoreLineEndings(true)] public void approve_public_api() { diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index a1bd2f539..e8e2a266a 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -16,6 +16,7 @@ +