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
This PR introduces a "back channel" file handle to exit tests, allowing us to
record issues that occur within exit test bodies. For example:
```swift
await #expect(exitsWith: .failure) {
let context = try #require(possiblyMissingContext)
...
}
```
In this example, if the call to `try #require()` finds `nil`, it will record an
issue, but that issue today will be lost because there's no mechanism to forward
the issue back to the parent process hosting the exit test. This PR fixes that!
Issues are converted to JSON using the same schema we use for event handling,
then written over a pipe back to the parent process where they are decoded. This
decoding is lossy, so there will be further refinement needed here to try to
preserve more information about the recorded issues. That said, "it's got good
bones" right?
On Darwin, Linux, and FreeBSD, the pipe's write end is allowed to survive into
the child process (i.e. no `FD_CLOEXEC`). On Windows, the equivalent is to tell
`CreateProcessW()` to explicitly inherit a `HANDLE`. The identity of this file
descriptor or handle is passed to the child process via environment variable.
The child process then parses the file descriptor or handle out of the
environment and converts it back to a `FileHandle` that is then connected to an
instance of `Configuration` with an event handler set, and off we go.
Because we can now report these issues back to the parent process, I've removed
the compile-time diagnostic in the `#expect(exitsWith:)` macro implementation
that we emit when we see a nested `#expect()` or `#require()` call.
"JSON encoder produced one or more newline characters while encoding an event to JSON. Please file a bug report at https://github.com/swiftlang/swift-testing/issues/new",
585
-
options:.for(.stderr)
586
-
)
587
-
#if SWT_TARGET_OS_APPLE
588
-
try?FileHandle.stderr.write(message)
589
-
#else
590
-
print(message)
591
-
#endif
592
-
#endif
593
-
594
-
// Remove the newline characters to conform to JSON lines specification.
"JSON encoder produced one or more newline characters while encoding an event to JSON. Please file a bug report at https://github.com/swiftlang/swift-testing/issues/new",
27
+
options:.for(.stderr)
28
+
)
29
+
#if SWT_TARGET_OS_APPLE
30
+
try?FileHandle.stderr.write(message)
31
+
#else
32
+
print(message)
33
+
#endif
34
+
#endif
35
+
36
+
// Remove the newline characters to conform to JSON lines specification.
37
+
varjson=Array(json)
38
+
json.removeAll(where: \.isASCIINewline)
39
+
try json.withUnsafeBytes(eventHandler)
40
+
}else{
41
+
// No newlines found, no need to copy the buffer.
42
+
tryeventHandler(json)
43
+
}
44
+
}
45
+
13
46
/// Create an event handler that encodes events as JSON and forwards them to
14
47
/// an ABI-friendly event handler.
15
48
///
16
49
/// - Parameters:
50
+
/// - encodeAsJSONLines: Whether or not to ensure JSON passed to
51
+
/// `eventHandler` is encoded as JSON Lines (i.e. that it does not contain
52
+
/// extra newlines.)
17
53
/// - eventHandler: The event handler to forward events to. See
18
54
/// ``ABIv0/EntryPoint-swift.typealias`` for more information.
19
55
///
@@ -27,10 +63,17 @@ extension ABIv0.Record {
27
63
/// performs additional postprocessing before writing JSON data to ensure it
0 commit comments