You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
food.isNutritious= isNutritious // ❌ ERROR: trying to capture state here
77
+
Customer.current.eat(food)
78
+
}
79
+
}
80
+
```
67
81
68
-
If the body returns before the child process exits, it is allowed to return and
69
-
the process exits naturally. If an error is thrown from the body, it is handled
70
-
as if the error were thrown from `main()` and the process is forced to exit.
82
+
If the body returns before the child process exits, the process exits as if
83
+
`main()` returned normally. If the body throws an error, Swift handles it as if
84
+
it were thrown from `main()` and forces the process to exit abnormally.
71
85
72
86
### Specify an exit condition
73
87
74
-
When you create an exit test, you must specify how you expect the child process
75
-
will exit by passing an instance of ``ExitTest/Condition``:
88
+
When you create an exit test, specify how you expect the child process exits by
89
+
passing an instance of ``ExitTest/Condition``:
76
90
77
-
- If the exit test's body should run to completion or exit normally (for
78
-
example, by calling `exit(EXIT_SUCCESS)` from the C standard library), pass
79
-
``ExitTest/Condition/success``.
80
-
- If the body will cause the child process to exit with some failure, but the
91
+
- If you expect the exit test's body to run to completion or exit normally (for
92
+
example, by calling [`exit(EXIT_SUCCESS)`](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/exit.3.html)
93
+
from the C standard library), pass ``ExitTest/Condition/success``.
94
+
- If you expect the body to cause the child process to exit abnormally, but the
81
95
exact status reported by the system is not important, pass
82
96
``ExitTest/Condition/failure``.
83
97
- If you need to check for a specific exit code or signal, pass
84
98
``ExitTest/Condition/exitCode(_:)`` or ``ExitTest/Condition/signal(_:)``.
85
99
86
100
When the child process exits, the parent process resumes and compares the exit
87
101
status of the child process against the expected exit condition you passed. If
88
-
they match, the exit test has passed; otherwise, it has failed and the testing
89
-
library records an issue.
102
+
they match, the exit test passes; otherwise, it fails and the testing library
103
+
records an issue.
90
104
91
105
### Gather output from the child process
92
106
107
+
The ``expect(exitsWith:observing:_:sourceLocation:performing:)`` and
108
+
``require(exitsWith:observing:_:sourceLocation:performing:)`` macros return an
109
+
instance of ``ExitTest/Result`` that contains information about the state of the
110
+
child process.
111
+
93
112
By default, the child process is configured without a standard output or
94
113
standard error stream. If your test needs to review the content of either of
95
-
these streams, you can pass its key path to ``expect(exitsWith:observing:_:sourceLocation:performing:)``
96
-
or ``require(exitsWith:observing:_:sourceLocation:performing:)``:
114
+
these streams, pass the key path to the corresponding ``ExitTest/Result``
115
+
property to the macro:
97
116
98
117
```swift
99
118
extensionCustomer {
@@ -120,36 +139,14 @@ extension Customer {
120
139
}
121
140
```
122
141
123
-
- Note: The content of the standard output and standard error streams may
124
-
contain any arbitrary sequence of bytes, including sequences that are not
125
-
valid UTF-8 and cannot be decoded by [`String.init(cString:)`](https://developer.apple.com/documentation/swift/string/init(cstring:)-6kr8s).
142
+
- Note: The content of the standard output and standard error streams can
143
+
contain any arbitrary sequence of bytes, including sequences that aren't valid
144
+
UTF-8 and can't be decoded by [`String.init(cString:)`](https://developer.apple.com/documentation/swift/string/init(cstring:)-6kr8s).
126
145
These streams are globally accessible within the child process, and any code
127
146
running in an exit test may write to it including the operating system and any
128
-
third-party dependencies you have declared in your package.
147
+
third-party dependencies you declare in your package description or Xcode
148
+
project.
129
149
130
150
The testing library always sets ``ExitTest/Result/statusAtExit`` to the actual
131
151
exit status of the child process (as reported by the system) even if you do not
132
152
pass it.
133
-
134
-
### Constraints on exit tests
135
-
136
-
#### State cannot be captured
137
-
138
-
Exit tests cannot capture any state originating in the parent process or from
139
-
the enclosing lexical context. For example, the following exit test will fail to
140
-
compile because it captures a variable declared outside the exit test itself:
0 commit comments