Skip to content

Commit 3eb7b35

Browse files
committed
Use initializer rather than mutating context dictionaries after creation
1 parent ff66fb8 commit 3eb7b35

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

Sources/Testing/ExitTests/ExitTest.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,10 @@ func callExitTest(
293293
let actualExitCondition = result.exitCondition
294294

295295
// Plumb the exit test's result through the general expectation machinery.
296-
var expectationContext = __ExpectationContext()
297-
expectationContext.sourceCode[.root] = sourceCode
298-
expectationContext.runtimeValues[.root] = { Expression.Value(reflecting: actualExitCondition) }
296+
let expectationContext = __ExpectationContext(
297+
sourceCode: [.root: sourceCode],
298+
runtimeValues: [.root: { Expression.Value(reflecting: actualExitCondition) }]
299+
)
299300
return check(
300301
expectedExitCondition == actualExitCondition,
301302
expectationContext: expectationContext,

Sources/Testing/Expectations/ExpectationChecking+Macro.swift

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ public func __checkEscapedCondition(
236236
isRequired: Bool,
237237
sourceLocation: SourceLocation
238238
) -> Result<Void, any Error> {
239-
var expectationContext = __ExpectationContext()
240-
expectationContext.sourceCode[.root] = sourceCode
239+
let expectationContext = __ExpectationContext(
240+
sourceCode: [.root: sourceCode],
241+
)
241242

242243
return check(
243244
condition,
@@ -265,8 +266,9 @@ public func __checkEscapedCondition<T>(
265266
isRequired: Bool,
266267
sourceLocation: SourceLocation
267268
) -> Result<T, any Error> where T: ~Copyable {
268-
var expectationContext = __ExpectationContext()
269-
expectationContext.sourceCode[.root] = sourceCode
269+
let expectationContext = __ExpectationContext(
270+
sourceCode: [.root: sourceCode],
271+
)
270272

271273
let result = check(
272274
optionalValue != nil,
@@ -394,8 +396,9 @@ public func __checkClosureCall(
394396
mismatchExplanationValue = "an error was thrown when none was expected: \(_description(of: error))"
395397
}
396398

397-
var expectationContext = __ExpectationContext()
398-
expectationContext.sourceCode[.root] = sourceCode
399+
let expectationContext = __ExpectationContext(
400+
sourceCode: [.root: sourceCode],
401+
)
399402
return check(
400403
success,
401404
expectationContext: expectationContext,
@@ -434,8 +437,9 @@ public func __checkClosureCall(
434437
mismatchExplanationValue = "an error was thrown when none was expected: \(_description(of: error))"
435438
}
436439

437-
var expectationContext = __ExpectationContext()
438-
expectationContext.sourceCode[.root] = sourceCode
440+
let expectationContext = __ExpectationContext(
441+
sourceCode: [.root: sourceCode],
442+
)
439443
return check(
440444
success,
441445
expectationContext: expectationContext,
@@ -520,8 +524,9 @@ public func __checkClosureCall<R>(
520524
isRequired: Bool,
521525
sourceLocation: SourceLocation
522526
) -> Result<(any Error)?, any Error> {
523-
var expectationContext = __ExpectationContext()
524-
expectationContext.sourceCode[.root] = sourceCode
527+
var expectationContext = __ExpectationContext(
528+
sourceCode: [.root: sourceCode],
529+
)
525530

526531
var errorMatches = false
527532
var mismatchExplanationValue: String? = nil
@@ -574,8 +579,9 @@ public func __checkClosureCall<R>(
574579
isolation: isolated (any Actor)? = #isolation,
575580
sourceLocation: SourceLocation
576581
) async -> Result<(any Error)?, any Error> {
577-
var expectationContext = __ExpectationContext()
578-
expectationContext.sourceCode[.root] = sourceCode
582+
var expectationContext = __ExpectationContext(
583+
sourceCode: [.root: sourceCode],
584+
)
579585

580586
var errorMatches = false
581587
var mismatchExplanationValue: String? = nil

0 commit comments

Comments
 (0)