Skip to content

Commit

Permalink
preserve exit status code
Browse files Browse the repository at this point in the history
tested on command line with:  cargo run --  foo; echo $?

before:  0
after: 2

added a test
  • Loading branch information
ahornby committed Jun 25, 2023
1 parent e178ccc commit 35f9602
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,28 @@ fn get_buck2_path() -> Result<PathBuf, Error> {
}

fn main() -> Result<(), Error> {
let buck2_path = dbg!(get_buck2_path()?);
let binary_path = dbg!(get_buck2_path()?);

// Collect information indented for buck2 binary.
let mut args = env::args_os();
args.next(); // Skip buckle
let envs = env::vars_os();

let envs = env::vars_os();

// Pass all file descriptors through as well.
Command::new(buck2_path)
let status = Command::new(&binary_path)
.args(args)
.envs(envs)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.expect("Failed to execute buck2.");
.unwrap_or_else(|_| panic!("Failed to execute {:?}", &binary_path))
.status;

if !status.success() {
std::process::exit(status.code().unwrap_or(1));
}

Ok(())
}
10 changes: 10 additions & 0 deletions tests/integration_buck2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ fn test_buck2_latest() {
assert!(stdout.starts_with("buck2 "), "found {}", stdout);
assert.success();
}

#[test]
fn test_buck2_fail() {
let mut cmd = Command::cargo_bin("buckle").unwrap();
cmd.arg("--totally-unknown-argument");
let assert = cmd.assert();
let stderr = String::from_utf8(assert.get_output().stderr.to_vec()).unwrap();
assert!(stderr.contains("/buckle/buck2/"), "found {}", stderr);
assert.failure();
}

0 comments on commit 35f9602

Please sign in to comment.