Skip to content

Diff tool arguments support #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions Sources/SnapshotTesting/AssertSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import XCTest
/// diffTool = "ksdiff"
public var diffTool: String? = nil

/// Diff tool arguments which will be passed at the end of the command.
public var diffToolArgs: String?

/// Whether or not to record all new references.
public var isRecording = false

Expand Down Expand Up @@ -286,18 +289,29 @@ public func verifySnapshot<Value, Format>(
#endif
}

let diffMessage = diffTool
.map { "\($0) \"\(snapshotFileUrl.path)\" \"\(failedSnapshotFileUrl.path)\"" }
?? """
@\(minus)
"\(snapshotFileUrl.path)"
@\(plus)
"\(failedSnapshotFileUrl.path)"
let diffMessage: String

if let diffTool = diffTool {
let message = "\(diffTool) \"\(snapshotFileUrl.path)\" \"\(failedSnapshotFileUrl.path)\""

To configure output for a custom diff tool, like Kaleidoscope:
if let diffToolArgs = diffToolArgs {
diffMessage = message + " " + diffToolArgs
} else {
diffMessage = message
}
} else {
diffMessage = """
@\(minus)
"\(snapshotFileUrl.path)"
@\(plus)
"\(failedSnapshotFileUrl.path)"

To configure output for a custom diff tool, like Kaleidoscope:

SnapshotTesting.diffTool = "ksdiff"
"""
}

SnapshotTesting.diffTool = "ksdiff"
"""
return """
Snapshot does not match reference.

Expand Down