(cmd: &str, args: &[&str])
| 41 | // Runs a system command with given args |
| 42 | #[allow(dead_code)] |
| 43 | fn run_cmd_with_args(cmd: &str, args: &[&str]) -> Result<serde_json::Value, IntTestError> { |
| 44 | let output = Command::new(cmd).args(args).output().unwrap(); |
| 45 | let mut value = output.stdout; |
| 46 | let error = output.stderr; |
| 47 | if value.is_empty() { |
| 48 | return Err(IntTestError::CmdExec(String::from_utf8(error).unwrap())); |
| 49 | } |
| 50 | value.pop(); // remove `\n` at end |
| 51 | let output_string = std::str::from_utf8(&value).unwrap(); |
| 52 | let json_value: serde_json::Value = match serde_json::from_str(output_string) { |
| 53 | Ok(value) => value, |
| 54 | Err(_) => json!(output_string), // bitcoin-cli will sometime return raw string |
| 55 | }; |
| 56 | Ok(json_value) |
| 57 | } |
| 58 | |
| 59 | // Helper Function |
| 60 | // Transforms a json value to string |
no outgoing calls
no test coverage detected