Skip to content

✅ add macOS platform support to disposable test assets#65

Merged
gimlichael merged 1 commit into
mainfrom
v11.1.0/fix-mac-os-issue-ii
Jun 5, 2026
Merged

✅ add macOS platform support to disposable test assets#65
gimlichael merged 1 commit into
mainfrom
v11.1.0/fix-mac-os-issue-ii

Conversation

@gimlichael

Copy link
Copy Markdown
Member

Updates conditional compilation directives to align with NET9.0+ where macOS support is available. Adds macOS native library loading via libSystem.B.dylib in UnmanagedDisposable for both NET9+ and earlier TFM branches. Ensures platform-specific resource disposal tests work on macOS.

Updates conditional compilation directives to align with NET9.0+ where macOS support is available. Adds macOS native library loading via libSystem.B.dylib in UnmanagedDisposable for both NET9+ and earlier TFM branches. Ensures platform-specific resource disposal tests work on macOS.
@gimlichael gimlichael self-assigned this Jun 5, 2026
@gimlichael gimlichael merged commit 070ce7e into main Jun 5, 2026
5 checks passed
@gimlichael gimlichael deleted the v11.1.0/fix-mac-os-issue-ii branch June 5, 2026 10:31
@greptile-apps

greptile-apps Bot commented Jun 5, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds macOS platform support to the UnmanagedDisposable test asset by loading libSystem.B.dylib via NativeLibrary, and aligns all conditional compilation guards from NET8_0_OR_GREATER to NET9_0_OR_GREATER across both production (HostFixture) and test code.

  • The macOS NativeLibrary.TryLoad / NativeLibrary.Free path added under #if NET9_0_OR_GREATER is correct and mirrors the existing Linux pattern; macOS CI targets net9.0/net10.0 which always satisfies that guard.
  • The identical macOS blocks added in the #else branch (legacy NativeLibraryLoader path) are unreachable: that branch compiles only for net48, which the build system restricts to Windows-only runners, so IsOSPlatform(OSX) can never be true there.
  • The NET8_0_OR_GREATER to NET9_0_OR_GREATER rename in HostFixture.cs is a no-op for the library's current TFMs (net10.0, net9.0, netstandard2.0) but would silently disable async disposal for any net8.0 TFM added later.

Confidence Score: 4/5

The macOS changes are safe and correctly gated behind NET9_0_OR_GREATER; the only concern is two unreachable macOS blocks in the legacy net48 code path that add noise but pose no runtime risk.

The core macOS addition in UnmanagedDisposable is correct and follows the existing Linux pattern. The #else branch copies produce dead code that is never compiled into a macOS-capable binary, which is not a runtime hazard but is a maintainability concern. The HostFixture.cs guard rename is a no-op across all current TFMs.

test/Codebelt.Extensions.Xunit.Tests/Assets/UnmanagedDisposable.cs — the macOS blocks in the #else (net48) section are unreachable and should be removed or documented.

Important Files Changed

Filename Overview
src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs Changed #if NET8_0_OR_GREATER to NET9_0_OR_GREATER for async OnDisposeManagedResourcesAsync; functionally identical for the library's current TFMs (net10.0, net9.0, netstandard2.0) but would silently drop async disposal if net8.0 were ever added.
test/Codebelt.Extensions.Xunit.Tests/Assets/UnmanagedDisposable.cs Adds macOS (libSystem.B.dylib) loading in both NET9+ and legacy #else branches; the legacy branch is dead code since net48 only runs on Windows and never satisfies IsOSPlatform(OSX).
test/Codebelt.Extensions.Xunit.Tests/Assets/AsyncDisposable.cs Guard changed from NET8_0_OR_GREATER to NET9_0_OR_GREATER; no behavioral change for the test's actual TFMs (net9.0, net10.0, net48).
test/Codebelt.Extensions.Xunit.Tests/DisposableTest.cs Async dispose test guard updated from NET8_0_OR_GREATER to NET9_0_OR_GREATER; no behavioral change for the test's current TFMs.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[UnmanagedDisposable constructor] --> B{NET9_0_OR_GREATER?}
    B -- Yes --> C{OS Platform}
    C -- Windows --> D[NativeLibrary.TryLoad kernel32.dll]
    C -- Linux --> E[NativeLibrary.TryLoad libc.so.6]
    C -- OSX NEW --> F[NativeLibrary.TryLoad libSystem.B.dylib]
    D --> G[_handle = CreateFileW result]
    E --> H[_handle = _libHandle]
    F --> H
    B -- No net48/Windows only --> I{OS Platform}
    I -- Windows --> J[NativeLibraryLoader kernel32.dll]
    I -- Linux --> K[NativeLibraryLoader libc.so.6]
    I -- OSX DEAD CODE --> L[NativeLibraryLoader libSystem.B.dylib]
    L -.->|net48 never runs on macOS| M((unreachable))
    subgraph Dispose
        N[OnDisposeUnmanagedResources] --> O{NET9_0_OR_GREATER?}
        O -- Yes --> P{OS Platform}
        P -- Windows --> Q[CloseHandle + NativeLibrary.Free]
        P -- Linux --> R[NativeLibrary.Free]
        P -- OSX NEW --> R
        O -- No --> S{OS Platform}
        S -- Windows --> T[_nativeLibrary.Dispose]
        S -- Linux --> U[_nativeLibrary.Dispose]
        S -- OSX DEAD CODE --> V[_nativeLibrary.Dispose]
        V -.->|net48 never runs on macOS| M
    end
