Skip to content
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
34 changes: 34 additions & 0 deletions Sources/Testing/Expectations/Expectation+Macro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,23 @@ 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.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.0)
/// @Available(Xcode, introduced: 16.0)
/// }
///
/// @DeprecationSummary { <!-- Warning when compiling DocC: rdar://141785948 -->
/// Examine the result of ``expect(throws:_:sourceLocation:performing:)-7du1h``
/// or ``expect(throws:_:sourceLocation:performing:)-1hfms`` instead:
///
/// ```swift
/// let error = #expect(throws: FoodTruckError.self) {
/// ...
/// }
/// #expect(error?.napkinCount == 0)
/// ```
/// }
@available(swift, deprecated: 100000.0, message: "Examine the result of '#expect(throws:)' instead.")
@discardableResult
@freestanding(expression) public macro expect<R>(
Expand Down Expand Up @@ -427,6 +444,23 @@ 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.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.0)
/// @Available(Xcode, introduced: 16.0)
/// }
///
/// @DeprecationSummary { <!-- Warning when compiling DocC: rdar://141785948 -->
/// Examine the result of ``expect(throws:_:sourceLocation:performing:)-7du1h``
/// or ``expect(throws:_:sourceLocation:performing:)-1hfms`` instead:
///
/// ```swift
/// let error = try #require(throws: FoodTruckError.self) {
/// ...
/// }
/// #expect(error.napkinCount == 0)
/// ```
/// }
@available(swift, deprecated: 100000.0, message: "Examine the result of '#require(throws:)' instead.")
@discardableResult
@freestanding(expression) public macro require<R>(
Expand Down
5 changes: 5 additions & 0 deletions Sources/Testing/Issues/Confirmation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public func confirmation<R>(
///
/// If an exact count is expected, use
/// ``confirmation(_:expectedCount:isolation:sourceLocation:_:)-5mqz2`` instead.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.1)
/// @Available(Xcode, introduced: 16.3)
/// }
public func confirmation<R>(
_ comment: Comment? = nil,
expectedCount: some RangeExpression<Int> & Sequence<Int> & Sendable,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

39 changes: 39 additions & 0 deletions Sources/Testing/Traits/Trait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public protocol Trait: Sendable {
/// ``scopeProvider(for:testCase:)-cjmg`` method for any trait with
/// `Never` as its test scope provider type must return `nil`, meaning that
/// the trait doesn't provide a custom scope for tests it's applied to.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.1)
/// @Available(Xcode, introduced: 16.3)
/// }
associatedtype TestScopeProvider: TestScoping = Never

/// Get this trait's scope provider for the specified test and optional test
Expand Down Expand Up @@ -98,6 +103,11 @@ public protocol Trait: Sendable {
/// associated ``Trait/TestScopeProvider`` type is the default `Never`, then
/// this method returns `nil` by default. This means that instances of this
/// trait don't provide a custom scope for tests to which they're applied.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.1)
/// @Available(Xcode, introduced: 16.3)
/// }
func scopeProvider(for test: Test, testCase: Test.Case?) -> TestScopeProvider?
}

Expand All @@ -109,6 +119,11 @@ public protocol Trait: Sendable {
/// conforms to this protocol. Create a custom scope to consolidate common
/// set-up and tear-down logic for tests which have similar needs, which allows
/// each test function to focus on the unique aspects of its test.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.1)
/// @Available(Xcode, introduced: 16.3)
/// }
public protocol TestScoping: Sendable {
/// Provide custom execution scope for a function call which is related to the
/// specified test or test case.
Expand Down Expand Up @@ -143,6 +158,11 @@ public protocol TestScoping: Sendable {
/// or throw an error if it's unable to provide a custom scope.
///
/// Issues recorded by this method are associated with `test`.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.1)
/// @Available(Xcode, introduced: 16.3)
/// }
func provideScope(for test: Test, testCase: Test.Case?, performing function: @Sendable () async throws -> Void) async throws
}

Expand All @@ -159,6 +179,11 @@ extension Trait where Self: TestScoping {
/// The testing library uses this implementation of
/// ``Trait/scopeProvider(for:testCase:)-cjmg`` when the trait type conforms
/// to ``TestScoping``.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.1)
/// @Available(Xcode, introduced: 16.3)
/// }
public func scopeProvider(for test: Test, testCase: Test.Case?) -> Self? {
testCase == nil ? nil : self
}
Expand All @@ -178,6 +203,11 @@ extension SuiteTrait where Self: TestScoping {
/// The testing library uses this implementation of
/// ``Trait/scopeProvider(for:testCase:)-cjmg`` when the trait type conforms
/// to both ``SuiteTrait`` and ``TestScoping``.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.1)
/// @Available(Xcode, introduced: 16.3)
/// }
public func scopeProvider(for test: Test, testCase: Test.Case?) -> Self? {
if test.isSuite {
isRecursive ? nil : self
Expand All @@ -188,6 +218,10 @@ extension SuiteTrait where Self: TestScoping {
}

extension Never: TestScoping {
/// @Metadata {
/// @Available(Swift, introduced: 6.1)
/// @Available(Xcode, introduced: 16.3)
/// }
public func provideScope(for test: Test, testCase: Test.Case?, performing function: @Sendable () async throws -> Void) async throws {}
}

Expand Down Expand Up @@ -236,6 +270,11 @@ extension Trait where TestScopeProvider == Never {
/// The testing library uses this implementation of
/// ``Trait/scopeProvider(for:testCase:)-cjmg`` when the trait type's
/// associated ``Trait/TestScopeProvider`` type is `Never`.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.1)
/// @Available(Xcode, introduced: 16.3)
/// }
public func scopeProvider(for test: Test, testCase: Test.Case?) -> Never? {
nil
}
Expand Down