Skip to content

Commit 0c5af7f

Browse files
committed
observedValues does not need to be a set
1 parent 17f466a commit 0c5af7f

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
@@ -28,7 +28,7 @@ public struct ExitTest: Sendable, ~Copyable {
2828
fileprivate var body: @Sendable () async throws -> Void = {}
2929

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

3333
/// Key paths representing results from within this exit test that should be
3434
/// observed and returned to the caller.
@@ -45,10 +45,12 @@ public struct ExitTest: Sendable, ~Copyable {
4545
/// Within a child process running an exit test, the value of this property is
4646
/// otherwise unspecified.
4747
@_spi(ForToolsIntegrationOnly)
48-
public var observedValues: Set<PartialKeyPath<ExitTest.Result>> {
48+
public var observedValues: [PartialKeyPath<ExitTest.Result>] {
4949
get {
5050
var result = _observedValues
51-
result.insert(\.exitCondition)
51+
if !result.contains(\.exitCondition) { // O(n), but n <= 3 (no Set needed)
52+
result.append(\.exitCondition)
53+
}
5254
return result
5355
}
5456
set {
@@ -208,7 +210,7 @@ extension ExitTest {
208210
/// convention.
209211
func callExitTest(
210212
exitsWith expectedExitCondition: ExitCondition,
211-
observing observedValues: Set<PartialKeyPath<ExitTest.Result>>,
213+
observing observedValues: [PartialKeyPath<ExitTest.Result>],
212214
expression: __Expression,
213215
comments: @autoclosure () -> [Comment],
214216
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)