Skip to content

Commit 78506a5

Browse files
committed
Make sure ExitTest.CapturedValue is still sufficiently available for the compiler when SWT_NO_EXIT_TESTS is defined.
1 parent 64789e2 commit 78506a5

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Sources/Testing/ExitTests/ExitTest.CapturedValue.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if !SWT_NO_EXIT_TESTS
1211
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
12+
#if SWT_NO_EXIT_TESTS
13+
@available(*, unavailable, message: "Exit tests are not available on this platform.")
14+
#endif
1315
extension ExitTest {
1416
/// A type representing a value captured by an exit test's body.
1517
///
@@ -46,6 +48,7 @@ extension ExitTest {
4648
/// encoded in the parent process and then updates the ``wrappedValue``
4749
/// property of each element in the array before calling the exit test's body.
4850
public struct CapturedValue: Sendable {
51+
#if !SWT_NO_EXIT_TESTS
4952
/// An enumeration of the different states a captured value can have.
5053
private enum _Kind: Sendable {
5154
/// The runtime value of the captured value is known.
@@ -65,20 +68,26 @@ extension ExitTest {
6568
init(typeOnly type: (some Codable & Sendable).Type) {
6669
_kind = .typeOnly(type)
6770
}
71+
#endif
6872

6973
/// The underlying value captured by this instance at runtime.
7074
///
7175
/// In a child process created by the current exit test handler, the value
7276
/// of this property is `nil` until the entry point sets it.
7377
public var wrappedValue: (any Codable & Sendable)? {
7478
get {
79+
#if !SWT_NO_EXIT_TESTS
7580
if case let .wrappedValue(wrappedValue) = _kind {
7681
return wrappedValue
7782
}
7883
return nil
84+
#else
85+
fatalError("Unsupported")
86+
#endif
7987
}
8088

8189
set {
90+
#if !SWT_NO_EXIT_TESTS
8291
let type = typeOfWrappedValue
8392

8493
func validate<T, U>(_ newValue: T, is expectedType: U.Type) {
@@ -91,6 +100,9 @@ extension ExitTest {
91100
} else {
92101
_kind = .typeOnly(type)
93102
}
103+
#else
104+
fatalError("Unsupported")
105+
#endif
94106
}
95107
}
96108

@@ -99,16 +111,21 @@ extension ExitTest {
99111
/// This type is known at compile time and is always available, even before
100112
/// this instance's ``wrappedValue`` property is set.
101113
public var typeOfWrappedValue: any (Codable & Sendable).Type {
114+
#if !SWT_NO_EXIT_TESTS
102115
switch _kind {
103116
case let .wrappedValue(wrappedValue):
104117
type(of: wrappedValue)
105118
case let .typeOnly(type):
106119
type
107120
}
121+
#else
122+
fatalError("Unsupported")
123+
#endif
108124
}
109125
}
110126
}
111127

128+
#if !SWT_NO_EXIT_TESTS
112129
// MARK: - Collection conveniences
113130

114131
extension Array where Element == ExitTest.CapturedValue {
@@ -166,3 +183,4 @@ extension Collection where Element == ExitTest.CapturedValue {
166183
}
167184
}
168185
#endif
186+

0 commit comments

Comments
 (0)