Skip to content

Commit e8a288a

Browse files
committed
Use initializer rather than mutating context dictionaries after creation
1 parent 5dca4b7 commit e8a288a

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

Sources/Testing/ExitTests/ExitTest.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,10 @@ func callExitTest(
291291
let actualExitCondition = result.exitCondition
292292

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

Sources/Testing/Expectations/ExpectationChecking+Macro.swift

+18-12
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)