Skip to content

Conversation

@grynspan
Copy link
Contributor

@grynspan grynspan commented Nov 9, 2023

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.

Note

Without changes (TBD) in swift-package-manager, using --xunit-output when 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:

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

Resolves rdar://118199250.

@grynspan
Copy link
Contributor Author

grynspan commented Nov 9, 2023

@swift-ci please test

1 similar comment
@grynspan
Copy link
Contributor Author

grynspan commented Nov 9, 2023

@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.
@grynspan grynspan force-pushed the jgrynspan/junit-xml-output branch from 9e31aa4 to 9e56630 Compare November 13, 2023 16:47
@stmontgomery stmontgomery added the enhancement New feature or request label Nov 13, 2023
grynspan and others added 3 commits November 13, 2023 16:05
Co-authored-by: Stuart Montgomery <smontgomery@apple.com>
Co-authored-by: Stuart Montgomery <smontgomery@apple.com>
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan merged commit f03cc98 into main Nov 14, 2023
@grynspan grynspan deleted the jgrynspan/junit-xml-output branch November 14, 2023 13:13
@grynspan grynspan added the swiftpm-integration 📦 Swift Package Manager integration label Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request swiftpm-integration 📦 Swift Package Manager integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants