Skip to content

Commit 51608bb

Browse files
committed
Fix test failure due to quoting change in str's Debug
Beginning with nightly-2021-03-27: note: panic did not contain expected string panic message: `"\"'a#\" is not a valid Ident"`, expected substring: `"\"\\'a#\" is not a valid Ident"` failures: lifetime_invalid
1 parent 130c977 commit 51608bb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

tests/test.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
2+
use std::panic;
23
use std::str::{self, FromStr};
34

45
#[test]
@@ -71,9 +72,24 @@ fn lifetime_number() {
7172
}
7273

7374
#[test]
74-
#[should_panic(expected = r#""\'a#" is not a valid Ident"#)]
7575
fn lifetime_invalid() {
76-
Ident::new("'a#", Span::call_site());
76+
let result = panic::catch_unwind(|| Ident::new("'a#", Span::call_site()));
77+
match result {
78+
Err(box_any) => {
79+
let message = box_any.downcast_ref::<String>().unwrap();
80+
let expected1 = r#""\'a#" is not a valid Ident"#; // 1.31.0 .. 1.53.0
81+
let expected2 = r#""'a#" is not a valid Ident"#; // 1.53.0 ..
82+
assert!(
83+
message == expected1 || message == expected2,
84+
"panic message does not match expected string\n\
85+
\x20 panic message: `{:?}`\n\
86+
\x20expected message: `{:?}`",
87+
message,
88+
expected2,
89+
);
90+
}
91+
Ok(_) => panic!("test did not panic as expected"),
92+
}
7793
}
7894

7995
#[test]

0 commit comments

Comments
 (0)