Browse Source

Fix xunit skip

when used in nameof it is not allowed to be a filed it must be a property
pull/2854/head
Stefan Nikolei 4 months ago
parent
commit
29ff120273
  1. 47
      tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.Trim.cs
  2. 74
      tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.cs
  3. 60
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs
  4. 22
      tests/ImageSharp.Tests/TestUtilities/Tests/BasicSerializerTests.cs
  5. 53
      tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs

47
tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.Trim.cs

@ -14,9 +14,7 @@ public partial class UniformUnmanagedMemoryPoolTests
public class Trim public class Trim
{ {
[CollectionDefinition(nameof(NonParallelTests), DisableParallelization = true)] [CollectionDefinition(nameof(NonParallelTests), DisableParallelization = true)]
public class NonParallelTests public class NonParallelTests { }
{
}
[Fact] [Fact]
public void TrimPeriodElapsed_TrimsHalfOfUnusedArrays() public void TrimPeriodElapsed_TrimsHalfOfUnusedArrays()
@ -24,7 +22,10 @@ public partial class UniformUnmanagedMemoryPoolTests
RemoteExecutor.Invoke(RunTest).Dispose(); RemoteExecutor.Invoke(RunTest).Dispose();
static void RunTest() static void RunTest()
{ {
UniformUnmanagedMemoryPool.TrimSettings trimSettings = new() { TrimPeriodMilliseconds = 5_000 }; UniformUnmanagedMemoryPool.TrimSettings trimSettings = new()
{
TrimPeriodMilliseconds = 5_000,
};
UniformUnmanagedMemoryPool pool = new(128, 256, trimSettings); UniformUnmanagedMemoryPool pool = new(128, 256, trimSettings);
UnmanagedMemoryHandle[] a = pool.Rent(64); UnmanagedMemoryHandle[] a = pool.Rent(64);
@ -37,7 +38,8 @@ public partial class UniformUnmanagedMemoryPoolTests
// 128 - 32 - 16 = 80 // 128 - 32 - 16 = 80
Assert.True( Assert.True(
UnmanagedMemoryHandle.TotalOutstandingHandles <= 80, UnmanagedMemoryHandle.TotalOutstandingHandles <= 80,
$"UnmanagedMemoryHandle.TotalOutstandingHandles={UnmanagedMemoryHandle.TotalOutstandingHandles} > 80"); $"UnmanagedMemoryHandle.TotalOutstandingHandles={UnmanagedMemoryHandle.TotalOutstandingHandles} > 80"
);
pool.Return(b); pool.Return(b);
} }
} }
@ -46,14 +48,12 @@ public partial class UniformUnmanagedMemoryPoolTests
// MultiplePoolInstances_TrimPeriodElapsed_AllAreTrimmed, // MultiplePoolInstances_TrimPeriodElapsed_AllAreTrimmed,
// which is strongly timing-sensitive, and might be flaky under high load. // which is strongly timing-sensitive, and might be flaky under high load.
[CollectionDefinition(nameof(NonParallelCollection), DisableParallelization = true)] [CollectionDefinition(nameof(NonParallelCollection), DisableParallelization = true)]
public class NonParallelCollection public class NonParallelCollection { }
{
}
[Collection(nameof(NonParallelCollection))] [Collection(nameof(NonParallelCollection))]
public class NonParallel public class NonParallel
{ {
public static readonly bool IsNotMacOS = !TestEnvironment.IsMacOS; public static bool IsNotMacOS => !TestEnvironment.IsMacOS;
// TODO: Investigate failures on macOS. All handles are released after GC. // TODO: Investigate failures on macOS. All handles are released after GC.
// (It seems to happen more consistently on .NET 6.) // (It seems to happen more consistently on .NET 6.)
@ -77,10 +77,16 @@ public partial class UniformUnmanagedMemoryPoolTests
static void RunTest() static void RunTest()
{ {
UniformUnmanagedMemoryPool.TrimSettings trimSettings1 = new() { TrimPeriodMilliseconds = 6_000 }; UniformUnmanagedMemoryPool.TrimSettings trimSettings1 = new()
{
TrimPeriodMilliseconds = 6_000,
};
UniformUnmanagedMemoryPool pool1 = new(128, 256, trimSettings1); UniformUnmanagedMemoryPool pool1 = new(128, 256, trimSettings1);
Thread.Sleep(8_000); // Let some callbacks fire already Thread.Sleep(8_000); // Let some callbacks fire already
UniformUnmanagedMemoryPool.TrimSettings trimSettings2 = new() { TrimPeriodMilliseconds = 3_000 }; UniformUnmanagedMemoryPool.TrimSettings trimSettings2 = new()
{
TrimPeriodMilliseconds = 3_000,
};
UniformUnmanagedMemoryPool pool2 = new(128, 256, trimSettings2); UniformUnmanagedMemoryPool pool2 = new(128, 256, trimSettings2);
pool1.Return(pool1.Rent(64)); pool1.Return(pool1.Rent(64));
@ -96,7 +102,8 @@ public partial class UniformUnmanagedMemoryPoolTests
Thread.Sleep(15_000); Thread.Sleep(15_000);
Assert.True( Assert.True(
UnmanagedMemoryHandle.TotalOutstandingHandles <= 64, UnmanagedMemoryHandle.TotalOutstandingHandles <= 64,
$"UnmanagedMemoryHandle.TotalOutstandingHandles={UnmanagedMemoryHandle.TotalOutstandingHandles} > 64"); $"UnmanagedMemoryHandle.TotalOutstandingHandles={UnmanagedMemoryHandle.TotalOutstandingHandles} > 64"
);
GC.KeepAlive(pool1); GC.KeepAlive(pool1);
GC.KeepAlive(pool2); GC.KeepAlive(pool2);
} }
@ -104,13 +111,16 @@ public partial class UniformUnmanagedMemoryPoolTests
[MethodImpl(MethodImplOptions.NoInlining)] [MethodImpl(MethodImplOptions.NoInlining)]
static void LeakPoolInstance() static void LeakPoolInstance()
{ {
UniformUnmanagedMemoryPool.TrimSettings trimSettings = new() { TrimPeriodMilliseconds = 4_000 }; UniformUnmanagedMemoryPool.TrimSettings trimSettings = new()
{
TrimPeriodMilliseconds = 4_000,
};
_ = new UniformUnmanagedMemoryPool(128, 256, trimSettings); _ = new UniformUnmanagedMemoryPool(128, 256, trimSettings);
} }
} }
} }
public static readonly bool Is32BitProcess = !Environment.Is64BitProcess; public static bool Is32BitProcess => !Environment.Is64BitProcess;
private static readonly List<byte[]> PressureArrays = []; private static readonly List<byte[]> PressureArrays = [];
[Fact] [Fact]
@ -129,11 +139,16 @@ public partial class UniformUnmanagedMemoryPoolTests
Assert.False(Environment.Is64BitProcess); Assert.False(Environment.Is64BitProcess);
const int oneMb = 1 << 20; const int oneMb = 1 << 20;
UniformUnmanagedMemoryPool.TrimSettings trimSettings = new() { HighPressureThresholdRate = 0.2f }; UniformUnmanagedMemoryPool.TrimSettings trimSettings = new()
{
HighPressureThresholdRate = 0.2f,
};
GCMemoryInfo memInfo = GC.GetGCMemoryInfo(); GCMemoryInfo memInfo = GC.GetGCMemoryInfo();
int highLoadThreshold = (int)(memInfo.HighMemoryLoadThresholdBytes / oneMb); int highLoadThreshold = (int)(memInfo.HighMemoryLoadThresholdBytes / oneMb);
highLoadThreshold = (int)(trimSettings.HighPressureThresholdRate * highLoadThreshold); highLoadThreshold = (int)(
trimSettings.HighPressureThresholdRate * highLoadThreshold
);
UniformUnmanagedMemoryPool pool = new(oneMb, 16, trimSettings); UniformUnmanagedMemoryPool pool = new(oneMb, 16, trimSettings);
pool.Return(pool.Rent(16)); pool.Return(pool.Rent(16));

