Skip to content

Commit 8c4c7e3

Browse files
Relax tolerance for .NET Core 2.x
1 parent 2a56b45 commit 8c4c7e3

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawTextOnImageTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public class DrawTextOnImageTests
2323

2424
private const string TestText = "Sphinx of black quartz, judge my vow\n0123456789";
2525

26-
private static readonly ImageComparer TextDrawingComparer = TestEnvironment.IsFramework
27-
? ImageComparer.TolerantPercentage(1e-3f) // Relax comparison on .NET Framework
26+
private static readonly ImageComparer TextDrawingComparer = TestEnvironment.IsFramework || TestEnvironment.NetCoreVersion.StartsWith("2")
27+
? ImageComparer.TolerantPercentage(1e-3f) // Relax comparison on .NET Framework and .NET Core 2.x
2828
: ImageComparer.TolerantPercentage(1e-5f);
2929

3030
private static readonly ImageComparer OutlinedTextDrawingComparer = ImageComparer.TolerantPercentage(5e-4f);

tests/ImageSharp.Drawing.Tests/TestUtilities/TestEnvironment.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ public static partial class TestEnvironment
2424

2525
private static readonly Lazy<string> SolutionDirectoryFullPathLazy = new Lazy<string>(GetSolutionDirectoryFullPathImpl);
2626

27+
private static readonly Lazy<string> NetCoreVersionLazy = new Lazy<string>(GetNetCoreVersion);
28+
2729
internal static bool IsFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework");
2830

31+
/// <summary>
32+
/// Gets the .NET Core version, if running on .NET Core, otherwise returns an empty string.
33+
/// </summary>
34+
internal static string NetCoreVersion => NetCoreVersionLazy.Value;
35+
2936
/// <summary>
3037
/// Gets a value indicating whether test execution runs on CI.
3138
/// </summary>
@@ -132,5 +139,22 @@ internal static string CreateOutputDirectory(string path, params string[] pathPa
132139

133140
return path;
134141
}
142+
143+
/// <summary>
144+
/// Solution borrowed from:
145+
/// https://github.com/dotnet/BenchmarkDotNet/issues/448#issuecomment-308424100
146+
/// </summary>
147+
private static string GetNetCoreVersion()
148+
{
149+
Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
150+
string[] assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
151+
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
152+
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
153+
{
154+
return assemblyPath[netCoreAppIndex + 1];
155+
}
156+
157+
return string.Empty;
158+
}
135159
}
136160
}

0 commit comments

Comments
 (0)