Skip to content

Instantly share code, notes, and snippets.

@osfameron
Last active August 18, 2020 16:41
Show Gist options
  • Save osfameron/ae4a6e9a6387131f8aa93ff0eb74f5fc to your computer and use it in GitHub Desktop.
Save osfameron/ae4a6e9a6387131f8aa93ff0eb74f5fc to your computer and use it in GitHub Desktop.
C# ApprovalTests - Custom reporter that outputs to command line and copies `cp` command to clipboard
using System.IO;
using ApprovalTests.Core;
using System;
using TextCopy;
namespace ApprovalTests.Reporters
{
/// Reporter class to work in `dotnet watch test` in VSCode
/// terminal window on Mac.
public class CLIReporter : IApprovalFailureReporter
{
public static readonly CLIReporter INSTANCE = new CLIReporter();
public void Report(string approved, string received)
{
if (File.Exists(approved))
{
var expected = File.ReadAllText(approved);
Console.WriteLine("Expected:");
Console.WriteLine("----");
Console.WriteLine(expected);
}
else
{
Console.WriteLine("No approved input.");
}
var got = File.ReadAllText(received);
Console.WriteLine("\nGot:");
Console.WriteLine("----");
Console.WriteLine(got);
var command = $"cp '{received}' '{approved}'";
Console.WriteLine("\n\n[Approval command on clipboard]");
ClipboardService.SetText(command);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment