Skip to content

Macro to check if a function returns a specific error #34299

Closed
@tredoe

Description

@tredoe

At testing, it's also necessary to have a macro to checking a specific error returned by a function.

This macro gets it, so it could be added to standard library:

    // Checks that the function returns the given error.
    macro_rules! test_err {
        ($func:expr, $err:expr) => ({
            let func = $func;

            match func {
                Err(ref e) if *e == $err => (),
                Err(e) => panic!("got error {:?}, want {:?}", e, $err),
                _ => panic!("want error {:?}", $err),
            }
        })
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions