Skip to content

Commit

Permalink
std: unix process_unsupported: Provide a wait status emulation (tidy)
Browse files Browse the repository at this point in the history
Move tests into a module as demanded by tidy.
  • Loading branch information
ijackson committed Aug 22, 2023
1 parent 281b050 commit f625528
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,6 @@ impl ExitStatus {
}
}

// Test that our emulation exactly matches Linux
//
// This test runs *on Linux* but it tests
// the implementation used on non-Unix `#[cfg(unix)]` platforms.
//
// I.e. we're using Linux as a proxy for "trad unix".
#[cfg(all(test, target_os = "linux"))]
mod compare_with_linux {
use super::ExitStatus as Emulated;
use crate::os::unix::process::ExitStatusExt as _;
use crate::process::ExitStatus as Real;

#[test]
fn compare() {
// Check that we handle out-of-range values similarly, too.
for wstatus in -0xf_ffff..0xf_ffff {
let emulated = Emulated::from(wstatus);
let real = Real::from_raw(wstatus);

macro_rules! compare { { $method:ident } => {
assert_eq!(
emulated.$method(),
real.$method(),
"{wstatus:#x}.{}()",
stringify!($method),
);
} }
compare!(code);
compare!(signal);
compare!(core_dumped);
compare!(stopped_signal);
compare!(continued);
compare!(into_raw);
}
}
}
#[cfg(test)]
#[path = "wait_status/tests.rs"] // needed because of strange layout of process_unsupported
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Note that tests in this file are run on Linux as well as on platforms using process_unsupported

// Test that our emulation exactly matches Linux
//
// This test runs *on Linux* but it tests
// the implementation used on non-Unix `#[cfg(unix)]` platforms.
//
// I.e. we're using Linux as a proxy for "trad unix".
#[cfg(target_os = "linux")]
#[test]
fn compare_with_linux() {
use super::ExitStatus as Emulated;
use crate::os::unix::process::ExitStatusExt as _;
use crate::process::ExitStatus as Real;

// Check that we handle out-of-range values similarly, too.
for wstatus in -0xf_ffff..0xf_ffff {
let emulated = Emulated::from(wstatus);
let real = Real::from_raw(wstatus);

macro_rules! compare { { $method:ident } => {
assert_eq!(
emulated.$method(),
real.$method(),
"{wstatus:#x}.{}()",
stringify!($method),
);
} }
compare!(code);
compare!(signal);
compare!(core_dumped);
compare!(stopped_signal);
compare!(continued);
compare!(into_raw);
}
}

0 comments on commit f625528

Please sign in to comment.