tidy/
known_bug.rs

1//! Tidy check to ensure that tests inside 'tests/crashes' have a '@known-bug' directive.
2
3use std::path::Path;
4
5use crate::diagnostics::{CheckId, DiagCtx};
6use crate::walk::*;
7
8pub fn check(filepath: &Path, diag_ctx: DiagCtx) {
9    let mut check = diag_ctx.start_check(CheckId::new("known_bug").path(filepath));
10    walk(filepath, |path, _is_dir| filter_not_rust(path), &mut |entry, contents| {
11        let file: &Path = entry.path();
12
13        // files in "auxiliary" do not need to crash by themselves
14        let test_path_segments =
15            file.iter().map(|s| s.to_string_lossy().into()).collect::<Vec<String>>();
16        let test_path_segments_str =
17            test_path_segments.iter().map(|s| s.as_str()).collect::<Vec<&str>>();
18
19        if !matches!(
20            test_path_segments_str[..],
21            [.., "tests", "crashes", "auxiliary", _aux_file_rs]
22        ) && !contents.lines().any(|line| line.starts_with("//@ known-bug: "))
23        {
24            check.error(format!(
25                "{} crash/ice test does not have a \"//@ known-bug: \" directive",
26                file.display()
27            ));
28        }
29    });
30}