Skip to content

Commit aa427e7

Browse files
authored
Make the ExitTest type move-only. (#712)
This PR adds `~Copyable` to `ExitTest`, which is a tools-only bit of SPI representing a (gasp) exit test. This change has the effect of making it impossible to accidentally invoke an exit test body in the parent process, and also impossible to accidentally invoke twice in the child process. Phew! ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 1a96c0c commit aa427e7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Sources/Testing/ExitTests/ExitTest.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ private import _TestingInternals
2020
/// Instances of this type describe an exit test defined by the test author and
2121
/// discovered or called at runtime.
2222
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
23-
public struct ExitTest: Sendable {
23+
public struct ExitTest: Sendable, ~Copyable {
2424
/// The expected exit condition of the exit test.
2525
public var expectedExitCondition: ExitCondition
2626

2727
/// The body closure of the exit test.
28-
fileprivate var body: @Sendable () async throws -> Void
28+
fileprivate var body: @Sendable () async throws -> Void = {}
2929

3030
/// The source location of the exit test.
3131
///
@@ -73,7 +73,7 @@ public struct ExitTest: Sendable {
7373
/// to terminate the process; if it does not, the testing library will
7474
/// terminate the process in a way that causes the corresponding expectation
7575
/// to fail.
76-
public func callAsFunction() async -> Never {
76+
public consuming func callAsFunction() async -> Never {
7777
Self._disableCrashReporting()
7878

7979
do {
@@ -146,7 +146,6 @@ extension ExitTest {
146146
///
147147
/// - Parameters:
148148
/// - expectedExitCondition: The expected exit condition.
149-
/// - body: The exit test body.
150149
/// - expression: The expression, corresponding to `condition`, that is being
151150
/// evaluated (if available at compile time.)
152151
/// - comments: An array of comments describing the expectation. This array
@@ -161,7 +160,7 @@ extension ExitTest {
161160
/// convention.
162161
func callExitTest(
163162
exitsWith expectedExitCondition: ExitCondition,
164-
performing body: @escaping @Sendable () async throws -> Void,
163+
performing _: @escaping @Sendable () async throws -> Void,
165164
expression: __Expression,
166165
comments: @autoclosure () -> [Comment],
167166
isRequired: Bool,
@@ -173,7 +172,7 @@ func callExitTest(
173172

174173
let actualExitCondition: ExitCondition
175174
do {
176-
let exitTest = ExitTest(expectedExitCondition: expectedExitCondition, body: body, sourceLocation: sourceLocation)
175+
let exitTest = ExitTest(expectedExitCondition: expectedExitCondition, sourceLocation: sourceLocation)
177176
actualExitCondition = try await configuration.exitTestHandler(exitTest)
178177
} catch {
179178
// An error here would indicate a problem in the exit test handler such as a
@@ -242,9 +241,11 @@ extension ExitTest {
242241
/// configurations is undefined.
243242
static func findInEnvironmentForEntryPoint() -> Self? {
244243
if var sourceLocationString = Environment.variable(named: "SWT_EXPERIMENTAL_EXIT_TEST_SOURCE_LOCATION") {
245-
return try? sourceLocationString.withUTF8 { sourceLocationBuffer in
244+
let sourceLocation = try? sourceLocationString.withUTF8 { sourceLocationBuffer in
246245
let sourceLocationBuffer = UnsafeRawBufferPointer(sourceLocationBuffer)
247-
let sourceLocation = try JSON.decode(SourceLocation.self, from: sourceLocationBuffer)
246+
return try JSON.decode(SourceLocation.self, from: sourceLocationBuffer)
247+
}
248+
if let sourceLocation {
248249
return find(at: sourceLocation)
249250
}
250251
}

0 commit comments

Comments
 (0)