Skip to content

Commit 2b1d626

Browse files
authored
Lower some symbols to SPI. (#548)
This PR lowers some API symbols to SPI, mostly as experimental tools-only. These symbols are, we believe, important but deserve more thought and design before we promote them to API. As well, this PR merges the `comment` and `comments` properties of `ConditionTrait` as redundant. Resolves rdar://131937376. ### Checklist: - [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 7b1fd7e commit 2b1d626

File tree

8 files changed

+21
-18
lines changed

8 files changed

+21
-18
lines changed

Sources/Testing/Issues/Issue.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ extension Issue {
215215
public var sourceContext: SourceContext
216216

217217
/// Whether or not this issue is known to occur.
218+
@_spi(ForToolsIntegrationOnly)
218219
public var isKnown = false
219220

220221
/// Initialize an issue instance with the specified details.

Sources/Testing/Parameterization/Test.Case.ID.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
@_spi(ForToolsIntegrationOnly)
1211
extension Test.Case: Identifiable {
1312
/// The ID of a test case.
1413
///
@@ -21,8 +20,10 @@ extension Test.Case: Identifiable {
2120
///
2221
/// The value of this property is `nil` if _any_ of the associated test
2322
/// case's arguments has a `nil` ID.
23+
@_spi(ForToolsIntegrationOnly)
2424
public var argumentIDs: [Argument.ID]?
2525

26+
@_spi(ForToolsIntegrationOnly)
2627
public init(argumentIDs: [Argument.ID]?) {
2728
self.argumentIDs = argumentIDs
2829
}

Sources/Testing/Parameterization/Test.Case.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extension Test {
1717
public struct Case: Sendable {
1818
/// A type representing an argument passed to a parameter of a parameterized
1919
/// test function.
20+
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
2021
public struct Argument: Sendable {
2122
/// A type representing the stable, unique identifier of a parameterized
2223
/// test argument.
@@ -71,6 +72,7 @@ extension Test {
7172
/// Non-parameterized test functions will have a single test case instance,
7273
/// and the value of this property will be an empty array for such test
7374
/// cases.
75+
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
7476
public var arguments: [Argument]
7577

7678
init(
@@ -117,6 +119,7 @@ extension Test {
117119
/// value that might be passed via this parameter to a test function. To
118120
/// obtain the arguments of a particular ``Test/Case`` paired with their
119121
/// corresponding parameters, use ``Test/Case/arguments``.
122+
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
120123
public struct Parameter: Sendable {
121124
/// The zero-based index of this parameter within its associated test's
122125
/// parameter list.

Sources/Testing/Test.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public struct Test: Sendable {
178178
/// an array of values describing its parameters, which may be empty if the
179179
/// test function is non-parameterized. If this instance represents a test
180180
/// suite, the value of this property is `nil`.
181+
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
181182
public var parameters: [Parameter]?
182183

183184
/// Whether or not this instance is a test suite containing other tests.

Sources/Testing/Testing.docc/Documentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ their problems.
5959
- ``Test(_:_:arguments:_:)``
6060
- ``Test(_:_:arguments:)-3rzok``
6161
- ``CustomTestArgumentEncodable``
62-
- ``Test/Parameter``
62+
<!-- - ``Test/Parameter`` -->
6363
- ``Test/Case``
6464

6565
### Behavior validation

Sources/Testing/Traits/Comment.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ extension Test {
144144
/// - traitType: The type of ``Trait`` whose comments should be returned.
145145
///
146146
/// - Returns: The comments found for the specified test trait type.
147+
@_spi(Experimental)
147148
public func comments<T>(from traitType: T.Type) -> [Comment] where T: Trait {
148149
traits.lazy
149150
.compactMap { $0 as? T }

Sources/Testing/Traits/ConditionTrait+Macro.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ extension Trait where Self == ConditionTrait {
6161
) -> Self {
6262
// TODO: Semantic capture of platform name/version (rather than just a comment)
6363
Self(
64-
comment: message ?? "Requires \(_description(ofPlatformName: platformName, version: version))",
6564
kind: .conditional(condition),
65+
comments: [message ?? "Requires \(_description(ofPlatformName: platformName, version: version))"],
6666
sourceLocation: sourceLocation
6767
)
6868
}
@@ -93,8 +93,8 @@ extension Trait where Self == ConditionTrait {
9393
) -> Self {
9494
// TODO: Semantic capture of platform name/version (rather than just a comment)
9595
Self(
96-
comment: message ?? "Obsolete as of \(_description(ofPlatformName: platformName, version: version))",
9796
kind: .conditional(condition),
97+
comments: [message ?? "Obsolete as of \(_description(ofPlatformName: platformName, version: version))"],
9898
sourceLocation: sourceLocation
9999
)
100100
}
@@ -112,8 +112,8 @@ extension Trait where Self == ConditionTrait {
112112
/// call it directly.
113113
public static func __unavailable(message: Comment?, sourceLocation: SourceLocation) -> Self {
114114
Self(
115-
comment: message ?? "Marked @available(*, unavailable)",
116115
kind: .unconditional(false),
116+
comments: [message ?? "Marked @available(*, unavailable)"],
117117
sourceLocation: sourceLocation
118118
)
119119
}

Sources/Testing/Traits/ConditionTrait.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
/// - ``Trait/disabled(if:_:sourceLocation:)``
2020
/// - ``Trait/disabled(_:sourceLocation:_:)``
2121
public struct ConditionTrait: TestTrait, SuiteTrait {
22-
/// An optional, user-specified comment describing this trait.
23-
public var comment: Comment?
24-
2522
/// An enumeration describing the kinds of conditions that can be represented
2623
/// by an instance of this type.
2724
enum Kind: Sendable {
@@ -68,6 +65,7 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
6865
/// If this trait was created using a function such as
6966
/// ``enabled(if:_:sourceLocation:)`` that is evaluated at runtime, the value
7067
/// of this property is `false`.
68+
@_spi(ForToolsIntegrationOnly)
7169
public var isConstant: Bool {
7270
switch kind {
7371
case .conditional:
@@ -77,6 +75,8 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
7775
}
7876
}
7977

78+
public var comments: [Comment]
79+
8080
/// The source location where this trait was specified.
8181
public var sourceLocation: SourceLocation
8282

@@ -93,17 +93,13 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
9393

9494
if !result {
9595
let sourceContext = SourceContext(sourceLocation: sourceLocation)
96-
throw SkipInfo(comment: commentOverride ?? comment, sourceContext: sourceContext)
96+
throw SkipInfo(comment: commentOverride ?? comments.first, sourceContext: sourceContext)
9797
}
9898
}
9999

100100
public var isRecursive: Bool {
101101
true
102102
}
103-
104-
public var comments: [Comment] {
105-
Array(comment)
106-
}
107103
}
108104

109105
// MARK: -
@@ -132,7 +128,7 @@ extension Trait where Self == ConditionTrait {
132128
_ comment: Comment? = nil,
133129
sourceLocation: SourceLocation = #_sourceLocation
134130
) -> Self {
135-
Self(comment: comment, kind: .conditional(condition), sourceLocation: sourceLocation)
131+
Self(kind: .conditional(condition), comments: Array(comment), sourceLocation: sourceLocation)
136132
}
137133

138134
/// Construct a condition trait that causes a test to be disabled if it
@@ -152,7 +148,7 @@ extension Trait where Self == ConditionTrait {
152148
sourceLocation: SourceLocation = #_sourceLocation,
153149
_ condition: @escaping @Sendable () async throws -> Bool
154150
) -> Self {
155-
Self(comment: comment, kind: .conditional(condition), sourceLocation: sourceLocation)
151+
Self(kind: .conditional(condition), comments: Array(comment), sourceLocation: sourceLocation)
156152
}
157153

158154
/// Construct a condition trait that disables a test unconditionally.
@@ -167,7 +163,7 @@ extension Trait where Self == ConditionTrait {
167163
_ comment: Comment? = nil,
168164
sourceLocation: SourceLocation = #_sourceLocation
169165
) -> Self {
170-
Self(comment: comment, kind: .unconditional(false), sourceLocation: sourceLocation)
166+
Self(kind: .unconditional(false), comments: Array(comment), sourceLocation: sourceLocation)
171167
}
172168

173169
/// Construct a condition trait that causes a test to be disabled if it
@@ -193,7 +189,7 @@ extension Trait where Self == ConditionTrait {
193189
_ comment: Comment? = nil,
194190
sourceLocation: SourceLocation = #_sourceLocation
195191
) -> Self {
196-
Self(comment: comment, kind: .conditional { !(try condition()) }, sourceLocation: sourceLocation)
192+
Self(kind: .conditional { !(try condition()) }, comments: Array(comment), sourceLocation: sourceLocation)
197193
}
198194

199195
/// Construct a condition trait that causes a test to be disabled if it
@@ -213,6 +209,6 @@ extension Trait where Self == ConditionTrait {
213209
sourceLocation: SourceLocation = #_sourceLocation,
214210
_ condition: @escaping @Sendable () async throws -> Bool
215211
) -> Self {
216-
Self(comment: comment, kind: .conditional { !(try await condition()) }, sourceLocation: sourceLocation)
212+
Self(kind: .conditional { !(try await condition()) }, comments: Array(comment), sourceLocation: sourceLocation)
217213
}
218214
}

0 commit comments

Comments
 (0)