mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
add assert_err macro
This commit is contained in:
14
src/error.rs
14
src/error.rs
@@ -16,6 +16,20 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// assert_err!(your_func(), Err(Error::UrlParsingFailed(_)));
|
||||
// assert_err!(your_func(), Err(Error::CanonicalizationFailed(_)));
|
||||
// assert_err!(your_func(), Err(Error::FileOpenFailed(er)) if er.kind() == ErrorKind::NotFound);
|
||||
#[macro_export]
|
||||
macro_rules! assert_err {
|
||||
($expression:expr, $($pattern:tt)+) => {
|
||||
match $expression {
|
||||
$($pattern)+ => (),
|
||||
ref e => panic!("expected `{}` but got `{:?}`", stringify!($($pattern)+), e),
|
||||
}
|
||||
}
|
||||
}
|
||||
pub use assert_err;
|
||||
|
||||
// Hello developer. Please add your error to the according subsection
|
||||
// that is commented, or make a new subsection. Keep it clean.
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ use super::{
|
||||
settings::{Settings, SettingsPtr},
|
||||
};
|
||||
use crate::{
|
||||
error::assert_err,
|
||||
system::{
|
||||
sleep_forever, StoppableTask, StoppableTaskPtr, Subscriber, SubscriberPtr, Subscription,
|
||||
},
|
||||
@@ -186,7 +187,7 @@ impl P2p {
|
||||
|
||||
async fn handle_stop(self: Arc<Self>, result: Result<()>) {
|
||||
assert!(result.is_err());
|
||||
//assert_eq!(result.unwrap_err(), Error::NetworkServiceStopped);
|
||||
assert_err!(result, Err(Error::NetworkServiceStopped));
|
||||
info!(target: "net::p2p::handle_stop()", "[P2P] Received stop signal. Shutting down.");
|
||||
// Stop the sessions
|
||||
self.session_manual().await.stop().await;
|
||||
|
||||
Reference in New Issue
Block a user