Skip to content
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

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

Closed
wants to merge 2 commits into from

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Aug 7, 2024

The documentation for the experimental exit tests feature currently says that on POSIX-like systems, only the low 8 bits of a process' exit code are preserved. This would be true if we used wait(), wait4(), etc. and WEXITSTATUS(), but we use waitid() instead which is supposed to preserve the full exit code. It does so on Darwin, but not on Linux; Windows doesn't use waitid() but does report the full exit code.

Now, we're not currently building for any other POSIX-like systems that support processes (WASI/Wasm doesn't count here), so I've left in some weasel words and added a canary unit test. It will let us know if/when we add a platform that where waitid() doesn't preserve all the bits of the exit code, and we can amend the documentation in that case.

Exit tests remain an experimental feature only.

Checklist:

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

@grynspan grynspan added bug Something isn't working documentation Improvements or additions to documentation linux 🐧 Linux support (all distros) darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support swift-6.1 labels Aug 7, 2024
@grynspan grynspan self-assigned this Aug 7, 2024
@grynspan
Copy link
Contributor Author

grynspan commented Aug 7, 2024

@swift-ci please test

@grynspan
Copy link
Contributor Author

grynspan commented Aug 7, 2024

Looks like Linux, or at least our CI's version, does not correctly implement waitid() per the POSIX rules. I suspected as much.

@grynspan grynspan changed the title Clarify that 8-bit exit codes aren't a problem on macOS/Linux/Windows. Clarify that 8-bit exit codes aren't a problem on macOS and Windows. Aug 7, 2024
@grynspan
Copy link
Contributor Author

grynspan commented Aug 7, 2024

@swift-ci please test

The documentation for the experimental exit tests feature currently says that on
POSIX-like systems, only the low 8 bits of a process' exit code are preserved.
This would be true if we used `wait()`, `wait4()`, etc. and `WEXITSTATUS()`, but
we use `waitid()` instead which is [supposed to](https://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html)
preserve the full exit code.

Now, we're not currently building for any other POSIX-like systems that support
processes (WASI/Wasm doesn't count here), so I've left in some weasel words and
added a canary unit test. It will let us know if/when we add a platform that
where `waitid()` doesn't preserve all the bits of the exit code, and we can
amend the documentation in that case.

Exit tests remain an experimental feature only.
@grynspan grynspan force-pushed the jgrynspan/8-bit-exit-codes-not-a-problem branch from 6ff8bef to 761c98b Compare August 8, 2024 14:38
@grynspan
Copy link
Contributor Author

grynspan commented Aug 8, 2024

@swift-ci please test

grynspan added a commit that referenced this pull request Aug 15, 2024
@grynspan grynspan added the exit-tests ☠️ Work related to exit tests label Aug 15, 2024
grynspan added a commit that referenced this pull request Aug 15, 2024
This PR supersedes #603, #613, and #614. Exit tests remain an experimental feature.

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

The documentation for the experimental exit tests feature currently says that on POSIX-like systems, only the low 8 bits of a process' exit code are preserved. This would be true if we used `wait()`, `wait4()`, etc. and `WEXITSTATUS()`, but we use `waitid()` instead which is [supposed to](https://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html) preserve the full exit code. It does so on Darwin, but not on Linux; Windows doesn't use `waitid()` but does report the full exit code.

Now, we're not currently building for any other POSIX-like systems that support processes (WASI/Wasm doesn't count here), so I've left in some weasel words and added a canary unit test. It will let us know if/when we add a platform that where `waitid()` doesn't preserve all the bits of the exit code, and we can amend the documentation in that case.

 ## Implement an equality operator for ExitCondition. (#613)

This PR implements `==` and `===` for `ExitCondition`, part of the experimental exit tests feature. These operators are necessary in order to allow for exit tests to support more complex matching by trailing closure (e.g. to support inspecting `stdout`.) Because `.failure` is a fuzzy case, `==` fuzzy-matches while `===` exactly matches. `Hashable` conformance is unavailable.

Example usage:

```swift
let lhs: ExitCondition = .failure
let rhs: ExitCondition = .signal(SIGTERM)
print(lhs == rhs) // prints "true"
print(lhs === rhs) // prints "false"
```

 ## Allow throwing an error from an exit test's body. (#614)

This PR amends the signatures of the exit test macros (`#expect(exitsWith:) {}` and `try #require(exitsWith:) {}`) to allow bodies to throw errors. If they do, they are treated as uncaught errors and the child process terminates abnormally (in the same way it does if an error is thrown from the main function of a Swift program.)
@grynspan grynspan mentioned this pull request Aug 15, 2024
2 tasks
@grynspan
Copy link
Contributor Author

Superseded by #615.

@grynspan grynspan closed this Aug 15, 2024
grynspan added a commit that referenced this pull request Aug 15, 2024
This PR supersedes #603, #613, and #614. Exit tests remain an experimental feature.

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

The documentation for the experimental exit tests feature currently says that on POSIX-like systems, only the low 8 bits of a process' exit code are preserved. This would be true if we used `wait()`, `wait4()`, etc. and `WEXITSTATUS()`, but we use `waitid()` instead which is [supposed to](https://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html) preserve the full exit code. It does so on Darwin, but not on Linux; Windows doesn't use `waitid()` but does report the full exit code.

Now, we're not currently building for any other POSIX-like systems that support processes (WASI/Wasm doesn't count here), so I've left in some weasel words and added a canary unit test. It will let us know if/when we add a platform that where `waitid()` doesn't preserve all the bits of the exit code, and we can amend the documentation in that case.

 ## Implement an equality operator for ExitCondition. (#613)

