mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-05 09:23:31 +00:00
Proper Unix terminology is "exit status" (vs "wait status"). "exit code" is imprecise on Unix and therefore unclear. (As far as I can tell, "exit code" is correct terminology on Windows.) This new wording is unfortunately inconsistent with the identifier names in the Rust stdlib. It is the identifier names that are wrong, as discussed at length in eg https://doc.rust-lang.org/nightly/std/process/struct.ExitStatus.html https://doc.rust-lang.org/nightly/std/os/unix/process/trait.ExitStatusExt.html Unfortunately for API stability reasons it would be a lot of work, and a lot of disruption, to change the names in the stdlib (eg to rename `std::process::ExitStatus` to `std::process::ChildStatus` or something), but we should fix the message output. Many (probably most) readers of these messages about exit statuses will be users and system administrators, not programmers, who won't even know that Rust has this wrong terminology. So I think the right thing is to fix the documentation (as I have already done) and, now, the terminology in the implementation. This is a user-visible change to the behaviour of all Rust programs which run Unix subprocesses. Hopefully no-one is matching against the exit status string, except perhaps in tests. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
31 lines
1.3 KiB
Rust
31 lines
1.3 KiB
Rust
#[test]
|
|
fn exitstatus_display_tests() {
|
|
// In practice this is the same on every Unix.
|
|
// If some weird platform turns out to be different, and this test fails, use #[cfg].
|
|
use crate::os::unix::process::ExitStatusExt;
|
|
use crate::process::ExitStatus;
|
|
|
|
let t = |v, s| assert_eq!(s, format!("{}", <ExitStatus as ExitStatusExt>::from_raw(v)));
|
|
|
|
t(0x0000f, "signal: 15");
|
|
t(0x0008b, "signal: 11 (core dumped)");
|
|
t(0x00000, "exit status: 0");
|
|
t(0x0ff00, "exit status: 255");
|
|
|
|
// On MacOS, 0x0137f is WIFCONTINUED, not WIFSTOPPED. Probably *BSD is similar.
|
|
// https://github.com/rust-lang/rust/pull/82749#issuecomment-790525956
|
|
// The purpose of this test is to test our string formatting, not our understanding of the wait
|
|
// status magic numbers. So restrict these to Linux.
|
|
if cfg!(target_os = "linux") {
|
|
t(0x0137f, "stopped (not terminated) by signal: 19");
|
|
t(0x0ffff, "continued (WIFCONTINUED)");
|
|
}
|
|
|
|
// Testing "unrecognised wait status" is hard because the wait.h macros typically
|
|
// assume that the value came from wait and isn't mad. With the glibc I have here
|
|
// this works:
|
|
if cfg!(all(target_os = "linux", target_env = "gnu")) {
|
|
t(0x000ff, "unrecognised wait status: 255 0xff");
|
|
}
|
|
}
|