74
tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.cs

@ -27,11 +27,13 @@ public partial class UniformUnmanagedMemoryPoolTests
public void Register(UnmanagedMemoryHandle handle) => this.handlesToDestroy.Add(handle); public void Register(UnmanagedMemoryHandle handle) => this.handlesToDestroy.Add(handle);
public void Register(IEnumerable<UnmanagedMemoryHandle> handles) => this.handlesToDestroy.AddRange(handles); public void Register(IEnumerable<UnmanagedMemoryHandle> handles) =>
this.handlesToDestroy.AddRange(handles);
public void Register(IntPtr memoryPtr) => this.ptrsToDestroy.Add(memoryPtr); public void Register(IntPtr memoryPtr) => this.ptrsToDestroy.Add(memoryPtr);
public void Register(IEnumerable<IntPtr> memoryPtrs) => this.ptrsToDestroy.AddRange(memoryPtrs); public void Register(IEnumerable<IntPtr> memoryPtrs) =>
this.ptrsToDestroy.AddRange(memoryPtrs);
public void Dispose() public void Dispose()
{ {
@ -93,7 +95,11 @@ public partial class UniformUnmanagedMemoryPoolTests
} }
} }
private static void CheckBuffer(int length, UniformUnmanagedMemoryPool pool, UnmanagedMemoryHandle h) private static void CheckBuffer(
int length,
UniformUnmanagedMemoryPool pool,
UnmanagedMemoryHandle h
)
{ {
Assert.False(h.IsInvalid); Assert.False(h.IsInvalid);
Span<byte> span = GetSpan(h, pool.BufferLength); Span<byte> span = GetSpan(h, pool.BufferLength);
@ -104,7 +110,8 @@ public partial class UniformUnmanagedMemoryPoolTests
Assert.True(span.SequenceEqual(expected)); Assert.True(span.SequenceEqual(expected));
} }
private static unsafe Span<byte> GetSpan(UnmanagedMemoryHandle h, int length) => new(h.Pointer, length); private static unsafe Span<byte> GetSpan(UnmanagedMemoryHandle h, int length) =>
new(h.Pointer, length);
[Theory] [Theory]
[InlineData(1, 1)] [InlineData(1, 1)]
@ -209,7 +216,11 @@ public partial class UniformUnmanagedMemoryPoolTests
[InlineData(0, 6, 5)] [InlineData(0, 6, 5)]
[InlineData(5, 1, 5)] [InlineData(5, 1, 5)]
[InlineData(4, 7, 10)] [InlineData(4, 7, 10)]
public void Rent_MultiBuffer_OverCapacity_ReturnsNull(int initialRent, int attempt, int capacity) public void Rent_MultiBuffer_OverCapacity_ReturnsNull(
int initialRent,
int attempt,
int capacity
)
{ {
UniformUnmanagedMemoryPool pool = new(128, capacity); UniformUnmanagedMemoryPool pool = new(128, capacity);
using CleanupUtil cleanup = new(pool); using CleanupUtil cleanup = new(pool);
@ -237,7 +248,7 @@ public partial class UniformUnmanagedMemoryPoolTests
cleanup.Register(b1); cleanup.Register(b1);
} }
public static readonly bool IsNotMacOS = !TestEnvironment.IsMacOS; public static bool IsNotMacOS => !TestEnvironment.IsMacOS;
// TODO: Investigate macOS failures // TODO: Investigate macOS failures
[Theory(Skip = "Skipped on macOS", SkipUnless = nameof(IsNotMacOS))] [Theory(Skip = "Skipped on macOS", SkipUnless = nameof(IsNotMacOS))]
@ -260,7 +271,10 @@ public partial class UniformUnmanagedMemoryPoolTests
pool.Release(); pool.Release();
// Do some unmanaged allocations to make sure new pool buffers are different: // Do some unmanaged allocations to make sure new pool buffers are different:
IntPtr[] dummy = Enumerable.Range(0, 100).Select(_ => Marshal.AllocHGlobal(16)).ToArray(); IntPtr[] dummy = Enumerable
.Range(0, 100)
.Select(_ => Marshal.AllocHGlobal(16))
.ToArray();
cleanup.Register(dummy); cleanup.Register(dummy);
if (bool.Parse(multipleInner)) if (bool.Parse(multipleInner))
@ -309,34 +323,38 @@ public partial class UniformUnmanagedMemoryPoolTests
using CleanupUtil cleanup = new(pool); using CleanupUtil cleanup = new(pool);
Random rnd = new(0); Random rnd = new(0);
Parallel.For(0, Environment.ProcessorCount, (int i) => Parallel.For(
{ 0,
List<UnmanagedMemoryHandle> allHandles = new(); Environment.ProcessorCount,
int pauseAt = rnd.Next(100); (int i) =>
for (int j = 0; j < 100; j++)
{ {
UnmanagedMemoryHandle[] data = pool.Rent(2); List<UnmanagedMemoryHandle> allHandles = new();
int pauseAt = rnd.Next(100);
for (int j = 0; j < 100; j++)
{
UnmanagedMemoryHandle[] data = pool.Rent(2);
GetSpan(data[0], pool.BufferLength).Fill((byte)i); GetSpan(data[0], pool.BufferLength).Fill((byte)i);
GetSpan(data[1], pool.BufferLength).Fill((byte)i); GetSpan(data[1], pool.BufferLength).Fill((byte)i);
allHandles.Add(data[0]); allHandles.Add(data[0]);
allHandles.Add(data[1]); allHandles.Add(data[1]);
if (j == pauseAt) if (j == pauseAt)
{ {
Thread.Sleep(15); Thread.Sleep(15);
}
} }
}
Span<byte> expected = new byte[8]; Span<byte> expected = new byte[8];
expected.Fill((byte)i); expected.Fill((byte)i);
foreach (UnmanagedMemoryHandle h in allHandles) foreach (UnmanagedMemoryHandle h in allHandles)
{ {
Assert.True(expected.SequenceEqual(GetSpan(h, pool.BufferLength))); Assert.True(expected.SequenceEqual(GetSpan(h, pool.BufferLength)));
pool.Return(new[] { h }); pool.Return(new[] { h });
}
} }
}); );
} }
[Theory] [Theory]

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

