Skip to content

Commit 8105068

Browse files
authored
Don't invoke XCTContext when running in the Testing framework. (#884)
1 parent 2d0d95e commit 8105068

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

Sources/SnapshotTesting/AssertSnapshot.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,10 @@ public func verifySnapshot<Value, Format>(
311311
func recordSnapshot() throws {
312312
try snapshotting.diffing.toData(diffable).write(to: snapshotFileUrl)
313313
#if !os(Linux) && !os(Windows)
314-
if ProcessInfo.processInfo.environment.keys.contains("__XCODE_BUILT_PRODUCTS_DIR_PATHS") {
314+
if
315+
!isSwiftTesting,
316+
ProcessInfo.processInfo.environment.keys.contains("__XCODE_BUILT_PRODUCTS_DIR_PATHS")
317+
{
315318
XCTContext.runActivity(named: "Attached Recorded Snapshot") { activity in
316319
let attachment = XCTAttachment(contentsOfFile: snapshotFileUrl)
317320
activity.add(attachment)

Sources/SnapshotTesting/Internal/RecordIssue.swift

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import XCTest
44
import Testing
55
#endif
66

7+
var isSwiftTesting: Bool {
8+
#if canImport(Testing)
9+
return Test.current != nil
10+
#else
11+
return false
12+
#endif
13+
}
14+
715
@_spi(Internals)
816
public func recordIssue(
917
_ message: @autoclosure () -> String,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#if canImport(Testing)
2+
import Testing
3+
import Foundation
4+
import InlineSnapshotTesting
5+
@_spi(Experimental) import SnapshotTesting
6+
7+
@Suite(
8+
.snapshots(
9+
record: .missing
10+
)
11+
)
12+
struct AssertSnapshotTests {
13+
@Test func dump() {
14+
struct User { let id: Int, name: String, bio: String }
15+
let user = User(id: 1, name: "Blobby", bio: "Blobbed around the world.")
16+
assertSnapshot(of: user, as: .dump)
17+
}
18+
}
19+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
▿ User
2+
- bio: "Blobbed around the world."
3+
- id: 1
4+
- name: "Blobby"

0 commit comments

Comments
 (0)