mirror of
https://github.com/sharkdp/hyperfine.git
synced 2024-09-11 14:07:02 +03:00
Move exit code function to separate file
This commit is contained in:
parent
811e6b5fcd
commit
b658e20110
@ -18,6 +18,7 @@ use crate::output::warnings::Warnings;
|
||||
use crate::shell::execute_and_time;
|
||||
use crate::timer::wallclocktimer::WallClockTimer;
|
||||
use crate::timer::{TimerStart, TimerStop};
|
||||
use crate::util::exit_code::extract_exit_code;
|
||||
use crate::util::min_max::{max, min};
|
||||
use crate::util::units::Second;
|
||||
|
||||
@ -223,27 +224,6 @@ fn run_cleanup_command(
|
||||
run_intermediate_command(shell, command, output_policy, error_output)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn extract_exit_code(status: ExitStatus) -> Option<i32> {
|
||||
use std::os::unix::process::ExitStatusExt;
|
||||
|
||||
/* From the ExitStatus::code documentation:
|
||||
"On Unix, this will return None if the process was terminated by a signal."
|
||||
In that case, ExitStatusExt::signal should never return None.
|
||||
*/
|
||||
status.code().or_else(||
|
||||
/* To differentiate between "normal" exit codes and signals, we are using
|
||||
something similar to bash exit codes (https://tldp.org/LDP/abs/html/exitcodes.html)
|
||||
by adding 128 to a signal integer value.
|
||||
*/
|
||||
status.signal().map(|s| 128 + s))
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
fn extract_exit_code(status: ExitStatus) -> Option<i32> {
|
||||
status.code()
|
||||
}
|
||||
|
||||
/// Run the benchmark for a single shell command
|
||||
pub fn run_benchmark(
|
||||
num: usize,
|
||||
|
22
src/util/exit_code.rs
Normal file
22
src/util/exit_code.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use std::process::ExitStatus;
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn extract_exit_code(status: ExitStatus) -> Option<i32> {
|
||||
use std::os::unix::process::ExitStatusExt;
|
||||
|
||||
// From the ExitStatus::code documentation:
|
||||
//
|
||||
// "On Unix, this will return None if the process was terminated by a signal."
|
||||
//
|
||||
// In that case, ExitStatusExt::signal should never return None.
|
||||
//
|
||||
// To differentiate between "normal" exit codes and signals, we are using a technique
|
||||
// similar to bash (https://tldp.org/LDP/abs/html/exitcodes.html) and add 128 to the
|
||||
// signal value.
|
||||
status.code().or_else(|| status.signal().map(|s| s + 128))
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
pub fn extract_exit_code(status: ExitStatus) -> Option<i32> {
|
||||
status.code()
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod exit_code;
|
||||
pub mod min_max;
|
||||
pub mod number;
|
||||
pub mod units;
|
||||
|
Loading…
Reference in New Issue
Block a user