cargo_nextest/
double_spawn.rs

1// Copyright (c) The nextest Contributors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4use crate::{ExpectedError, Result, output::OutputContext};
5use camino::Utf8PathBuf;
6use clap::Args;
7use nextest_runner::double_spawn::double_spawn_child_init;
8use std::os::unix::process::CommandExt;
9
10#[derive(Debug, Args)]
11pub(crate) struct DoubleSpawnOpts {
12    /// The program to execute.
13    program: Utf8PathBuf,
14
15    /// The args to execute the program with, provided as a string.
16    args: String,
17}
18
19impl DoubleSpawnOpts {
20    // output is passed in to ensure that the context is initialized.
21    pub(crate) fn exec(self, _output: OutputContext) -> Result<i32> {
22        double_spawn_child_init();
23        let args = shell_words::split(&self.args).map_err(|err| {
24            ExpectedError::DoubleSpawnParseArgsError {
25                args: self.args,
26                err,
27            }
28        })?;
29        let mut command = std::process::Command::new(&self.program);
30        // Note: exec only returns an error -- in the success case it never returns.
31        let err = command.args(args).exec();
32        Err(ExpectedError::DoubleSpawnExecError {
33            command: Box::new(command),
34            current_dir: std::env::current_dir(),
35            err,
36        })
37    }
38}