Skip to content

Commit

Permalink
Use cross-platform code in favor of accurate exit codes (#4372)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Dec 20, 2024
1 parent e09c6fa commit f817a79
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
24 changes: 13 additions & 11 deletions crates/cli/src/bin/wasm-bindgen-test-runner/deno.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use std::fs;
use std::path::Path;
use std::process::Command;
use std::{fs, process};

use anyhow::{Context, Error};

use crate::{
node::{exec, SHARED_SETUP},
Cli,
};
use crate::{node::SHARED_SETUP, Cli};

pub fn execute(module: &str, tmpdir: &Path, cli: Cli, tests: &[String]) -> Result<(), Error> {
let mut js_to_execute = format!(
Expand Down Expand Up @@ -60,10 +57,15 @@ if (!ok) Deno.exit(1);"#,
.arg(&js_path)
.args(args),
)*/
exec(
Command::new("deno")
.arg("run")
.arg("--allow-read")
.arg(&js_path),
)
let status = Command::new("deno")
.arg("run")
.arg("--allow-read")
.arg(&js_path)
.status()?;

if !status.success() {
process::exit(status.code().unwrap_or(1))
} else {
Ok(())
}
}
33 changes: 12 additions & 21 deletions crates/cli/src/bin/wasm-bindgen-test-runner/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::process;
use std::process::Command;

use anyhow::{Context, Error};
Expand Down Expand Up @@ -138,27 +139,17 @@ pub fn execute(
.map(|s| s.to_string())
.filter(|s| !s.is_empty())
.collect::<Vec<_>>();
exec(
Command::new("node")
.env("NODE_PATH", env::join_paths(&path).unwrap())
.arg("--expose-gc")
.args(&extra_node_args)
.arg(&js_path),
)
}

#[cfg(unix)]
pub fn exec(cmd: &mut Command) -> Result<(), Error> {
use std::os::unix::prelude::*;
Err(Error::from(cmd.exec()).context(format!(
"failed to execute `{}`",
cmd.get_program().to_string_lossy()
)))
}
let status = Command::new("node")
.env("NODE_PATH", env::join_paths(&path).unwrap())
.arg("--expose-gc")
.args(&extra_node_args)
.arg(&js_path)
.status()?;

#[cfg(windows)]
pub fn exec(cmd: &mut Command) -> Result<(), Error> {
use std::process;
let status = cmd.status()?;
process::exit(status.code().unwrap_or(3));
if !status.success() {
process::exit(status.code().unwrap_or(1))
} else {
Ok(())
}
}

0 comments on commit f817a79

Please sign in to comment.