Skip to content

Emit a specific exit code when no tests match inputs to swift test. #536

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 6 commits into from
Jul 15, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Jul 13, 2024

This PR modifies the entry point function used by Swift Package Manager so that when no tests match the inputs (or, in the case of swift test list, when there are no Swift Testing tests in the test target), Swift Package Manager can detect it and respond appropriately.

Because exit codes exist in a flat namespace, and because on POSIX-y systems only the low 8 bits of an exit code are reliable, our options here are limited. I have selected the EX_UNAVAILABLE code from sysexits.h to represent this state. On Windows, all 32 bits of the exit code are propagated, but there is no EX_UNAVAILABLE value, so I've used the Win32 ERROR_NOT_FOUND error code instead. My assumption is that neither of these codes is likely to actually be passed to exit() by test code (because why would they be?)

A separate PR is required in Swift Package Manager to correctly handle this exit code and emit the noMatchingTests diagnostic that's currently emitted only for XCTest.

Resolves rdar://131704539.

Checklist:

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

This PR modifies the entry point function used by Swift Package Manager so that
when no tests match the inputs (or, in the case of `swift test list`, when there
are no Swift Testing tests in the test target), Swift Package Manager can detect
it and respond appropriately.

Because exit codes exist in a flat namespace, and because on POSIX-y systems
only the low 8 bits of an exit code are reliable, our options here are limited.
I have selected the `EX_UNAVAILABLE` code from sysexits.h to represent this
state. On Windows, all 32 bits of the exit code are propagated, but there is no
`EX_UNAVAILABLE` value, so I've used the Win32 `ERROR_NOT_FOUND` error code
instead. My assumption is that neither of these codes is likely to _actually_
be passed to `exit()` by test code (because why would they be?)

A separate PR is required in Swift Package Manager to correctly handle this
exit code and emit the `noMatchingTests` diagnostic that's currently emitted
only for XCTest.
@grynspan grynspan added enhancement New feature or request swiftpm-integration 📦 Swift Package Manager integration windows 🪟 Windows support linux 🐧 Linux support (all distros) darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support labels Jul 13, 2024
@grynspan grynspan self-assigned this Jul 13, 2024
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan
Copy link
Contributor Author

@swift-ci please test

grynspan added a commit to swiftlang/swift-package-manager that referenced this pull request Jul 14, 2024
This PR detects when a Swift Testing run returns `EXIT_NO_TESTS_FOUND` and
treats it as a successful test run.

This change handles the change from swiftlang/swift-testing#536.
Separately, the refactor in #7766 stops Swift Package Manager from reporting
`"No matching test cases were run"` when XCTest has no tests matching passed
`--filter` arguments. A third PR after these two have been merged will restore
that functionality by collating results from both XCTest and Swift Testing.

This change partially resolves rdar://131704587.
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan requested a review from bnbarham July 14, 2024 15:00
@grynspan grynspan merged commit 1be3357 into main Jul 15, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/custom-exit-status-for-zero-tests branch July 15, 2024 15:48
grynspan added a commit to swiftlang/swift-package-manager that referenced this pull request Jul 15, 2024
This PR detects when a Swift Testing run returns `EXIT_NO_TESTS_FOUND`
and treats it as a successful test run.

This change handles the change from
swiftlang/swift-testing#536. Separately, the
refactor in #7766 stops Swift Package Manager from reporting `"No
matching test cases were run"` when XCTest has no tests matching passed
`--filter` arguments. A third PR after these two have been merged will
restore that functionality by collating results from both XCTest and
Swift Testing.

> [!NOTE]
> Test coverage can be added after Swift Testing is in the Swift
toolchain.

This change partially resolves rdar://131704587.
grynspan added a commit to swiftlang/swift-package-manager that referenced this pull request Jul 16, 2024
This PR detects when a Swift Testing run returns `EXIT_NO_TESTS_FOUND`
and treats it as a successful test run.

This change handles the change from
swiftlang/swift-testing#536. Separately, the
refactor in #7766 stops Swift Package Manager from reporting `"No
matching test cases were run"` when XCTest has no tests matching passed
`--filter` arguments. A third PR after these two have been merged will
restore that functionality by collating results from both XCTest and
Swift Testing.

> [!NOTE]
> Test coverage can be added after Swift Testing is in the Swift
toolchain.

This change partially resolves rdar://131704587.
grynspan added a commit to swiftlang/swift-package-manager that referenced this pull request Jul 18, 2024
This PR detects when a Swift Testing run returns `EXIT_NO_TESTS_FOUND`
and treats it as a successful test run.

This change handles the change from
swiftlang/swift-testing#536. Separately, the
refactor in #7766 stops Swift Package Manager from reporting `"No
matching test cases were run"` when XCTest has no tests matching passed
`--filter` arguments. A third PR after these two have been merged will
restore that functionality by collating results from both XCTest and
Swift Testing.

> [!NOTE]
> Test coverage can be added after Swift Testing is in the Swift
toolchain.

This change partially resolves rdar://131704587.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support enhancement New feature or request linux 🐧 Linux support (all distros) swiftpm-integration 📦 Swift Package Manager integration windows 🪟 Windows support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants