1e67f6c0fb
Avoid scanning temporary files created by editors like this one created by Vim: ---- old_test_headers stdout ---- thread 'old_test_headers' panicked at tests/headers.rs:19:74: tests/ui/.regex.rs.swp: stream did not contain valid UTF-8 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
35 lines
1015 B
Rust
35 lines
1015 B
Rust
use regex::Regex;
|
|
use std::fs;
|
|
use walkdir::WalkDir;
|
|
|
|
#[test]
|
|
fn old_test_headers() {
|
|
let old_headers = Regex::new(
|
|
r"^//( ?\[\w+\])? ?((check|build|run|ignore|aux|only|needs|rustc|unset|no|normalize|run|compile)-|edition|incremental|revisions).*",
|
|
)
|
|
.unwrap();
|
|
let mut failed = false;
|
|
|
|
for entry in WalkDir::new("tests") {
|
|
let entry = entry.unwrap();
|
|
let is_hidden_file = entry
|
|
.file_name()
|
|
.to_str()
|
|
.expect("non-UTF-8 file name")
|
|
.starts_with('.');
|
|
if is_hidden_file || !entry.file_type().is_file() {
|
|
continue;
|
|
}
|
|
|
|
let file = fs::read_to_string(entry.path()).unwrap_or_else(|err| panic!("{}: {err}", entry.path().display()));
|
|
|
|
if let Some(header) = old_headers.find(&file) {
|
|
println!("Found header `{}` in {}", header.as_str(), entry.path().display());
|
|
|
|
failed = true;
|
|
}
|
|
}
|
|
|
|
assert!(!failed, "use `//@foo` style test headers instead");
|
|
}
|