Skip to content

Commit

Permalink
rename ProcessStatus to Exit
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Nov 24, 2024
1 parent 3b4a1a2 commit 0bafd24
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::options::{Options, TestTool};
use crate::outcome::{Phase, PhaseResult};
use crate::output::ScenarioOutput;
use crate::package::PackageSelection;
use crate::process::{Process, ProcessStatus};
use crate::process::{Exit, Process};
use crate::Result;

/// Run cargo build, check, or test.
Expand Down Expand Up @@ -56,7 +56,7 @@ pub fn run_cargo(
)?;
check_interrupted()?;
debug!(?process_status, elapsed = ?start.elapsed());
if let ProcessStatus::Failure(code) = process_status {
if let Exit::Failure(code) = process_status {
// 100 "one or more tests failed" from <https://docs.rs/nextest-metadata/latest/nextest_metadata/enum.NextestExitCode.html>;
// I'm not addind a dependency to just get one integer.
if argv[1] == "nextest" && code != 100 {
Expand Down
14 changes: 7 additions & 7 deletions src/outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::Serializer;
use tracing::warn;

use crate::console::plural;
use crate::process::ProcessStatus;
use crate::process::Exit;
use crate::*;

/// What phase of running a scenario.
Expand Down Expand Up @@ -193,7 +193,7 @@ impl ScenarioOutcome {
self.phase_results.last().unwrap().phase
}

pub fn last_phase_result(&self) -> ProcessStatus {
pub fn last_phase_result(&self) -> Exit {
self.phase_results.last().unwrap().process_status
}

Expand Down Expand Up @@ -284,7 +284,7 @@ pub struct PhaseResult {
/// How long did it take?
pub duration: Duration,
/// Did it succeed?
pub process_status: ProcessStatus,
pub process_status: Exit,
/// What command was run, as an argv list.
pub argv: Vec<String>,
}
Expand Down Expand Up @@ -324,7 +324,7 @@ pub enum SummaryOutcome {
mod test {
use std::time::Duration;

use crate::process::ProcessStatus;
use crate::process::Exit;

use super::{Phase, PhaseResult, Scenario, ScenarioOutcome};

Expand All @@ -339,13 +339,13 @@ mod test {
PhaseResult {
phase: Phase::Build,
duration: Duration::from_secs(2),
process_status: ProcessStatus::Success,
process_status: Exit::Success,
argv: vec!["cargo".into(), "build".into()],
},
PhaseResult {
phase: Phase::Test,
duration: Duration::from_secs(3),
process_status: ProcessStatus::Success,
process_status: Exit::Success,
argv: vec!["cargo".into(), "test".into()],
},
],
Expand All @@ -355,7 +355,7 @@ mod test {
Some(&PhaseResult {
phase: Phase::Build,
duration: Duration::from_secs(2),
process_status: ProcessStatus::Success,
process_status: Exit::Success,
argv: vec!["cargo".into(), "build".into()],
})
);
Expand Down
16 changes: 8 additions & 8 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Process {
jobserver: &Option<jobserver::Client>,
scenario_output: &mut ScenarioOutput,
console: &Console,
) -> Result<ProcessStatus> {
) -> Result<Exit> {
let mut child = Process::start(argv, env, cwd, timeout, jobserver, scenario_output)?;
let process_status = loop {
if let Some(exit_status) = child.poll()? {
Expand Down Expand Up @@ -102,11 +102,11 @@ impl Process {

/// Check if the child process has finished; if so, return its status.
#[mutants::skip] // It's hard to avoid timeouts if this never works...
pub fn poll(&mut self) -> Result<Option<ProcessStatus>> {
pub fn poll(&mut self) -> Result<Option<Exit>> {
if self.timeout.is_some_and(|t| self.start.elapsed() > t) {
debug!("timeout, terminating child process...",);
self.terminate()?;
Ok(Some(ProcessStatus::Timeout))
Ok(Some(Exit::Timeout))
} else if let Err(e) = check_interrupted() {
debug!("interrupted, terminating child process...");
self.terminate()?;
Expand Down Expand Up @@ -139,7 +139,7 @@ impl Process {

/// The result of running a single child process.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize)]
pub enum ProcessStatus {
pub enum Exit {
/// Exited with status 0.
Success,
/// Exited with status non-0.
Expand All @@ -153,17 +153,17 @@ pub enum ProcessStatus {
Other,
}

impl ProcessStatus {
impl Exit {
pub fn is_success(&self) -> bool {
*self == ProcessStatus::Success
*self == Exit::Success
}

pub fn is_timeout(&self) -> bool {
*self == ProcessStatus::Timeout
*self == Exit::Timeout
}

pub fn is_failure(&self) -> bool {
matches!(self, ProcessStatus::Failure(_))
matches!(self, Exit::Failure(_))
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/process/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tracing::warn;

use crate::Result;

use super::ProcessStatus;
use super::Exit;

#[allow(unknown_lints, clippy::needless_pass_by_ref_mut)] // To match Windows
#[mutants::skip] // hard to exercise the ESRCH edge case
Expand Down Expand Up @@ -37,16 +37,16 @@ pub(super) fn configure_command(command: &mut Command) {
command.process_group(0);
}

pub(super) fn interpret_exit(status: ExitStatus) -> ProcessStatus {
pub(super) fn interpret_exit(status: ExitStatus) -> Exit {
if let Some(code) = status.code() {
if code == 0 {
ProcessStatus::Success
Exit::Success
} else {
ProcessStatus::Failure(code as u32)
Exit::Failure(code as u32)
}
} else if let Some(signal) = status.signal() {
return ProcessStatus::Signalled(signal as u8);
return Exit::Signalled(signal as u8);
} else {
ProcessStatus::Other
Exit::Other
}
}
12 changes: 6 additions & 6 deletions src/process/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ use anyhow::Context;

use crate::Result;

use super::ProcessStatus;
use super::Exit;

#[mutants::skip] // hard to exercise the ESRCH edge case
pub(super) fn terminate_child(child: &mut Child) -> Result<()> {
child.kill().context("Kill child")
}

#[mutants::skip]
pub(super) fn configure_command(command: &mut Command) {}
pub(super) fn configure_command(_command: &mut Command) {}

pub(super) fn interpret_exit(status: ExitStatus) -> ProcessStatus {
pub(super) fn interpret_exit(status: ExitStatus) -> Exit {
if let Some(code) = status.code() {
if code == 0 {
ProcessStatus::Success
Exit::Success
} else {
ProcessStatus::Failure(code as u32)
Exit::Failure(code as u32)
}
} else {
ProcessStatus::Other
Exit::Other
}
}

0 comments on commit 0bafd24

Please sign in to comment.