-
Notifications
You must be signed in to change notification settings - Fork 1
✅ add macOS platform support to disposable test assets #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ public delegate IntPtr CreateFileDelegate(string lpFileName, | |
|
|
||
| public UnmanagedDisposable() | ||
| { | ||
| #if NET8_0_OR_GREATER | ||
| #if NET9_0_OR_GREATER | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| if (NativeLibrary.TryLoad("kernel32.dll", GetType().Assembly, DllImportSearchPath.System32, out _libHandle)) | ||
|
|
@@ -53,6 +53,13 @@ public UnmanagedDisposable() | |
| _handle = _libHandle; // i don't know of any native methods on unix | ||
| } | ||
| } | ||
| else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
| { | ||
| if (NativeLibrary.TryLoad("libSystem.B.dylib", GetType().Assembly, DllImportSearchPath.SafeDirectories, out _libHandle)) | ||
| { | ||
| _handle = _libHandle; // i don't know of any native methods on unix | ||
| } | ||
| } | ||
| #else | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
|
|
@@ -74,6 +81,12 @@ public UnmanagedDisposable() | |
| _libHandle = _nativeLibrary.Handle; | ||
| _handle = _libHandle; // i don't know of any native methods on unix | ||
| } | ||
| 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 | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
|
|
@@ -89,7 +102,7 @@ protected override void OnDisposeManagedResources() | |
|
|
||
| protected override void OnDisposeUnmanagedResources() | ||
| { | ||
| #if NET8_0_OR_GREATER | ||
| #if NET9_0_OR_GREATER | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| if (_handle != IntPtr.Zero) | ||
|
|
@@ -106,6 +119,10 @@ protected override void OnDisposeUnmanagedResources() | |
| { | ||
| NativeLibrary.Free(_libHandle); | ||
| } | ||
| else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
| { | ||
| NativeLibrary.Free(_libHandle); | ||
| } | ||
| #else | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
|
|
@@ -121,6 +138,10 @@ protected override void OnDisposeUnmanagedResources() | |
| { | ||
| _nativeLibrary.Dispose(); | ||
| } | ||
| else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
| { | ||
| _nativeLibrary.Dispose(); | ||
| } | ||
|
Comment on lines
+141
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same issue as the constructor: the Prompt To Fix With AIThis 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! |
||
| #endif | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#else(net48) blockThe
#elseblock only compiles for target frameworks whereNET9_0_OR_GREATERis false. FromDirectory.Build.props, the only such test TFM isnet48, which the project explicitly restricts to Windows-only runners.RuntimeInformation.IsOSPlatform(OSPlatform.OSX)can never betrueinside this block, so the new_nativeLibrary = new NativeLibrary("libSystem.B.dylib")assignment and the corresponding_nativeLibrary.Dispose()call inOnDisposeUnmanagedResourcesare unreachable. macOS tests always targetnet9.0ornet10.0, meaning they always hit the#if NET9_0_OR_GREATERbranch added above.Prompt To Fix With AI
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!