11import XCTest
22
3+ #if canImport(Testing)
4+ import Testing
5+ #endif
6+
37/// Enhances failure messages with a command line diff tool expression that can be copied and pasted
48/// into a terminal.
59@available (
@@ -9,12 +13,33 @@ import XCTest
913 " Use 'withSnapshotTesting' to customize the diff tool. See the documentation for more information. "
1014)
1115public var diffTool : SnapshotTestingConfiguration . DiffTool {
12- get { _diffTool }
16+ get {
17+ _diffTool
18+ }
1319 set { _diffTool = newValue }
1420}
1521
1622@_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
1843
1944/// Whether or not to record all new references.
2045@available (
@@ -28,7 +53,26 @@ public var isRecording: Bool {
2853}
2954
3055@_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 = {
3276 if let value = ProcessInfo . processInfo. environment [ " SNAPSHOT_TESTING_RECORD " ] ,
3377 let record = SnapshotTestingConfiguration . Record ( rawValue: value)
3478 {
@@ -311,7 +355,9 @@ public func verifySnapshot<Value, Format>(
311355 func recordSnapshot( ) throws {
312356 try snapshotting. diffing. toData ( diffable) . write ( to: snapshotFileUrl)
313357 #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+ {
315361 XCTContext . runActivity ( named: " Attached Recorded Snapshot " ) { activity in
316362 let attachment = XCTAttachment ( contentsOfFile: snapshotFileUrl)
317363 activity. add ( attachment)
@@ -373,7 +419,9 @@ public func verifySnapshot<Value, Format>(
373419
374420 if !attachments. isEmpty {
375421 #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+ {
377425 XCTContext . runActivity ( named: " Attached Failure Diff " ) { activity in
378426 attachments. forEach {
379427 activity. add ( $0)
0 commit comments