Skip to content

Commit

Permalink
Fix test failure due to quoting change in str's Debug
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dtolnay committed Mar 27, 2021
1 parent 130c977 commit 51608bb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use std::panic;
use std::str::{self, FromStr};

#[test]
Expand Down Expand Up @@ -71,9 +72,24 @@ fn lifetime_number() {
}

#[test]
#[should_panic(expected = r#""\'a#" is not a valid Ident"#)]
fn lifetime_invalid() {
Ident::new("'a#", Span::call_site());
let result = panic::catch_unwind(|| Ident::new("'a#", Span::call_site()));
match result {
Err(box_any) => {
let message = box_any.downcast_ref::<String>().unwrap();
let expected1 = r#""\'a#" is not a valid Ident"#; // 1.31.0 .. 1.53.0
let expected2 = r#""'a#" is not a valid Ident"#; // 1.53.0 ..
assert!(
message == expected1 || message == expected2,
"panic message does not match expected string\n\
\x20 panic message: `{:?}`\n\
\x20expected message: `{:?}`",
message,
expected2,
);
}
Ok(_) => panic!("test did not panic as expected"),
}
}

#[test]
Expand Down

0 comments on commit 51608bb

Please sign in to comment.