Skip to content

Prefer native Swift Testing image attachments on supported toolchains#1067

Merged
stephencelis merged 3 commits intopointfreeco:mainfrom
ajkolean:feature/native-swift-testing-image-attachments
Mar 19, 2026
Merged

Prefer native Swift Testing image attachments on supported toolchains#1067
stephencelis merged 3 commits intopointfreeco:mainfrom
ajkolean:feature/native-swift-testing-image-attachments

Conversation

@ajkolean
Copy link
Copy Markdown
Contributor

This builds on the Swift Testing attachment support added in #1064 and refined in #1065.

Currently, Swift Testing attachments in AssertSnapshot.swift are recorded as generic Data attachments via Attachment.record(data, ...). On newer toolchains, Swift Testing supports attaching image types directly, so PNG snapshot artifacts can be recorded as native image attachments instead.

This change adds a small helper to prefer native Swift Testing image attachments for PNG snapshot artifacts when supported, while preserving the existing fallback behavior everywhere else.

What changes

  • add a small recordSwiftTestingAttachment helper
  • for .png attachments on supported toolchains:
    • decode the data as UIImage / NSImage
    • record it with Attachment.record(..., as: .png, sourceLocation: ...)
  • otherwise fall back to the existing Attachment.record(data, ...) path
  • update both Swift Testing attachment recording sites to use the helper
  • preserve existing SourceLocation behavior from Record attachment when recording new snapshots. #1065

Notes

  • This is a focused enhancement to the existing Swift Testing attachment path.
  • Non-image attachments are unchanged.
  • Older toolchains continue to use the existing Data attachment behavior.
  • XCTest behavior is unchanged.

Xcode 26.4 adds native Swift Testing image attachments, so this change aligns SnapshotTesting’s PNG snapshot artifacts with the newer test-reporting API on supported toolchains.

On Swift 6.3+ (Xcode 26.4+), CGImage/UIImage/NSImage/CIImage conform to
Attachable. Add a helper that detects .png attachment names and records
native image attachments instead of raw Data, enabling better Xcode
integration (preview, thumbnails). Falls back to data attachments on
older toolchains or for non-image data.
Copilot AI review requested due to automatic review settings March 19, 2026 06:30

This comment was marked as off-topic.

Copy link
Copy Markdown
Member

@stephencelis stephencelis left a comment

Choose a reason for hiding this comment

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

Thanks!

@stephencelis stephencelis merged commit 05b6f05 into pointfreeco:main Mar 19, 2026
3 checks passed
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.

4 participants