Browse Source

cli: Propagate mocha exit status on error

Armani Ferrante 4 years ago
parent
commit
79b791ffa8
2 changed files with 9 additions and 4 deletions
  1. 4 0
      CHANGELOG.md
  2. 5 4
      cli/src/main.rs

+ 4 - 0
CHANGELOG.md

@@ -15,6 +15,10 @@ incremented for features.
 
 * ts: Allow preloading instructions for state rpc transactions ([cf9c84](https://github.com/project-serum/anchor/commit/cf9c847e4144989b5bc1936149d171e90204777b)).
 
+## Fixes
+
+* cli: Propagates mocha test exit status on error.
+
 ## [0.2.1] - 2021-02-11
 
 ### Features

+ 5 - 4
cli/src/main.rs

@@ -606,19 +606,20 @@ fn test(skip_deploy: bool) -> Result<()> {
         let log_streams = stream_logs(&cfg.cluster.url())?;
 
         // Run the tests.
-        if let Err(e) = std::process::Command::new("mocha")
+        let exit = std::process::Command::new("mocha")
             .arg("-t")
             .arg("1000000")
             .arg("tests/")
             .env("ANCHOR_PROVIDER_URL", cfg.cluster.url())
             .stdout(Stdio::inherit())
             .stderr(Stdio::inherit())
-            .output()
-        {
+            .output()?;
+
+        if !exit.status.success() {
             if let Some(mut validator_handle) = validator_handle {
                 validator_handle.kill()?;
             }
-            return Err(anyhow::format_err!("{}", e.to_string()));
+            std::process::exit(exit.status.code().unwrap());
         }
         if let Some(mut validator_handle) = validator_handle {
             validator_handle.kill()?;