Don't panic in serde_test

Panics lead to reporting errors in tests inside of serde_test internals,
returning errors moves the report location to the corresponding assert_tokens
expression
This commit is contained in:
Mingun
2023-04-30 00:06:00 +05:00
parent f583401284
commit ac8ea72d88
2 changed files with 27 additions and 22 deletions
+6 -8
View File
@@ -63,14 +63,12 @@ macro_rules! assert_next_token {
($ser:expr, $actual:expr, $pat:pat, $guard:expr) => {
match $ser.next_token() {
Some($pat) if $guard => {}
Some(expected) => {
panic!("expected Token::{} but serialized as {}",
expected, $actual);
}
None => {
panic!("expected end of tokens, but {} was serialized",
$actual);
}
Some(expected) => return Err(ser::Error::custom(
format!("expected Token::{} but serialized as {}", expected, $actual)
)),
None => return Err(ser::Error::custom(
format!("expected end of tokens, but {} was serialized", $actual)
)),
}
};
}