Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 22, 2024
1 parent aead0b5 commit 4ee7c3b
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 118 deletions.
9 changes: 2 additions & 7 deletions src/ApprovalTests/Reporters/DiffToolReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@

namespace ApprovalTests.Reporters;

public class DiffToolReporter : IEnvironmentAwareReporter
public class DiffToolReporter(DiffTool diffTool) : IEnvironmentAwareReporter
{
DiffTool diffTool;

public DiffToolReporter(DiffTool diffTool) =>
this.diffTool = diffTool;

public void Report(string approved, string received) =>
DiffRunner.Launch(diffTool, received, approved);

public bool IsWorkingInThisEnvironment(string forFile) =>
DiffTools.IsDetectedFor(diffTool, forFile);
DiffTools.IsDetectedForFile(diffTool, forFile);
}
11 changes: 2 additions & 9 deletions src/ApprovalTests/Reporters/ExecutableQueryFailure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@

namespace ApprovalTests.Reporters;

public class ExecutableQueryFailure : IApprovalFailureReporter, IApprovalReporterWithCleanUp
public class ExecutableQueryFailure(IExecutableQuery query, IApprovalFailureReporter reporter) :
IApprovalFailureReporter, IApprovalReporterWithCleanUp
{
const string FileNameSuffix = ".queryresults.txt";
const string Header = "\t\tDo NOT approve\n\t\tThis File will be Deleted\n\t\tit is for feedback purposes only.\n\t\tAn additional file has been opened with only the query which you can approve.\n";
readonly IExecutableQuery query;
readonly IApprovalFailureReporter reporter;

public ExecutableQueryFailure(IExecutableQuery query, IApprovalFailureReporter reporter)
{
this.query = query;
this.reporter = reporter;
}

public void CleanUp(string approved, string received)
{
Expand Down
8 changes: 2 additions & 6 deletions src/ApprovalTests/Reporters/FileLauncherWithDelayReporter.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using ApprovalTests.Core;
using ApprovalTests.Reporters;

public class FileLauncherWithDelayReporter : IApprovalFailureReporter
public class FileLauncherWithDelayReporter(int seconds = 2) :
IApprovalFailureReporter
{
public static readonly FileLauncherWithDelayReporter INSTANCE = new();

readonly int seconds;

public FileLauncherWithDelayReporter(int seconds = 2) =>
this.seconds = seconds;

public void Report(string approved, string received)
{
FileLauncherReporter.INSTANCE.Report(approved, received);
Expand Down
8 changes: 3 additions & 5 deletions src/ApprovalTests/Reporters/FirstWorkingReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

namespace ApprovalTests.Reporters;

public class FirstWorkingReporter : IEnvironmentAwareReporter, IApprovalReporterWithCleanUp
public class FirstWorkingReporter(IEnumerable<IEnvironmentAwareReporter> reporters) :
IEnvironmentAwareReporter, IApprovalReporterWithCleanUp
{
public IEnumerable<IEnvironmentAwareReporter> Reporters { get; }
public IEnumerable<IEnvironmentAwareReporter> Reporters { get; } = reporters;

public FirstWorkingReporter(params IEnvironmentAwareReporter[] reporters) :
this((IEnumerable<IEnvironmentAwareReporter>) reporters)
{

}

public FirstWorkingReporter(IEnumerable<IEnvironmentAwareReporter> reporters) =>
Reporters = reporters;

public void Report(string approved, string received)
{
var r = Reporters.FirstOrDefault(_ => _.IsWorkingInThisEnvironment(received));
Expand Down
8 changes: 3 additions & 5 deletions src/ApprovalTests/Reporters/IgnoreLineEndingsAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
namespace ApprovalTests.Reporters;

public class IgnoreLineEndingsAttribute : Attribute
public class IgnoreLineEndingsAttribute(bool ignoreLineEndings) :
Attribute
{
public IgnoreLineEndingsAttribute(bool ignoreLineEndings) =>
IgnoreLineEndings = ignoreLineEndings;

public bool IgnoreLineEndings { get; }
public bool IgnoreLineEndings { get; } = ignoreLineEndings;
}
8 changes: 2 additions & 6 deletions src/ApprovalTests/Reporters/InvalidReporterConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

namespace ApprovalTests.Reporters;

public class InvalidReporterConfiguration : IEnvironmentAwareReporter
public class InvalidReporterConfiguration(Type reporter) :
IEnvironmentAwareReporter
{
readonly Type reporter;

public InvalidReporterConfiguration(Type reporter) =>
this.reporter = reporter;

public void Report(string approved, string received) =>
throw BuildException();

Expand Down
16 changes: 4 additions & 12 deletions src/ApprovalTests/Reporters/TestFrameworks/AssertReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,16 @@

namespace ApprovalTests.Reporters.TestFrameworks;

public class AssertReporter : IEnvironmentAwareReporter
public class AssertReporter(string assertClass, string areEqual, string frameworkAttribute)
: IEnvironmentAwareReporter
{
protected readonly string areEqual;
readonly string assertClass;
readonly string frameworkAttribute;

public AssertReporter(string assertClass, string areEqual, string frameworkAttribute)
{
this.assertClass = assertClass;
this.areEqual = areEqual;
this.frameworkAttribute = frameworkAttribute;
}
protected readonly string areEqual = areEqual;

public virtual void Report(string approved, string received) =>
AssertFileContents(approved, received);

public virtual bool IsWorkingInThisEnvironment(string forFile) =>
FileExtensions.IsText(forFile) && IsFrameworkUsed();
FileExtensions.IsTextFile(forFile) && IsFrameworkUsed();

public bool IsFrameworkUsed() =>
AttributeStackTraceParser.GetFirstFrameForAttribute(Approvals.CurrentCaller, frameworkAttribute) !=
Expand Down
8 changes: 2 additions & 6 deletions src/ApprovalTests/Reporters/Tools/AraxisMergeReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace ApprovalTests.Reporters;

public class AraxisMergeReporter : DiffToolReporter
public class AraxisMergeReporter() :
DiffToolReporter(DiffTool.AraxisMerge)
{
public static readonly AraxisMergeReporter INSTANCE = new();

public AraxisMergeReporter()
: base(DiffTool.AraxisMerge)
{
}
}
8 changes: 2 additions & 6 deletions src/ApprovalTests/Reporters/Tools/BeyondCompareReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace ApprovalTests.Reporters;

public class BeyondCompareReporter : DiffToolReporter
public class BeyondCompareReporter() :
DiffToolReporter(DiffTool.BeyondCompare)
{
public static readonly BeyondCompareReporter INSTANCE = new();

public BeyondCompareReporter()
: base(DiffTool.BeyondCompare)
{
}
}
7 changes: 2 additions & 5 deletions src/ApprovalTests/Reporters/Tools/KDiff3Reporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace ApprovalTests.Reporters;

public class KDiff3Reporter : DiffToolReporter
public class KDiff3Reporter() :
DiffToolReporter(DiffTool.KDiff3)
{
public static readonly KDiff3Reporter INSTANCE = new();

public KDiff3Reporter() : base(DiffTool.KDiff3)
{
}
}
7 changes: 2 additions & 5 deletions src/ApprovalTests/Reporters/Tools/KaleidoscopeDiffReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace ApprovalTests.Reporters;

public class KaleidoscopeDiffReporter : DiffToolReporter
public class KaleidoscopeDiffReporter() :
DiffToolReporter(DiffTool.Kaleidoscope)
{
public static readonly KaleidoscopeDiffReporter INSTANCE = new();

public KaleidoscopeDiffReporter() : base(DiffTool.Kaleidoscope)
{
}
}
7 changes: 2 additions & 5 deletions src/ApprovalTests/Reporters/Tools/MeldReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace ApprovalTests.Reporters;

public class MeldReporter : DiffToolReporter
public class MeldReporter() :
DiffToolReporter(DiffTool.Meld)
{
public static readonly MeldReporter INSTANCE = new();

public MeldReporter() : base(DiffTool.Meld)
{
}
}
7 changes: 2 additions & 5 deletions src/ApprovalTests/Reporters/Tools/P4MergeReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace ApprovalTests.Reporters;

public class P4MergeReporter : DiffToolReporter
public class P4MergeReporter() :
DiffToolReporter(DiffTool.P4Merge)
{
public static readonly P4MergeReporter INSTANCE = new();

public P4MergeReporter() : base(DiffTool.P4Merge)
{
}
}
7 changes: 2 additions & 5 deletions src/ApprovalTests/Reporters/Tools/RiderReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace ApprovalTests.Reporters;

public class RiderReporter : DiffToolReporter
public class RiderReporter() :
DiffToolReporter(DiffTool.Rider)
{
public static readonly RiderReporter INSTANCE = new();

public RiderReporter() : base(DiffTool.Rider)
{
}
}
7 changes: 2 additions & 5 deletions src/ApprovalTests/Reporters/Tools/TkDiffReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace ApprovalTests.Reporters;

public class TkDiffReporter : DiffToolReporter
public class TkDiffReporter() :
DiffToolReporter(DiffTool.TkDiff)
{
public static readonly TkDiffReporter INSTANCE = new();

public TkDiffReporter() : base(DiffTool.TkDiff)
{
}
}
3 changes: 2 additions & 1 deletion src/ApprovalTests/Reporters/Tools/TortoiseDiffReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public class TortoiseDiffReporter : FirstWorkingReporter
{
public static readonly TortoiseDiffReporter INSTANCE = new();

public TortoiseDiffReporter() : base(TortoiseTextDiffReporter.INSTANCE, TortoiseGitTextDiffReporter.INSTANCE, TortoiseImageDiffReporter.INSTANCE)
public TortoiseDiffReporter() :
base(TortoiseTextDiffReporter.INSTANCE, TortoiseGitTextDiffReporter.INSTANCE, TortoiseImageDiffReporter.INSTANCE)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace ApprovalTests.Reporters;

public class TortoiseGitTextDiffReporter : DiffToolReporter
public class TortoiseGitTextDiffReporter() :
DiffToolReporter(DiffTool.TortoiseGitMerge)
{
public static readonly TortoiseGitTextDiffReporter INSTANCE = new();

public TortoiseGitTextDiffReporter() : base(DiffTool.TortoiseGitMerge)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace ApprovalTests.Reporters;

public class TortoiseImageDiffReporter : DiffToolReporter
public class TortoiseImageDiffReporter() :
DiffToolReporter(DiffTool.TortoiseIDiff)
{
public static readonly TortoiseImageDiffReporter INSTANCE = new();

public TortoiseImageDiffReporter() : base(DiffTool.TortoiseIDiff)
{
}
}
7 changes: 2 additions & 5 deletions src/ApprovalTests/Reporters/Tools/TortoiseTextDiffReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace ApprovalTests.Reporters;

public class TortoiseTextDiffReporter : DiffToolReporter
public class TortoiseTextDiffReporter() :
DiffToolReporter(DiffTool.TortoiseMerge)
{
public static readonly TortoiseTextDiffReporter INSTANCE = new();

public TortoiseTextDiffReporter() : base(DiffTool.TortoiseMerge)
{
}
}
7 changes: 2 additions & 5 deletions src/ApprovalTests/Reporters/Tools/VisualStudioReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace ApprovalTests.Reporters;

public class VisualStudioReporter : DiffToolReporter
public class VisualStudioReporter() :
DiffToolReporter(DiffTool.VisualStudio)
{
public static readonly VisualStudioReporter INSTANCE = new();

public VisualStudioReporter() : base(DiffTool.VisualStudio)
{
}
}
7 changes: 2 additions & 5 deletions src/ApprovalTests/Reporters/Tools/WinMergeReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace ApprovalTests.Reporters;

public class WinMergeReporter : DiffToolReporter
public class WinMergeReporter() :
DiffToolReporter(DiffTool.WinMerge)
{
public static readonly WinMergeReporter INSTANCE = new();

public WinMergeReporter() : base(DiffTool.WinMerge)
{
}
}

0 comments on commit 4ee7c3b

Please sign in to comment.