Skip to content

Route swift-testing output to /dev/stdout, CONOUT$ #1046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

plemarquand
Copy link
Contributor

Currently we are merging two streams of information to produce swift-testing test output, the JSON event stream written to a named pipe and the stream of data from stdout. This captures both testing events and user outputs produced by things like print() statements.

However, this approach interleaves the two sources in an arbitrary order. Print statements produced during a test run are typically read after events on the named pipe, which makes it difficult to tell what prints belong to what test.

In order to enforce the correct order we can configure swift-testing to write its events to /dev/stdout (or CONOUT$ on Windows). Swift-testing aquires a lock to the fd it is writing events and output to, so the order of events and prints is correctly enforced.

This also simplifies a lot of the code that worked with the JSON event stream as we can now rely solely on the task's stdout/stderr output without the need for named pipes.

When parsing stdout we try and parse a JSON event that matches the swift-testing event schema, and if we fail we print the line directly. If it is parseable, we process it as a swift-testing JSON event and omit it from the test run output.

@plemarquand
Copy link
Contributor Author

Output on Windows will appear incorrectly ordered until swiftlang/swift-testing#654 lands, which will adjust the locking behaviour of swift-testing w/ CONOUT$ on Windows to match how it works on Darwin/Linux.

@plemarquand plemarquand force-pushed the swift-testing-dev-stdout branch from bc46f22 to 1c4e7ff Compare August 30, 2024 15:51
Currently we are merging two streams of information to produce
swift-testing test output, the JSON event stream written to a named pipe
and the stream of data from stdout. This captures both testing events
and user outputs produced by things like `print()` statements.

However, this approach interleaves the two sources in an arbitrary
order. Print statements produced during a test run are typically read
after events on the named pipe, which makes it difficult to tell what
prints belong to what test.

In order to enforce the correct order we can configure swift-testing to
write its events to /dev/stdout (or CONOUT$ on Windows). Swift-testing
aquires a lock to the `fd` it is writing events and output to, so the
order of events and prints is correctly enforced.

This also simplifies a lot of the code that worked with the JSON event
stream as we can now rely solely on the task's stdout/stderr output
without the need for named pipes.

When parsing stdout we try and parse a JSON event that matches the
swift-testing event schema, and if we fail we print the line directly.
If it is parseable, we process it as a swift-testing JSON event and omit
it from the test run output.
@plemarquand plemarquand force-pushed the swift-testing-dev-stdout branch from 1c4e7ff to 8b55188 Compare September 3, 2024 17:45
@plemarquand
Copy link
Contributor Author

This addresses #1054, however currently this approach doesn't account for the line wrapping that occurs when you write long JSON events to /dev/stdout.

@plemarquand
Copy link
Contributor Author

This is supplanted by #1058 which is a simpler approach with less edge cases to contend with

@plemarquand plemarquand closed this Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant