summaryrefslogtreecommitdiffstats
path: root/vendor/sysinfo/tests/code_checkers/mod.rs
blob: db645341db9fb9ca8ea2b8959ec195827532cde0 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Take a look at the license at the top of the repository in the LICENSE file.

mod docs;
mod headers;
mod signals;
mod utils;

use std::path::Path;
use utils::TestResult;

#[allow(clippy::type_complexity)]
const CHECKS: &[(fn(&str, &Path) -> TestResult, &[&str])] = &[
    (headers::check_license_header, &["src", "tests", "examples"]),
    (signals::check_signals, &["src"]),
    (docs::check_docs, &["src"]),
];

fn handle_tests(res: &mut [TestResult]) {
    utils::read_dirs(
        &["benches", "examples", "src", "tests"],
        &mut |p: &Path, c: &str| {
            if let Some(first) = p.iter().next().and_then(|first| first.to_str()) {
                for (pos, (check, filter)) in CHECKS.iter().enumerate() {
                    if filter.contains(&first) {
                        res[pos] += check(c, p);
                    }
                }
            }
        },
    );
}

#[test]
fn code_checks() {
    let mut res = Vec::new();

    for _ in CHECKS {
        res.push(TestResult {
            nb_tests: 0,
            nb_errors: 0,
        });
    }

    handle_tests(&mut res);

    for r in res {
        assert_eq!(r.nb_errors, 0);
        assert_ne!(r.nb_tests, 0);
    }
}