Skip to content

Commit 951ef8c

Browse files
Use error codes in test attributes.
1 parent 53ee7c9 commit 951ef8c

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WebGPUFactAttribute.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,7 @@ public WebGPUFactAttribute()
1414
{
1515
if (!WebGPUProbe.IsComputeSupported)
1616
{
17-
this.Skip = "WebGPU compute is not available on this system.";
18-
}
19-
}
20-
}
21-
22-
/// <summary>
23-
/// A <see cref="TheoryAttribute"/> that skips when WebGPU compute is not available on the current system.
24-
/// </summary>
25-
public class WebGPUTheoryAttribute : TheoryAttribute
26-
{
27-
public WebGPUTheoryAttribute()
28-
{
29-
if (!WebGPUProbe.IsComputeSupported)
30-
{
31-
this.Skip = "WebGPU compute is not available on this system.";
17+
this.Skip = WebGPUProbe.ComputeUnsupportedSkipMessage;
3218
}
3319
}
3420
}
@@ -38,8 +24,23 @@ public WebGPUTheoryAttribute()
3824
/// </summary>
3925
internal static class WebGPUProbe
4026
{
41-
private static bool? computeSupported;
27+
private static WebGPUEnvironmentError? computeProbeResult;
28+
29+
/// <summary>
30+
/// Gets the cached WebGPU compute-pipeline probe result.
31+
/// </summary>
32+
internal static WebGPUEnvironmentError ComputeProbeResult
33+
=> computeProbeResult ??= WebGPUEnvironment.ProbeComputePipelineSupport();
4234

35+
/// <summary>
36+
/// Gets a value indicating whether WebGPU compute is supported on the current system.
37+
/// </summary>
4338
internal static bool IsComputeSupported
44-
=> computeSupported ??= WebGPUEnvironment.ProbeComputePipelineSupport() == WebGPUEnvironmentError.Success;
39+
=> ComputeProbeResult == WebGPUEnvironmentError.Success;
40+
41+
/// <summary>
42+
/// Gets the skip message used when WebGPU compute is unavailable.
43+
/// </summary>
44+
internal static string ComputeUnsupportedSkipMessage
45+
=> $"WebGPU compute is not available on this system: {ComputeProbeResult}.";
4546
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
namespace SixLabors.ImageSharp.Drawing.Tests.TestUtilities.Attributes;
5+
6+
/// <summary>
7+
/// A <see cref="TheoryAttribute"/> that skips when WebGPU compute is not available on the current system.
8+
/// </summary>
9+
public class WebGPUTheoryAttribute : TheoryAttribute
10+
{
11+
public WebGPUTheoryAttribute()
12+
{
13+
if (!WebGPUProbe.IsComputeSupported)
14+
{
15+
this.Skip = WebGPUProbe.ComputeUnsupportedSkipMessage;
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)