1
1
import XCTest
2
2
3
+ #if canImport(Testing)
4
+ import Testing
5
+ #endif
6
+
3
7
/// Enhances failure messages with a command line diff tool expression that can be copied and pasted
4
8
/// into a terminal.
5
9
@available (
@@ -9,12 +13,33 @@ import XCTest
9
13
" Use 'withSnapshotTesting' to customize the diff tool. See the documentation for more information. "
10
14
)
11
15
public var diffTool : SnapshotTestingConfiguration . DiffTool {
12
- get { _diffTool }
16
+ get {
17
+ _diffTool
18
+ }
13
19
set { _diffTool = newValue }
14
20
}
15
21
16
22
@_spi ( Internals)
17
- public var _diffTool : SnapshotTestingConfiguration . DiffTool = . default
23
+ public var _diffTool : SnapshotTestingConfiguration . DiffTool {
24
+ get {
25
+ #if canImport(Testing)
26
+ if let test = Test . current {
27
+ for trait in test. traits. reversed ( ) {
28
+ if let diffTool = ( trait as? _SnapshotsTestTrait ) ? . configuration. diffTool {
29
+ return diffTool
30
+ }
31
+ }
32
+ }
33
+ #endif
34
+ return __diffTool
35
+ }
36
+ set {
37
+ __diffTool = newValue
38
+ }
39
+ }
40
+
41
+ @_spi ( Internals)
42
+ public var __diffTool : SnapshotTestingConfiguration . DiffTool = . default
18
43
19
44
/// Whether or not to record all new references.
20
45
@available (
@@ -28,7 +53,26 @@ public var isRecording: Bool {
28
53
}
29
54
30
55
@_spi ( Internals)
31
- public var _record : SnapshotTestingConfiguration . Record = {
56
+ public var _record : SnapshotTestingConfiguration . Record {
57
+ get {
58
+ #if canImport(Testing)
59
+ if let test = Test . current {
60
+ for trait in test. traits. reversed ( ) {
61
+ if let record = ( trait as? _SnapshotsTestTrait ) ? . configuration. record {
62
+ return record
63
+ }
64
+ }
65
+ }
66
+ #endif
67
+ return __record
68
+ }
69
+ set {
70
+ __record = newValue
71
+ }
72
+ }
73
+
74
+ @_spi ( Internals)
75
+ public var __record : SnapshotTestingConfiguration . Record = {
32
76
if let value = ProcessInfo . processInfo. environment [ " SNAPSHOT_TESTING_RECORD " ] ,
33
77
let record = SnapshotTestingConfiguration . Record ( rawValue: value)
34
78
{
@@ -311,7 +355,9 @@ public func verifySnapshot<Value, Format>(
311
355
func recordSnapshot( ) throws {
312
356
try snapshotting. diffing. toData ( diffable) . write ( to: snapshotFileUrl)
313
357
#if !os(Linux) && !os(Windows)
314
- if ProcessInfo . processInfo. environment. keys. contains ( " __XCODE_BUILT_PRODUCTS_DIR_PATHS " ) {
358
+ if !isSwiftTesting,
359
+ ProcessInfo . processInfo. environment. keys. contains ( " __XCODE_BUILT_PRODUCTS_DIR_PATHS " )
360
+ {
315
361
XCTContext . runActivity ( named: " Attached Recorded Snapshot " ) { activity in
316
362
let attachment = XCTAttachment ( contentsOfFile: snapshotFileUrl)
317
363
activity. add ( attachment)
@@ -373,7 +419,9 @@ public func verifySnapshot<Value, Format>(
373
419
374
420
if !attachments. isEmpty {
375
421
#if !os(Linux) && !os(Windows)
376
- if ProcessInfo . processInfo. environment. keys. contains ( " __XCODE_BUILT_PRODUCTS_DIR_PATHS " ) {
422
+ if ProcessInfo . processInfo. environment. keys. contains ( " __XCODE_BUILT_PRODUCTS_DIR_PATHS " ) ,
423
+ !isSwiftTesting
424
+ {
377
425
XCTContext . runActivity ( named: " Attached Failure Diff " ) { activity in
378
426
attachments. forEach {
379
427
activity. add ( $0)
0 commit comments