Skip to content

Commit a7a8d00

Browse files
committed
observedValues does not need to be a set
1 parent ebb0bff commit a7a8d00

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Sources/Testing/ExitTests/ExitTest.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public struct ExitTest: Sendable, ~Copyable {
3636
fileprivate var body: @Sendable () async throws -> Void = {}
3737

3838
/// Storage for ``observedValues``.
39-
fileprivate nonisolated(unsafe) var _observedValues = Set<PartialKeyPath<ExitTest.Result>>()
39+
fileprivate nonisolated(unsafe) var _observedValues = [PartialKeyPath<ExitTest.Result>]()
4040

4141
/// Key paths representing results from within this exit test that should be
4242
/// observed and returned to the caller.
@@ -53,10 +53,12 @@ public struct ExitTest: Sendable, ~Copyable {
5353
/// Within a child process running an exit test, the value of this property is
5454
/// otherwise unspecified.
5555
@_spi(ForToolsIntegrationOnly)
56-
public var observedValues: Set<PartialKeyPath<ExitTest.Result>> {
56+
public var observedValues: [PartialKeyPath<ExitTest.Result>] {
5757
get {
5858
var result = _observedValues
59-
result.insert(\.exitCondition)
59+
if !result.contains(\.exitCondition) { // O(n), but n <= 3 (no Set needed)
60+
result.append(\.exitCondition)
61+
}
6062
return result
6163
}
6264
set {
@@ -232,7 +234,7 @@ extension ExitTest {
232234
/// convention.
233235
func callExitTest(
234236
exitsWith expectedExitCondition: ExitCondition,
235-
observing observedValues: Set<PartialKeyPath<ExitTest.Result>>,
237+
observing observedValues: [PartialKeyPath<ExitTest.Result>],
236238
expression: __Expression,
237239
comments: @autoclosure () -> [Comment],
238240
isRequired: Bool,

Sources/Testing/Expectations/Expectation+Macro.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public macro require<R>(
516516
@discardableResult
517517
@freestanding(expression) public macro expect(
518518
exitsWith expectedExitCondition: ExitCondition,
519-
observing observedValues: Set<PartialKeyPath<ExitTest.Result>> = [],
519+
observing observedValues: [PartialKeyPath<ExitTest.Result>] = [],
520520
_ comment: @autoclosure () -> Comment? = nil,
521521
sourceLocation: SourceLocation = #_sourceLocation,
522522
performing expression: @convention(thin) () async throws -> Void
@@ -629,7 +629,7 @@ public macro require<R>(
629629
@discardableResult
630630
@freestanding(expression) public macro require(
631631
exitsWith expectedExitCondition: ExitCondition,
632-
observing observedValues: Set<PartialKeyPath<ExitTest.Result>> = [],
632+
observing observedValues: [PartialKeyPath<ExitTest.Result>] = [],
633633
_ comment: @autoclosure () -> Comment? = nil,
634634
sourceLocation: SourceLocation = #_sourceLocation,
635635
performing expression: @convention(thin) () async throws -> Void

Sources/Testing/Expectations/ExpectationChecking+Macro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ public func __checkClosureCall<R>(
11421142
@_spi(Experimental)
11431143
public func __checkClosureCall(
11441144
exitsWith expectedExitCondition: ExitCondition,
1145-
observing observedValues: Set<PartialKeyPath<ExitTest.Result>>,
1145+
observing observedValues: [PartialKeyPath<ExitTest.Result>],
11461146
performing body: @convention(thin) () -> Void,
11471147
expression: __Expression,
11481148
comments: @autoclosure () -> [Comment],

0 commit comments

Comments
 (0)