err

Macro err 

Source
macro_rules! err {
    ($fmt:expr, $($arg:expr),*) => { ... };
    ($fmt:expr) => { ... };
}
Expand description

A macro to create an Error::TestFailed.

Unlike fail, which returns a result that contains an error variant, this macro will only return the underlying error. This is particularly useful when mapping errors to test failures rather than separate errors with predefined Display implementations.

ยงExample

use extel::{prelude::*, err};
use thiserror::Error;

#[derive(Error, Debug)]
enum MyCustomError {
    #[error("{0}")]
    CriticalError(String)
}

fn blow_up() -> Result<(), MyCustomError> {
    Err(MyCustomError::CriticalError("UH OH!".into()))
}

const EXPECTED: &str = "Hello, world!";

fn my_test() -> ExtelResult {
    let output = cmd!("echo -n \"{}\"", EXPECTED).output()?;
    let output_string = String::from_utf8(output.stdout)?;
    let code = output.status.code().ok_or(err!("could not extract code"))?;
    let err = blow_up().map_err(|e| err!("{}", e))?;
    extel_assert!(output_string == *EXPECTED && code == 0)
}

assert!(my_test().is_err())