From b467f413c83e2ceba59ba798583a1c57db9700cb Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Wed, 2 Apr 2025 08:51:39 -0700 Subject: [PATCH 01/10] Introduce SnapshotUITesting module for UITest support Swift Testing is not compatible with UITest targets at the moment, but unfortunately `#if canImport` still returns `true`, making it difficult to ship libraries that provide tools for both `Testing` and `XCTest`, like the `assertSnapshot`. The previous workarounds we relied on have stopped working, and so we need a new approach. In this PR we have introduced a forwards-compatible `SnapshotUITesting` module that does not rely on any imports of `Testing` internally. We can then introduce Swift Testing support in the `SnapshotTesting` module, instead. --- Package.swift | 19 +++++- Package@swift-6.0.swift | 23 ++++++- Sources/SnapshotTesting/Exports.swift | 2 + .../Internal/RecordIssue.swift | 40 ------------ .../SnapshotTesting/SnapshotsTestTrait.swift | 45 +++++++------ .../AssertSnapshot.swift | 65 +++++++------------ .../Async.swift | 0 .../Common/Internal.swift | 0 .../Common/PlistEncoder.swift | 0 .../Common/String+SpecialCharacters.swift | 0 .../Common/View.swift | 0 .../Common/XCTAttachment.swift | 0 .../Diff.swift | 0 .../Diffing.swift | 0 .../Articles/CustomStrategies.md | 0 .../Articles/IntegratingWithTestFrameworks.md | 0 .../MigrationGuides/MigratingTo1.17.md | 0 .../MigrationGuides/MigrationGuides.md | 0 .../Extensions/AssertSnapshot.md | 0 .../SnapshotTestingDeprecations.md | 0 .../diffTool-property-deprecation.md | 0 .../isRecording-property-deprecation.md | 0 .../Extensions/SnapshotsTrait.md | 0 .../Extensions/Snapshotting.md | 0 .../Extensions/WithSnapshotTesting.md | 0 .../Documentation.docc/SnapshotTesting.md | 0 .../Extensions/Wait.swift | 0 .../Internal/Deprecations.swift | 4 +- .../SnapshotTestingConfiguration.swift | 3 +- .../SnapshotsTestTrait.swift | 9 +++ .../Snapshotting.swift | 0 .../Snapshotting/Any.swift | 0 .../Snapshotting/CALayer.swift | 0 .../Snapshotting/CGPath.swift | 0 .../Snapshotting/CaseIterable.swift | 0 .../Snapshotting/Data.swift | 0 .../Snapshotting/Encodable.swift | 0 .../Snapshotting/NSBezierPath.swift | 0 .../Snapshotting/NSImage.swift | 2 +- .../Snapshotting/NSView.swift | 0 .../Snapshotting/NSViewController.swift | 0 .../Snapshotting/SceneKit.swift | 0 .../Snapshotting/SpriteKit.swift | 0 .../Snapshotting/String.swift | 2 +- .../Snapshotting/SwiftUIView.swift | 0 .../Snapshotting/UIBezierPath.swift | 0 .../Snapshotting/UIImage.swift | 2 +- .../Snapshotting/UIView.swift | 0 .../Snapshotting/UIViewController.swift | 0 .../Snapshotting/URLRequest.swift | 0 Sources/SnapshotUITesting/Exports.swift | 1 + 51 files changed, 105 insertions(+), 112 deletions(-) create mode 100644 Sources/SnapshotTesting/Exports.swift delete mode 100644 Sources/SnapshotTesting/Internal/RecordIssue.swift rename Sources/{SnapshotTesting => SnapshotTestingCore}/AssertSnapshot.swift (94%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Async.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Common/Internal.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Common/PlistEncoder.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Common/String+SpecialCharacters.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Common/View.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Common/XCTAttachment.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Diff.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Diffing.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/Articles/CustomStrategies.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/Articles/IntegratingWithTestFrameworks.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/Articles/MigrationGuides/MigratingTo1.17.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/Articles/MigrationGuides/MigrationGuides.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/Extensions/AssertSnapshot.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/Extensions/Deprecations/SnapshotTestingDeprecations.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/Extensions/Deprecations/diffTool-property-deprecation.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/Extensions/Deprecations/isRecording-property-deprecation.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/Extensions/SnapshotsTrait.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/Extensions/Snapshotting.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/Extensions/WithSnapshotTesting.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Documentation.docc/SnapshotTesting.md (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Extensions/Wait.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Internal/Deprecations.swift (99%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/SnapshotTestingConfiguration.swift (99%) create mode 100644 Sources/SnapshotTestingCore/SnapshotsTestTrait.swift rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/Any.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/CALayer.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/CGPath.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/CaseIterable.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/Data.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/Encodable.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/NSBezierPath.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/NSImage.swift (99%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/NSView.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/NSViewController.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/SceneKit.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/SpriteKit.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/String.swift (96%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/SwiftUIView.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/UIBezierPath.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/UIImage.swift (99%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/UIView.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/UIViewController.swift (100%) rename Sources/{SnapshotTesting => SnapshotTestingCore}/Snapshotting/URLRequest.swift (100%) create mode 100644 Sources/SnapshotUITesting/Exports.swift diff --git a/Package.swift b/Package.swift index c7a6f7e66..b6fd068fd 100644 --- a/Package.swift +++ b/Package.swift @@ -19,6 +19,10 @@ let package = Package( name: "InlineSnapshotTesting", targets: ["InlineSnapshotTesting"] ), + .library( + name: "SnapshotUITesting", + targets: ["SnapshotUITesting"] + ), .library( name: "SnapshotTestingCustomDump", targets: ["SnapshotTestingCustomDump"] @@ -26,11 +30,18 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.3"), + .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", branch: "test-traits"), .package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"602.0.0"), ], targets: [ .target( - name: "SnapshotTesting" + name: "SnapshotTestingCore" + ), + .target( + name: "SnapshotTesting", + dependencies: [ + "SnapshotTestingCore", + ] ), .testTarget( name: "SnapshotTestingTests", @@ -65,5 +76,11 @@ let package = Package( .product(name: "CustomDump", package: "swift-custom-dump"), ] ), + .target( + name: "SnapshotUITesting", + dependencies: [ + "SnapshotTesting", + ] + ), ] ) diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift index 68cfa74ce..1e87ae73a 100644 --- a/Package@swift-6.0.swift +++ b/Package@swift-6.0.swift @@ -19,6 +19,10 @@ let package = Package( name: "InlineSnapshotTesting", targets: ["InlineSnapshotTesting"] ), + .library( + name: "SnapshotUITesting", + targets: ["SnapshotUITesting"] + ), .library( name: "SnapshotTestingCustomDump", targets: ["SnapshotTestingCustomDump"] @@ -26,11 +30,22 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.3"), + .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", branch: "test-traits"), .package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"602.0.0"), ], targets: [ .target( - name: "SnapshotTesting" + name: "SnapshotTestingCore", + dependencies: [ + .product(name: "IssueReporting", package: "xctest-dynamic-overlay"), + .product(name: "IssueReportingTestSupport", package: "xctest-dynamic-overlay"), + ] + ), + .target( + name: "SnapshotTesting", + dependencies: [ + "SnapshotTestingCore", + ] ), .testTarget( name: "SnapshotTestingTests", @@ -65,6 +80,12 @@ let package = Package( .product(name: "CustomDump", package: "swift-custom-dump"), ] ), + .target( + name: "SnapshotUITesting", + dependencies: [ + "SnapshotTestingCore", + ] + ), ], swiftLanguageModes: [.v5] ) diff --git a/Sources/SnapshotTesting/Exports.swift b/Sources/SnapshotTesting/Exports.swift new file mode 100644 index 000000000..1c14613c9 --- /dev/null +++ b/Sources/SnapshotTesting/Exports.swift @@ -0,0 +1,2 @@ +@_exported import SnapshotTestingCore + diff --git a/Sources/SnapshotTesting/Internal/RecordIssue.swift b/Sources/SnapshotTesting/Internal/RecordIssue.swift deleted file mode 100644 index 214761180..000000000 --- a/Sources/SnapshotTesting/Internal/RecordIssue.swift +++ /dev/null @@ -1,40 +0,0 @@ -import XCTest - -#if canImport(Testing) - 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, - fileID: StaticString, - filePath: StaticString, - line: UInt, - column: UInt -) { - #if canImport(Testing) - if Test.current != nil { - Issue.record( - Comment(rawValue: message()), - sourceLocation: SourceLocation( - fileID: fileID.description, - filePath: filePath.description, - line: Int(line), - column: Int(column) - ) - ) - } else { - XCTFail(message(), file: filePath, line: line) - } - #else - XCTFail(message(), file: filePath, line: line) - #endif -} diff --git a/Sources/SnapshotTesting/SnapshotsTestTrait.swift b/Sources/SnapshotTesting/SnapshotsTestTrait.swift index 9fa4f9a53..9fff98585 100644 --- a/Sources/SnapshotTesting/SnapshotsTestTrait.swift +++ b/Sources/SnapshotTesting/SnapshotsTestTrait.swift @@ -1,12 +1,30 @@ #if canImport(Testing) + @_spi(Internals) import SnapshotTestingCore import Testing - /// A type representing the configuration of snapshot testing. - public struct _SnapshotsTestTrait: SuiteTrait, TestTrait { - public let isRecursive = true - let configuration: SnapshotTestingConfiguration + extension _SnapshotsTestTrait: SuiteTrait, TestTrait { + } + #if compiler(>=6.1) + extension _SnapshotsTestTrait: TestScoping { + public func provideScope( + for test: Test, + testCase: Test.Case?, + performing function: () async throws -> Void + ) async throws { + try await withSnapshotTesting( + record: configuration.record, + diffTool: configuration.diffTool + ) { + try await File.$counter.withValue(File.Counter()) { + try await function() + } + } + } + } + #endif + extension Trait where Self == _SnapshotsTestTrait { /// Configure snapshot testing in a suite or test. public static var snapshots: Self { @@ -39,23 +57,4 @@ _SnapshotsTestTrait(configuration: configuration) } } - - #if compiler(>=6.1) - extension _SnapshotsTestTrait: TestScoping { - public func provideScope( - for test: Test, - testCase: Test.Case?, - performing function: () async throws -> Void - ) async throws { - try await withSnapshotTesting( - record: configuration.record, - diffTool: configuration.diffTool - ) { - try await File.$counter.withValue(File.Counter()) { - try await function() - } - } - } - } - #endif #endif diff --git a/Sources/SnapshotTesting/AssertSnapshot.swift b/Sources/SnapshotTestingCore/AssertSnapshot.swift similarity index 94% rename from Sources/SnapshotTesting/AssertSnapshot.swift rename to Sources/SnapshotTestingCore/AssertSnapshot.swift index 11e761422..f27a81d4a 100644 --- a/Sources/SnapshotTesting/AssertSnapshot.swift +++ b/Sources/SnapshotTestingCore/AssertSnapshot.swift @@ -1,8 +1,5 @@ import XCTest - -#if canImport(Testing) - import Testing -#endif +import IssueReporting /// Enhances failure messages with a command line diff tool expression that can be copied and pasted /// into a terminal. @@ -22,15 +19,13 @@ public var diffTool: SnapshotTestingConfiguration.DiffTool { @_spi(Internals) public var _diffTool: SnapshotTestingConfiguration.DiffTool { get { - #if canImport(Testing) - if let test = Test.current { - for trait in test.traits.reversed() { - if let diffTool = (trait as? _SnapshotsTestTrait)?.configuration.diffTool { - return diffTool - } + if case let .swiftTesting(testing) = TestContext.current, let test = testing?.test { + for trait in test.traits.reversed() { + if let diffTool = (trait as? _SnapshotsTestTrait)?.configuration.diffTool { + return diffTool } } - #endif + } return __diffTool } set { @@ -55,15 +50,13 @@ public var isRecording: Bool { @_spi(Internals) public var _record: SnapshotTestingConfiguration.Record { get { - #if canImport(Testing) - if let test = Test.current { - for trait in test.traits.reversed() { - if let record = (trait as? _SnapshotsTestTrait)?.configuration.record { - return record - } + if case let .swiftTesting(testing) = TestContext.current, let test = testing?.test { + for trait in test.traits.reversed() { + if let record = (trait as? _SnapshotsTestTrait)?.configuration.record { + return record } } - #endif + } return __record } set { @@ -124,7 +117,7 @@ public func assertSnapshot( column: column ) guard let message = failure else { return } - recordIssue( + reportIssue( message, fileID: fileID, filePath: filePath, @@ -285,13 +278,9 @@ public func verifySnapshot( line: UInt = #line, column: UInt = #column ) -> String? { - #if canImport(Testing) - if Test.current == nil { - CleanCounterBetweenTestCases.registerIfNeeded() - } - #else + if TestContext.current?.isSwiftTesting != true { CleanCounterBetweenTestCases.registerIfNeeded() - #endif + } let record = (recording == true ? .all : recording == false ? .missing : nil) @@ -370,7 +359,7 @@ public func verifySnapshot( } #if !os(Android) && !os(Linux) && !os(Windows) - if !isSwiftTesting, + if TestContext.current?.isSwiftTesting != true, ProcessInfo.processInfo.environment.keys.contains("__XCODE_BUILT_PRODUCTS_DIR_PATHS") { XCTContext.runActivity(named: "Attached Recorded Snapshot") { activity in @@ -457,8 +446,8 @@ public func verifySnapshot( if !attachments.isEmpty { #if !os(Linux) && !os(Android) && !os(Windows) - if ProcessInfo.processInfo.environment.keys.contains("__XCODE_BUILT_PRODUCTS_DIR_PATHS"), - !isSwiftTesting + if TestContext.current?.isSwiftTesting != true, + ProcessInfo.processInfo.environment.keys.contains("__XCODE_BUILT_PRODUCTS_DIR_PATHS") { XCTContext.runActivity(named: "Attached Failure Diff") { activity in attachments.forEach { @@ -502,15 +491,11 @@ public func verifySnapshot( // MARK: - Private private var counter: File.Counter { - #if canImport(Testing) - if Test.current != nil { - return File.counter - } else { - return _counter - } - #else + if TestContext.current?.isSwiftTesting == true { + return File.counter + } else { return _counter - #endif + } } private let _counter = File.Counter() @@ -558,14 +543,14 @@ private class CleanCounterBetweenTestCases: NSObject, XCTestObservation { } } -enum File { - @TaskLocal static var counter = Counter() +package enum File { + @TaskLocal package static var counter = Counter() - final class Counter: @unchecked Sendable { + package final class Counter: @unchecked Sendable { private var counts: [String: Int] = [:] private let lock = NSLock() - init() {} + package init() {} func next(for key: String) -> Int { lock.lock() diff --git a/Sources/SnapshotTesting/Async.swift b/Sources/SnapshotTestingCore/Async.swift similarity index 100% rename from Sources/SnapshotTesting/Async.swift rename to Sources/SnapshotTestingCore/Async.swift diff --git a/Sources/SnapshotTesting/Common/Internal.swift b/Sources/SnapshotTestingCore/Common/Internal.swift similarity index 100% rename from Sources/SnapshotTesting/Common/Internal.swift rename to Sources/SnapshotTestingCore/Common/Internal.swift diff --git a/Sources/SnapshotTesting/Common/PlistEncoder.swift b/Sources/SnapshotTestingCore/Common/PlistEncoder.swift similarity index 100% rename from Sources/SnapshotTesting/Common/PlistEncoder.swift rename to Sources/SnapshotTestingCore/Common/PlistEncoder.swift diff --git a/Sources/SnapshotTesting/Common/String+SpecialCharacters.swift b/Sources/SnapshotTestingCore/Common/String+SpecialCharacters.swift similarity index 100% rename from Sources/SnapshotTesting/Common/String+SpecialCharacters.swift rename to Sources/SnapshotTestingCore/Common/String+SpecialCharacters.swift diff --git a/Sources/SnapshotTesting/Common/View.swift b/Sources/SnapshotTestingCore/Common/View.swift similarity index 100% rename from Sources/SnapshotTesting/Common/View.swift rename to Sources/SnapshotTestingCore/Common/View.swift diff --git a/Sources/SnapshotTesting/Common/XCTAttachment.swift b/Sources/SnapshotTestingCore/Common/XCTAttachment.swift similarity index 100% rename from Sources/SnapshotTesting/Common/XCTAttachment.swift rename to Sources/SnapshotTestingCore/Common/XCTAttachment.swift diff --git a/Sources/SnapshotTesting/Diff.swift b/Sources/SnapshotTestingCore/Diff.swift similarity index 100% rename from Sources/SnapshotTesting/Diff.swift rename to Sources/SnapshotTestingCore/Diff.swift diff --git a/Sources/SnapshotTesting/Diffing.swift b/Sources/SnapshotTestingCore/Diffing.swift similarity index 100% rename from Sources/SnapshotTesting/Diffing.swift rename to Sources/SnapshotTestingCore/Diffing.swift diff --git a/Sources/SnapshotTesting/Documentation.docc/Articles/CustomStrategies.md b/Sources/SnapshotTestingCore/Documentation.docc/Articles/CustomStrategies.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/Articles/CustomStrategies.md rename to Sources/SnapshotTestingCore/Documentation.docc/Articles/CustomStrategies.md diff --git a/Sources/SnapshotTesting/Documentation.docc/Articles/IntegratingWithTestFrameworks.md b/Sources/SnapshotTestingCore/Documentation.docc/Articles/IntegratingWithTestFrameworks.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/Articles/IntegratingWithTestFrameworks.md rename to Sources/SnapshotTestingCore/Documentation.docc/Articles/IntegratingWithTestFrameworks.md diff --git a/Sources/SnapshotTesting/Documentation.docc/Articles/MigrationGuides/MigratingTo1.17.md b/Sources/SnapshotTestingCore/Documentation.docc/Articles/MigrationGuides/MigratingTo1.17.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/Articles/MigrationGuides/MigratingTo1.17.md rename to Sources/SnapshotTestingCore/Documentation.docc/Articles/MigrationGuides/MigratingTo1.17.md diff --git a/Sources/SnapshotTesting/Documentation.docc/Articles/MigrationGuides/MigrationGuides.md b/Sources/SnapshotTestingCore/Documentation.docc/Articles/MigrationGuides/MigrationGuides.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/Articles/MigrationGuides/MigrationGuides.md rename to Sources/SnapshotTestingCore/Documentation.docc/Articles/MigrationGuides/MigrationGuides.md diff --git a/Sources/SnapshotTesting/Documentation.docc/Extensions/AssertSnapshot.md b/Sources/SnapshotTestingCore/Documentation.docc/Extensions/AssertSnapshot.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/Extensions/AssertSnapshot.md rename to Sources/SnapshotTestingCore/Documentation.docc/Extensions/AssertSnapshot.md diff --git a/Sources/SnapshotTesting/Documentation.docc/Extensions/Deprecations/SnapshotTestingDeprecations.md b/Sources/SnapshotTestingCore/Documentation.docc/Extensions/Deprecations/SnapshotTestingDeprecations.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/Extensions/Deprecations/SnapshotTestingDeprecations.md rename to Sources/SnapshotTestingCore/Documentation.docc/Extensions/Deprecations/SnapshotTestingDeprecations.md diff --git a/Sources/SnapshotTesting/Documentation.docc/Extensions/Deprecations/diffTool-property-deprecation.md b/Sources/SnapshotTestingCore/Documentation.docc/Extensions/Deprecations/diffTool-property-deprecation.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/Extensions/Deprecations/diffTool-property-deprecation.md rename to Sources/SnapshotTestingCore/Documentation.docc/Extensions/Deprecations/diffTool-property-deprecation.md diff --git a/Sources/SnapshotTesting/Documentation.docc/Extensions/Deprecations/isRecording-property-deprecation.md b/Sources/SnapshotTestingCore/Documentation.docc/Extensions/Deprecations/isRecording-property-deprecation.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/Extensions/Deprecations/isRecording-property-deprecation.md rename to Sources/SnapshotTestingCore/Documentation.docc/Extensions/Deprecations/isRecording-property-deprecation.md diff --git a/Sources/SnapshotTesting/Documentation.docc/Extensions/SnapshotsTrait.md b/Sources/SnapshotTestingCore/Documentation.docc/Extensions/SnapshotsTrait.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/Extensions/SnapshotsTrait.md rename to Sources/SnapshotTestingCore/Documentation.docc/Extensions/SnapshotsTrait.md diff --git a/Sources/SnapshotTesting/Documentation.docc/Extensions/Snapshotting.md b/Sources/SnapshotTestingCore/Documentation.docc/Extensions/Snapshotting.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/Extensions/Snapshotting.md rename to Sources/SnapshotTestingCore/Documentation.docc/Extensions/Snapshotting.md diff --git a/Sources/SnapshotTesting/Documentation.docc/Extensions/WithSnapshotTesting.md b/Sources/SnapshotTestingCore/Documentation.docc/Extensions/WithSnapshotTesting.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/Extensions/WithSnapshotTesting.md rename to Sources/SnapshotTestingCore/Documentation.docc/Extensions/WithSnapshotTesting.md diff --git a/Sources/SnapshotTesting/Documentation.docc/SnapshotTesting.md b/Sources/SnapshotTestingCore/Documentation.docc/SnapshotTesting.md similarity index 100% rename from Sources/SnapshotTesting/Documentation.docc/SnapshotTesting.md rename to Sources/SnapshotTestingCore/Documentation.docc/SnapshotTesting.md diff --git a/Sources/SnapshotTesting/Extensions/Wait.swift b/Sources/SnapshotTestingCore/Extensions/Wait.swift similarity index 100% rename from Sources/SnapshotTesting/Extensions/Wait.swift rename to Sources/SnapshotTestingCore/Extensions/Wait.swift diff --git a/Sources/SnapshotTesting/Internal/Deprecations.swift b/Sources/SnapshotTestingCore/Internal/Deprecations.swift similarity index 99% rename from Sources/SnapshotTesting/Internal/Deprecations.swift rename to Sources/SnapshotTestingCore/Internal/Deprecations.swift index 9a5b9f217..ab1aa4a74 100644 --- a/Sources/SnapshotTesting/Internal/Deprecations.swift +++ b/Sources/SnapshotTestingCore/Internal/Deprecations.swift @@ -1,4 +1,5 @@ import Foundation +import IssueReporting import XCTest // Deprecated after 1.12.0: @@ -20,7 +21,6 @@ public func _assertInlineSnapshot( line: UInt = #line, column: UInt = #column ) { - let failure = _verifyInlineSnapshot( matching: try value(), as: snapshotting, @@ -34,7 +34,7 @@ public func _assertInlineSnapshot( column: column ) guard let message = failure else { return } - recordIssue(message, fileID: fileID, filePath: filePath, line: line, column: column) + reportIssue(message, fileID: fileID, filePath: filePath, line: line, column: column) } @available( diff --git a/Sources/SnapshotTesting/SnapshotTestingConfiguration.swift b/Sources/SnapshotTestingCore/SnapshotTestingConfiguration.swift similarity index 99% rename from Sources/SnapshotTesting/SnapshotTestingConfiguration.swift rename to Sources/SnapshotTestingCore/SnapshotTestingConfiguration.swift index 28cba97fe..7bf5b4ff2 100644 --- a/Sources/SnapshotTesting/SnapshotTestingConfiguration.swift +++ b/Sources/SnapshotTestingCore/SnapshotTestingConfiguration.swift @@ -31,8 +31,7 @@ public func withSnapshotTesting( try SnapshotTestingConfiguration.$current.withValue( SnapshotTestingConfiguration( record: record ?? SnapshotTestingConfiguration.current?.record ?? _record, - diffTool: diffTool ?? SnapshotTestingConfiguration.current?.diffTool - ?? SnapshotTesting._diffTool + diffTool: diffTool ?? SnapshotTestingConfiguration.current?.diffTool ?? _diffTool ) ) { try operation() diff --git a/Sources/SnapshotTestingCore/SnapshotsTestTrait.swift b/Sources/SnapshotTestingCore/SnapshotsTestTrait.swift new file mode 100644 index 000000000..2d60c9464 --- /dev/null +++ b/Sources/SnapshotTestingCore/SnapshotsTestTrait.swift @@ -0,0 +1,9 @@ +/// A type representing the configuration of snapshot testing. +public struct _SnapshotsTestTrait: Sendable { + public let isRecursive = true + package let configuration: SnapshotTestingConfiguration + + package init(configuration: SnapshotTestingConfiguration) { + self.configuration = configuration + } +} diff --git a/Sources/SnapshotTesting/Snapshotting.swift b/Sources/SnapshotTestingCore/Snapshotting.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting.swift rename to Sources/SnapshotTestingCore/Snapshotting.swift diff --git a/Sources/SnapshotTesting/Snapshotting/Any.swift b/Sources/SnapshotTestingCore/Snapshotting/Any.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/Any.swift rename to Sources/SnapshotTestingCore/Snapshotting/Any.swift diff --git a/Sources/SnapshotTesting/Snapshotting/CALayer.swift b/Sources/SnapshotTestingCore/Snapshotting/CALayer.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/CALayer.swift rename to Sources/SnapshotTestingCore/Snapshotting/CALayer.swift diff --git a/Sources/SnapshotTesting/Snapshotting/CGPath.swift b/Sources/SnapshotTestingCore/Snapshotting/CGPath.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/CGPath.swift rename to Sources/SnapshotTestingCore/Snapshotting/CGPath.swift diff --git a/Sources/SnapshotTesting/Snapshotting/CaseIterable.swift b/Sources/SnapshotTestingCore/Snapshotting/CaseIterable.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/CaseIterable.swift rename to Sources/SnapshotTestingCore/Snapshotting/CaseIterable.swift diff --git a/Sources/SnapshotTesting/Snapshotting/Data.swift b/Sources/SnapshotTestingCore/Snapshotting/Data.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/Data.swift rename to Sources/SnapshotTestingCore/Snapshotting/Data.swift diff --git a/Sources/SnapshotTesting/Snapshotting/Encodable.swift b/Sources/SnapshotTestingCore/Snapshotting/Encodable.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/Encodable.swift rename to Sources/SnapshotTestingCore/Snapshotting/Encodable.swift diff --git a/Sources/SnapshotTesting/Snapshotting/NSBezierPath.swift b/Sources/SnapshotTestingCore/Snapshotting/NSBezierPath.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/NSBezierPath.swift rename to Sources/SnapshotTestingCore/Snapshotting/NSBezierPath.swift diff --git a/Sources/SnapshotTesting/Snapshotting/NSImage.swift b/Sources/SnapshotTestingCore/Snapshotting/NSImage.swift similarity index 99% rename from Sources/SnapshotTesting/Snapshotting/NSImage.swift rename to Sources/SnapshotTestingCore/Snapshotting/NSImage.swift index be4fd7cd4..e87fa77c0 100644 --- a/Sources/SnapshotTesting/Snapshotting/NSImage.swift +++ b/Sources/SnapshotTestingCore/Snapshotting/NSImage.swift @@ -24,7 +24,7 @@ let message = compare( old, new, precision: precision, perceptualPrecision: perceptualPrecision) else { return nil } - let difference = SnapshotTesting.diff(old, new) + let difference = SnapshotTestingCore.diff(old, new) let oldAttachment = XCTAttachment(image: old) oldAttachment.name = "reference" let newAttachment = XCTAttachment(image: new) diff --git a/Sources/SnapshotTesting/Snapshotting/NSView.swift b/Sources/SnapshotTestingCore/Snapshotting/NSView.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/NSView.swift rename to Sources/SnapshotTestingCore/Snapshotting/NSView.swift diff --git a/Sources/SnapshotTesting/Snapshotting/NSViewController.swift b/Sources/SnapshotTestingCore/Snapshotting/NSViewController.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/NSViewController.swift rename to Sources/SnapshotTestingCore/Snapshotting/NSViewController.swift diff --git a/Sources/SnapshotTesting/Snapshotting/SceneKit.swift b/Sources/SnapshotTestingCore/Snapshotting/SceneKit.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/SceneKit.swift rename to Sources/SnapshotTestingCore/Snapshotting/SceneKit.swift diff --git a/Sources/SnapshotTesting/Snapshotting/SpriteKit.swift b/Sources/SnapshotTestingCore/Snapshotting/SpriteKit.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/SpriteKit.swift rename to Sources/SnapshotTestingCore/Snapshotting/SpriteKit.swift diff --git a/Sources/SnapshotTesting/Snapshotting/String.swift b/Sources/SnapshotTestingCore/Snapshotting/String.swift similarity index 96% rename from Sources/SnapshotTesting/Snapshotting/String.swift rename to Sources/SnapshotTestingCore/Snapshotting/String.swift index 44aeab0b4..c27ef2f86 100644 --- a/Sources/SnapshotTesting/Snapshotting/String.swift +++ b/Sources/SnapshotTestingCore/Snapshotting/String.swift @@ -14,7 +14,7 @@ extension Diffing where Value == String { ) { old, new in guard old != new else { return nil } let hunks = chunk( - diff: SnapshotTesting.diff( + diff: SnapshotTestingCore.diff( old.split(separator: "\n", omittingEmptySubsequences: false).map(String.init), new.split(separator: "\n", omittingEmptySubsequences: false).map(String.init) )) diff --git a/Sources/SnapshotTesting/Snapshotting/SwiftUIView.swift b/Sources/SnapshotTestingCore/Snapshotting/SwiftUIView.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/SwiftUIView.swift rename to Sources/SnapshotTestingCore/Snapshotting/SwiftUIView.swift diff --git a/Sources/SnapshotTesting/Snapshotting/UIBezierPath.swift b/Sources/SnapshotTestingCore/Snapshotting/UIBezierPath.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/UIBezierPath.swift rename to Sources/SnapshotTestingCore/Snapshotting/UIBezierPath.swift diff --git a/Sources/SnapshotTesting/Snapshotting/UIImage.swift b/Sources/SnapshotTestingCore/Snapshotting/UIImage.swift similarity index 99% rename from Sources/SnapshotTesting/Snapshotting/UIImage.swift rename to Sources/SnapshotTestingCore/Snapshotting/UIImage.swift index 3d1bb5319..833a05e99 100644 --- a/Sources/SnapshotTesting/Snapshotting/UIImage.swift +++ b/Sources/SnapshotTestingCore/Snapshotting/UIImage.swift @@ -35,7 +35,7 @@ let message = compare( old, new, precision: precision, perceptualPrecision: perceptualPrecision) else { return nil } - let difference = SnapshotTesting.diff(old, new) + let difference = SnapshotTestingCore.diff(old, new) let oldAttachment = XCTAttachment(image: old) oldAttachment.name = "reference" let isEmptyImage = new.size == .zero diff --git a/Sources/SnapshotTesting/Snapshotting/UIView.swift b/Sources/SnapshotTestingCore/Snapshotting/UIView.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/UIView.swift rename to Sources/SnapshotTestingCore/Snapshotting/UIView.swift diff --git a/Sources/SnapshotTesting/Snapshotting/UIViewController.swift b/Sources/SnapshotTestingCore/Snapshotting/UIViewController.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/UIViewController.swift rename to Sources/SnapshotTestingCore/Snapshotting/UIViewController.swift diff --git a/Sources/SnapshotTesting/Snapshotting/URLRequest.swift b/Sources/SnapshotTestingCore/Snapshotting/URLRequest.swift similarity index 100% rename from Sources/SnapshotTesting/Snapshotting/URLRequest.swift rename to Sources/SnapshotTestingCore/Snapshotting/URLRequest.swift diff --git a/Sources/SnapshotUITesting/Exports.swift b/Sources/SnapshotUITesting/Exports.swift new file mode 100644 index 000000000..e06ee292c --- /dev/null +++ b/Sources/SnapshotUITesting/Exports.swift @@ -0,0 +1 @@ +@_exported import SnapshotTestingCore From 3f4afbc0865f163d069fb44475c3ec019bd9060f Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Sun, 13 Apr 2025 09:02:15 -0700 Subject: [PATCH 02/10] wip --- Package.resolved | 7 +-- Package@swift-6.0.swift | 2 + .../AssertInlineSnapshot.swift | 48 +++++++------------ 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/Package.resolved b/Package.resolved index bf61dcf39..9cf66bd83 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,4 +1,5 @@ { + "originHash" : "a41783670236cbc3ec9cdb23f88f801e615535963582d78dda1cea364d671298", "pins" : [ { "identity" : "swift-custom-dump", @@ -23,10 +24,10 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", "state" : { - "revision" : "a3f634d1a409c7979cabc0a71b3f26ffa9fc8af1", - "version" : "1.4.3" + "branch" : "test-traits", + "revision" : "67e9e7944953203ffe98fa3cc2d05fe6c11918ed" } } ], - "version" : 2 + "version" : 3 } diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift index 1e87ae73a..738034566 100644 --- a/Package@swift-6.0.swift +++ b/Package@swift-6.0.swift @@ -62,6 +62,8 @@ let package = Package( dependencies: [ "SnapshotTesting", "SnapshotTestingCustomDump", + .product(name: "IssueReporting", package: "xctest-dynamic-overlay"), + .product(name: "IssueReportingTestSupport", package: "xctest-dynamic-overlay"), .product(name: "SwiftParser", package: "swift-syntax"), .product(name: "SwiftSyntax", package: "swift-syntax"), .product(name: "SwiftSyntaxBuilder", package: "swift-syntax"), diff --git a/Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift b/Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift index 142cec513..342bca769 100644 --- a/Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift +++ b/Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift @@ -2,6 +2,7 @@ import Foundation #if canImport(SwiftSyntax509) @_spi(Internals) import SnapshotTesting + import IssueReporting import SwiftParser import SwiftSyntax import SwiftSyntaxBuilder @@ -49,7 +50,7 @@ import Foundation ) { let record = record ?? SnapshotTestingConfiguration.current?.record ?? _record withSnapshotTesting(record: record) { - let _: Void = installTestObserver + let _: Void = installAtExitHook do { var actual: String? let expectation = XCTestExpectation() @@ -62,7 +63,7 @@ import Foundation case .completed: break case .timedOut: - recordIssue( + reportIssue( """ Exceeded timeout of \(timeout) seconds waiting for snapshot. @@ -77,7 +78,7 @@ import Foundation ) return case .incorrectOrder, .interrupted, .invertedFulfillment: - recordIssue( + reportIssue( "Couldn't snapshot value", fileID: fileID, filePath: filePath, @@ -86,7 +87,7 @@ import Foundation ) return @unknown default: - recordIssue( + reportIssue( "Couldn't snapshot value", fileID: fileID, filePath: filePath, @@ -130,7 +131,7 @@ import Foundation if let difference = snapshotting.diffing.diff(expected ?? "", actual ?? "")?.0 { failure += " Difference: …\n\n\(difference.indenting(by: 2))" } - recordIssue( + reportIssue( """ \(failure) @@ -146,7 +147,7 @@ import Foundation guard let expected else { - recordIssue( + reportIssue( """ No expected value to assert against. """, @@ -181,7 +182,7 @@ import Foundation column: column ) } catch { - recordIssue( + reportIssue( "Threw error: \(error)", fileID: fileID, filePath: filePath, @@ -305,7 +306,7 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable { visitor.walk(testSource.sourceFile) trailingClosureLine = visitor.trailingClosureLine } - recordIssue( + reportIssue( message(), fileID: fileID, filePath: filePath, @@ -334,31 +335,12 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable { // MARK: - Private #if canImport(SwiftSyntax509) - private let installTestObserver: Void = { - final class InlineSnapshotObserver: NSObject, XCTestObservation { - func testBundleDidFinish(_ testBundle: Bundle) { - writeInlineSnapshots() - } - } - DispatchQueue.mainSync { - XCTestObservationCenter.shared.addTestObserver(InlineSnapshotObserver()) + private let installAtExitHook: Void = { + atexit { + writeInlineSnapshots() } }() - extension DispatchQueue { - private static let key = DispatchSpecificKey() - private static let value: UInt8 = 0 - - fileprivate static func mainSync(execute block: () -> R) -> R { - Self.main.setSpecific(key: key, value: value) - if getSpecific(key: key) == value { - return block() - } else { - return main.sync(execute: block) - } - } - } - @_spi(Internals) public struct File: Hashable { public let path: StaticString public static func == (lhs: Self, rhs: Self) -> Bool { @@ -488,7 +470,8 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable { .prefix(while: { $0 == " " || $0 == "\t" }) ) let delimiter = String( - repeating: "#", count: (snapshot.actual ?? "").hashCount(isMultiline: true) + repeating: "#", + count: (snapshot.actual ?? "").hashCount(isMultiline: true) ) let leadingIndent = leadingTrivia + self.indent let snapshotLabel = TokenSyntax( @@ -575,7 +558,8 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable { MultipleTrailingClosureElementSyntax( label: snapshotLabel, closure: snapshotClosure.with( - \.leadingTrivia, snapshotClosure.leadingTrivia + .space + \.leadingTrivia, + snapshotClosure.leadingTrivia + .space ) ) } From 86691bfb1fddf907466a6bf6a18164e5073426b9 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Sun, 13 Apr 2025 09:09:23 -0700 Subject: [PATCH 03/10] wip --- Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift b/Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift index 342bca769..e2a809f47 100644 --- a/Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift +++ b/Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift @@ -549,7 +549,7 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable { functionCallExpr.trailingClosure = nil } } else { - fatalError() + fatalError("Inline snapshot visitor visited unexpected node") } case 1...: @@ -608,11 +608,11 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable { } functionCallExpr.additionalTrailingClosures.append(newElement) } else { - fatalError() + fatalError("Inline snapshot visitor visited unexpected node") } default: - fatalError() + fatalError("Inline snapshot visitor visited unexpected node") } } From ec951be39b8996fd1428541b72f525fb220d94c0 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 14 Apr 2025 10:48:06 -0700 Subject: [PATCH 04/10] wip --- .gitignore | 1 + Package.resolved | 33 --------------------------------- 2 files changed, 1 insertion(+), 33 deletions(-) delete mode 100644 Package.resolved diff --git a/.gitignore b/.gitignore index 54fcc576d..c4154a9f2 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ playground.xcworkspace # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. # Packages/ # Package.pins +Package.resolved .build/ .swiftpm diff --git a/Package.resolved b/Package.resolved deleted file mode 100644 index 9cf66bd83..000000000 --- a/Package.resolved +++ /dev/null @@ -1,33 +0,0 @@ -{ - "originHash" : "a41783670236cbc3ec9cdb23f88f801e615535963582d78dda1cea364d671298", - "pins" : [ - { - "identity" : "swift-custom-dump", - "kind" : "remoteSourceControl", - "location" : "https://github.com/pointfreeco/swift-custom-dump", - "state" : { - "revision" : "82645ec760917961cfa08c9c0c7104a57a0fa4b1", - "version" : "1.3.3" - } - }, - { - "identity" : "swift-syntax", - "kind" : "remoteSourceControl", - "location" : "https://github.com/swiftlang/swift-syntax", - "state" : { - "revision" : "0687f71944021d616d34d922343dcef086855920", - "version" : "600.0.1" - } - }, - { - "identity" : "xctest-dynamic-overlay", - "kind" : "remoteSourceControl", - "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", - "state" : { - "branch" : "test-traits", - "revision" : "67e9e7944953203ffe98fa3cc2d05fe6c11918ed" - } - } - ], - "version" : 3 -} From 83244580b98c1f0f68d954ae0b9ae991d71a3c88 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 14 Apr 2025 11:01:31 -0700 Subject: [PATCH 05/10] wip --- Package.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index b6fd068fd..cca6c6da8 100644 --- a/Package.swift +++ b/Package.swift @@ -35,7 +35,11 @@ let package = Package( ], targets: [ .target( - name: "SnapshotTestingCore" + name: "SnapshotTestingCore", + dependencies: [ + .product(name: "IssueReporting", package: "xctest-dynamic-overlay"), + .product(name: "IssueReportingTestSupport", package: "xctest-dynamic-overlay"), + ] ), .target( name: "SnapshotTesting", @@ -58,6 +62,8 @@ let package = Package( dependencies: [ "SnapshotTesting", "SnapshotTestingCustomDump", + .product(name: "IssueReporting", package: "xctest-dynamic-overlay"), + .product(name: "IssueReportingTestSupport", package: "xctest-dynamic-overlay"), .product(name: "SwiftParser", package: "swift-syntax"), .product(name: "SwiftSyntax", package: "swift-syntax"), .product(name: "SwiftSyntaxBuilder", package: "swift-syntax"), From fe15913c9c2a109dad53773a2036a191d035d1a3 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 14 Apr 2025 11:14:56 -0700 Subject: [PATCH 06/10] wip --- .github/workflows/ci.yml | 2 +- Sources/SnapshotTestingCore/Snapshotting/Any.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b45ebc78c..6db659418 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: strategy: matrix: swift: - - '5.9' + - '6.1' container: swift:${{ matrix.swift }} name: Linux (Swift ${{ matrix.swift }}) diff --git a/Sources/SnapshotTestingCore/Snapshotting/Any.swift b/Sources/SnapshotTestingCore/Snapshotting/Any.swift index eaa2e3a60..9a5b432b5 100644 --- a/Sources/SnapshotTestingCore/Snapshotting/Any.swift +++ b/Sources/SnapshotTestingCore/Snapshotting/Any.swift @@ -202,7 +202,7 @@ extension NSObject: AnySnapshotStringConvertible { return purgePointers(self.debugDescription) } #else - open var snapshotDescription: String { + public var snapshotDescription: String { return purgePointers(self.debugDescription) } #endif From b14ef62f902df108865580eb7347ca908563566a Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 14 Apr 2025 11:16:06 -0700 Subject: [PATCH 07/10] wip --- .github/workflows/ci.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6db659418..d389a9376 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,13 +13,12 @@ jobs: strategy: matrix: xcode: - - 15.4 - - '16.1' + - '16.2' name: macOS - runs-on: macos-14 + runs-on: macos-15 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Select Xcode ${{ matrix.xcode }} run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app - name: Run tests @@ -42,7 +41,7 @@ jobs: # strategy: # matrix: # swift: - # - "5.9.1" + # - "6.1" # name: Windows (Swift ${{ matrix.swift }}) # runs-on: windows-latest From 0061fc2f6abf8848356a21981effd65ab9274217 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 17 Apr 2025 12:02:47 -0700 Subject: [PATCH 08/10] fix --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index cca6c6da8..832227204 100644 --- a/Package.swift +++ b/Package.swift @@ -85,7 +85,7 @@ let package = Package( .target( name: "SnapshotUITesting", dependencies: [ - "SnapshotTesting", + "SnapshotTestingCore", ] ), ] From deff4825e0b456922ab1a17bc086ee4913d1a843 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 17 Apr 2025 12:09:17 -0700 Subject: [PATCH 09/10] wip --- .../SnapshotTestingTests/testTraits.ipad-10-2.txt | 10 +++++----- .../SnapshotTestingTests/testTraits.ipad-9-7.txt | 10 +++++----- .../SnapshotTestingTests/testTraits.ipad-mini.txt | 10 +++++----- .../SnapshotTestingTests/testTraits.ipad-pro-10-5.txt | 10 +++++----- .../SnapshotTestingTests/testTraits.ipad-pro-11.txt | 10 +++++----- .../SnapshotTestingTests/testTraits.ipad-pro-12-9.txt | 10 +++++----- .../SnapshotTestingTests/testTraits.iphone-8-plus.txt | 10 +++++----- .../SnapshotTestingTests/testTraits.iphone-8.txt | 10 +++++----- .../SnapshotTestingTests/testTraits.iphone-se.txt | 10 +++++----- .../SnapshotTestingTests/testTraits.iphone-x.txt | 10 +++++----- .../SnapshotTestingTests/testTraits.iphone-xr.txt | 10 +++++----- .../SnapshotTestingTests/testTraits.iphone-xs-max.txt | 10 +++++----- ...ler.label-accessibility-extra-extra-extra-large.txt | 2 +- ...ontroller.label-accessibility-extra-extra-large.txt | 2 +- ...hViewController.label-accessibility-extra-large.txt | 2 +- ...itsWithViewController.label-accessibility-large.txt | 2 +- ...tsWithViewController.label-accessibility-medium.txt | 2 +- ...ithViewController.label-extra-extra-extra-large.txt | 2 +- ...raitsWithViewController.label-extra-extra-large.txt | 2 +- .../testTraitsWithViewController.label-extra-large.txt | 2 +- .../testTraitsWithViewController.label-extra-small.txt | 2 +- .../testTraitsWithViewController.label-large.txt | 2 +- .../testTraitsWithViewController.label-medium.txt | 2 +- .../testTraitsWithViewController.label-small.txt | 2 +- .../SnapshotTestingTests/testUIView.2.txt | 4 ++-- 25 files changed, 74 insertions(+), 74 deletions(-) diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-10-2.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-10-2.txt index 19def6c4b..f9a8bdfc6 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-10-2.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-10-2.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-9-7.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-9-7.txt index 5b61a8817..3d42c0029 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-9-7.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-9-7.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-mini.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-mini.txt index 5b61a8817..3d42c0029 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-mini.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-mini.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-10-5.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-10-5.txt index ea083ba9c..45c0667cf 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-10-5.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-10-5.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-11.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-11.txt index 5c67f05e9..f790f6d17 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-11.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-11.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-12-9.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-12-9.txt index 90452d45a..7af2b2a5a 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-12-9.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.ipad-pro-12-9.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-8-plus.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-8-plus.txt index 93b959a4b..a74d2eabc 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-8-plus.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-8-plus.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-8.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-8.txt index 08bee7ef6..9afd49cc6 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-8.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-8.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-se.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-se.txt index 763b19fec..d4cb1ed21 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-se.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-se.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-x.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-x.txt index f54f99daf..7f2e73889 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-x.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-x.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-xr.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-xr.txt index b0bf07c2d..bff35c607 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-xr.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-xr.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-xs-max.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-xs-max.txt index 78e7d7163..bff35c607 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-xs-max.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraits.iphone-xs-max.txt @@ -1,5 +1,5 @@ -> - | > - | > - | > - | > \ No newline at end of file +> + | > + | > + | > + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-extra-extra-large.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-extra-extra-large.txt index 35d74863f..5b248233b 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-extra-extra-large.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-extra-extra-large.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-extra-large.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-extra-large.txt index 439239f60..b9d57272c 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-extra-large.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-extra-large.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-large.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-large.txt index 755c396da..1c68f8ea4 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-large.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-extra-large.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-large.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-large.txt index e66e4d7a8..12572f8e9 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-large.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-large.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-medium.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-medium.txt index 95f759b9d..8e8a1c99b 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-medium.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-accessibility-medium.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-extra-extra-large.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-extra-extra-large.txt index a17b28168..3a4337ef9 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-extra-extra-large.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-extra-extra-large.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-extra-large.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-extra-large.txt index 997d81791..11289a44c 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-extra-large.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-extra-large.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-large.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-large.txt index 66bd0f22e..38fba25dd 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-large.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-large.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-small.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-small.txt index fb9ad73b2..e0eba3a85 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-small.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-extra-small.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-large.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-large.txt index 9ecd7c7e5..a34f8ba37 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-large.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-large.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-medium.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-medium.txt index fcafb7324..631af891c 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-medium.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-medium.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-small.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-small.txt index 783b3ceab..782c7b4d7 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-small.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testTraitsWithViewController.label-small.txt @@ -1,2 +1,2 @@ > - | > \ No newline at end of file + | > \ No newline at end of file diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testUIView.2.txt b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testUIView.2.txt index de44a684f..60db5e53d 100644 --- a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testUIView.2.txt +++ b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testUIView.2.txt @@ -1,2 +1,2 @@ -> - | > \ No newline at end of file +; layer = > + | ; layer = > \ No newline at end of file From 70575026488894b948e97204582ceea748c5fb3c Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 17 Apr 2025 12:15:19 -0700 Subject: [PATCH 10/10] wip --- .spi.yml | 2 ++ Package.swift | 4 ++++ Package@swift-6.0.swift | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/.spi.yml b/.spi.yml index 569d5fd45..dc6876f5a 100644 --- a/.spi.yml +++ b/.spi.yml @@ -8,7 +8,9 @@ builder: configs: - documentation_targets: # First item in the list is the "landing" (default) target + - SnapshotTestingCore - SnapshotTesting - InlineSnapshotTesting + #- SnapshotUITesting - platform: watchos scheme: InlineSnapshotTesting diff --git a/Package.swift b/Package.swift index 832227204..c5125e306 100644 --- a/Package.swift +++ b/Package.swift @@ -15,6 +15,10 @@ let package = Package( name: "SnapshotTesting", targets: ["SnapshotTesting"] ), + .library( + name: "SnapshotTestingCore", + targets: ["SnapshotTestingCore"] + ), .library( name: "InlineSnapshotTesting", targets: ["InlineSnapshotTesting"] diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift index 738034566..21f57ed73 100644 --- a/Package@swift-6.0.swift +++ b/Package@swift-6.0.swift @@ -15,6 +15,10 @@ let package = Package( name: "SnapshotTesting", targets: ["SnapshotTesting"] ), + .library( + name: "SnapshotTestingCore", + targets: ["SnapshotTestingCore"] + ), .library( name: "InlineSnapshotTesting", targets: ["InlineSnapshotTesting"]