diff options
author | 2021-09-22 13:22:45 +0200 | |
---|---|---|
committer | 2021-09-23 16:11:04 +0200 | |
commit | b71df58f2fb4ed85d4c8cf806d5837ce63c73f31 (patch) | |
tree | de4cbe4b43d399d4dcf2021c33225ccd00627434 /xtask/src/command.rs | |
parent | c8621d78b9b1c0c67dff31404ade873a9d7b426e (diff) | |
download | rtic-b71df58f2fb4ed85d4c8cf806d5837ce63c73f31.tar.gz rtic-b71df58f2fb4ed85d4c8cf806d5837ce63c73f31.tar.zst rtic-b71df58f2fb4ed85d4c8cf806d5837ce63c73f31.zip |
The great docs update
Diffstat (limited to 'xtask/src/command.rs')
-rw-r--r-- | xtask/src/command.rs | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/xtask/src/command.rs b/xtask/src/command.rs index 8bf49849..d94a7ab3 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -1,14 +1,16 @@ -use crate::RunResult; +use crate::{RunResult, TestRunError}; use core::fmt; use os_pipe::pipe; use std::{fs::File, io::Read, path::Path, process::Command}; +#[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq)] pub enum BuildMode { Release, Debug, } +#[derive(Debug)] pub enum CargoCommand<'a> { Run { example: &'a str, @@ -146,17 +148,26 @@ pub fn run_command(command: &CargoCommand) -> anyhow::Result<RunResult> { /// Check if `run` was sucessful. /// returns Ok in case the run went as expected, /// Err otherwise -pub fn run_successful(run: &RunResult, expected_output_file: String) -> anyhow::Result<()> { - let mut file_handle = File::open(expected_output_file)?; +pub fn run_successful(run: &RunResult, expected_output_file: String) -> Result<(), TestRunError> { + let mut file_handle = + File::open(expected_output_file.clone()).map_err(|_| TestRunError::FileError { + file: expected_output_file.clone(), + })?; let mut expected_output = String::new(); - file_handle.read_to_string(&mut expected_output)?; - if expected_output == run.output && run.exit_status.success() { - Ok(()) + file_handle + .read_to_string(&mut expected_output) + .map_err(|_| TestRunError::FileError { + file: expected_output_file.clone(), + })?; + + if expected_output != run.output { + Err(TestRunError::FileCmpError { + expected: expected_output.clone(), + got: run.output.clone(), + }) + } else if !run.exit_status.success() { + Err(TestRunError::CommandError(run.clone())) } else { - Err(anyhow::anyhow!( - "Run failed with exit status {}: {}", - run.exit_status, - run.output - )) + Ok(()) } } |