This PR implements `==` and `===` for `ExitCondition`, part of the experimental exit tests feature. These operators are necessary in order to allow for exit tests to support more complex matching by trailing closure (e.g. to support inspecting `stdout`.) Because `.failure` is a fuzzy case, `==` fuzzy-matches while `===` exactly matches. `Hashable` conformance is unavailable.

Example usage:

```swift
let lhs: ExitCondition = .failure
let rhs: ExitCondition = .signal(SIGTERM)
print(lhs == rhs) // prints "true"
print(lhs === rhs) // prints "false"
```

 ## Allow throwing an error from an exit test's body. (#614)

This PR amends the signatures of the exit test macros (`#expect(exitsWith:) {}` and `try #require(exitsWith:) {}`) to allow bodies to throw errors. If they do, they are treated as uncaught errors and the child process terminates abnormally (in the same way it does if an error is thrown from the main function of a Swift program.)
grynspan added a commit that referenced this pull request Aug 21, 2024
This PR supersedes #603, #613, and #614. Exit tests remain an
experimental feature.

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

The documentation for the experimental exit tests feature currently says
that on POSIX-like systems, only the low 8 bits of a process' exit code
are preserved. This would be true if we used `wait()`, `wait4()`, etc.
and `WEXITSTATUS()`, but we use `waitid()` instead which is [supposed
to](https://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html)
preserve the full exit code. It does so on Darwin, but not on Linux;
Windows doesn't use `waitid()` but does report the full exit code.

Now, we're not currently building for any other POSIX-like systems that
support processes (WASI/Wasm doesn't count here), so I've left in some
weasel words and added a canary unit test. It will let us know if/when
we add a platform that where `waitid()` doesn't preserve all the bits of
the exit code, and we can amend the documentation in that case.

 ## Implement an equality operator for ExitCondition. (#613)

This PR implements `==` and `===` for `ExitCondition`, part of the
experimental exit tests feature. These operators are necessary in order
to allow for exit tests to support more complex matching by trailing
closure (e.g. to support inspecting `stdout`.) Because `.failure` is a
fuzzy case, `==` fuzzy-matches while `===` exactly matches. `Hashable`
conformance is unavailable.

Example usage:

```swift
let lhs: ExitCondition = .failure
let rhs: ExitCondition = .signal(SIGTERM)
print(lhs == rhs) // prints "true"
print(lhs === rhs) // prints "false"
```

 ## Allow throwing an error from an exit test's body. (#614)

This PR amends the signatures of the exit test macros
(`#expect(exitsWith:) {}` and `try #require(exitsWith:) {}`) to allow
bodies to throw errors. If they do, they are treated as uncaught errors
and the child process terminates abnormally (in the same way it does if
an error is thrown from the main function of a Swift program.)

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
@grynspan grynspan added this to the Swift 6.1 milestone Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support documentation Improvements or additions to documentation exit-tests ☠️ Work related to exit tests linux 🐧 Linux support (all distros)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant