From eef99b26796eb366fd4d811d00307147dfc2be33 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 5 May 2025 17:32:11 +0200 Subject: [PATCH] test: Add assert messages in the `assert_timeline_stream` macro. This patch improves the `assert_timeline_stream` macro by adding a bunch of assert messages in case it fails. --- .../integration/timeline/sliding_sync.rs | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs b/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs index 92e29664c..46fb1ce49 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs @@ -86,7 +86,8 @@ macro_rules! assert_timeline_stream { **value, matrix_sdk_ui::timeline::TimelineItemKind::Virtual( matrix_sdk_ui::timeline::VirtualTimelineItem::DateDivider(_) - ) + ), + "`--- date divider ---` has failed", ); } ); @@ -110,8 +111,13 @@ macro_rules! assert_timeline_stream { assert_matches!( &**value, matrix_sdk_ui::timeline::TimelineItemKind::Event(event_timeline_item) => { - assert_eq!(event_timeline_item.event_id().unwrap().as_str(), $event_id); - } + assert_eq!( + event_timeline_item.event_id().unwrap().as_str(), + $event_id, + concat!("`append ", $event_id, "` has failed: event ID does not match"), + ); + }, + concat!("`append ", $event_id, "` has failed: timeline item kind does not match"), ); } ); @@ -136,7 +142,8 @@ macro_rules! assert_timeline_stream { &**value, matrix_sdk_ui::timeline::TimelineItemKind::Virtual( matrix_sdk_ui::timeline::VirtualTimelineItem::DateDivider(_) - ) => {} + ), + "`prepend --- date divider ---` has failed", ); } ); @@ -162,7 +169,8 @@ macro_rules! assert_timeline_stream { &**value, matrix_sdk_ui::timeline::TimelineItemKind::Virtual( matrix_sdk_ui::timeline::VirtualTimelineItem::TimelineStart - ) => {} + ), + "`prepend --- timeline start ---` has failed", ); } ); @@ -186,8 +194,13 @@ macro_rules! assert_timeline_stream { assert_matches!( &**value, matrix_sdk_ui::timeline::TimelineItemKind::Event(event_timeline_item) => { - assert_eq!(event_timeline_item.event_id().unwrap().as_str(), $event_id); - } + assert_eq!( + event_timeline_item.event_id().unwrap().as_str(), + $event_id, + concat!("`prepend ", $event_id, "` has failed: event ID does not match"), + ); + }, + concat!("`prepend ", $event_id, "` has failed: timeline item kind does not match"), ); } ); @@ -211,8 +224,13 @@ macro_rules! assert_timeline_stream { assert_matches!( &**value, matrix_sdk_ui::timeline::TimelineItemKind::Event(event_timeline_item) => { - assert_eq!(event_timeline_item.event_id().unwrap().as_str(), $event_id); - } + assert_eq!( + event_timeline_item.event_id().unwrap().as_str(), + $event_id, + concat!("`insert [", $index, "] ", $event_id, "` has failed: event ID does not match"), + ); + }, + concat!("`insert [", $index, "] ", $event_id, "` has failed: timeline item kind does not match"), ); } ); @@ -236,8 +254,13 @@ macro_rules! assert_timeline_stream { assert_matches!( &**value, matrix_sdk_ui::timeline::TimelineItemKind::Event(event_timeline_item) => { - assert_eq!(event_timeline_item.event_id().unwrap().as_str(), $event_id); - } + assert_eq!( + event_timeline_item.event_id().unwrap().as_str(), + $event_id, + concat!("`update [", $index, "] ", $event_id, "` has failed: event ID does not match"), + ); + }, + concat!("`update [", $index, "] ", $event_id, "` has failed: timeline item kind does not match"), ); } ); @@ -257,7 +280,8 @@ macro_rules! assert_timeline_stream { { assert_matches!( $iterator .next(), - Some(eyeball_im::VectorDiff::Remove { index: $index }) + Some(eyeball_im::VectorDiff::Remove { index: $index }), + concat!("`remove [", $index, "]` has failed"), ); } ] @@ -275,7 +299,8 @@ macro_rules! assert_timeline_stream { { assert_matches!( $iterator .next(), - Some(eyeball_im::VectorDiff::Clear) + Some(eyeball_im::VectorDiff::Clear), + "clear has failed", ); } ] @@ -285,7 +310,9 @@ macro_rules! assert_timeline_stream { ( @_ [ $iterator:ident ] [] [ $( $accumulator:tt )* ] ) => { $( $accumulator )* - assert!($iterator .next().is_none(), concat!(stringify!($iterator), " has not been entirely read")); + let next = $iterator .next(); + + assert!(next.is_none(), "`{}` has not been entirely read; received `{:?}`", stringify!( $iterator ), next); }; ( [ $stream:ident ] $( $all:tt )* ) => {