@@ -33,8 +33,20 @@ public struct ExitTest: Sendable {
33
33
public var sourceLocation : SourceLocation
34
34
35
35
/// Call the exit test in the current process.
36
- public func callAsFunction( ) async -> Void {
36
+ ///
37
+ /// This function invokes the closure originally passed to
38
+ /// `#expect(exitsWith:)` _in the current process_. That closure is expected
39
+ /// to terminate the process; if it does not, the testing library will
40
+ /// terminate the process in a way that causes the corresponding expectation
41
+ /// to fail.
42
+ public func callAsFunction( ) async -> Never {
37
43
await body ( )
44
+
45
+ // Run some glue code that terminates the process with an exit condition
46
+ // that does not match the expected one. If the exit test's body doesn't
47
+ // terminate, we'll manually call exit() and cause the test to fail.
48
+ let expectingFailure = expectedExitCondition. matches ( . failure)
49
+ exit ( expectingFailure ? EXIT_SUCCESS : EXIT_FAILURE)
38
50
}
39
51
}
40
52
@@ -96,19 +108,7 @@ extension ExitTest {
96
108
}
97
109
}
98
110
99
- if var result = context. result {
100
- // Add some glue code that terminates the process with an exit condition
101
- // that does not match the expected one. If the exit test's body doesn't
102
- // terminate, we'll manually call exit() and cause the test to fail.
103
- let expectingFailure = result. expectedExitCondition. matches ( . failure)
104
- result. body = { [ body = result. body] in
105
- await body ( )
106
- exit ( expectingFailure ? EXIT_SUCCESS : EXIT_FAILURE)
107
- }
108
- return result
109
- }
110
-
111
- return nil
111
+ return context. result
112
112
}
113
113
}
114
114
@@ -288,34 +288,30 @@ extension ExitTest {
288
288
// to run.
289
289
childEnvironment [ " SWT_EXPERIMENTAL_EXIT_TEST_SOURCE_LOCATION " ] = try String ( data: JSONEncoder ( ) . encode ( exitTest. sourceLocation) , encoding: . utf8) !
290
290
291
- let actualExitCode : Int32
292
- let wasSignalled : Bool
293
- do {
294
- ( actualExitCode, wasSignalled) = try await withCheckedThrowingContinuation { continuation in
295
- let process = Process ( )
296
- process. executableURL = childProcessURL
297
- process. arguments = childArguments
298
- process. environment = childEnvironment
299
- process. terminationHandler = { process in
300
- continuation. resume ( returning: ( process. terminationStatus, process. terminationReason == . uncaughtSignal) )
301
- }
302
- do {
303
- try process. run ( )
304
- } catch {
305
- continuation. resume ( throwing: error)
306
- }
291
+ let ( actualExitCode, wasSignalled) = try await withCheckedThrowingContinuation { continuation in
292
+ let process = Process ( )
293
+ process. executableURL = childProcessURL
294
+ process. arguments = childArguments
295
+ process. environment = childEnvironment
296
+ process. terminationHandler = { process in
297
+ continuation. resume ( returning: ( process. terminationStatus, process. terminationReason == . uncaughtSignal) )
298
+ }
299
+ do {
300
+ try process. run ( )
301
+ } catch {
302
+ continuation. resume ( throwing: error)
307
303
}
304
+ }
308
305
309
- if wasSignalled {
306
+ if wasSignalled {
310
307
#if os(Windows)
311
- // Actually an uncaught SEH/VEH exception (which we don't model yet.)
312
- return . failure
308
+ // Actually an uncaught SEH/VEH exception (which we don't model yet.)
309
+ return . failure
313
310
#else
314
- return . signal( actualExitCode)
311
+ return . signal( actualExitCode)
315
312
#endif
316
- }
317
- return . exitCode( actualExitCode)
318
313
}
314
+ return . exitCode( actualExitCode)
319
315
}
320
316
}
321
317
}
0 commit comments