Skip to content

Conversation

@grynspan
Copy link
Contributor

@grynspan grynspan commented Oct 18, 2024

This PR adds stdout and stderr capture to exit tests.

Gathering these streams can be very expensive, so they are opt-in. There is a new argument to #expect(exitsWith:), observedValues, to which you can pass one or more key paths on ExitTest.Result to indicate which bits you want:

 let result = try await #require(exitsWith: .failure, observing: [\.standardOutputContent]) {
   print("Goodbye, world!")
   fatalError()
 }
 #expect(result.standardOutputContent.contains(UInt8(ascii: "G")))

Some changes to pipes were needed to satisfy the compiler's concerns about Pipe being a move-only type that contains other move-only types—now it's just a function that returns two FileHandle instances. This is simpler anyway.

It is possible some callers will want stdout and stderr to be set, but to something other than a pipe (such as a file on disk or a PTY.) While these are interesting cases, they are beyond the scope of this PR.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@grynspan grynspan added enhancement New feature or request tools integration 🛠️ Integration of swift-testing into tools/IDEs exit-tests ☠️ Work related to exit tests command-line experience ⌨️ enhancements to the command line interface labels Oct 18, 2024
@grynspan grynspan added this to the Swift 6.1 milestone Oct 18, 2024
@grynspan grynspan self-assigned this Oct 18, 2024
@grynspan
Copy link
Contributor Author

@swift-ci test

1 similar comment
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

3 similar comments
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan force-pushed the jgrynspan/child-process-stdio branch from 0c5af7f to a7a8d00 Compare October 21, 2024 16:07
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan mentioned this pull request Oct 22, 2024
2 tasks
@grynspan grynspan force-pushed the jgrynspan/child-process-stdio branch from a7a8d00 to 555d59a Compare October 22, 2024 14:41
This PR adds `stdout` and `stderr` capture to exit tests.

Gathering these streams can be very expensive, so they are _opt-in_. There is a
new argument to `#expect(exitsWith:)`, `observedValues`, to which you can pass
one or more key paths on `ExitTest.Result` to indicate which bits you want:

```swift
 let result = await #expect(exitsWith: .failure, observing: [\.standardOutputContent]) {
   print("Goodbye, world!")
   fatalError()
 }
 #expect(result.standardOutputContent.contains(UInt8(ascii: "G")))
```

Some changes to pipes were needed to satisfy the compiler's concerns about
`Pipe` being a move-only type that contains other move-only types—now it's just
a function that returns two `FileHandle` instances. This is simpler anyway.

It is possible some callers will want `stdout` and `stderr` to be set, but to
something other than a pipe (such as a file on disk or a PTY.) While these are
interesting cases, they are beyond the scope of this PR.
@grynspan grynspan force-pushed the jgrynspan/child-process-stdio branch from 555d59a to 1d3b1d4 Compare October 22, 2024 17:29
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan merged commit e6abba8 into main Oct 22, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/child-process-stdio branch October 22, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command-line experience ⌨️ enhancements to the command line interface enhancement New feature or request exit-tests ☠️ Work related to exit tests tools integration 🛠️ Integration of swift-testing into tools/IDEs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants