Skip to content

Mark #expect(_:throws:) and #require(_:throws:) as to-be-deprecated. #875

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

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ is not statically available. The problematic overloads will also be deprecated:
-) where E: Error & Equatable
+) -> E where E: Error & Equatable

+@available(*, deprecated, message: "Examine the result of '#expect(throws:)' instead.")
+@available(swift, introduced: 6.0, deprecated: 100000.0, message: "Examine the result of '#expect(throws:)' instead.")
+@discardableResult
@freestanding(expression) public macro expect<R>(
_ comment: @autoclosure () -> Comment? = nil,
Expand All @@ -115,7 +115,7 @@ is not statically available. The problematic overloads will also be deprecated:
-)
+) -> (any Error)?

+@available(*, deprecated, message: "Examine the result of '#require(throws:)' instead.")
+@available(swift, introduced: 6.0, deprecated: 100000.0, message: "Examine the result of '#require(throws:)' instead.")
+@discardableResult
@freestanding(expression) public macro require<R>(
_ comment: @autoclosure () -> Comment? = nil,
Expand Down
4 changes: 2 additions & 2 deletions Sources/Testing/Expectations/Expectation+Macro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public macro require<R>(
/// ``expect(throws:_:sourceLocation:performing:)-1hfms`` instead. If the thrown
/// error need only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error),
/// use ``expect(throws:_:sourceLocation:performing:)-7du1h`` instead.
@available(*, deprecated, message: "Examine the result of '#expect(throws:)' instead.")
@available(swift, introduced: 6.0, deprecated: 100000.0, message: "Examine the result of '#expect(throws:)' instead.")
@discardableResult
@freestanding(expression) public macro expect<R>(
_ comment: @autoclosure () -> Comment? = nil,
Expand Down Expand Up @@ -427,7 +427,7 @@ public macro require<R>(
///
/// If `expression` should _never_ throw, simply invoke the code without using
/// this macro. The test will then fail if an error is thrown.
@available(*, deprecated, message: "Examine the result of '#require(throws:)' instead.")
@available(swift, introduced: 6.0, deprecated: 100000.0, message: "Examine the result of '#require(throws:)' instead.")
@discardableResult
@freestanding(expression) public macro require<R>(
_ comment: @autoclosure () -> Comment? = nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors
-->

@Metadata {
@Available(Swift, introduced: 6.0, deprecated: 999.0)
@Available(Xcode, introduced: 16.0, deprecated: 999.0)
@Available(Swift, introduced: 6.0)
@Available(Xcode, introduced: 16.0)
}

@DeprecationSummary {
@DeprecationSummary { <!-- Warning when compiling DocC: rdar://141785948 -->
Examine the result of ``expect(throws:_:sourceLocation:performing:)-7du1h`` or
``expect(throws:_:sourceLocation:performing:)-1hfms`` instead:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors
-->

@Metadata {
@Available(Swift, introduced: 6.0, deprecated: 999.0)
@Available(Xcode, introduced: 16.0, deprecated: 999.0)
@Available(Swift, introduced: 6.0)
@Available(Xcode, introduced: 16.0)
}

@DeprecationSummary {
@DeprecationSummary { <!-- Warning when compiling DocC: rdar://141785948 -->
Examine the result of ``require(throws:_:sourceLocation:performing:)-7n34r``
or ``require(throws:_:sourceLocation:performing:)-4djuw`` instead:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ running your test if the code doesn't throw the expected error.

To check that the code under test throws an error of any type, pass
`(any Error).self` as the first argument to either
``expect(throws:_:sourceLocation:performing:)-1xr34`` or
``require(_:_:sourceLocation:)-5l63q``:
``expect(throws:_:sourceLocation:performing:)-1hfms`` or
``require(throws:_:sourceLocation:performing:)-7n34r``:

```swift
@Test func cannotAddToppingToPizzaBeforeStartOfList() {
Expand Down
8 changes: 0 additions & 8 deletions Tests/TestingTests/IssueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ final class IssueTests: XCTestCase {
}.run(configuration: .init())
}

@available(*, deprecated)
func testErrorCheckingWithExpect() async throws {
let expectationFailed = expectation(description: "Expectation failed")
expectationFailed.isInverted = true
Expand Down Expand Up @@ -540,7 +539,6 @@ final class IssueTests: XCTestCase {
await fulfillment(of: [expectationFailed], timeout: 0.0)
}

@available(*, deprecated)
func testErrorCheckingWithExpect_Mismatching() async throws {
let expectationFailed = expectation(description: "Expectation failed")
expectationFailed.expectedFulfillmentCount = 13
Expand Down Expand Up @@ -665,7 +663,6 @@ final class IssueTests: XCTestCase {
await fulfillment(of: [expectationFailed], timeout: 0.0)
}

@available(*, deprecated)
func testErrorCheckingWithExpectAsync() async throws {
let expectationFailed = expectation(description: "Expectation failed")
expectationFailed.isInverted = true
Expand Down Expand Up @@ -709,7 +706,6 @@ final class IssueTests: XCTestCase {
await fulfillment(of: [expectationFailed], timeout: 0.0)
}

@available(*, deprecated)
func testErrorCheckingWithExpectAsync_Mismatching() async throws {
let expectationFailed = expectation(description: "Expectation failed")
expectationFailed.expectedFulfillmentCount = 13
Expand Down Expand Up @@ -826,7 +822,6 @@ final class IssueTests: XCTestCase {
await fulfillment(of: [expectationFailed], timeout: 0.0)
}

@available(*, deprecated)
func testErrorCheckingWithExpect_ThrowingFromErrorMatcher() async throws {
let errorCaught = expectation(description: "Error matcher's error caught")
let expectationFailed = expectation(description: "Expectation failed")
Expand Down Expand Up @@ -854,7 +849,6 @@ final class IssueTests: XCTestCase {
await fulfillment(of: [errorCaught, expectationFailed], timeout: 0.0)
}

@available(*, deprecated)
func testErrorCheckingWithExpectAsync_ThrowingFromErrorMatcher() async throws {
let errorCaught = expectation(description: "Error matcher's error caught")
let expectationFailed = expectation(description: "Expectation failed")
Expand Down Expand Up @@ -882,7 +876,6 @@ final class IssueTests: XCTestCase {
await fulfillment(of: [errorCaught, expectationFailed], timeout: 0.0)
}

@available(*, deprecated)
func testErrorCheckingWithRequire_ThrowingFromErrorMatcher() async throws {
let errorCaught = expectation(description: "Error matcher's error caught")
let expectationFailed = expectation(description: "Expectation failed")
Expand Down Expand Up @@ -911,7 +904,6 @@ final class IssueTests: XCTestCase {
await fulfillment(of: [errorCaught, expectationFailed], timeout: 0.0)
}

@available(*, deprecated)
func testErrorCheckingWithRequireAsync_ThrowingFromErrorMatcher() async throws {
let errorCaught = expectation(description: "Error matcher's error caught")
let expectationFailed = expectation(description: "Expectation failed")
Expand Down