swift-testing icon indicating copy to clipboard operation
swift-testing copied to clipboard

Add a cross-import overlay with AppKit to allow attaching `NSImage`s.

Open grynspan opened this issue 11 months ago • 1 comments

This PR adds on to the Core Graphics cross-import overlay added in #827 to allow attaching instances of NSImage to a test.

NSImage is a more complicated animal because it is not Sendable, but we don't want to make a (potentially very expensive) deep copy of its data until absolutely necessary. So we check inside the image to see if its contained representations are known to be safely copyable (i.e. copies made with NSCopying do not share any mutable state with their originals.) If it looks safe to make a copy of the image by calling copy(), we do so; otherwise, we try to make a deep copy of the image.

Due to how Swift implements polymorphism in protocol requirements, and because we don't really know what they're doing, subclasses of NSImage just get a call to copy() instead of deep introspection.

UIImage support will be implemented in a separate PR.

[!NOTE] Attachments remain an experimental feature.

Checklist:

  • [x] Code and documentation should follow the style of the Style Guide.
  • [x] If public symbols are renamed or modified, DocC references should be updated.

grynspan avatar Dec 19 '24 19:12 grynspan

@swift-ci test

grynspan avatar Dec 19 '24 19:12 grynspan

@swift-ci test

grynspan avatar Jul 02 '25 17:07 grynspan

@swift-ci test Linux

grynspan avatar Jul 02 '25 17:07 grynspan

@swift-ci test

grynspan avatar Jul 02 '25 17:07 grynspan

@swift-ci test

grynspan avatar Jul 02 '25 17:07 grynspan