Skip to content

Commit 9cf764b

Browse files
committed
fix self_tests
1 parent facba6a commit 9cf764b

File tree

1 file changed

+14
-10
lines changed
  • rustfmt-core/rustfmt-lib/src/test

1 file changed

+14
-10
lines changed

rustfmt-core/rustfmt-lib/src/test/mod.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use std::path::{Path, PathBuf};
77
use std::str::Chars;
88
use std::thread;
99

10-
use rustfmt_emitter::rustfmt_diff::{
11-
make_diff, print_diff, Mismatch, ModifiedChunk, OutputWriter,
12-
};
10+
use rustfmt_emitter::rustfmt_diff::{make_diff, print_diff, Mismatch, ModifiedChunk, OutputWriter};
1311

1412
use crate::config::{Color, Config, EmitMode, FileName, NewlineStyle, ReportTactic};
1513
use crate::formatting::{ReportedErrors, SourceFile};
@@ -96,7 +94,7 @@ fn is_file_skip(path: &Path) -> bool {
9694
// Returns a `Vec` containing `PathBuf`s of files with an `rs` extension in the
9795
// given path. The `recursive` argument controls if files from subdirectories
9896
// are also returned.
99-
fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
97+
fn get_test_files(path: &Path, recursive: bool, is_file_skip: fn(&Path) -> bool) -> Vec<PathBuf> {
10098
let mut files = vec![];
10199
if path.is_dir() {
102100
for entry in fs::read_dir(path)
@@ -105,7 +103,7 @@ fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
105103
let entry = entry.expect("couldn't get `DirEntry`");
106104
let path = entry.path();
107105
if path.is_dir() && recursive {
108-
files.append(&mut get_test_files(&path, recursive));
106+
files.append(&mut get_test_files(&path, recursive, is_file_skip));
109107
} else if path.extension().map_or(false, |f| f == "rs") && !is_file_skip(&path) {
110108
files.push(path);
111109
}
@@ -179,7 +177,7 @@ fn system_tests() {
179177
init_log();
180178
run_test_with(&TestSetting::default(), || {
181179
// Get all files in the tests/source directory.
182-
let files = get_test_files(Path::new("tests/source"), true);
180+
let files = get_test_files(Path::new("tests/source"), true, is_file_skip);
183181
let (_reports, count, fails) = check_files(files, &None);
184182

185183
// Display results.
@@ -198,7 +196,7 @@ fn system_tests() {
198196
#[test]
199197
fn coverage_tests() {
200198
init_log();
201-
let files = get_test_files(Path::new("tests/coverage/source"), true);
199+
let files = get_test_files(Path::new("tests/coverage/source"), true, is_file_skip);
202200
let (_reports, count, fails) = check_files(files, &None);
203201

204202
println!("Ran {} tests in coverage mode.", count);
@@ -362,7 +360,7 @@ fn idempotence_tests() {
362360
return;
363361
}
364362
// Get all files in the tests/target directory.
365-
let files = get_test_files(Path::new("tests/target"), true);
363+
let files = get_test_files(Path::new("tests/target"), true, is_file_skip);
366364
let (_reports, count, fails) = check_files(files, &None);
367365

368366
// Display results.
@@ -380,12 +378,19 @@ fn idempotence_tests() {
380378
// no warnings are emitted.
381379
#[test]
382380
fn self_tests() {
381+
fn is_file_skip(path: &Path) -> bool {
382+
let skip_file_white_list = ["target", "tests"];
383+
skip_file_white_list
384+
.iter()
385+
.any(|file_path| is_subpath(path, file_path))
386+
}
387+
383388
init_log();
384389
// Issue-3443: these tests require nightly
385390
if !is_nightly_channel!() {
386391
return;
387392
}
388-
let mut files = get_test_files(Path::new("tests"), false);
393+
let mut files = get_test_files(Path::new("../../rustfmt-core"), true, is_file_skip);
389394
files.push(PathBuf::from("src/lib.rs"));
390395

391396
let (reports, count, fails) = check_files(files, &Some(PathBuf::from("../../rustfmt.toml")));
@@ -809,4 +814,3 @@ fn string_eq_ignore_newline_repr_test() {
809814
assert!(string_eq_ignore_newline_repr("a\r\n\r\n\r\nb", "a\n\n\nb"));
810815
assert!(!string_eq_ignore_newline_repr("a\r\nbcd", "a\nbcdefghijk"));
811816
}
812-

0 commit comments

Comments
 (0)