From f6c51fa7609b1057ca5420127440413c54971ff6 Mon Sep 17 00:00:00 2001 From: mbrandonw Date: Mon, 8 Jul 2024 20:22:29 +0000 Subject: [PATCH] Run swift-format --- Sources/SnapshotTesting/Diffing.swift | 2 +- .../SnapshotTestingConfiguration.swift | 20 +- .../SnapshotTesting/SnapshotsTestTrait.swift | 2 +- .../AssertInlineSnapshotSwiftTests.swift | 504 +++++++++--------- .../SnapshotTestingTests.swift | 2 +- .../SnapshotsTraitTests.swift | 57 +- .../WithSnapshotTestingTests.swift | 3 +- 7 files changed, 294 insertions(+), 296 deletions(-) diff --git a/Sources/SnapshotTesting/Diffing.swift b/Sources/SnapshotTesting/Diffing.swift index 357159fff..c189578ec 100644 --- a/Sources/SnapshotTesting/Diffing.swift +++ b/Sources/SnapshotTesting/Diffing.swift @@ -14,7 +14,7 @@ public struct Diffing { public var diff: (Value, Value) -> (String, [XCTAttachment])? /// Creates a new `Diffing` on `Value`. - /// + /// /// - Parameters: /// - toData: A function used to convert a value _to_ data. /// - fromData: A function used to produce a value _from_ data. diff --git a/Sources/SnapshotTesting/SnapshotTestingConfiguration.swift b/Sources/SnapshotTesting/SnapshotTestingConfiguration.swift index 93c2e7122..28cba97fe 100644 --- a/Sources/SnapshotTesting/SnapshotTestingConfiguration.swift +++ b/Sources/SnapshotTesting/SnapshotTestingConfiguration.swift @@ -61,7 +61,7 @@ public func withSnapshotTesting( public struct SnapshotTestingConfiguration: Sendable { @_spi(Internals) @TaskLocal public static var current: Self? - + /// The diff tool use to print helpful test failure messages. /// /// See ``DiffTool-swift.struct`` for more information. @@ -79,7 +79,7 @@ public struct SnapshotTestingConfiguration: Sendable { self.diffTool = diffTool self.record = record } - + /// The record mode of the snapshot test. /// /// There are 4 primary strategies for recording: ``Record-swift.struct/all``, @@ -87,7 +87,7 @@ public struct SnapshotTestingConfiguration: Sendable { /// ``Record-swift.struct/failed`` public struct Record: Equatable, Sendable { private let storage: Storage - + public init?(rawValue: String) { switch rawValue { case "all": @@ -114,7 +114,7 @@ public struct SnapshotTestingConfiguration: Sendable { /// Records only the snapshots that are missing from disk. public static let missing = Self(storage: .missing) - /// Does not record any snapshots. If a snapshot is missing a test failure will be raised. This + /// Does not record any snapshots. If a snapshot is missing a test failure will be raised. This /// option is appropriate when running tests on CI so that re-tries of tests do not /// surprisingly pass after snapshots are unexpectedly generated. public static let never = Self(storage: .never) @@ -130,14 +130,14 @@ public struct SnapshotTestingConfiguration: Sendable { case never } } - + /// Describes the diff command used to diff two files on disk. /// /// This type can be created with a closure that takes two arguments: the first argument is /// is a file path to the currently recorded snapshot on disk, and the second argument is the /// file path to a _failed_ snapshot that was recorded to a temporary location on disk. You can /// use these two file paths to construct a command that can be used to compare the two files. - /// + /// /// For example, to use ImageMagick's `compare` tool and pipe the result into Preview.app, you /// could create the following `DiffTool`: /// @@ -193,22 +193,22 @@ public struct SnapshotTestingConfiguration: Sendable { } @available( - iOS, + iOS, deprecated: 9999, message: "Use '.all' instead of 'true', and '.missing' instead of 'false'." ) @available( - macOS, + macOS, deprecated: 9999, message: "Use '.all' instead of 'true', and '.missing' instead of 'false'." ) @available( - tvOS, + tvOS, deprecated: 9999, message: "Use '.all' instead of 'true', and '.missing' instead of 'false'." ) @available( - watchOS, + watchOS, deprecated: 9999, message: "Use '.all' instead of 'true', and '.missing' instead of 'false'." ) diff --git a/Sources/SnapshotTesting/SnapshotsTestTrait.swift b/Sources/SnapshotTesting/SnapshotsTestTrait.swift index 4a392ff16..6b4b82f77 100644 --- a/Sources/SnapshotTesting/SnapshotsTestTrait.swift +++ b/Sources/SnapshotTesting/SnapshotsTestTrait.swift @@ -19,7 +19,7 @@ ) ) } - + /// Configure snapshot testing in a suite or test. /// /// - Parameter configuration: The configuration to use. diff --git a/Tests/InlineSnapshotTestingTests/AssertInlineSnapshotSwiftTests.swift b/Tests/InlineSnapshotTestingTests/AssertInlineSnapshotSwiftTests.swift index 15a1f2eb2..448925cd5 100644 --- a/Tests/InlineSnapshotTestingTests/AssertInlineSnapshotSwiftTests.swift +++ b/Tests/InlineSnapshotTestingTests/AssertInlineSnapshotSwiftTests.swift @@ -1,307 +1,307 @@ #if canImport(Testing) -import Testing -import Foundation -import InlineSnapshotTesting -@_spi(Experimental) import SnapshotTesting - -@Suite( - .snapshots( - record: .missing + import Testing + import Foundation + import InlineSnapshotTesting + @_spi(Experimental) import SnapshotTesting + + @Suite( + .snapshots( + record: .missing + ) ) -) -struct AssertInlineSnapshotTests { - @Test func inlineSnapshot() { - assertInlineSnapshot(of: ["Hello", "World"], as: .dump) { - """ - ▿ 2 elements - - "Hello" - - "World" - - """ - } - } - - @Test func inlineSnapshot_NamedTrailingClosure() { - assertInlineSnapshot( - of: ["Hello", "World"], as: .dump, - matches: { + struct AssertInlineSnapshotTests { + @Test func inlineSnapshot() { + assertInlineSnapshot(of: ["Hello", "World"], as: .dump) { """ ▿ 2 elements - "Hello" - "World" """ - }) - } - - @Test func inlineSnapshot_Escaping() { - assertInlineSnapshot(of: "Hello\"\"\"#, world", as: .lines) { - ##""" - Hello"""#, world - """## + } } - } - - @Test func customInlineSnapshot() { - assertCustomInlineSnapshot { - "Hello" - } is: { - """ - - "Hello" - """ + @Test func inlineSnapshot_NamedTrailingClosure() { + assertInlineSnapshot( + of: ["Hello", "World"], as: .dump, + matches: { + """ + ▿ 2 elements + - "Hello" + - "World" + + """ + }) } - } - @Test func customInlineSnapshot_Multiline() { - assertCustomInlineSnapshot { - """ - "Hello" - "World" - """ - } is: { - #""" - - "\"Hello\"\n\"World\"" - - """# + @Test func inlineSnapshot_Escaping() { + assertInlineSnapshot(of: "Hello\"\"\"#, world", as: .lines) { + ##""" + Hello"""#, world + """## + } } - } - @Test func customInlineSnapshot_SingleTrailingClosure() { - assertCustomInlineSnapshot(of: { "Hello" }) { - """ - - "Hello" + @Test func customInlineSnapshot() { + assertCustomInlineSnapshot { + "Hello" + } is: { + """ + - "Hello" - """ + """ + } } - } - @Test func customInlineSnapshot_MultilineSingleTrailingClosure() { - assertCustomInlineSnapshot( - of: { "Hello" } - ) { - """ - - "Hello" + @Test func customInlineSnapshot_Multiline() { + assertCustomInlineSnapshot { + """ + "Hello" + "World" + """ + } is: { + #""" + - "\"Hello\"\n\"World\"" - """ + """# + } } - } - @Test func customInlineSnapshot_NoTrailingClosure() { - assertCustomInlineSnapshot( - of: { "Hello" }, - is: { + @Test func customInlineSnapshot_SingleTrailingClosure() { + assertCustomInlineSnapshot(of: { "Hello" }) { """ - "Hello" """ } - ) - } - - @Test func argumentlessInlineSnapshot() { - func assertArgumentlessInlineSnapshot( - expected: (() -> String)? = nil, - file: StaticString = #filePath, - function: StaticString = #function, - line: UInt = #line, - column: UInt = #column - ) { - assertInlineSnapshot( - of: "Hello", - as: .dump, - syntaxDescriptor: InlineSnapshotSyntaxDescriptor( - trailingClosureLabel: "is", - trailingClosureOffset: 1 - ), - matches: expected, - file: file, - function: function, - line: line, - column: column - ) } - assertArgumentlessInlineSnapshot { - """ - - "Hello" + @Test func customInlineSnapshot_MultilineSingleTrailingClosure() { + assertCustomInlineSnapshot( + of: { "Hello" } + ) { + """ + - "Hello" - """ + """ + } } - } - @Test func multipleInlineSnapshots() { - func assertResponse( - of url: () -> String, - head: (() -> String)? = nil, - body: (() -> String)? = nil, - file: StaticString = #filePath, - function: StaticString = #function, - line: UInt = #line, - column: UInt = #column - ) { - assertInlineSnapshot( - of: """ - HTTP/1.1 200 OK - Content-Type: text/html; charset=utf-8 - """, - as: .lines, - message: "Head did not match", - syntaxDescriptor: InlineSnapshotSyntaxDescriptor( - trailingClosureLabel: "head", - trailingClosureOffset: 1 - ), - matches: head, - file: file, - function: function, - line: line, - column: column - ) - assertInlineSnapshot( - of: """ - - - - - Point-Free - - - -

What's the point?

- - - """, - as: .lines, - message: "Body did not match", - syntaxDescriptor: InlineSnapshotSyntaxDescriptor( - trailingClosureLabel: "body", - trailingClosureOffset: 2 - ), - matches: body, - file: file, - function: function, - line: line, - column: column + @Test func customInlineSnapshot_NoTrailingClosure() { + assertCustomInlineSnapshot( + of: { "Hello" }, + is: { + """ + - "Hello" + + """ + } ) } - assertResponse { - """ - https://www.pointfree.co/ - """ - } head: { - """ - HTTP/1.1 200 OK - Content-Type: text/html; charset=utf-8 - """ - } body: { - """ - - - - - Point-Free - - - -

What's the point?

- - - """ - } - } + @Test func argumentlessInlineSnapshot() { + func assertArgumentlessInlineSnapshot( + expected: (() -> String)? = nil, + file: StaticString = #filePath, + function: StaticString = #function, + line: UInt = #line, + column: UInt = #column + ) { + assertInlineSnapshot( + of: "Hello", + as: .dump, + syntaxDescriptor: InlineSnapshotSyntaxDescriptor( + trailingClosureLabel: "is", + trailingClosureOffset: 1 + ), + matches: expected, + file: file, + function: function, + line: line, + column: column + ) + } - @Test func asyncThrowing() async throws { - func assertAsyncThrowingInlineSnapshot( - of value: () -> String, - is expected: (() -> String)? = nil, - file: StaticString = #filePath, - function: StaticString = #function, - line: UInt = #line, - column: UInt = #column - ) async throws { - assertInlineSnapshot( - of: value(), - as: .dump, - syntaxDescriptor: InlineSnapshotSyntaxDescriptor( - trailingClosureLabel: "is", - trailingClosureOffset: 1 - ), - matches: expected, - file: file, - function: function, - line: line, - column: column - ) + assertArgumentlessInlineSnapshot { + """ + - "Hello" + + """ + } } - try await assertAsyncThrowingInlineSnapshot { - "Hello" - } is: { - """ - - "Hello" + @Test func multipleInlineSnapshots() { + func assertResponse( + of url: () -> String, + head: (() -> String)? = nil, + body: (() -> String)? = nil, + file: StaticString = #filePath, + function: StaticString = #function, + line: UInt = #line, + column: UInt = #column + ) { + assertInlineSnapshot( + of: """ + HTTP/1.1 200 OK + Content-Type: text/html; charset=utf-8 + """, + as: .lines, + message: "Head did not match", + syntaxDescriptor: InlineSnapshotSyntaxDescriptor( + trailingClosureLabel: "head", + trailingClosureOffset: 1 + ), + matches: head, + file: file, + function: function, + line: line, + column: column + ) + assertInlineSnapshot( + of: """ + + + + + Point-Free + + + +

What's the point?

+ + + """, + as: .lines, + message: "Body did not match", + syntaxDescriptor: InlineSnapshotSyntaxDescriptor( + trailingClosureLabel: "body", + trailingClosureOffset: 2 + ), + matches: body, + file: file, + function: function, + line: line, + column: column + ) + } - """ + assertResponse { + """ + https://www.pointfree.co/ + """ + } head: { + """ + HTTP/1.1 200 OK + Content-Type: text/html; charset=utf-8 + """ + } body: { + """ + + + + + Point-Free + + + +

What's the point?

+ + + """ + } } - } - @Test func nestedInClosureFunction() { - func withDependencies(operation: () -> Void) { - operation() - } + @Test func asyncThrowing() async throws { + func assertAsyncThrowingInlineSnapshot( + of value: () -> String, + is expected: (() -> String)? = nil, + file: StaticString = #filePath, + function: StaticString = #function, + line: UInt = #line, + column: UInt = #column + ) async throws { + assertInlineSnapshot( + of: value(), + as: .dump, + syntaxDescriptor: InlineSnapshotSyntaxDescriptor( + trailingClosureLabel: "is", + trailingClosureOffset: 1 + ), + matches: expected, + file: file, + function: function, + line: line, + column: column + ) + } - withDependencies { - assertInlineSnapshot(of: "Hello", as: .dump) { + try await assertAsyncThrowingInlineSnapshot { + "Hello" + } is: { """ - "Hello" """ } } - } - @Test func carriageReturnInlineSnapshot() { - assertInlineSnapshot(of: "This is a line\r\nAnd this is a line\r\n", as: .lines) { - """ - This is a line\r - And this is a line\r + @Test func nestedInClosureFunction() { + func withDependencies(operation: () -> Void) { + operation() + } + + withDependencies { + assertInlineSnapshot(of: "Hello", as: .dump) { + """ + - "Hello" - """ + """ + } + } } - } - @Test func carriageReturnRawInlineSnapshot() { - assertInlineSnapshot(of: "\"\"\"#This is a line\r\nAnd this is a line\r\n", as: .lines) { - ##""" - """#This is a line\##r - And this is a line\##r + @Test func carriageReturnInlineSnapshot() { + assertInlineSnapshot(of: "This is a line\r\nAnd this is a line\r\n", as: .lines) { + """ + This is a line\r + And this is a line\r - """## + """ + } + } + + @Test func carriageReturnRawInlineSnapshot() { + assertInlineSnapshot(of: "\"\"\"#This is a line\r\nAnd this is a line\r\n", as: .lines) { + ##""" + """#This is a line\##r + And this is a line\##r + + """## + } } } -} - -private func assertCustomInlineSnapshot( - of value: () -> String, - is expected: (() -> String)? = nil, - file: StaticString = #filePath, - function: StaticString = #function, - line: UInt = #line, - column: UInt = #column -) { - assertInlineSnapshot( - of: value(), - as: .dump, - syntaxDescriptor: InlineSnapshotSyntaxDescriptor( - trailingClosureLabel: "is", - trailingClosureOffset: 1 - ), - matches: expected, - file: file, - function: function, - line: line, - column: column - ) -} + + private func assertCustomInlineSnapshot( + of value: () -> String, + is expected: (() -> String)? = nil, + file: StaticString = #filePath, + function: StaticString = #function, + line: UInt = #line, + column: UInt = #column + ) { + assertInlineSnapshot( + of: value(), + as: .dump, + syntaxDescriptor: InlineSnapshotSyntaxDescriptor( + trailingClosureLabel: "is", + trailingClosureOffset: 1 + ), + matches: expected, + file: file, + function: function, + line: line, + column: column + ) + } #endif diff --git a/Tests/SnapshotTestingTests/SnapshotTestingTests.swift b/Tests/SnapshotTestingTests/SnapshotTestingTests.swift index 95a66b18f..047f6af94 100644 --- a/Tests/SnapshotTestingTests/SnapshotTestingTests.swift +++ b/Tests/SnapshotTestingTests/SnapshotTestingTests.swift @@ -23,7 +23,7 @@ import XCTest final class SnapshotTestingTests: XCTestCase { override func invokeTest() { withSnapshotTesting( - record: .missing, + record: .missing, diffTool: .ksdiff ) { super.invokeTest() diff --git a/Tests/SnapshotTestingTests/SnapshotsTraitTests.swift b/Tests/SnapshotTestingTests/SnapshotsTraitTests.swift index a3a7ad2f5..0d2a685d2 100644 --- a/Tests/SnapshotTestingTests/SnapshotsTraitTests.swift +++ b/Tests/SnapshotTestingTests/SnapshotsTraitTests.swift @@ -1,54 +1,53 @@ #if compiler(>=6) && canImport(Testing) -@_spi(Experimental) import Testing -@_spi(Experimental) @_spi(Internals) import SnapshotTesting + @_spi(Experimental) import Testing + @_spi(Experimental) @_spi(Internals) import SnapshotTesting - -struct SnapshotsTraitTests { - @Test(.snapshots(diffTool: "ksdiff")) - func testDiffTool() { - #expect( - SnapshotTestingConfiguration.current? - .diffTool?(currentFilePath: "old.png", failedFilePath: "new.png") - == "ksdiff old.png new.png" - ) - } - - @Suite(.snapshots(diffTool: "ksdiff")) - struct OverrideDiffTool { - @Test(.snapshots(diffTool: "difftool")) - func testDiffToolOverride() { + struct SnapshotsTraitTests { + @Test(.snapshots(diffTool: "ksdiff")) + func testDiffTool() { #expect( SnapshotTestingConfiguration.current? .diffTool?(currentFilePath: "old.png", failedFilePath: "new.png") - == "difftool old.png new.png" + == "ksdiff old.png new.png" ) } - @Suite(.snapshots(record: .all)) - struct OverrideRecord { - @Test - func config() { + @Suite(.snapshots(diffTool: "ksdiff")) + struct OverrideDiffTool { + @Test(.snapshots(diffTool: "difftool")) + func testDiffToolOverride() { #expect( SnapshotTestingConfiguration.current? .diffTool?(currentFilePath: "old.png", failedFilePath: "new.png") - == "ksdiff old.png new.png" + == "difftool old.png new.png" ) - #expect(SnapshotTestingConfiguration.current?.record == .all) } - @Suite(.snapshots(record: .failed, diffTool: "diff")) - struct OverrideDiffToolAndRecord { + @Suite(.snapshots(record: .all)) + struct OverrideRecord { @Test func config() { #expect( SnapshotTestingConfiguration.current? .diffTool?(currentFilePath: "old.png", failedFilePath: "new.png") - == "diff old.png new.png" + == "ksdiff old.png new.png" ) - #expect(SnapshotTestingConfiguration.current?.record == .failed) + #expect(SnapshotTestingConfiguration.current?.record == .all) + } + + @Suite(.snapshots(record: .failed, diffTool: "diff")) + struct OverrideDiffToolAndRecord { + @Test + func config() { + #expect( + SnapshotTestingConfiguration.current? + .diffTool?(currentFilePath: "old.png", failedFilePath: "new.png") + == "diff old.png new.png" + ) + #expect(SnapshotTestingConfiguration.current?.record == .failed) + } } } } } -} #endif diff --git a/Tests/SnapshotTestingTests/WithSnapshotTestingTests.swift b/Tests/SnapshotTestingTests/WithSnapshotTestingTests.swift index b6f6c6f57..0116964ec 100644 --- a/Tests/SnapshotTestingTests/WithSnapshotTestingTests.swift +++ b/Tests/SnapshotTestingTests/WithSnapshotTestingTests.swift @@ -1,6 +1,5 @@ -import XCTest - @_spi(Internals) @testable import SnapshotTesting +import XCTest class WithSnapshotTestingTests: XCTestCase { func testNesting() {