summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/headers.rs
blob: 7eec9a9cdd2b9ebfd7c0b71541aff27e8808783c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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();
        if !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");
}