Loading
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
test/Codebelt.Extensions.Xunit.Tests/Assets/UnmanagedDisposable.cs:84-89
**Dead code: macOS branch inside the `#else` (net48) block**

The `#else` block only compiles for target frameworks where `NET9_0_OR_GREATER` is false. From `Directory.Build.props`, the only such test TFM is `net48`, which the project explicitly restricts to Windows-only runners. `RuntimeInformation.IsOSPlatform(OSPlatform.OSX)` can never be `true` inside this block, so the new `_nativeLibrary = new NativeLibrary("libSystem.B.dylib")` assignment and the corresponding `_nativeLibrary.Dispose()` call in `OnDisposeUnmanagedResources` are unreachable. macOS tests always target `net9.0` or `net10.0`, meaning they always hit the `#if NET9_0_OR_GREATER` branch added above.

### Issue 2 of 2
test/Codebelt.Extensions.Xunit.Tests/Assets/UnmanagedDisposable.cs:141-144
**Dead code: macOS disposal inside the `#else` block**

Same issue as the constructor: the `#else` guard makes this reachable only under `net48`, which never runs on macOS. The `_nativeLibrary.Dispose()` call here will never be executed in any supported CI configuration.

Reviews (1): Last reviewed commit: "✅ add macOS platform support to disposab..." | Re-trigger Greptile

Comment on lines +84 to +89
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
_nativeLibrary = new NativeLibrary("libSystem.B.dylib");
_libHandle = _nativeLibrary.Handle;
_handle = _libHandle; // i don't know of any native methods on unix
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Dead code: macOS branch inside the #else (net48) block

The #else block only compiles for target frameworks where NET9_0_OR_GREATER is false. From Directory.Build.props, the only such test TFM is net48, which the project explicitly restricts to Windows-only runners. RuntimeInformation.IsOSPlatform(OSPlatform.OSX) can never be true inside this block, so the new _nativeLibrary = new NativeLibrary("libSystem.B.dylib") assignment and the corresponding _nativeLibrary.Dispose() call in OnDisposeUnmanagedResources are unreachable. macOS tests always target net9.0 or net10.0, meaning they always hit the #if NET9_0_OR_GREATER branch added above.

Prompt To Fix With AI
This is a comment left during a code review.
Path: test/Codebelt.Extensions.Xunit.Tests/Assets/UnmanagedDisposable.cs
Line: 84-89

Comment:
**Dead code: macOS branch inside the `#else` (net48) block**

The `#else` block only compiles for target frameworks where `NET9_0_OR_GREATER` is false. From `Directory.Build.props`, the only such test TFM is `net48`, which the project explicitly restricts to Windows-only runners. `RuntimeInformation.IsOSPlatform(OSPlatform.OSX)` can never be `true` inside this block, so the new `_nativeLibrary = new NativeLibrary("libSystem.B.dylib")` assignment and the corresponding `_nativeLibrary.Dispose()` call in `OnDisposeUnmanagedResources` are unreachable. macOS tests always target `net9.0` or `net10.0`, meaning they always hit the `#if NET9_0_OR_GREATER` branch added above.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +141 to +144
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
_nativeLibrary.Dispose();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Dead code: macOS disposal inside the #else block

Same issue as the constructor: the #else guard makes this reachable only under net48, which never runs on macOS. The _nativeLibrary.Dispose() call here will never be executed in any supported CI configuration.

Prompt To Fix With AI
This is a comment left during a code review.
Path: test/Codebelt.Extensions.Xunit.Tests/Assets/UnmanagedDisposable.cs
Line: 141-144

Comment:
**Dead code: macOS disposal inside the `#else` block**

Same issue as the constructor: the `#else` guard makes this reachable only under `net48`, which never runs on macOS. The `_nativeLibrary.Dispose()` call here will never be executed in any supported CI configuration.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants