Skip to content

Commit

Permalink
Disfavor another unimplemented deprecation (#123)
Browse files Browse the repository at this point in the history
* Disfavor another `unimplemented` deprecation

When XCTestDynamicOverlay and IssueReporting are both imported into a
file, the deprecated version takes precedence in certain situations,
triggering a warning. This PR should address.

* fix
  • Loading branch information
stephencelis authored Sep 6, 2024
1 parent 3788750 commit 75f739f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Examples/ExamplesTests/SwiftTestingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
withKnownIssue {
reportIssue()
} matching: { issue in
issue.description == "Expectation failed: "
issue.description == "Issue recorded"
}
}

@Test func reportIssue_CustomMessage() {
withKnownIssue {
reportIssue("Something went wrong")
} matching: { issue in
issue.description == "Expectation failed: Something went wrong"
issue.description == "Issue recorded: Something went wrong"
}
}

Expand Down
19 changes: 3 additions & 16 deletions Sources/XCTestDynamicOverlay/Internal/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public var XCTCurrentTestCase: AnyObject? {
}

@_disfavoredOverload
@available(*, deprecated, renamed: "unimplemented(_:placeholder:)")
@available(*, unavailable, renamed: "unimplemented(_:placeholder:)")
public func unimplemented<Result>(
_ description: @autoclosure @escaping @Sendable () -> String = "",
file filePath: StaticString = #filePath,
Expand All @@ -260,23 +260,10 @@ public func unimplemented<Result>(
line: UInt = #line,
column: UInt = #column
) -> Result {
let description = description()
_fail(
description,
nil,
fileID: fileID,
filePath: filePath,
function: function,
line: line,
column: column
)
do {
return try _generatePlaceholder()
} catch {
_unimplementedFatalError(description, file: filePath, line: line)
}
fatalError()
}

@_disfavoredOverload
@available(*, deprecated, renamed: "unimplemented(_:placeholder:)")
public func unimplemented<each Argument, Result>(
_ description: @autoclosure @escaping @Sendable () -> String = "",
Expand Down
29 changes: 29 additions & 0 deletions Tests/IssueReportingTests/UnimplementedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,34 @@
"""
}
}

@MainActor
@Test func mainActor() throws {
final class Model: Sendable {
let line = #line + 1
let callback: @Sendable @MainActor () throws -> Void = IssueReporting.unimplemented()
}

let model = Model()
try withKnownIssue {
try withKnownIssue {
_ = try model.callback()
} matching: { issue in
issue.description == """
Issue recorded: Unimplemented …
Defined in 'Model' at:
IssueReportingTests/UnimplementedTests.swift:\(model.line)
Invoked with:
()
"""
}
} matching: { issue in
issue.description == """
Caught error: UnimplementedFailure(description: "")
"""
}
}
}
#endif
9 changes: 4 additions & 5 deletions Tests/XCTestDynamicOverlayTests/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ struct User { let id: UUID }
@available(*, deprecated)
@MainActor let fm01: @MainActor () -> Int = unimplemented("fm01")

@available(*, deprecated)
private struct Autoclosing {
init(
_: @autoclosure () -> Int = unimplemented(),
_: @autoclosure () async -> Int = unimplemented(),
_: @autoclosure () throws -> Int = unimplemented(),
_: @autoclosure () async throws -> Int = unimplemented()
_: @autoclosure () -> Int = unimplemented(placeholder: 0),
_: @autoclosure () async -> Int = unimplemented(placeholder: 0),
_: @autoclosure () throws -> Int = unimplemented(placeholder: 0),
_: @autoclosure () async throws -> Int = unimplemented(placeholder: 0)
) async {}
}

0 comments on commit 75f739f

Please sign in to comment.