Skip to content

Commit dcc5f04

Browse files
committed
Fix global threshold not being respected
1 parent 2ada854 commit dcc5f04

21 files changed

+98
-12
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The following will use ImageHash to compare the images instead of the default Di
4848
```cs
4949
[Test]
5050
public Task CompareImage() =>
51-
VerifyFile("sample.jpg");
51+
VerifyFile("sample1.jpg");
5252
```
5353
<sup><a href='/src/Tests/Samples.cs#L4-L10' title='Snippet source file'>snippet source</a> | <a href='#snippet-CompareImage' title='Start of snippet'>anchor</a></sup>
5454
<!-- endSnippet -->

src/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649;NU1608;NU1109</NoWarn>
5-
<Version>3.0.2</Version>
5+
<Version>3.0.3</Version>
66
<AssemblyVersion>1.0.0</AssemblyVersion>
77
<LangVersion>preview</LangVersion>
88
<ImplicitUsings>enable</ImplicitUsings>
@@ -13,4 +13,4 @@
1313
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1414
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
1515
</PropertyGroup>
16-
</Project>
16+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
static class ModuleInitializer
2+
{
3+
[ModuleInitializer]
4+
public static void Init()
5+
{
6+
VerifyImageSharpCompare.RegisterComparers(threshold: 10);
7+
VerifierSettings.InitializePlugins();
8+
}
9+
}

src/Tests/sample.jpg renamed to src/Tests.CustomThreshold/Tests.CompareImageWithCustomThreshold.verified.jpg

File renamed without changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="NUnit" />
8+
<PackageReference Include="NUnit3TestAdapter" />
9+
<PackageReference Include="Verify.NUnit" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
11+
<ProjectReference Include="..\Verify.ImageSharp.Compare\Verify.ImageSharp.Compare.csproj" />
12+
<PackageReference Include="ProjectDefaults" PrivateAssets="all" />
13+
<None Update=".\sample*.*">
14+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
15+
</None>
16+
</ItemGroup>
17+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
Type: VerifyException,
3+
Message:
4+
Directory: {ProjectDirectory}
5+
NotEqual:
6+
- Received: Tests.FailingCompareInner.received.jpg
7+
Verified: Tests.FailingCompareInner.verified.jpg
8+
9+
FileContent:
10+
11+
NotEqual:
12+
13+
Received: Tests.FailingCompareInner.received.jpg
14+
Verified: Tests.FailingCompareInner.verified.jpg
15+
Compare Result:
16+
similarity(159345906) > threshold(10).
17+
If this difference is acceptable, use:
18+
19+
* Globally: VerifyImageSharpCompare.RegisterComparers(159345906);
20+
* For one test: Verifier.VerifyFile("file.jpg").UseImageHash(159345906);
21+
22+
23+
}
366 KB
Loading
366 KB
Loading

src/Tests.CustomThreshold/Tests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[TestFixture]
2+
public class Tests
3+
{
4+
[Test]
5+
public Task Working() =>
6+
VerifyFile("sample1.jpg");
7+
8+
[Test]
9+
public Task FailingCompare() =>
10+
ThrowsTask(async () =>
11+
{
12+
await VerifyFile("sample2.jpg")
13+
.DisableDiff()
14+
.UseMethodName("FailingCompareInner");
15+
})
16+
.IgnoreStackTrace()
17+
.ScrubLinesContaining("clipboard", "DiffEngineTray");
18+
}
366 KB
Loading

0 commit comments

Comments
 (0)