x пре 3 година
родитељ
комит
21df1a2f52
2 измењених фајлова са 16 додато и 1 уклоњено
  1. 14 0
      src/error.rs
  2. 2 1
      src/net/p2p.rs

+ 14 - 0
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.
 

+ 2 - 1
src/net/p2p.rs

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