Skip to content

Commit

Permalink
Factor out failure processing in round-trip test
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 16, 2024
1 parent a60446a commit da2ea6b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tests/test_round_trip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,21 @@ fn test_round_trip() {
}

fn test(path: &Path, failed: &AtomicUsize, abort_after: usize) {
let failed = || {
let prev_failed = failed.fetch_add(1, Ordering::Relaxed);
if prev_failed + 1 >= abort_after {
process::exit(1);
}
};

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) => {
errorf!("=== {}: syn failed to parse\n{:?}\n", path.display(), msg);
let prev_failed = failed.fetch_add(1, Ordering::Relaxed);
if prev_failed + 1 >= abort_after {
process::exit(1);
}
failed();
return;
}
};
Expand Down Expand Up @@ -138,10 +142,7 @@ fn test(path: &Path, failed: &AtomicUsize, abort_after: usize) {
}
};
if !equal {
let prev_failed = failed.fetch_add(1, Ordering::Relaxed);
if prev_failed + 1 >= abort_after {
process::exit(1);
}
failed();
}
});
}
Expand Down

0 comments on commit da2ea6b

Please sign in to comment.