diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-02-06 10:05:14 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-02-06 10:05:14 +0100 |
| commit | 7eeaf41b1177ddfe70f70203afa499f04bb8de2d (patch) | |
| tree | e5fc2e9d4378b6dda6c9fb91b789da64d76315ae /talpid_openvpn_plugin/src | |
| parent | 1c15ddfd97afeba755ab591c205785f9be7608e1 (diff) | |
| parent | ec1b76dd28c90894200fc0a19fa964643e815cbf (diff) | |
| download | mullvadvpn-7eeaf41b1177ddfe70f70203afa499f04bb8de2d.tar.xz mullvadvpn-7eeaf41b1177ddfe70f70203afa499f04bb8de2d.zip | |
Merge branch 'assert_matches'
Diffstat (limited to 'talpid_openvpn_plugin/src')
| -rw-r--r-- | talpid_openvpn_plugin/src/ffi/parse.rs | 16 | ||||
| -rw-r--r-- | talpid_openvpn_plugin/src/lib.rs | 4 |
2 files changed, 6 insertions, 14 deletions
diff --git a/talpid_openvpn_plugin/src/ffi/parse.rs b/talpid_openvpn_plugin/src/ffi/parse.rs index de8e7a16a7..db26335d27 100644 --- a/talpid_openvpn_plugin/src/ffi/parse.rs +++ b/talpid_openvpn_plugin/src/ffi/parse.rs @@ -70,22 +70,10 @@ mod tests { use std::os::raw::c_char; use std::ptr; - /// Assert macro that fails if the given pattern does not match the given expression - /// TODO(Linus): Very useful macro for asserting on patterns where the type does not implement - /// Eq. Thus it should probably be moved to a general place/crate when needed in more places. - macro_rules! assert_pat { - ($expected:pat, $actual:expr) => {{ - if let $expected = $actual {} else { - let msg = stringify!($expected); - panic!("Expected {}. Got {:?}", msg, $actual); - } - }} - } - #[test] fn string_array_null() { let result = unsafe { string_array(ptr::null()) }; - assert_pat!(Err(Error(ErrorKind::Null, _)), result); + assert_matches!(result, Err(Error(ErrorKind::Null, _))); } #[test] @@ -128,7 +116,7 @@ mod tests { let test_str = "foobar\0"; let ptr_arr = [test_str as *const _ as *const c_char, ptr::null()]; let result = unsafe { env(&ptr_arr as *const *const c_char) }; - assert_pat!(Err(Error(ErrorKind::NoEqual(_), _)), result); + assert_matches!(result, Err(Error(ErrorKind::NoEqual(_), _))); } #[test] diff --git a/talpid_openvpn_plugin/src/lib.rs b/talpid_openvpn_plugin/src/lib.rs index 91fcd34396..d2d1ea9d74 100644 --- a/talpid_openvpn_plugin/src/lib.rs +++ b/talpid_openvpn_plugin/src/lib.rs @@ -4,6 +4,10 @@ extern crate lazy_static; #[macro_use] extern crate error_chain; +#[cfg(test)] +#[macro_use] +extern crate assert_matches; + mod ffi; /// Publicly export the functions making up the public interface of the plugin. These are the C FFI |
