Skip to content

Commit b627153

Browse files
authored
Merge pull request #2318 from davidalber/config-option-subdirectories
Moving config option tests to a dedicated subdirectory
2 parents e0d3068 + 8b4e9df commit b627153

File tree

181 files changed

+46
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+46
-0
lines changed

tests/system.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,52 @@ fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
5252
files
5353
}
5454

55+
fn verify_config_used(path: &Path, config_name: &str) {
56+
for entry in fs::read_dir(path).expect(&format!(
57+
"Couldn't read {} directory",
58+
path.to_str().unwrap()
59+
)) {
60+
let entry = entry.expect("Couldn't get directory entry");
61+
let path = entry.path();
62+
if path.extension().map_or(false, |f| f == "rs") {
63+
// check if "// rustfmt-<config_name>:" appears in the file.
64+
let filebuf = BufReader::new(
65+
fs::File::open(&path).expect(&format!("Couldn't read file {}", path.display())),
66+
);
67+
assert!(
68+
filebuf
69+
.lines()
70+
.map(|l| l.unwrap())
71+
.take_while(|l| l.starts_with("//"))
72+
.any(|l| l.starts_with(&format!("// rustfmt-{}", config_name))),
73+
format!(
74+
"config option file {} does not contain expected config name",
75+
path.display()
76+
)
77+
);
78+
}
79+
}
80+
}
81+
82+
#[test]
83+
fn verify_config_test_names() {
84+
for path in &[
85+
Path::new("tests/source/configs"),
86+
Path::new("tests/target/configs"),
87+
] {
88+
for entry in fs::read_dir(path).expect("Couldn't read configs directory") {
89+
let entry = entry.expect("Couldn't get directory entry");
90+
let path = entry.path();
91+
if path.is_dir() {
92+
let config_name = path.file_name().unwrap().to_str().unwrap();
93+
94+
// Make sure that config name is used in the files in the directory.
95+
verify_config_used(&path, &config_name);
96+
}
97+
}
98+
}
99+
}
100+
55101
// Integration tests. The files in the tests/source are formatted and compared
56102
// to their equivalent in tests/target. The target file and config can be
57103
// overridden by annotations in the source file. The input and output must match

0 commit comments

Comments
 (0)