Skip to content

Commit 48223a6

Browse files
committed
ci: fix WindowsOnly test skip with runtime SkipAttribute
TUnit's --treenode-filter doesn't support compound filters with & or AND operators reliably across platforms. Instead of CI filtering: 1. Add SkipOnNonWindowsAttribute (extends TUnit's SkipAttribute) - Runtime check: OperatingSystem.IsWindows() - Auto-skips WindowsOnly tests on non-Windows 2. Bitmap test classes now use both attributes: - [WindowsOnly] - CategoryAttribute for categorization/documentation - [SkipOnNonWindows] - SkipAttribute for runtime skip 3. Simplified CI workflow: - Single --treenode-filter for OpenBugs only (all platforms) - WindowsOnly handled at runtime by SkipOnNonWindows - Clean job names without platform-specific filters
1 parent e0454d9 commit 48223a6

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

.github/workflows/build-and-release.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,14 @@ jobs:
4444
# NOTE: Test project currently only targets net10.0. See TODO in NumSharp.UnitTest.csproj
4545
# to re-enable net8.0 when TUnit compatibility is resolved.
4646
#
47-
# Test filtering (TUnit --treenode-filter syntax):
48-
# - OpenBugs: excluded on all platforms (known-failing bug reproductions)
49-
# - WindowsOnly: excluded on non-Windows (require GDI+/System.Drawing.Common)
47+
# Test filtering:
48+
# - OpenBugs: excluded via --treenode-filter (known-failing bug reproductions)
49+
# - WindowsOnly: auto-skipped at runtime via [SkipOnNonWindows] attribute
5050
- name: Test (net10.0)
51-
shell: bash
5251
run: |
53-
if [[ "$RUNNER_OS" == "Windows" ]]; then
54-
FILTER='/*/*/*/*[Category!=OpenBugs]'
55-
else
56-
FILTER='/*/*/*/*[(Category!=OpenBugs) AND (Category!=WindowsOnly)]'
57-
fi
5852
dotnet run --project test/NumSharp.UnitTest/NumSharp.UnitTest.csproj \
5953
--configuration Release --no-build --framework net10.0 \
60-
-- --treenode-filter "$FILTER" --report-trx
54+
-- --treenode-filter '/*/*/*/*[Category!=OpenBugs]' --report-trx
6155
6256
- name: Upload Test Results
6357
uses: actions/upload-artifact@v4

test/NumSharp.UnitTest/NumSharp.Bitmap/BitmapExtensionsTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace NumSharp.UnitTest
99
{
1010
[WindowsOnly]
11+
[SkipOnNonWindows]
1112
public class BitmapExtensionsTests : TestClass
1213
{
1314
// ================================================================

test/NumSharp.UnitTest/NumSharp.Bitmap/BitmapWithAlphaTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace NumSharp.UnitTest
99
{
1010
[WindowsOnly]
11+
[SkipOnNonWindows]
1112
public class BitmapWithAlphaTests : TestClass
1213
{
1314
[Test]

test/NumSharp.UnitTest/OpenBugs.Bitmap.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ namespace NumSharp.UnitTest
5656
/// </summary>
5757
[OpenBugs]
5858
[WindowsOnly]
59+
[SkipOnNonWindows]
5960
public class OpenBugsBitmap : TestClass
6061
{
6162

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using TUnit.Core;
4+
5+
namespace NumSharp.UnitTest.Utilities;
6+
7+
/// <summary>
8+
/// Skips the test on non-Windows platforms (Linux, macOS).
9+
/// Used for tests requiring GDI+/System.Drawing.Common.
10+
///
11+
/// This is separate from <see cref="WindowsOnlyAttribute"/> which is a CategoryAttribute
12+
/// for CI filtering. Use both together:
13+
/// <code>
14+
/// [WindowsOnly] // CategoryAttribute for CI filtering
15+
/// [SkipOnNonWindows] // SkipAttribute for runtime skip
16+
/// public class BitmapTests { }
17+
/// </code>
18+
/// </summary>
19+
public class SkipOnNonWindowsAttribute : SkipAttribute
20+
{
21+
public SkipOnNonWindowsAttribute() : base("Requires Windows (GDI+/System.Drawing.Common)") { }
22+
23+
public override Task<bool> ShouldSkip(TestRegisteredContext context)
24+
=> Task.FromResult(!OperatingSystem.IsWindows());
25+
}

0 commit comments

Comments
 (0)