Skip to content

Commit d8cfd56

Browse files
committed
process::unix: Test wait status formatting
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
1 parent fbd575a commit d8cfd56

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

library/std/src/sys/unix/process/process_unix.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,7 @@ impl fmt::Display for ExitStatus {
542542
}
543543
}
544544
}
545+
546+
#[cfg(test)]
547+
#[path = "process_unix/tests.rs"]
548+
mod tests;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#[test]
2+
fn exitstatus_display_tests() {
3+
// In practice this is the same on every Unix.
4+
// If some weird platform turns out to be different, and this test fails, use #[cfg].
5+
use crate::os::unix::process::ExitStatusExt;
6+
use crate::process::ExitStatus;
7+
8+
let t = |v, s| assert_eq!(s, format!("{}", <ExitStatus as ExitStatusExt>::from_raw(v)));
9+
10+
t(0x0000f, "signal: 15");
11+
t(0x0008b, "signal: 11 (core dumped)");
12+
t(0x00000, "exit code: 0");
13+
t(0x0ff00, "exit code: 255");
14+
t(0x0137f, "stopped (not terminated) by signal: 19");
15+
t(0x0ffff, "continued (WIFCONTINUED)");
16+
17+
// Testing "unrecognised wait status" is hard because the wait.h macros typically
18+
// assume that the value came from wait and isn't mad. With the glibc I have here
19+
// this works:
20+
#[cfg(target_env = "gnu")]
21+
t(0x000ff, "unrecognised wait status: 255 0xff");
22+
}

0 commit comments

Comments
 (0)