Skip to content
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

Fix recordIssue for Xcode beta 3. #869

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
51 changes: 39 additions & 12 deletions Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Foundation
timeout: TimeInterval = 5,
syntaxDescriptor: InlineSnapshotSyntaxDescriptor = InlineSnapshotSyntaxDescriptor(),
matches expected: (() -> String)? = nil,
file: StaticString = #filePath,
file: StaticString = #file,
function: StaticString = #function,
line: UInt = #line,
column: UInt = #column
Expand Down Expand Up @@ -70,15 +70,29 @@ import Foundation
loaded. If a timeout is unavoidable, consider setting the "timeout" parameter of
"assertInlineSnapshot" to a higher value.
""",
file: file,
line: line
fileID: file,
filePath: file,
line: line,
column: 0
)
return
case .incorrectOrder, .interrupted, .invertedFulfillment:
recordIssue("Couldn't snapshot value", file: file, line: line)
recordIssue(
"Couldn't snapshot value",
fileID: file,
filePath: file,
line: line,
column: 0
)
return
@unknown default:
recordIssue("Couldn't snapshot value", file: file, line: line)
recordIssue(
"Couldn't snapshot value",
fileID: file,
filePath: file,
line: line,
column: 0
)
return
}
}
Expand Down Expand Up @@ -119,8 +133,10 @@ import Foundation

Re-run "\(function)" to assert against the newly-recorded snapshot.
""",
file: file,
line: line
fileID: file,
filePath: file,
line: line,
column: 0
)
return
}
Expand All @@ -131,8 +147,10 @@ import Foundation
"""
No expected value to assert against.
""",
file: file,
line: line
fileID: file,
filePath: file,
line: line,
column: 0
)
return
}
Expand All @@ -152,7 +170,13 @@ import Foundation
column: column
)
} catch {
recordIssue("Threw error: \(error)", file: file, line: line)
recordIssue(
"Threw error: \(error)",
fileID: file,
filePath: file,
line: line,
column: 0
)
}
}
}
Expand Down Expand Up @@ -267,8 +291,11 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable {
}
recordIssue(
message(),
file: file,
line: trailingClosureLine.map(UInt.init) ?? line
fileID: file,
filePath: file,
line: trailingClosureLine.map(UInt.init) ?? line,
column: 0

)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SnapshotTesting/AssertSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public func assertSnapshot<Value, Format>(
line: line
)
guard let message = failure else { return }
recordIssue(message, file: file, line: line)
recordIssue(message, fileID: file, filePath: file, line: line, column: 0)
}

/// Asserts that a given value matches references on disk.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SnapshotTesting/Internal/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public func _assertInlineSnapshot<Value>(
line: line
)
guard let message = failure else { return }
recordIssue(message, file: file, line: line)
recordIssue(message, fileID: file, filePath: file, line: line, column: 0)
}

@available(
Expand Down
18 changes: 12 additions & 6 deletions Sources/SnapshotTesting/Internal/RecordIssue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ import XCTest
@_spi(Internals)
public func recordIssue(
_ message: @autoclosure () -> String,
file: StaticString = #filePath,
line: UInt = #line
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column
) {
#if canImport(Testing)
if Test.current != nil {
Issue.record(
Comment(rawValue: message()),
filePath: file.description,
line: Int(line)
sourceLocation: SourceLocation(
fileID: fileID.description,
filePath: filePath.description,
line: Int(line),
column: Int(column)
)
)
} else {
XCTFail(message(), file: file, line: line)
XCTFail(message(), file: filePath, line: line)
}
#else
XCTFail(message(), file: file, line: line)
XCTFail(message(), file: filePath, line: line)
#endif
}
Loading