Skip to content

Promote Issue Handling Traits to public API #1198

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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: 1 addition & 3 deletions Sources/Testing/Testing.docc/Traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ types that customize the behavior of your tests.
- ``Trait/bug(_:id:_:)-10yf5``
- ``Trait/bug(_:id:_:)-3vtpl``

<!--
### Handling issues

- ``Trait/compactMapIssues(_:)``
- ``Trait/filterIssues(_:)``
-->

### Creating custom traits

Expand All @@ -67,8 +65,8 @@ types that customize the behavior of your tests.
- ``Bug``
- ``Comment``
- ``ConditionTrait``
- ``IssueHandlingTrait``
- ``ParallelizationTrait``
- ``Tag``
- ``Tag/List``
- ``TimeLimitTrait``
<!--- ``IssueHandlingTrait``-->
21 changes: 19 additions & 2 deletions Sources/Testing/Traits/IssueHandlingTrait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
///
/// - ``Trait/compactMapIssues(_:)``
/// - ``Trait/filterIssues(_:)``
@_spi(Experimental)
///
/// @Metadata {
/// @Available(Swift, introduced: 99.9) // TODO: Replace with final version
/// }
public struct IssueHandlingTrait: TestTrait, SuiteTrait {
/// A function which handles an issue and returns an optional replacement.
///
Expand All @@ -49,6 +52,10 @@ public struct IssueHandlingTrait: TestTrait, SuiteTrait {
///
/// - Returns: An issue to replace `issue`, or else `nil` if the issue should
/// not be recorded.
///
/// @Metadata {
/// @Available(Swift, introduced: 99.9) // TODO: Replace with final version
/// }
public func handleIssue(_ issue: Issue) -> Issue? {
_handler(issue)
}
Expand All @@ -58,6 +65,9 @@ public struct IssueHandlingTrait: TestTrait, SuiteTrait {
}
}

/// @Metadata {
/// @Available(Swift, introduced: 99.9) // TODO: Replace with final version
/// }
extension IssueHandlingTrait: TestScoping {
public func scopeProvider(for test: Test, testCase: Test.Case?) -> Self? {
// Provide scope for tests at both the suite and test case levels, but not
Expand Down Expand Up @@ -126,7 +136,6 @@ extension IssueHandlingTrait: TestScoping {
}
}

@_spi(Experimental)
extension Trait where Self == IssueHandlingTrait {
/// Constructs an trait that transforms issues recorded by a test.
///
Expand Down Expand Up @@ -158,6 +167,10 @@ extension Trait where Self == IssueHandlingTrait {
/// - Note: `transform` will never be passed an issue for which the value of
/// ``Issue/kind`` is ``Issue/Kind/system``, and may not return such an
/// issue.
///
/// @Metadata {
/// @Available(Swift, introduced: 99.9) // TODO: Replace with final version
/// }
public static func compactMapIssues(_ transform: @escaping @Sendable (Issue) -> Issue?) -> Self {
Self(handler: transform)
}
Expand Down Expand Up @@ -192,6 +205,10 @@ extension Trait where Self == IssueHandlingTrait {
///
/// - Note: `isIncluded` will never be passed an issue for which the value of
/// ``Issue/kind`` is ``Issue/Kind/system``.
///
/// @Metadata {
/// @Available(Swift, introduced: 99.9) // TODO: Replace with final version
/// }
public static func filterIssues(_ isIncluded: @escaping @Sendable (Issue) -> Bool) -> Self {
Self { issue in
isIncluded(issue) ? issue : nil
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestingTests/Traits/IssueHandlingTraitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//

@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
@testable @_spi(ForToolsIntegrationOnly) import Testing

@Suite("IssueHandlingTrait Tests")
struct IssueHandlingTraitTests {
Expand Down