Skip to content

Commit

Permalink
ThrowIfVerifyHasBeenRun in comparers (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 9, 2023
1 parent d66472e commit 96717dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/Verify.Tests/Comparer/ComparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ public async Task Instance_with_message()
Assert.Contains("theMessage", exception.Message);
}

[Fact]
public async Task Static_with_message()
[ModuleInitializer]
public static void Static_with_messageInit()
{
FileExtensions.AddTextExtension("staticComparerExtMessage");
VerifierSettings.RegisterStringComparer("staticComparerExtMessage", CompareWithMessage);
}

[Fact]
public async Task Static_with_message()
{
var settings = new VerifySettings();
settings.DisableDiff();
settings.UseMethodName("Static_with_message_temp");
Expand All @@ -39,11 +44,16 @@ public async Task Static_with_message()

#endif

[Fact]
public async Task Static()
[ModuleInitializer]
public static void StaticInit()
{
FileExtensions.AddTextExtension("staticComparerExt");
VerifierSettings.RegisterStringComparer("staticComparerExt", Compare);
}

[Fact]
public async Task Static()
{
await Verify("TheText", "staticComparerExt");
PrefixUnique.Clear();
await Verify("thetext", "staticComparerExt");
Expand Down
7 changes: 6 additions & 1 deletion src/Verify/Compare/SharedSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@ internal static bool TryGetStringComparer(string extension, [NotNullWhen(true)]

public static void RegisterStreamComparer(string extension, StreamCompare compare)
{
InnerVerifier.ThrowIfVerifyHasBeenRun();
Guard.AgainstBadExtension(extension, nameof(extension));
streamComparers[extension] = compare;
}

public static void RegisterStringComparer(string extension, StringCompare compare)
{
InnerVerifier.ThrowIfVerifyHasBeenRun();
Guard.AgainstBadExtension(extension, nameof(extension));
stringComparers[extension] = compare;
}

public static void SetDefaultStringComparer(StringCompare compare) =>
public static void SetDefaultStringComparer(StringCompare compare)
{
InnerVerifier.ThrowIfVerifyHasBeenRun();
defaultStringComparer = compare;
}
}

0 comments on commit 96717dd

Please sign in to comment.