Skip to content

Commit 271f080

Browse files
committed
Cleaning recently changed docs (#924)
Improving the style and explanation of recent additions to the documentation. The recent changes to test traits are great, and come with some very nice documentation. I've done what I can to improve the style and the wording to make it easier to understand, and to make the style consistent with other documentation in the project. Changed the documentation for `Trait` and associated types. There are no behavioral changes in this PR, but I hope that the existing behavior is easier to use with better documentation. - [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 0e6ae14 commit 271f080

File tree

8 files changed

+220
-231
lines changed

8 files changed

+220
-231
lines changed

Diff for: Sources/Testing/Testing.docc/Traits.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ See https://swift.org/LICENSE.txt for license information
1010
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
1111
-->
1212

13-
Add traits to tests to annotate them or customize their behavior.
13+
Annotate test functions and suites, and customize their behavior.
1414

1515
## Overview
1616

1717
Pass built-in traits to test functions or suite types to comment, categorize,
18-
classify, and modify runtime behaviors. You can also use the ``Trait``, ``TestTrait``,
19-
and ``SuiteTrait`` protocols to create your own types that customize the
20-
behavior of test functions.
18+
classify, and modify the runtime behavior of test suites and test functions.
19+
Implement the ``TestTrait``, and ``SuiteTrait`` protocols to create your own
20+
types that customize the behavior of your tests.
2121

2222
## Topics
2323

Diff for: Sources/Testing/Testing.docc/Traits/Trait.md

+7-16
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,25 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors
2020
- ``Trait/disabled(if:_:sourceLocation:)``
2121
- ``Trait/disabled(_:sourceLocation:_:)``
2222

23-
### Limiting the running time of tests
24-
25-
- ``Trait/timeLimit(_:)``
26-
27-
### Running tests serially or in parallel
23+
### Controlling how tests are run
2824

25+
- ``Trait/timeLimit(_:)-4kzjp``
2926
- ``Trait/serialized``
30-
31-
### Categorizing tests
27+
28+
### Categorizing tests and adding information
3229

3330
- ``Trait/tags(_:)``
31+
- ``Trait/comments``
3432

3533
### Associating bugs
3634

3735
- ``Trait/bug(_:_:)``
3836
- ``Trait/bug(_:id:_:)-10yf5``
3937
- ``Trait/bug(_:id:_:)-3vtpl``
4038

41-
### Adding information to tests
42-
43-
- ``Trait/comments``
44-
45-
### Preparing internal state
46-
47-
- ``Trait/prepare(for:)-3s3zo``
48-
49-
### Providing custom execution scope for tests
39+
### Running code before and after a test or suite
5040

5141
- ``TestScoping``
5242
- ``Trait/scopeProvider(for:testCase:)-cjmg``
5343
- ``Trait/TestScopeProvider``
44+
- ``Trait/prepare(for:)-3s3zo``

Diff for: Sources/Testing/Traits/Bug.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
/// A type representing a bug report tracked by a test.
11+
/// A type that represents a bug report tracked by a test.
1212
///
1313
/// To add this trait to a test, use one of the following functions:
1414
///
1515
/// - ``Trait/bug(_:_:)``
1616
/// - ``Trait/bug(_:id:_:)-10yf5``
1717
/// - ``Trait/bug(_:id:_:)-3vtpl``
1818
public struct Bug {
19-
/// A URL linking to more information about the bug, if available.
19+
/// A URL that links to more information about the bug, if available.
2020
///
2121
/// The value of this property represents a URL conforming to
2222
/// [RFC 3986](https://www.ietf.org/rfc/rfc3986.txt).
@@ -59,42 +59,42 @@ extension Bug: TestTrait, SuiteTrait {
5959
}
6060

6161
extension Trait where Self == Bug {
62-
/// Construct a bug to track with a test.
62+
/// Constructs a bug to track with a test.
6363
///
6464
/// - Parameters:
65-
/// - url: A URL referring to this bug in the associated bug-tracking
65+
/// - url: A URL that refers to this bug in the associated bug-tracking
6666
/// system.
6767
/// - title: Optionally, the human-readable title of the bug.
6868
///
69-
/// - Returns: An instance of ``Bug`` representing the specified bug.
69+
/// - Returns: An instance of ``Bug`` that represents the specified bug.
7070
public static func bug(_ url: _const String, _ title: Comment? = nil) -> Self {
7171
Self(url: url, title: title)
7272
}
7373

74-
/// Construct a bug to track with a test.
74+
/// Constructs a bug to track with a test.
7575
///
7676
/// - Parameters:
77-
/// - url: A URL referring to this bug in the associated bug-tracking
77+
/// - url: A URL that refers to this bug in the associated bug-tracking
7878
/// system.
7979
/// - id: The unique identifier of this bug in its associated bug-tracking
8080
/// system.
8181
/// - title: Optionally, the human-readable title of the bug.
8282
///
83-
/// - Returns: An instance of ``Bug`` representing the specified bug.
83+
/// - Returns: An instance of ``Bug`` that represents the specified bug.
8484
public static func bug(_ url: _const String? = nil, id: some Numeric, _ title: Comment? = nil) -> Self {
8585
Self(url: url, id: String(describing: id), title: title)
8686
}
8787

88-
/// Construct a bug to track with a test.
88+
/// Constructs a bug to track with a test.
8989
///
9090
/// - Parameters:
91-
/// - url: A URL referring to this bug in the associated bug-tracking
91+
/// - url: A URL that refers to this bug in the associated bug-tracking
9292
/// system.
9393
/// - id: The unique identifier of this bug in its associated bug-tracking
9494
/// system.
9595
/// - title: Optionally, the human-readable title of the bug.
9696
///
97-
/// - Returns: An instance of ``Bug`` representing the specified bug.
97+
/// - Returns: An instance of ``Bug`` that represents the specified bug.
9898
public static func bug(_ url: _const String? = nil, id: _const String, _ title: Comment? = nil) -> Self {
9999
Self(url: url, id: id, title: title)
100100
}

Diff for: Sources/Testing/Traits/Comment.swift

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
/// A type representing a comment related to a test.
11+
/// A type that represents a comment related to a test.
1212
///
13-
/// This type may be used to provide context or background information about a
13+
/// Use this type to provide context or background information about a
1414
/// test's purpose, explain how a complex test operates, or include details
1515
/// which may be helpful when diagnosing issues recorded by a test.
1616
///
1717
/// To add a comment to a test or suite, add a code comment before its `@Test`
1818
/// or `@Suite` attribute. See <doc:AddingComments> for more details.
1919
///
20-
/// - Note: This type is not intended to reference bugs related to a test.
21-
/// Instead, use ``Trait/bug(_:_:)``, ``Trait/bug(_:id:_:)-10yf5``, or
22-
/// ``Trait/bug(_:id:_:)-3vtpl``.
20+
/// - Note: To reference bugs related to a test, use ``Trait/bug(_:_:)``,
21+
/// ``Trait/bug(_:id:_:)-10yf5``, or ``Trait/bug(_:id:_:)-3vtpl``.
2322
public struct Comment: RawRepresentable, Sendable {
24-
/// The single comment string contained in this instance.
23+
/// The single comment string that this comment contains.
2524
///
26-
/// To obtain the complete set of comments applied to a test, see
25+
/// To get the complete set of comments applied to a test, see
2726
/// ``Test/comments``.
2827
public var rawValue: String
2928

Diff for: Sources/Testing/Traits/ConditionTrait.swift

+53-56
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
/// A type that defines a condition which must be satisfied for a test to be
12-
/// enabled.
11+
/// A type that defines a condition which must be satisfied for the testing
12+
/// library to enable a test.
1313
///
1414
/// To add this trait to a test, use one of the following functions:
1515
///
@@ -19,10 +19,10 @@
1919
/// - ``Trait/disabled(if:_:sourceLocation:)``
2020
/// - ``Trait/disabled(_:sourceLocation:_:)``
2121
public struct ConditionTrait: TestTrait, SuiteTrait {
22-
/// An enumeration describing the kinds of conditions that can be represented
23-
/// by an instance of this type.
22+
/// An enumeration that describes the conditions that an instance of this type
23+
/// can represent.
2424
enum Kind: Sendable {
25-
/// The trait is conditional on the result of calling a function.
25+
/// Enabling the test is conditional on the result of calling a function.
2626
///
2727
/// - Parameters:
2828
/// - body: The function to call. The result of this function determines
@@ -39,7 +39,8 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
3939
/// - body: The function to call. The result of this function determines
4040
/// whether or not the condition was met.
4141
///
42-
/// - Returns: An instance of this type.
42+
/// - Returns: A trait that marks a test's enabled status as the result of
43+
/// calling a function.
4344
static func conditional(_ body: @escaping @Sendable () async throws -> Bool) -> Self {
4445
conditional { () -> (Bool, comment: Comment?) in
4546
return (try await body(), nil)
@@ -49,14 +50,14 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
4950
/// The trait is unconditional and always has the same result.
5051
///
5152
/// - Parameters:
52-
/// - value: Whether or not the condition was met.
53+
/// - value: Whether or not the test is enabled.
5354
case unconditional(_ value: Bool)
5455
}
5556

56-
/// The kind of condition represented by this instance.
57+
/// The kind of condition represented by this trait.
5758
var kind: Kind
5859

59-
/// Whether or not this trait has a condition that is evaluated at runtime.
60+
/// Whether this trait's condition is constant, or evaluated at runtime.
6061
///
6162
/// If this trait was created using a function such as
6263
/// ``disabled(_:sourceLocation:)`` that unconditionally enables or disables a
@@ -77,7 +78,7 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
7778

7879
public var comments: [Comment]
7980

80-
/// The source location where this trait was specified.
81+
/// The source location where this trait is specified.
8182
public var sourceLocation: SourceLocation
8283

8384
public func prepare(for test: Test) async throws {
@@ -110,24 +111,23 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
110111
// MARK: -
111112

112113
extension Trait where Self == ConditionTrait {
113-
/// Construct a condition trait that causes a test to be disabled if it
114-
/// returns `false`.
114+
/// Constructs a condition trait that disables a test if it returns `false`.
115115
///
116116
/// - Parameters:
117-
/// - condition: A closure containing the trait's custom condition logic. If
118-
/// this closure returns `true`, the test is allowed to run. Otherwise,
119-
/// the test is skipped.
120-
/// - comment: An optional, user-specified comment describing this trait.
117+
/// - condition: A closure that contains the trait's custom condition logic.
118+
/// If this closure returns `true`, the trait allows the test to run.
119+
/// Otherwise, the testing library skips the test.
120+
/// - comment: An optional comment that describes this trait.
121121
/// - sourceLocation: The source location of the trait.
122122
///
123-
/// - Returns: An instance of ``ConditionTrait`` that will evaluate the
124-
/// specified closure.
125-
///
126-
/// @Comment {
127-
/// - Bug: `condition` cannot be `async` without making this function
128-
/// `async` even though `condition` is not evaluated locally.
129-
/// ([103037177](rdar://103037177))
130-
/// }
123+
/// - Returns: An instance of ``ConditionTrait`` that evaluates the
124+
/// closure you provide.
125+
//
126+
// @Comment {
127+
// - Bug: `condition` cannot be `async` without making this function
128+
// `async` even though `condition` is not evaluated locally.
129+
// ([103037177](rdar://103037177))
130+
// }
131131
public static func enabled(
132132
if condition: @autoclosure @escaping @Sendable () throws -> Bool,
133133
_ comment: Comment? = nil,
@@ -136,18 +136,17 @@ extension Trait where Self == ConditionTrait {
136136
Self(kind: .conditional(condition), comments: Array(comment), sourceLocation: sourceLocation)
137137
}
138138

139-
/// Construct a condition trait that causes a test to be disabled if it
140-
/// returns `false`.
139+
/// Constructs a condition trait that disables a test if it returns `false`.
141140
///
142141
/// - Parameters:
143-
/// - comment: An optional, user-specified comment describing this trait.
142+
/// - comment: An optional comment that describes this trait.
144143
/// - sourceLocation: The source location of the trait.
145-
/// - condition: A closure containing the trait's custom condition logic. If
146-
/// this closure returns `true`, the test is allowed to run. Otherwise,
147-
/// the test is skipped.
144+
/// - condition: A closure that contains the trait's custom condition logic.
145+
/// If this closure returns `true`, the trait allows the test to run.
146+
/// Otherwise, the testing library skips the test.
148147
///
149-
/// - Returns: An instance of ``ConditionTrait`` that will evaluate the
150-
/// specified closure.
148+
/// - Returns: An instance of ``ConditionTrait`` that evaluates the
149+
/// closure you provide.
151150
public static func enabled(
152151
_ comment: Comment? = nil,
153152
sourceLocation: SourceLocation = #_sourceLocation,
@@ -156,13 +155,13 @@ extension Trait where Self == ConditionTrait {
156155
Self(kind: .conditional(condition), comments: Array(comment), sourceLocation: sourceLocation)
157156
}
158157

159-
/// Construct a condition trait that disables a test unconditionally.
158+
/// Constructs a condition trait that disables a test unconditionally.
160159
///
161160
/// - Parameters:
162-
/// - comment: An optional, user-specified comment describing this trait.
161+
/// - comment: An optional comment that describes this trait.
163162
/// - sourceLocation: The source location of the trait.
164163
///
165-
/// - Returns: An instance of ``ConditionTrait`` that will always disable the
164+
/// - Returns: An instance of ``ConditionTrait`` that always disables the
166165
/// test to which it is added.
167166
public static func disabled(
168167
_ comment: Comment? = nil,
@@ -171,24 +170,23 @@ extension Trait where Self == ConditionTrait {
171170
Self(kind: .unconditional(false), comments: Array(comment), sourceLocation: sourceLocation)
172171
}
173172

174-
/// Construct a condition trait that causes a test to be disabled if it
175-
/// returns `true`.
173+
/// Constructs a condition trait that disables a test if its value is true.
176174
///
177175
/// - Parameters:
178-
/// - condition: A closure containing the trait's custom condition logic. If
179-
/// this closure returns `false`, the test is allowed to run. Otherwise,
180-
/// the test is skipped.
181-
/// - comment: An optional, user-specified comment describing this trait.
176+
/// - condition: A closure that contains the trait's custom condition logic.
177+
/// If this closure returns `false`, the trait allows the test to run.
178+
/// Otherwise, the testing library skips the test.
179+
/// - comment: An optional comment that describes this trait.
182180
/// - sourceLocation: The source location of the trait.
183181
///
184-
/// - Returns: An instance of ``ConditionTrait`` that will evaluate the
185-
/// specified closure.
186-
///
187-
/// @Comment {
188-
/// - Bug: `condition` cannot be `async` without making this function
189-
/// `async` even though `condition` is not evaluated locally.
190-
/// ([103037177](rdar://103037177))
191-
/// }
182+
/// - Returns: An instance of ``ConditionTrait`` that evaluates the
183+
/// closure you provide.
184+
//
185+
// @Comment {
186+
// - Bug: `condition` cannot be `async` without making this function
187+
// `async` even though `condition` is not evaluated locally.
188+
// ([103037177](rdar://103037177))
189+
// }
192190
public static func disabled(
193191
if condition: @autoclosure @escaping @Sendable () throws -> Bool,
194192
_ comment: Comment? = nil,
@@ -197,17 +195,16 @@ extension Trait where Self == ConditionTrait {
197195
Self(kind: .conditional { !(try condition()) }, comments: Array(comment), sourceLocation: sourceLocation)
198196
}
199197

200-
/// Construct a condition trait that causes a test to be disabled if it
201-
/// returns `true`.
198+
/// Constructs a condition trait that disables a test if its value is true.
202199
///
203200
/// - Parameters:
204-
/// - comment: An optional, user-specified comment describing this trait.
201+
/// - comment: An optional comment that describes this trait.
205202
/// - sourceLocation: The source location of the trait.
206-
/// - condition: A closure containing the trait's custom condition logic. If
207-
/// this closure returns `false`, the test is allowed to run. Otherwise,
208-
/// the test is skipped.
203+
/// - condition: A closure that contains the trait's custom condition logic.
204+
/// If this closure returns `false`, the trait allows the test to run.
205+
/// Otherwise, the testing library skips the test.
209206
///
210-
/// - Returns: An instance of ``ConditionTrait`` that will evaluate the
207+
/// - Returns: An instance of ``ConditionTrait`` that evaluates the
211208
/// specified closure.
212209
public static func disabled(
213210
_ comment: Comment? = nil,

Diff for: Sources/Testing/Traits/ParallelizationTrait.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
/// A type that affects whether or not a test or suite is parallelized.
11+
/// A type that defines whether the testing library runs this test serially
12+
/// or in parallel.
1213
///
13-
/// When added to a parameterized test function, this trait causes that test to
14-
/// run its cases serially instead of in parallel. When applied to a
15-
/// non-parameterized test function, this trait has no effect. When applied to a
16-
/// test suite, this trait causes that suite to run its contained test functions
17-
/// and sub-suites serially instead of in parallel.
14+
/// When you add this trait to a parameterized test function, that test runs its
15+
/// cases serially instead of in parallel. This trait has no effect when you
16+
/// apply it to a non-parameterized test function.
1817
///
19-
/// This trait is recursively applied: if it is applied to a suite, any
20-
/// parameterized tests or test suites contained in that suite are also
21-
/// serialized (as are any tests contained in those suites, and so on.)
18+
/// When you add this trait to a test suite, that suite runs its
19+
/// contained test functions (including their cases, when parameterized) and
20+
/// sub-suites serially instead of in parallel. If the sub-suites have children,
21+
/// they also run serially.
2222
///
2323
/// This trait does not affect the execution of a test relative to its peers or
24-
/// to unrelated tests. This trait has no effect if test parallelization is
25-
/// globally disabled (by, for example, passing `--no-parallel` to the
24+
/// to unrelated tests. This trait has no effect if you disable test
25+
/// parallelization globally (for example, by passing `--no-parallel` to the
2626
/// `swift test` command.)
2727
///
2828
/// To add this trait to a test, use ``Trait/serialized``.

0 commit comments

Comments
 (0)