Skip to content

Commit

Permalink
Catch panics in round-trip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 16, 2024
1 parent da2ea6b commit 8454aa4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tests/test_round_trip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,25 @@ fn test(path: &Path, failed: &AtomicUsize, abort_after: usize) {

let content = fs::read_to_string(path).unwrap();

let start = Instant::now();
let (krate, elapsed) = match syn::parse_file(&content) {
Ok(krate) => (krate, start.elapsed()),
Err(msg) => {
let (back, elapsed) = match panic::catch_unwind(|| {
let start = Instant::now();
let result = syn::parse_file(&content);
let elapsed = start.elapsed();
result.map(|krate| (quote!(#krate).to_string(), elapsed))
}) {
Err(_) => {
errorf!("=== {}: syn panic\n", path.display());
failed();
return;
}
Ok(Err(msg)) => {
errorf!("=== {}: syn failed to parse\n{:?}\n", path.display(), msg);
failed();
return;
}
Ok(Ok(result)) => result,
};
let back = quote!(#krate).to_string();

let edition = repo::edition(path).parse().unwrap();

rustc_span::create_session_if_not_set_then(edition, |_| {
Expand Down

0 comments on commit 8454aa4

Please sign in to comment.