@@ -10,6 +10,11 @@ See https://swift.org/LICENSE.txt for license information
10
10
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
11
11
-->
12
12
13
+ @Metadata {
14
+ @Available (macOS, introduced: 10.15)
15
+ @Available (Swift, introduced: 6.2)
16
+ }
17
+
13
18
Use exit tests to test functionality that may cause a test process to exit.
14
19
15
20
## Overview
@@ -33,7 +38,9 @@ precondition will fail and Swift will force the process to exit. You can write
33
38
an exit test to validate preconditions like the ones above and to make sure that
34
39
your functions correctly catch invalid inputs.
35
40
36
- ## Create an exit test
41
+ - Note: Exit tests are available on macOS, Linux, FreeBSD, OpenBSD, and Windows.
42
+
43
+ ### Create an exit test
37
44
38
45
To create an exit test, call either the `` expect(exitsWith:observing:_:sourceLocation:performing:) ``
39
46
or the `` require(exitsWith:observing:_:sourceLocation:performing:) `` macro:
@@ -63,7 +70,7 @@ If the body returns before the child process exits, it is allowed to return and
63
70
the process exits naturally. If an error is thrown from the body, it is handled
64
71
as if the error were thrown from ` main() ` and the process is forced to exit.
65
72
66
- ## Specify an exit condition
73
+ ### Specify an exit condition
67
74
68
75
When you create an exit test, you must specify how you expect the child process
69
76
will exit by passing an instance of `` ExitTest/Condition `` :
@@ -82,7 +89,7 @@ status of the child process against the expected exit condition you passed. If
82
89
they match, the exit test has passed; otherwise, it has failed and the testing
83
90
library records an issue.
84
91
85
- ## Gather output from the child process
92
+ ### Gather output from the child process
86
93
87
94
By default, the child process is configured without a standard output or
88
95
standard error stream. If your test needs to review the content of either of
@@ -123,9 +130,9 @@ extension Customer {
123
130
The actual exit condition of the child process is always reported by the testing
124
131
library even if you do not specify it in ` observedValues ` .
125
132
126
- ## Constraints on exit tests
133
+ ### Constraints on exit tests
127
134
128
- ### State cannot be captured
135
+ #### State cannot be captured
129
136
130
137
Exit tests cannot capture any state originating in the parent process or from
131
138
the enclosing lexical context. For example, the following exit test will fail to
@@ -142,6 +149,6 @@ compile because it captures a variable declared outside the exit test itself:
142
149
}
143
150
```
144
151
145
- ### Exit tests cannot be nested
152
+ #### Exit tests cannot be nested
146
153
147
154
An exit test cannot run within another exit test.
0 commit comments