Skip to content

Commit

Permalink
Pass only .rs file paths to for_each_rust_file closure
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Apr 1, 2023
1 parent f7b4ef3 commit c001c26
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
23 changes: 16 additions & 7 deletions tests/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ mod progress;
use self::progress::Progress;
use anyhow::Result;
use flate2::read::GzDecoder;
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use std::fs;
use std::path::Path;
use std::path::{Path, PathBuf};
use tar::Archive;
use walkdir::{DirEntry, WalkDir};

Expand Down Expand Up @@ -200,14 +200,23 @@ static EXCLUDE_DIRS: &[&str] = &[
"src/tools/rust-analyzer/crates/syntax/test_data/reparse/fuzz-failures",
];

pub fn for_each_rust_file(for_each: impl Fn(DirEntry) + Sync + Send) {
WalkDir::new("tests/rust")
pub fn for_each_rust_file(for_each: impl Fn(&Path) + Sync + Send) {
let mut dir_entries = Vec::new();

for entry in WalkDir::new("tests/rust")
.sort_by_file_name()
.into_iter()
.filter_entry(base_dir_filter)
.collect::<Result<Vec<DirEntry>, walkdir::Error>>()
.unwrap()
.into_par_iter()
{
let entry = entry.unwrap();
if !entry.file_type().is_dir() {
dir_entries.push(entry.into_path());
}
}

dir_entries
.par_iter()
.map(PathBuf::as_path)
.for_each(for_each);
}

Expand Down
7 changes: 1 addition & 6 deletions tests/test_precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,7 @@ fn test_rustc_precedence() {
// 2018 edition is hard
let edition_regex = Regex::new(r"\b(async|try)[!(]").unwrap();

repo::for_each_rust_file(|entry| {
let path = entry.path();
if path.is_dir() {
return;
}

repo::for_each_rust_file(|path| {
let content = fs::read_to_string(path).unwrap();
let content = edition_regex.replace_all(&content, "_$0");

Expand Down
7 changes: 1 addition & 6 deletions tests/test_round_trip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ fn test_round_trip() {

let failed = AtomicUsize::new(0);

repo::for_each_rust_file(|entry| {
let path = entry.path();
if !path.is_dir() {
test(path, &failed, abort_after);
}
});
repo::for_each_rust_file(|path| test(path, &failed, abort_after));

let failed = failed.load(Ordering::Relaxed);
if failed > 0 {
Expand Down

0 comments on commit c001c26

Please sign in to comment.