Skip to content

Commit 9114a83

Browse files
committed
observedValues does not need to be a set
1 parent 5aff959 commit 9114a83

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

3737
/// Storage for ``observedValues``.
38-
fileprivate nonisolated(unsafe) var _observedValues = Set<PartialKeyPath<ExitTestArtifacts>>()
38+
fileprivate nonisolated(unsafe) var _observedValues = [PartialKeyPath<ExitTestArtifacts>]()
3939

4040
/// Key paths representing results from within this exit test that should be
4141
/// observed and returned to the caller.
@@ -52,10 +52,12 @@ public struct ExitTest: Sendable, ~Copyable {
5252
/// Within a child process running an exit test, the value of this property is
5353
/// otherwise unspecified.
5454
@_spi(ForToolsIntegrationOnly)
55-
public var observedValues: Set<PartialKeyPath<ExitTestArtifacts>> {
55+
public var observedValues: [PartialKeyPath<ExitTestArtifacts>] {
5656
get {
5757
var result = _observedValues
58-
result.insert(\.exitCondition)
58+
if !result.contains(\.exitCondition) { // O(n), but n <= 3 (no Set needed)
59+
result.append(\.exitCondition)
60+
}
5961
return result
6062
}
6163
set {
@@ -228,7 +230,7 @@ extension ExitTest {
228230
/// convention.
229231
func callExitTest(
230232
exitsWith expectedExitCondition: ExitCondition,
231-
observing observedValues: Set<PartialKeyPath<ExitTestArtifacts>>,
233+
observing observedValues: [PartialKeyPath<ExitTestArtifacts>],
232234
expression: __Expression,
233235
comments: @autoclosure () -> [Comment],
234236
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<ExitTestArtifacts>> = [],
519+
observing observedValues: [PartialKeyPath<ExitTestArtifacts>] = [],
520520
_ comment: @autoclosure () -> Comment? = nil,
521521
sourceLocation: SourceLocation = #_sourceLocation,
522522
performing expression: @convention(thin) () async throws -> Void
@@ -628,7 +628,7 @@ public macro require<R>(
628628
@discardableResult
629629
@freestanding(expression) public macro require(
630630
exitsWith expectedExitCondition: ExitCondition,
631-
observing observedValues: Set<PartialKeyPath<ExitTestArtifacts>> = [],
631+
observing observedValues: [PartialKeyPath<ExitTestArtifacts>] = [],
632632
_ comment: @autoclosure () -> Comment? = nil,
633633
sourceLocation: SourceLocation = #_sourceLocation,
634634
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<ExitTestArtifacts>>,
1145+
observing observedValues: [PartialKeyPath<ExitTestArtifacts>],
11461146
performing body: @convention(thin) () -> Void,
11471147
expression: __Expression,
11481148
comments: @autoclosure () -> [Comment],

0 commit comments

Comments
 (0)