Skip to content

Commit 644b963

Browse files
committed
Mark #expect(_:throws:) and #require(_:throws:) as to-be-deprecated. (#875)
These symbols should go through a transition period where they are documented as to-be-deprecated rather than being deprecated outright. My mistake. With this change applied, Xcode treats these macros as deprecated (deemphasizing them in autocomplete, for instance) and DocC marks them as deprecated in an unspecified Swift version, but no warning is emitted if they are used. This is consistent with API marked `API_TO_BE_DEPRECATED` or `deprecated: 100000.0` in Apple's SDKs. > [!NOTE] > There is a bug in the DocC compiler that emits a diagnostic of the form: > > > ⚠️ 'require(_:sourceLocation:performing:throws:)' isn't unconditionally deprecated > > This issue is being tracked already with rdar://141785948. Resolves #873. - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 39d9c14 commit 644b963

File tree

5 files changed

+10
-18
lines changed

5 files changed

+10
-18
lines changed

Documentation/Proposals/0006-return-errors-from-expect-throws.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ is not statically available. The problematic overloads will also be deprecated:
105105
-) where E: Error & Equatable
106106
+) -> E where E: Error & Equatable
107107

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

118-
+@available(*, deprecated, message: "Examine the result of '#require(throws:)' instead.")
118+
+@available(swift, introduced: 6.0, deprecated: 100000.0, message: "Examine the result of '#require(throws:)' instead.")
119119
+@discardableResult
120120
@freestanding(expression) public macro require<R>(
121121
_ comment: @autoclosure () -> Comment? = nil,

Sources/Testing/Expectations/Expectation+Macro.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public macro require<R>(
375375
/// ``expect(throws:_:sourceLocation:performing:)-1hfms`` instead. If the thrown
376376
/// error need only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error),
377377
/// use ``expect(throws:_:sourceLocation:performing:)-7du1h`` instead.
378-
@available(*, deprecated, message: "Examine the result of '#expect(throws:)' instead.")
378+
@available(swift, introduced: 6.0, deprecated: 100000.0, message: "Examine the result of '#expect(throws:)' instead.")
379379
@discardableResult
380380
@freestanding(expression) public macro expect<R>(
381381
_ comment: @autoclosure () -> Comment? = nil,
@@ -427,7 +427,7 @@ public macro require<R>(
427427
///
428428
/// If `expression` should _never_ throw, simply invoke the code without using
429429
/// this macro. The test will then fail if an error is thrown.
430-
@available(*, deprecated, message: "Examine the result of '#require(throws:)' instead.")
430+
@available(swift, introduced: 6.0, deprecated: 100000.0, message: "Examine the result of '#require(throws:)' instead.")
431431
@discardableResult
432432
@freestanding(expression) public macro require<R>(
433433
_ comment: @autoclosure () -> Comment? = nil,

Sources/Testing/Testing.docc/AvailabilityStubs/ExpectComplexThrows.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors
1111
-->
1212

1313
@Metadata {
14-
@Available(Swift, introduced: 6.0, deprecated: 999.0)
15-
@Available(Xcode, introduced: 16.0, deprecated: 999.0)
14+
@Available(Swift, introduced: 6.0)
15+
@Available(Xcode, introduced: 16.0)
1616
}
1717

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

Sources/Testing/Testing.docc/AvailabilityStubs/RequireComplexThrows.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors
1111
-->
1212

1313
@Metadata {
14-
@Available(Swift, introduced: 6.0, deprecated: 999.0)
15-
@Available(Xcode, introduced: 16.0, deprecated: 999.0)
14+
@Available(Swift, introduced: 6.0)
15+
@Available(Xcode, introduced: 16.0)
1616
}
1717

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

Tests/TestingTests/IssueTests.swift

-8
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ final class IssueTests: XCTestCase {
491491
}.run(configuration: .init())
492492
}
493493

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)