Skip to content
Draft
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
4 changes: 2 additions & 2 deletions Sources/Testing/Test+Cancellation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ extension Test: TestCancellable {
/// attribute the cancellation.
///
/// - Throws: An error indicating that the current test or test case has been
/// cancelled.
/// cancelled. The testing library does not treat this error as a test
/// failure.
///
/// The testing library runs each test and each test case in its own task.
/// When you call this function, the testing library cancels the task
Expand Down Expand Up @@ -206,7 +207,6 @@ extension Test: TestCancellable {
/// - Important: If the current task is not associated with a test (for
/// example, because it was created with [`Task.detached(name:priority:operation:)`](https://developer.apple.com/documentation/swift/task/detached(name:priority:operation:)-795w1))
/// this function records an issue and cancels the current task.
@_spi(Experimental)
public static func cancel(_ comment: Comment? = nil, sourceLocation: SourceLocation = #_sourceLocation) throws -> Never {
let skipInfo = SkipInfo(comment: comment, sourceContext: SourceContext(backtrace: nil, sourceLocation: sourceLocation))
try Self.cancel(with: skipInfo)
Expand Down
20 changes: 9 additions & 11 deletions Sources/Testing/Testing.docc/EnablingAndDisabling.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,17 @@ func allIngredientsAvailable(for food: Food) -> Bool { ... }
func makeSundae() async throws { ... }
```

<!--
### End a test after it has already started

TODO: document Test.cancel() and Test.Case.cancel() here

If a test has already started running and you determine it cannot complete and
should end early without failing, use ``Test/cancel(_:sourceLocation:)`` to
cancel the test:
If a test is running and you determine it cannot complete and should end early
without failing, use ``Test/cancel(_:sourceLocation:)`` to cancel the test:

```swift
...
@Test("Can make sundaes")
func makeSundae() throws {
guard let iceCreamMaker = IceCreamMaker() else {
try Test.cancel("The ice cream maker isn't working right now")
}
...
}
```

If the test is parameterized and you only want to cancel the current test case
rather than the entire test, use ``Test/Case/cancel(_:sourceLocation:)``.
-->
14 changes: 3 additions & 11 deletions Sources/Testing/Testing.docc/MigratingFromXCTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,9 @@ test function with an instance of this trait type to control whether it runs:
}
}

<!-- TODO: document Test.cancel() and Test.Case.cancel() here, and update
relevant links to use proper DocC symbol references.

If a test has already started running and you determine it cannot complete and
should end early without failing, use `Test/cancel(_:sourceLocation:)` instead
of [`XCTSkip`](https://developer.apple.com/documentation/xctest/xctskip) to
cancel the task associated with the current test:
If a test is running and you determine it cannot complete and should end early
without failing, use ``Test/cancel(_:sourceLocation:)`` instead of [`XCTSkip`](https://developer.apple.com/documentation/xctest/xctskip)
to cancel the task associated with the current test:

@Row {
@Column {
Expand Down Expand Up @@ -593,10 +589,6 @@ cancel the task associated with the current test:
}
}

If the test is parameterized and you only want to cancel the current test case
rather than the entire test, use `Test/Case/cancel(_:sourceLocation:)`.
-->

### Annotate known issues

A test may have a known issue that sometimes or always prevents it from passing.
Expand Down