add assert_err macro

This commit is contained in:
x
2023-08-24 11:16:26 +02:00
parent d4ba515f7d
commit 21df1a2f52
2 changed files with 16 additions and 1 deletions

View File

@@ -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.

View File

@@ -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;