Skip to content

Commit

Permalink
Don't invoke XCTContext when running in the Testing framework.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Aug 1, 2024
1 parent 2d0d95e commit 9341833
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/SnapshotTesting/AssertSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ public func verifySnapshot<Value, Format>(
func recordSnapshot() throws {
try snapshotting.diffing.toData(diffable).write(to: snapshotFileUrl)
#if !os(Linux) && !os(Windows)
if ProcessInfo.processInfo.environment.keys.contains("__XCODE_BUILT_PRODUCTS_DIR_PATHS") {
if
!isSwiftTesting,
ProcessInfo.processInfo.environment.keys.contains("__XCODE_BUILT_PRODUCTS_DIR_PATHS")
{
XCTContext.runActivity(named: "Attached Recorded Snapshot") { activity in
let attachment = XCTAttachment(contentsOfFile: snapshotFileUrl)
activity.add(attachment)
Expand Down
8 changes: 8 additions & 0 deletions Sources/SnapshotTesting/Internal/RecordIssue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import XCTest
import Testing
#endif

var isSwiftTesting: Bool {
#if canImport(Testing)
return Test.current != nil
#else
return false
#endif
}

@_spi(Internals)
public func recordIssue(
_ message: @autoclosure () -> String,
Expand Down
19 changes: 19 additions & 0 deletions Tests/SnapshotTestingTests/AssertSnapshotSwiftTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#if canImport(Testing)
import Testing
import Foundation
import InlineSnapshotTesting
@_spi(Experimental) import SnapshotTesting

@Suite(
.snapshots(
record: .missing
)
)
struct AssertSnapshotTests {
@Test func dump() {
struct User { let id: Int, name: String, bio: String }
let user = User(id: 1, name: "Blobby", bio: "Blobbed around the world.")
assertSnapshot(of: user, as: .dump)
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
▿ User
- bio: "Blobbed around the world."
- id: 1
- name: "Blobby"

0 comments on commit 9341833

Please sign in to comment.