8
8
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9
9
//
10
10
11
- #if !SWT_NO_EXIT_TESTS
12
11
@_spi ( Experimental) @_spi ( ForToolsIntegrationOnly)
12
+ #if SWT_NO_EXIT_TESTS
13
+ @available ( * , unavailable, message: " Exit tests are not available on this platform. " )
14
+ #endif
13
15
extension ExitTest {
14
16
/// A type representing a value captured by an exit test's body.
15
17
///
@@ -46,6 +48,7 @@ extension ExitTest {
46
48
/// encoded in the parent process and then updates the ``wrappedValue``
47
49
/// property of each element in the array before calling the exit test's body.
48
50
public struct CapturedValue : Sendable {
51
+ #if !SWT_NO_EXIT_TESTS
49
52
/// An enumeration of the different states a captured value can have.
50
53
private enum _Kind : Sendable {
51
54
/// The runtime value of the captured value is known.
@@ -65,20 +68,26 @@ extension ExitTest {
65
68
init ( typeOnly type: ( some Codable & Sendable ) . Type) {
66
69
_kind = . typeOnly( type)
67
70
}
71
+ #endif
68
72
69
73
/// The underlying value captured by this instance at runtime.
70
74
///
71
75
/// In a child process created by the current exit test handler, the value
72
76
/// of this property is `nil` until the entry point sets it.
73
77
public var wrappedValue : ( any Codable & Sendable ) ? {
74
78
get {
79
+ #if !SWT_NO_EXIT_TESTS
75
80
if case let . wrappedValue( wrappedValue) = _kind {
76
81
return wrappedValue
77
82
}
78
83
return nil
84
+ #else
85
+ fatalError ( " Unsupported " )
86
+ #endif
79
87
}
80
88
81
89
set {
90
+ #if !SWT_NO_EXIT_TESTS
82
91
let type = typeOfWrappedValue
83
92
84
93
func validate< T, U> ( _ newValue: T , is expectedType: U . Type ) {
@@ -91,6 +100,9 @@ extension ExitTest {
91
100
} else {
92
101
_kind = . typeOnly( type)
93
102
}
103
+ #else
104
+ fatalError ( " Unsupported " )
105
+ #endif
94
106
}
95
107
}
96
108
@@ -99,16 +111,21 @@ extension ExitTest {
99
111
/// This type is known at compile time and is always available, even before
100
112
/// this instance's ``wrappedValue`` property is set.
101
113
public var typeOfWrappedValue : any ( Codable & Sendable ) . Type {
114
+ #if !SWT_NO_EXIT_TESTS
102
115
switch _kind {
103
116
case let . wrappedValue( wrappedValue) :
104
117
type ( of: wrappedValue)
105
118
case let . typeOnly( type) :
106
119
type
107
120
}
121
+ #else
122
+ fatalError ( " Unsupported " )
123
+ #endif
108
124
}
109
125
}
110
126
}
111
127
128
+ #if !SWT_NO_EXIT_TESTS
112
129
// MARK: - Collection conveniences
113
130
114
131
extension Array where Element == ExitTest . CapturedValue {
@@ -166,3 +183,4 @@ extension Collection where Element == ExitTest.CapturedValue {
166
183
}
167
184
}
168
185
#endif
186
+
0 commit comments