Skip to content

Clarify that 8-bit exit codes aren't a problem on macOS and Windows. #603

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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/Testing/ExitTests/ExitCondition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public enum ExitCondition: Sendable {
/// | Linux | [`<stdlib.h>`](https://sourceware.org/glibc/manual/latest/html_node/Exit-Status.html), `<sysexits.h>` |
/// | Windows | [`<stdlib.h>`](https://learn.microsoft.com/en-us/cpp/c-runtime-library/exit-success-exit-failure) |
///
/// On POSIX-like systems including macOS and Linux, only the low unsigned 8
/// bits (0&ndash;255) of the exit code are reliably preserved and reported to
/// a parent process.
/// On macOS and Windows, the full exit code reported by the process is
/// yielded to the parent process. Linux and other POSIX-like systems may only
/// reliably report the low unsigned 8 bits (0&ndash;255) of the exit code.
case exitCode(_ exitCode: CInt)

/// The process terminated with the given signal.
Expand Down
18 changes: 18 additions & 0 deletions Tests/TestingTests/ExitTestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ private import _TestingInternals
}.run(configuration: configuration)
}
}

#if !os(Linux)
@Test("Exit test reports > 8 bits of the exit code")
func fullWidthExitCode() async {
// On macOS and Linux, we use waitid() which per POSIX should report the
// full exit code, not just the low 8 bits. This behaviour is not
// well-documented and while Darwin correctly reports the full value, Linux
// does not (at least as of this writing) and other POSIX-like systems may
// also have issues. This test serves as a canary when adding new platforms
// that we need to document the difference.
//
// Windows does not have the 8-bit exit code restriction and always reports
// the full CInt value back to the testing library.
await #expect(exitsWith: .exitCode(512)) {
exit(512)
}
}
#endif
}

// MARK: - Fixtures
Expand Down