From 4ee7c3b7d2e0d724c79d91657fa1ab0481f2d7fe Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 23 Jan 2024 10:47:06 +1100 Subject: [PATCH] cleanup --- src/ApprovalTests/Reporters/DiffToolReporter.cs | 9 ++------- .../Reporters/ExecutableQueryFailure.cs | 11 ++--------- .../Reporters/FileLauncherWithDelayReporter.cs | 8 ++------ .../Reporters/FirstWorkingReporter.cs | 8 +++----- .../Reporters/IgnoreLineEndingsAttribute.cs | 8 +++----- .../Reporters/InvalidReporterConfiguration.cs | 8 ++------ .../Reporters/TestFrameworks/AssertReporter.cs | 16 ++++------------ .../Reporters/Tools/AraxisMergeReporter.cs | 8 ++------ .../Reporters/Tools/BeyondCompareReporter.cs | 8 ++------ .../Reporters/Tools/KDiff3Reporter.cs | 7 ++----- .../Reporters/Tools/KaleidoscopeDiffReporter.cs | 7 ++----- .../Reporters/Tools/MeldReporter.cs | 7 ++----- .../Reporters/Tools/P4MergeReporter.cs | 7 ++----- .../Reporters/Tools/RiderReporter.cs | 7 ++----- .../Reporters/Tools/TkDiffReporter.cs | 7 ++----- .../Reporters/Tools/TortoiseDiffReporter.cs | 3 ++- .../Tools/TortoiseGitTextDiffReporter.cs | 7 ++----- .../Reporters/Tools/TortoiseImageDiffReporter.cs | 7 ++----- .../Reporters/Tools/TortoiseTextDiffReporter.cs | 7 ++----- .../Reporters/Tools/VisualStudioReporter.cs | 7 ++----- .../Reporters/Tools/WinMergeReporter.cs | 7 ++----- 21 files changed, 46 insertions(+), 118 deletions(-) diff --git a/src/ApprovalTests/Reporters/DiffToolReporter.cs b/src/ApprovalTests/Reporters/DiffToolReporter.cs index 819692d8..2fb4f799 100644 --- a/src/ApprovalTests/Reporters/DiffToolReporter.cs +++ b/src/ApprovalTests/Reporters/DiffToolReporter.cs @@ -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); } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/ExecutableQueryFailure.cs b/src/ApprovalTests/Reporters/ExecutableQueryFailure.cs index 44471407..3c0a4e70 100644 --- a/src/ApprovalTests/Reporters/ExecutableQueryFailure.cs +++ b/src/ApprovalTests/Reporters/ExecutableQueryFailure.cs @@ -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) { diff --git a/src/ApprovalTests/Reporters/FileLauncherWithDelayReporter.cs b/src/ApprovalTests/Reporters/FileLauncherWithDelayReporter.cs index 745ade41..54d9236b 100644 --- a/src/ApprovalTests/Reporters/FileLauncherWithDelayReporter.cs +++ b/src/ApprovalTests/Reporters/FileLauncherWithDelayReporter.cs @@ -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); diff --git a/src/ApprovalTests/Reporters/FirstWorkingReporter.cs b/src/ApprovalTests/Reporters/FirstWorkingReporter.cs index d70eaff7..28c4d4cb 100644 --- a/src/ApprovalTests/Reporters/FirstWorkingReporter.cs +++ b/src/ApprovalTests/Reporters/FirstWorkingReporter.cs @@ -2,9 +2,10 @@ namespace ApprovalTests.Reporters; -public class FirstWorkingReporter : IEnvironmentAwareReporter, IApprovalReporterWithCleanUp +public class FirstWorkingReporter(IEnumerable reporters) : + IEnvironmentAwareReporter, IApprovalReporterWithCleanUp { - public IEnumerable Reporters { get; } + public IEnumerable Reporters { get; } = reporters; public FirstWorkingReporter(params IEnvironmentAwareReporter[] reporters) : this((IEnumerable) reporters) @@ -12,9 +13,6 @@ public FirstWorkingReporter(params IEnvironmentAwareReporter[] reporters) : } - public FirstWorkingReporter(IEnumerable reporters) => - Reporters = reporters; - public void Report(string approved, string received) { var r = Reporters.FirstOrDefault(_ => _.IsWorkingInThisEnvironment(received)); diff --git a/src/ApprovalTests/Reporters/IgnoreLineEndingsAttribute.cs b/src/ApprovalTests/Reporters/IgnoreLineEndingsAttribute.cs index 5aa21d52..78bbf2b3 100644 --- a/src/ApprovalTests/Reporters/IgnoreLineEndingsAttribute.cs +++ b/src/ApprovalTests/Reporters/IgnoreLineEndingsAttribute.cs @@ -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; } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/InvalidReporterConfiguration.cs b/src/ApprovalTests/Reporters/InvalidReporterConfiguration.cs index 8de5131f..25c0ee4e 100644 --- a/src/ApprovalTests/Reporters/InvalidReporterConfiguration.cs +++ b/src/ApprovalTests/Reporters/InvalidReporterConfiguration.cs @@ -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(); diff --git a/src/ApprovalTests/Reporters/TestFrameworks/AssertReporter.cs b/src/ApprovalTests/Reporters/TestFrameworks/AssertReporter.cs index e94651f3..f3e9fe16 100644 --- a/src/ApprovalTests/Reporters/TestFrameworks/AssertReporter.cs +++ b/src/ApprovalTests/Reporters/TestFrameworks/AssertReporter.cs @@ -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) != diff --git a/src/ApprovalTests/Reporters/Tools/AraxisMergeReporter.cs b/src/ApprovalTests/Reporters/Tools/AraxisMergeReporter.cs index 965d8845..dfc3170e 100644 --- a/src/ApprovalTests/Reporters/Tools/AraxisMergeReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/AraxisMergeReporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/BeyondCompareReporter.cs b/src/ApprovalTests/Reporters/Tools/BeyondCompareReporter.cs index e49141c5..515a106c 100644 --- a/src/ApprovalTests/Reporters/Tools/BeyondCompareReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/BeyondCompareReporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/KDiff3Reporter.cs b/src/ApprovalTests/Reporters/Tools/KDiff3Reporter.cs index 79360da2..202f49ed 100644 --- a/src/ApprovalTests/Reporters/Tools/KDiff3Reporter.cs +++ b/src/ApprovalTests/Reporters/Tools/KDiff3Reporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/KaleidoscopeDiffReporter.cs b/src/ApprovalTests/Reporters/Tools/KaleidoscopeDiffReporter.cs index 86784efd..b4d05452 100644 --- a/src/ApprovalTests/Reporters/Tools/KaleidoscopeDiffReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/KaleidoscopeDiffReporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/MeldReporter.cs b/src/ApprovalTests/Reporters/Tools/MeldReporter.cs index c9b8eafb..5f3140cf 100644 --- a/src/ApprovalTests/Reporters/Tools/MeldReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/MeldReporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/P4MergeReporter.cs b/src/ApprovalTests/Reporters/Tools/P4MergeReporter.cs index a60b93fe..afc2fbda 100644 --- a/src/ApprovalTests/Reporters/Tools/P4MergeReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/P4MergeReporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/RiderReporter.cs b/src/ApprovalTests/Reporters/Tools/RiderReporter.cs index 18896e12..2ca62c63 100644 --- a/src/ApprovalTests/Reporters/Tools/RiderReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/RiderReporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/TkDiffReporter.cs b/src/ApprovalTests/Reporters/Tools/TkDiffReporter.cs index 9003ca42..fb8e7dc3 100644 --- a/src/ApprovalTests/Reporters/Tools/TkDiffReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/TkDiffReporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/TortoiseDiffReporter.cs b/src/ApprovalTests/Reporters/Tools/TortoiseDiffReporter.cs index aced3cc8..e1d51153 100644 --- a/src/ApprovalTests/Reporters/Tools/TortoiseDiffReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/TortoiseDiffReporter.cs @@ -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) { } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/TortoiseGitTextDiffReporter.cs b/src/ApprovalTests/Reporters/Tools/TortoiseGitTextDiffReporter.cs index fe4123cb..264ba362 100644 --- a/src/ApprovalTests/Reporters/Tools/TortoiseGitTextDiffReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/TortoiseGitTextDiffReporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/TortoiseImageDiffReporter.cs b/src/ApprovalTests/Reporters/Tools/TortoiseImageDiffReporter.cs index 743c7b3f..5eda46c7 100644 --- a/src/ApprovalTests/Reporters/Tools/TortoiseImageDiffReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/TortoiseImageDiffReporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/TortoiseTextDiffReporter.cs b/src/ApprovalTests/Reporters/Tools/TortoiseTextDiffReporter.cs index 9e643762..51800ca2 100644 --- a/src/ApprovalTests/Reporters/Tools/TortoiseTextDiffReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/TortoiseTextDiffReporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/VisualStudioReporter.cs b/src/ApprovalTests/Reporters/Tools/VisualStudioReporter.cs index a0965ed7..3406f2d6 100644 --- a/src/ApprovalTests/Reporters/Tools/VisualStudioReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/VisualStudioReporter.cs @@ -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) - { - } } \ No newline at end of file diff --git a/src/ApprovalTests/Reporters/Tools/WinMergeReporter.cs b/src/ApprovalTests/Reporters/Tools/WinMergeReporter.cs index b7251964..1daba929 100644 --- a/src/ApprovalTests/Reporters/Tools/WinMergeReporter.cs +++ b/src/ApprovalTests/Reporters/Tools/WinMergeReporter.cs @@ -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) - { - } } \ No newline at end of file