@@ -246,7 +246,7 @@ describes how the child process is expected to have exited:
246
246
standard, but not to the degree that signals are supported by POSIX-like or
247
247
UNIX-derived operating systems. Swift Testing makes a "best effort" to emulate
248
248
signal-handling support on Windows. See [ this] ( https://forums.swift.org/t/swift-on-windows-question-about-signals-and-exceptions/76640/2 )
249
- Swift forum message for more information.
249
+ Swift forum message for more information.
250
250
251
251
The type is declared as:
252
252
@@ -287,7 +287,7 @@ extension ExitTest {
287
287
public static var failure: Self { get }
288
288
289
289
public init (_ statusAtExit : StatusAtExit)
290
-
290
+
291
291
/// Creates a condition that matches when a process terminates with a given
292
292
/// exit code.
293
293
///
@@ -311,7 +311,7 @@ extension ExitTest {
311
311
/// systems may only reliably report the low unsigned 8 bits (0–255) of
312
312
/// the exit code.
313
313
public static func exitCode (_ exitCode : CInt ) -> Self
314
-
314
+
315
315
/// Creates a condition that matches when a process terminates with a given
316
316
/// signal.
317
317
///
@@ -624,7 +624,7 @@ and control returns to the test function that is awaiting the exit test:
624
624
625
625
``` swift
626
626
await #expect (exitsWith : .failure ) {
627
- throw TacoError.noTacosFound
627
+ throw TacoError.noTacosFound
628
628
}
629
629
```
630
630
@@ -737,7 +737,7 @@ let result = try await #require(process, exitsWith: .success)
737
737
case signal (CInt )
738
738
}
739
739
```
740
-
740
+
741
741
This simplified the set of types used for exit tests, but made comparing two
742
742
exit conditions complicated and necessitated a ` == ` operator that did not
743
743
satisfy the requirements of the ` Equatable ` protocol.
@@ -756,7 +756,7 @@ let result = try await #require(process, exitsWith: .success)
756
756
I settled on ` StatusAtExit ` because it was distinct and makes it clear that it
757
757
represents the status of a process _ at exit time_ . ` ExitStatus ` could be
758
758
interpreted as the status of the exit itself, i.e.:
759
-
759
+
760
760
``` swift
761
761
enum ExitStatus {
762
762
case running
@@ -766,6 +766,42 @@ let result = try await #require(process, exitsWith: .success)
766
766
}
767
767
```
768
768
769
+ - Using parameter packs to specify observed values and return types:
770
+
771
+ ``` swift
772
+ @freestanding (expression) public macro require <each T >(
773
+ exitsWith expectedExitCondition : ExitTest.Condition,
774
+ observing observedValues : (repeat (KeyPath<ExitTest.Result, each T>)) = (),
775
+ _ comment : @autoclosure () -> Comment? = nil ,
776
+ sourceLocation : SourceLocation = #_sourceLocation ,
777
+ performing expression : @escaping @Sendable @convention (thin) () async throws -> Void
778
+ ) -> (repeat each T)
779
+ ```
780
+
781
+ Using a parameter pack in this way would make it impossible to access
782
+ properties of the returned ` ExitTest.Result ` value that weren't observed, and
783
+ in general would mean developers wouldn't even need to use ` ExitTest.Result ` :
784
+
785
+ ``` swift
786
+ let (status, stderr) = try await #expect (
787
+ exitsWith : .failure ,
788
+ observing : (\.statusAtExit , \.standardErrorContent )
789
+ ) { ... }
790
+ #expect (status == ... )
791
+ #expect (stderr.contains (... ))
792
+ ```
793
+
794
+ Unfortunately, the ` #expect(exitsWith:) ` and ` #require(exitsWith:) ` macros do
795
+ not have enough information at compile time to correctly infer the types of
796
+ the key paths passed as ` observedValues ` above, so we end up with rather
797
+ obscure errors:
798
+
799
+ > 🛑 Cannot convert value of type 'KeyPath<_ , _ >' to expected argument type
800
+ > 'KeyPath<ExitTest.Result, _ >'
801
+
802
+ If, in the future, this error is resolved, we may wish to revisit this option,
803
+ so it can also be considered a "future direction" for the feature.
804
+
769
805
- Changing the implementation of ` precondition() ` , ` fatalError() ` , etc. in the
770
806
standard library so that they do not terminate the current process while
771
807
testing, thus removing the need to spawn a child process for an exit test.
0 commit comments