-
Notifications
You must be signed in to change notification settings - Fork 128
Implement swift test --xunit-output.
#108
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
|
@swift-ci please test |
1 similar comment
Contributor
Author
|
@swift-ci please test |
This PR implements the `--xunit-output` option when using SwiftPM. Note that internally, the code refers to JUnit rather than xUnit: that's because the format produced by XCTest and SwiftPM today does not _not_ conform to the xUnit schema(s) described at https://www.xunit.org, but rather are a variant of the (schema-less?) JUnit format. This change renames `Event.Recorder` to `Event.ConsoleOutputRecorder` and adds `Event.JUnitXMLRecorder`. It adds a protocol, `EventRecorder` (remember that protocols cannot be nested in types, so no dot) to which both of these types conform, although that's a formality only as we are not doing anything generic over recorder instances. If the user specifies `--xunit-output` when calling into `swift test`, we open a file (using good ol' `fopen()`.) Our first official use of a non-copyable type is here (hooray!) as we use one to box the resulting file handle and ensure we call `fclose()` after tests finish running. We do **not** use Foundation's `FileHandle` for this purpose because, although it has the right ownership semantics, it does not expose API for creating _new_ files, only for opening existing ones. `fopen()` can of course fail, so we now need to potentially throw a C error code. I've added an internal `CError` type to represent them. We're not using `POSIXError` here because it's a Foundation dependency, but also because it's possible for `errno` to be set to a value that is not representable as an instance of `POSIXErrorCode`, which is a closed enumeration. Resolves rdar://118199250.
9e31aa4 to
9e56630
Compare
Sources/Testing/Events/Recorder/Event.ConsoleOutputRecorder.swift
Outdated
Show resolved
Hide resolved
Co-authored-by: Stuart Montgomery <smontgomery@apple.com>
Co-authored-by: Stuart Montgomery <smontgomery@apple.com>
Contributor
Author
|
@swift-ci please test |
stmontgomery
approved these changes
Nov 13, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the
--xunit-outputoption when using SwiftPM. Note that internally, the code refers to JUnit rather than xUnit: that's because the format produced by XCTest and SwiftPM today does not not conform to the xUnit schema(s) described at https://www.xunit.org, but rather are a variant of the (schema-less?) JUnit format.This change renames
Event.RecordertoEvent.ConsoleOutputRecorderand addsEvent.JUnitXMLRecorder. It adds a protocol,EventRecorder(remember that protocols cannot be nested in types, so no dot) to which both of these types conform, although that's a formality only as we are not doing anything generic over recorder instances.If the user specifies
--xunit-outputwhen calling intoswift test, we open a file (using good ol'fopen().) Our first official use of a non-copyable type is here (hooray!) as we use one to box the resulting file handle and ensure we callfclose()after tests finish running. We do not use Foundation'sFileHandlefor this purpose because, although it has the right ownership semantics, it does not expose API for creating new files, only for opening existing ones.fopen()can of course fail, so we now need to potentially throw a C error code. I've added an internalCErrortype to represent them. We're not usingPOSIXErrorhere because it's a Foundation dependency, but also because it's possible forerrnoto be set to a value that is not representable as an instance ofPOSIXErrorCode, which is a closed enumeration.Note
Without changes (TBD) in swift-package-manager, using
--xunit-outputwhen running both swift-testing and XCTest tests will result in one library overwriting the other's output. The work to resolve that will need to take place on the SwiftPM side.Checklist:
Resolves rdar://118199250.