[][src]Macro assert_not_modified::assert_not_modified

macro_rules! assert_not_modified {
    ($data: ident, $block_which_should_not_modify_data: expr) => { ... };

Given a variable and a block of code, executes the block of code and checks that the variable has not changed.

The given variable must implement Clone and Debug.


Panics if data is modified with message "Data was modified where it should not have been".


 #[macro_use] extern crate assert_not_modified;

 // This function returns Err but modifies x anyway. This is misleading.
 fn modify_x_or_err(x: &mut i32) -> Result<(), String> {
     *x = *x + 1;
     Err("Something wrong happened !".to_owned())

 // This test will expose the lying function :
 assert!(std::panic::catch_unwind(|| {
     let mut x = 3;
     assert_not_modified!(x, modify_x_or_err(&mut x)); // Panics