-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathConfiguration.swift
206 lines (179 loc) · 7.41 KB
/
Configuration.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//
/// A type containing settings for preparing and running tests.
@_spi(ForToolsIntegrationOnly)
public struct Configuration: Sendable {
/// Initialize an instance of this type representing the default
/// configuration.
public init() {}
// MARK: - Parallelization
/// Whether or not to parallelize the execution of tests and test cases.
public var isParallelizationEnabled = true
/// A type describing whether or not, and how, to iterate a test plan
/// repeatedly.
///
/// When a ``Runner`` is run, it will run all tests in its corresponding
/// ``Runner/Plan`` according to the policy described by its
/// ``Configuration/repetitionPolicy-swift.property`` property. For instance,
/// if that property is set to:
///
/// ```swift
/// .repeating(.untilIssueRecorded, count: 10)
/// ```
///
/// The entire test plan will be run repeatedly, up to 10 times. If an issue
/// is recorded, the current iteration will complete, but no further
/// iterations will be attempted.
///
/// If the value of an instance's ``maximumIterationCount`` property is `1`,
/// the value of its ``continuationCondition-swift.property`` property has no
/// effect.
public struct RepetitionPolicy: Sendable {
/// An enumeration describing the conditions under which test iterations
/// should continue.
public enum ContinuationCondition: Sendable {
/// The test plan should continue iterating until an unknown issue is
/// recorded.
///
/// When this continuation condition is used and an issue is recorded, the
/// current iteration will complete, but no further iterations will be
/// attempted.
case untilIssueRecorded
/// The test plan should continue iterating until an iteration completes
/// with no unknown issues recorded.
case whileIssueRecorded
}
/// The conditions under which test iterations should continue.
///
/// If the value of this property is `nil`, a test plan will be run
/// ``maximumIterationCount`` times regardless of whether or not issues are
/// encountered while running.
public var continuationCondition: ContinuationCondition?
/// The maximum number of times the test run should iterate.
///
/// - Precondition: The value of this property must be greater than or equal
/// to `1`.
public var maximumIterationCount: Int {
willSet {
precondition(newValue >= 1, "Test runs must iterate at least once.")
}
}
/// Create an instance of this type.
///
/// - Parameters:
/// - continuationCondition: The conditions under which test iterations
/// should continue. If `nil`, the iterations should continue
/// unconditionally `count` times.
/// - maximumIterationCount: The maximum number of times the test run
/// should iterate.
public static func repeating(_ continuationCondition: ContinuationCondition? = nil, maximumIterationCount: Int) -> Self {
Self(continuationCondition: continuationCondition, maximumIterationCount: maximumIterationCount)
}
/// An instance of this type representing a single iteration.
public static var once: Self {
repeating(maximumIterationCount: 1)
}
}
/// Whether or not, and how, to iterate the test plan repeatedly.
///
/// By default, the value of this property allows for a single iteration.
public var repetitionPolicy: RepetitionPolicy = .once
// MARK: - Main actor isolation
#if !SWT_NO_GLOBAL_ACTORS
/// Whether or not synchronous test functions need to run on the main actor.
///
/// This property is available on platforms where UI testing is implemented.
public var isMainActorIsolationEnforced = false
#endif
// MARK: - Time limits
/// Storage for the ``defaultTestTimeLimit`` property.
private var _defaultTestTimeLimit: (any Sendable)?
/// The default amount of time a test may run for before timing out if it does
/// not have an instance of ``TimeLimitTrait`` applied to it.
///
/// If the value of this property is `nil`, individual test functions may run
/// up to the limit specified by ``maximumTestTimeLimit``.
///
/// To determine the actual time limit that applies to an instance of
/// ``Test`` at runtime, use ``Test/adjustedTimeLimit(configuration:)``.
@available(_clockAPI, *)
public var defaultTestTimeLimit: Duration? {
get {
_defaultTestTimeLimit as? Duration
}
set {
_defaultTestTimeLimit = newValue
}
}
/// Storage for the ``maximumTestTimeLimit`` property.
private var _maximumTestTimeLimit: (any Sendable)?
/// The maximum amount of time a test may run for before timing out,
/// regardless of the value of ``defaultTestTimeLimit`` or individual
/// instances of ``TimeLimitTrait`` applied to it.
///
/// If the value of this property is `nil`, individual test functions may run
/// indefinitely.
///
/// To determine the actual time limit that applies to an instance of
/// ``Test`` at runtime, use ``Test/adjustedTimeLimit(configuration:)``.
@available(_clockAPI, *)
public var maximumTestTimeLimit: Duration? {
get {
_maximumTestTimeLimit as? Duration
}
set {
_maximumTestTimeLimit = newValue
}
}
/// Storage for the ``testTimeLimitGranularity`` property.
private var _testTimeLimitGranularity: (any Sendable)?
/// The granularity to enforce on test time limits.
///
/// By default, test time limit granularity is limited to intervals of one
/// minute (60 seconds.) If finer or coarser granularity is required, the
/// value of this property can be adjusted.
@available(_clockAPI, *)
public var testTimeLimitGranularity: Duration {
get {
(_testTimeLimitGranularity as? Duration) ?? .seconds(60)
}
set {
_testTimeLimitGranularity = newValue
}
}
// MARK: - Event handling
/// Whether or not events of the kind
/// ``Event/Kind-swift.enum/expectationChecked(_:)`` should be delivered to
/// this configuration's ``eventHandler`` closure.
///
/// By default, events of this kind are not delivered to event handlers
/// because they occur frequently in a typical test run and can generate
/// significant backpressure on the event handler.
@_spi(ForToolsIntegrationOnly)
public var deliverExpectationCheckedEvents = false
/// The event handler to which events should be passed when they occur.
@_spi(ForToolsIntegrationOnly)
public var eventHandler: Event.Handler = { _, _ in }
// MARK: - Test selection
/// The test filter to which tests should be filtered when run.
public var testFilter: TestFilter = .unfiltered
// MARK: - Test case selection
/// A function that handles filtering test cases.
///
/// - Parameters:
/// - testCase: The test case to be filtered.
/// - test: The test which `testCase` is associated with.
///
/// - Returns: A Boolean value representing if the test case satisfied the
/// filter.
public typealias TestCaseFilter = @Sendable (_ testCase: Test.Case, _ test: Test) -> Bool
/// The test case filter to which test cases should be filtered when run.
public var testCaseFilter: TestCaseFilter = { _, _ in true }
}