@ -15,11 +15,14 @@ public static partial class TestEnvironment
private const string ActualOutputDirectoryRelativePath = @"tests\Images\ActualOutput"; private const string ActualOutputDirectoryRelativePath = @"tests\Images\ActualOutput";
private const string ReferenceOutputDirectoryRelativePath = @"tests\Images\External\ReferenceOutput"; private const string ReferenceOutputDirectoryRelativePath =
@"tests\Images\External\ReferenceOutput";
private const string ToolsDirectoryRelativePath = @"tests\Images\External\tools"; private const string ToolsDirectoryRelativePath = @"tests\Images\External\tools";
private static readonly Lazy<string> SolutionDirectoryFullPathLazy = new(GetSolutionDirectoryFullPathImpl); private static readonly Lazy<string> SolutionDirectoryFullPathLazy = new(
GetSolutionDirectoryFullPathImpl
);
private static readonly Lazy<Version> NetCoreVersionLazy = new(GetNetCoreVersion); private static readonly Lazy<Version> NetCoreVersionLazy = new(GetNetCoreVersion);
@ -52,7 +55,9 @@ public static partial class TestEnvironment
internal static string SolutionDirectoryFullPath => SolutionDirectoryFullPathLazy.Value; internal static string SolutionDirectoryFullPath => SolutionDirectoryFullPathLazy.Value;
private static readonly FileInfo TestAssemblyFile = new(typeof(TestEnvironment).GetTypeInfo().Assembly.Location); private static readonly FileInfo TestAssemblyFile = new(
typeof(TestEnvironment).GetTypeInfo().Assembly.Location
);
private static string GetSolutionDirectoryFullPathImpl() private static string GetSolutionDirectoryFullPathImpl()
{ {
@ -68,12 +73,15 @@ public static partial class TestEnvironment
{ {
throw new DirectoryNotFoundException( throw new DirectoryNotFoundException(
$"Unable to find ImageSharp solution directory from {TestAssemblyFile} because of {ex.GetType().Name}!", $"Unable to find ImageSharp solution directory from {TestAssemblyFile} because of {ex.GetType().Name}!",
ex); ex
);
} }
if (directory == null) if (directory == null)
{ {
throw new DirectoryNotFoundException($"Unable to find ImageSharp solution directory from {TestAssemblyFile}!"); throw new DirectoryNotFoundException(
$"Unable to find ImageSharp solution directory from {TestAssemblyFile}!"
);
} }
} }
@ -82,7 +90,7 @@ public static partial class TestEnvironment
private static string GetFullPath(string relativePath) => private static string GetFullPath(string relativePath) =>
Path.Combine(SolutionDirectoryFullPath, relativePath) Path.Combine(SolutionDirectoryFullPath, relativePath)
.Replace('\\', Path.DirectorySeparatorChar); .Replace('\\', Path.DirectorySeparatorChar);
/// <summary> /// <summary>
/// Gets the correct full path to the Input Images directory. /// Gets the correct full path to the Input Images directory.
@ -92,17 +100,21 @@ public static partial class TestEnvironment
/// <summary> /// <summary>
/// Gets the correct full path to the Actual Output directory. (To be written to by the test cases.) /// Gets the correct full path to the Actual Output directory. (To be written to by the test cases.)
/// </summary> /// </summary>
internal static string ActualOutputDirectoryFullPath => GetFullPath(ActualOutputDirectoryRelativePath); internal static string ActualOutputDirectoryFullPath =>
GetFullPath(ActualOutputDirectoryRelativePath);
/// <summary> /// <summary>
/// Gets the correct full path to the Expected Output directory. (To compare the test results to.) /// Gets the correct full path to the Expected Output directory. (To compare the test results to.)
/// </summary> /// </summary>
internal static string ReferenceOutputDirectoryFullPath => GetFullPath(ReferenceOutputDirectoryRelativePath); internal static string ReferenceOutputDirectoryFullPath =>
GetFullPath(ReferenceOutputDirectoryRelativePath);
internal static string ToolsDirectoryFullPath => GetFullPath(ToolsDirectoryRelativePath); internal static string ToolsDirectoryFullPath => GetFullPath(ToolsDirectoryRelativePath);
internal static string GetReferenceOutputFileName(string actualOutputFileName) => internal static string GetReferenceOutputFileName(string actualOutputFileName) =>
actualOutputFileName.Replace("ActualOutput", @"External\ReferenceOutput").Replace('\\', Path.DirectorySeparatorChar); actualOutputFileName
.Replace("ActualOutput", @"External\ReferenceOutput")
.Replace('\\', Path.DirectorySeparatorChar);
internal static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); internal static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
@ -110,7 +122,7 @@ public static partial class TestEnvironment
internal static bool IsMono => Type.GetType("Mono.Runtime") != null; // https://stackoverflow.com/a/721194 internal static bool IsMono => Type.GetType("Mono.Runtime") != null; // https://stackoverflow.com/a/721194
internal static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); public static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
internal static bool Is64BitProcess => IntPtr.Size == 8; internal static bool Is64BitProcess => IntPtr.Size == 8;
@ -123,9 +135,7 @@ public static partial class TestEnvironment
/// <summary> /// <summary>
/// A dummy operation to enforce the execution of the static constructor. /// A dummy operation to enforce the execution of the static constructor.
/// </summary> /// </summary>
internal static void EnsureSharedInitializersDone() internal static void EnsureSharedInitializersDone() { }
{
}
/// <summary> /// <summary>
/// Creates the image output directory. /// Creates the image output directory.
@ -164,8 +174,10 @@ public static partial class TestEnvironment
return; return;
} }
string remoteExecutorConfigPath = string remoteExecutorConfigPath = Path.Combine(
Path.Combine(TestAssemblyFile.DirectoryName, "Microsoft.DotNet.RemoteExecutor.exe.config"); TestAssemblyFile.DirectoryName,
"Microsoft.DotNet.RemoteExecutor.exe.config"
);
if (File.Exists(remoteExecutorConfigPath)) if (File.Exists(remoteExecutorConfigPath))
{ {
@ -196,11 +208,15 @@ public static partial class TestEnvironment
string windowsSdksDir = Path.Combine( string windowsSdksDir = Path.Combine(
Environment.GetEnvironmentVariable("PROGRAMFILES(x86)"), Environment.GetEnvironmentVariable("PROGRAMFILES(x86)"),
"Microsoft SDKs", "Microsoft SDKs",
"Windows"); "Windows"
);
FileInfo corFlagsFile = Find(new DirectoryInfo(windowsSdksDir), "CorFlags.exe"); FileInfo corFlagsFile = Find(new DirectoryInfo(windowsSdksDir), "CorFlags.exe");
string remoteExecutorPath = Path.Combine(TestAssemblyFile.DirectoryName, "Microsoft.DotNet.RemoteExecutor.exe"); string remoteExecutorPath = Path.Combine(
TestAssemblyFile.DirectoryName,
"Microsoft.DotNet.RemoteExecutor.exe"
);
string remoteExecutorTmpPath = $"{remoteExecutorPath}._tmp"; string remoteExecutorTmpPath = $"{remoteExecutorPath}._tmp";
@ -220,7 +236,7 @@ public static partial class TestEnvironment
Arguments = args, Arguments = args,
UseShellExecute = false, UseShellExecute = false,
RedirectStandardOutput = true, RedirectStandardOutput = true,
RedirectStandardError = true RedirectStandardError = true,
}; };
using Process proc = Process.Start(si); using Process proc = Process.Start(si);
@ -231,7 +247,8 @@ public static partial class TestEnvironment
if (proc.ExitCode != 0) if (proc.ExitCode != 0)
{ {
throw new Exception( throw new Exception(
$@"Failed to run {si.FileName} {si.Arguments}:\n STDOUT: {standardOutput}\n STDERR: {standardError}"); $@"Failed to run {si.FileName} {si.Arguments}:\n STDOUT: {standardOutput}\n STDERR: {standardError}"
);
} }
File.Delete(remoteExecutorPath); File.Delete(remoteExecutorPath);
@ -265,7 +282,10 @@ public static partial class TestEnvironment
private static Version GetNetCoreVersion() private static Version GetNetCoreVersion()
{ {
Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly; Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
string[] assemblyPath = assembly.Location.Split(['/', '\\'], StringSplitOptions.RemoveEmptyEntries); string[] assemblyPath = assembly.Location.Split(
['/', '\\'],
StringSplitOptions.RemoveEmptyEntries
);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App"); int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2) if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
{ {

22
tests/ImageSharp.Tests/TestUtilities/Tests/BasicSerializerTests.cs

@ -18,16 +18,16 @@ public class BasicSerializerTests
public virtual void Deserialize(IXunitSerializationInfo info) public virtual void Deserialize(IXunitSerializationInfo info)
{ {
info.AddValue(nameof(this.Length), this.Length); this.Length = info.GetValue<double>(nameof(this.Length));
info.AddValue(nameof(this.Name), this.Name); this.Name = info.GetValue<string>(nameof(this.Name));
info.AddValue(nameof(this.Lives), this.Lives); this.Lives = info.GetValue<int>(nameof(this.Lives));
} }
public virtual void Serialize(IXunitSerializationInfo info) public virtual void Serialize(IXunitSerializationInfo info)
{ {
this.Length = info.GetValue<double>(nameof(this.Length)); info.AddValue(nameof(this.Length), this.Length);
this.Name = info.GetValue<string>(nameof(this.Name)); info.AddValue(nameof(this.Name), this.Name);
this.Lives = info.GetValue<int>(nameof(this.Lives)); info.AddValue(nameof(this.Lives), this.Lives);
} }
} }
@ -37,8 +37,8 @@ public class BasicSerializerTests
public override void Deserialize(IXunitSerializationInfo info) public override void Deserialize(IXunitSerializationInfo info)
{ {
this.Strength = info.GetValue<double>(nameof(this.Strength));
base.Deserialize(info); base.Deserialize(info);
this.Strength = info.GetValue<double>(nameof(this.Strength));
} }
public override void Serialize(IXunitSerializationInfo info) public override void Serialize(IXunitSerializationInfo info)
@ -51,7 +51,13 @@ public class BasicSerializerTests
[Fact] [Fact]
public void SerializeDeserialize_ShouldPreserveValues() public void SerializeDeserialize_ShouldPreserveValues()
{ {
DerivedObj obj = new() { Length = 123.1, Name = "Lol123!", Lives = 7, Strength = 4.8 }; DerivedObj obj = new()
{
Length = 123.1,
Name = "Lol123!",
Lives = 7,
Strength = 4.8,
};
string str = BasicSerializer.Serialize(obj); string str = BasicSerializer.Serialize(obj);
BaseObj mirrorBase = BasicSerializer.Deserialize<BaseObj>(str); BaseObj mirrorBase = BasicSerializer.Deserialize<BaseObj>(str);

53
tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs

@ -2,7 +2,6 @@
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
using Microsoft.DotNet.RemoteExecutor; using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Gif;
@ -15,8 +14,7 @@ namespace SixLabors.ImageSharp.Tests;
public class TestEnvironmentTests public class TestEnvironmentTests
{ {
public TestEnvironmentTests(ITestOutputHelper output) public TestEnvironmentTests(ITestOutputHelper output) => this.Output = output;
=> this.Output = output;
private ITestOutputHelper Output { get; } private ITestOutputHelper Output { get; }
@ -27,21 +25,24 @@ public class TestEnvironmentTests
} }
[Fact] [Fact]
public void SolutionDirectoryFullPath() public void SolutionDirectoryFullPath() =>
=> this.CheckPath(TestEnvironment.SolutionDirectoryFullPath); this.CheckPath(TestEnvironment.SolutionDirectoryFullPath);
[Fact] [Fact]
public void InputImagesDirectoryFullPath() public void InputImagesDirectoryFullPath() =>
=> this.CheckPath(TestEnvironment.InputImagesDirectoryFullPath); this.CheckPath(TestEnvironment.InputImagesDirectoryFullPath);
[Fact] [Fact]
public void ExpectedOutputDirectoryFullPath() public void ExpectedOutputDirectoryFullPath() =>
=> this.CheckPath(TestEnvironment.ReferenceOutputDirectoryFullPath); this.CheckPath(TestEnvironment.ReferenceOutputDirectoryFullPath);
[Fact] [Fact]
public void GetReferenceOutputFileName() public void GetReferenceOutputFileName()
{ {
string actual = Path.Combine(TestEnvironment.ActualOutputDirectoryFullPath, @"foo\bar\lol.jpeg"); string actual = Path.Combine(
TestEnvironment.ActualOutputDirectoryFullPath,
@"foo\bar\lol.jpeg"
);
string expected = TestEnvironment.GetReferenceOutputFileName(actual); string expected = TestEnvironment.GetReferenceOutputFileName(actual);
this.Output.WriteLine(expected); this.Output.WriteLine(expected);
@ -54,7 +55,10 @@ public class TestEnvironmentTests
[InlineData("lol/Baz.JPG", typeof(JpegEncoder))] [InlineData("lol/Baz.JPG", typeof(JpegEncoder))]
[InlineData("lol/Baz.gif", typeof(GifEncoder))] [InlineData("lol/Baz.gif", typeof(GifEncoder))]
[InlineData("lol/foobar.webp", typeof(WebpEncoder))] [InlineData("lol/foobar.webp", typeof(WebpEncoder))]
public void GetReferenceEncoder_ReturnsCorrectEncoders_Windows(string fileName, Type expectedEncoderType) public void GetReferenceEncoder_ReturnsCorrectEncoders_Windows(
string fileName,
Type expectedEncoderType
)
{ {
if (!TestEnvironment.IsWindows) if (!TestEnvironment.IsWindows)
{ {
@ -71,7 +75,10 @@ public class TestEnvironmentTests
[InlineData("lol/Baz.JPG", typeof(JpegDecoder))] [InlineData("lol/Baz.JPG", typeof(JpegDecoder))]
[InlineData("lol/Baz.gif", typeof(GifDecoder))] [InlineData("lol/Baz.gif", typeof(GifDecoder))]
[InlineData("lol/foobar.webp", typeof(WebpDecoder))] [InlineData("lol/foobar.webp", typeof(WebpDecoder))]
public void GetReferenceDecoder_ReturnsCorrectDecoders_Windows(string fileName, Type expectedDecoderType) public void GetReferenceDecoder_ReturnsCorrectDecoders_Windows(
string fileName,
Type expectedDecoderType
)
{ {
if (!TestEnvironment.IsWindows) if (!TestEnvironment.IsWindows)
{ {
@ -88,7 +95,10 @@ public class TestEnvironmentTests
[InlineData("lol/Baz.JPG", typeof(JpegEncoder))] [InlineData("lol/Baz.JPG", typeof(JpegEncoder))]
[InlineData("lol/Baz.gif", typeof(GifEncoder))] [InlineData("lol/Baz.gif", typeof(GifEncoder))]
[InlineData("lol/foobar.webp", typeof(WebpEncoder))] [InlineData("lol/foobar.webp", typeof(WebpEncoder))]
public void GetReferenceEncoder_ReturnsCorrectEncoders_Linux(string fileName, Type expectedEncoderType) public void GetReferenceEncoder_ReturnsCorrectEncoders_Linux(
string fileName,
Type expectedEncoderType
)
{ {
if (!TestEnvironment.IsLinux) if (!TestEnvironment.IsLinux)
{ {
@ -105,7 +115,10 @@ public class TestEnvironmentTests
[InlineData("lol/Baz.JPG", typeof(JpegDecoder))] [InlineData("lol/Baz.JPG", typeof(JpegDecoder))]
[InlineData("lol/Baz.gif", typeof(GifDecoder))] [InlineData("lol/Baz.gif", typeof(GifDecoder))]
[InlineData("lol/foobar.webp", typeof(WebpDecoder))] [InlineData("lol/foobar.webp", typeof(WebpDecoder))]
public void GetReferenceDecoder_ReturnsCorrectDecoders_Linux(string fileName, Type expectedDecoderType) public void GetReferenceDecoder_ReturnsCorrectDecoders_Linux(
string fileName,
Type expectedDecoderType
)
{ {
if (!TestEnvironment.IsLinux) if (!TestEnvironment.IsLinux)
{ {
@ -118,9 +131,13 @@ public class TestEnvironmentTests
// RemoteExecutor does not work with "dotnet xunit" used to run tests on 32 bit .NET Framework: // RemoteExecutor does not work with "dotnet xunit" used to run tests on 32 bit .NET Framework:
// https://github.com/SixLabors/ImageSharp/blob/381dff8640b721a34b1227c970fcf6ad6c5e3e72/ci-test.ps1#L30 // https://github.com/SixLabors/ImageSharp/blob/381dff8640b721a34b1227c970fcf6ad6c5e3e72/ci-test.ps1#L30
public static bool IsNot32BitNetFramework = !TestEnvironment.IsFramework || TestEnvironment.Is64BitProcess; public static bool IsNot32BitNetFramework =>
!TestEnvironment.IsFramework || TestEnvironment.Is64BitProcess;
[Fact(Skip = "Not supported on 32-bit .NET Framework", SkipUnless = nameof(IsNot32BitNetFramework))] [Fact(
Skip = "Not supported on 32-bit .NET Framework",
SkipUnless = nameof(IsNot32BitNetFramework)
)]
public void RemoteExecutor_FailingRemoteTestShouldFailLocalTest() public void RemoteExecutor_FailingRemoteTestShouldFailLocalTest()
{ {
static void FailingCode() static void FailingCode()
@ -128,6 +145,8 @@ public class TestEnvironmentTests
Assert.False(true); Assert.False(true);
} }
Assert.ThrowsAny<RemoteExecutionException>(() => RemoteExecutor.Invoke(FailingCode).Dispose()); Assert.ThrowsAny<RemoteExecutionException>(() =>
RemoteExecutor.Invoke(FailingCode).Dispose()
);
} }
} }

Loading…
Cancel
Save