1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Tools for integrating `matrixcompare` with `proptest`.
//!
//! In order to use this module, you need to enable the `proptest-support` feature.

/// Internal macro.
#[macro_export]
#[doc(hidden)]
macro_rules! build_proptest_message {
    ($failure:expr) => {
        format!(
            "Comparison failure at {}:{}. Error:\n {}",
            file!(),
            line!(),
            $failure
        );
    };
}

/// A version of `assert_matrix_eq` suitable for use in `proptest` property-based tests.
///
/// Works exactly as `assert_matrix_eq`, except that instead of causing a panic,
/// it returns an error compatible with property-based tests from the `proptest` crate.
///
/// Requires the `proptest-support` feature to be enabled.
#[macro_export]
macro_rules! prop_assert_matrix_eq {
    ($($args:tt)*) => {
        let failure_handler = |msg| {
            // Add filename and line numbers to message (since we don't panic, it's useful
            // to have this information in the output).
            let amended_message = $crate::build_proptest_message!(msg);
            return ::core::result::Result::Err(
                ::proptest::test_runner::TestCaseError::fail(amended_message));
        };
        $crate::base_matrix_eq!(failure_handler, $($args)*);
    }
}

/// A version of `assert_scalar_eq` suitable for use in `proptest` property-based tests.
///
/// Works exactly as `assert_scalar_eq`, except that instead of causing a panic,
/// it returns an error compatible with property-based tests from the `proptest` crate.
///
/// Requires the `proptest-support` feature to be enabled.
#[macro_export]
macro_rules! prop_assert_scalar_eq {
    ($($args:tt)*) => {
        let failure_handler = |msg| {
            // Add filename and line numbers to message (since we don't panic, it's useful
            // to have this information in the output).
            let amended_message = $crate::build_proptest_message!(msg);
            return ::core::result::Result::Err(
                ::proptest::test_runner::TestCaseError::fail(amended_message));
        };
        $crate::base_scalar_eq!(failure_handler, $($args)*);
    }
}