-
Notifications
You must be signed in to change notification settings - Fork 632
Add Swift Testing attachments for snapshot failures (Swift 6.2+) #1021
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
Open
ajkolean
wants to merge
13
commits into
pointfreeco:main
Choose a base branch
from
ajkolean:feature/swift-testing-attachments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Swift Testing attachments for snapshot failures (Swift 6.2+) #1021
ajkolean
wants to merge
13
commits into
pointfreeco:main
from
ajkolean:feature/swift-testing-attachments
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Create DualAttachment to bridge XCTest and Swift Testing attachments - Store attachment data alongside XCTAttachments for Swift Testing - Record attachments via Swift Testing's Attachment API when available - Add three separate attachments for string diffs (reference, actual, diff) - Optimize large image attachments with automatic compression Addresses pointfreeco#909
- Keep string snapshots with single patch attachment (original behavior) - Only image snapshots create three attachments (reference, failure, difference) - Focus on adding Swift Testing support without changing existing attachment patterns - Add comprehensive tests to verify attachment creation
- Update SwiftTestingAttachmentTests to use withKnownIssue properly for expected failures - Add compiler conditional for inline snapshot test to handle Swift 6.2+ error message format changes - Remove unnecessary @_spi annotations from UIImage snapshots - Update documentation formatting to match existing patterns - Ensure all tests pass with expected known issues
- Match existing codebase pattern using NSLock with @unchecked Sendable - Replace DispatchQueue.sync with lock.lock()/defer { lock.unlock() } - Consistent with Counter class implementation in AssertSnapshot.swift
- Add STAttachments helper to centralize Swift Testing attachment recording - Add proper platform guards matching project conventions for XCTest imports - Simplify nested #if conditions using && operator - Add UUID-based storage for reliable attachment retrieval
Replace brittle AttachmentStorage with direct data embedding in XCTAttachment.userInfo. This eliminates: - Global storage with ObjectIdentifier keys that could collide - Thread synchronization overhead - Complex UUID tracking The new approach embeds image data directly in XCTAttachment's userInfo dictionary, making the data flow direct and collision-free without changing any public APIs.
Hey @mbrandonw just noticed you had this branch a while back: Feel free to use this PR as a reference if helpful. 🙂 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for recording snapshot failure artifacts as Swift Testing attachments while maintaining existing XCTest behavior.
Changes
available (canImport(Testing)
andcompiler(>=6.2))
.UIImage
,NSImage
) to bundle raw PNG data alongsideXCTAttachments
so they can be re-recorded under Swift Testing.XCTContext
attachments forXCTest
.SwiftTestingAttachmentTests
suite to verify attachment behavior for both text and image snapshots.Documentation/SwiftTestingAttachments.md
explaining feature, usage, and requirements.Why this matters
Adds richer diagnostics for snapshot failures directly in Xcode’s native Swift Testing UI without altering behavior for XCTest users.
Related discussion
See GitHub Discussion #909: “No screenshots attachments in Swift Testing tests” — this PR implements the solution requested there.
Let me know if you want it tweaked further!