-
Notifications
You must be signed in to change notification settings - Fork 966
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #725 from Humanizr/fix-approval-nullref
Use DiffPlex reporter to avoid NRE on build
- Loading branch information
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters