]> git.proxmox.com Git - rustc.git/blob - vendor/sysinfo-0.26.7/tests/code_checkers/signals.rs
New upstream version 1.73.0+dfsg1
[rustc.git] / vendor / sysinfo-0.26.7 / tests / code_checkers / signals.rs
1 // Take a look at the license at the top of the repository in the LICENSE file.
2
3 use super::utils::{show_error, TestResult};
4 use std::path::Path;
5
6 fn check_supported_signals_decl<'a>(lines: &mut impl Iterator<Item = &'a str>, p: &Path) -> usize {
7 for line in lines {
8 let trimmed = line.trim();
9 if trimmed.starts_with("const SUPPORTED_SIGNALS: &'static [Signal]") {
10 if trimmed != "const SUPPORTED_SIGNALS: &'static [Signal] = supported_signals();" {
11 show_error(
12 p,
13 "SystemExt::SUPPORTED_SIGNALS should be declared using `supported_signals()`",
14 );
15 return 1;
16 }
17 break;
18 }
19 }
20 0
21 }
22
23 fn check_kill_decl<'a>(lines: &mut impl Iterator<Item = &'a str>, p: &Path) -> usize {
24 let mut errors = 0;
25
26 while let Some(line) = lines.next() {
27 let trimmed = line.trim();
28 if trimmed.starts_with("fn kill(") {
29 show_error(p, "`ProcessExt::kill` should not be reimplemented!");
30 errors += 1;
31 } else if trimmed.starts_with("fn kill_with(") {
32 if let Some(line) = lines.next() {
33 let trimmed = line.trim();
34 if trimmed.ends_with("::system::convert_signal(signal)?;") || trimmed == "None" {
35 continue;
36 } else {
37 show_error(p, "`ProcessExt::kill_with` should use `convert_signal`");
38 errors += 1;
39 }
40 }
41 }
42 }
43 errors
44 }
45
46 pub fn check_signals(content: &str, p: &Path) -> TestResult {
47 let mut lines = content.lines();
48 let mut res = TestResult {
49 nb_tests: 0,
50 nb_errors: 0,
51 };
52
53 while let Some(line) = lines.next() {
54 let trimmed = line.trim();
55 if trimmed.starts_with("impl SystemExt for System {") {
56 res.nb_tests += 1;
57 res.nb_errors += check_supported_signals_decl(&mut lines, p);
58 } else if trimmed.starts_with("impl ProcessExt for Process {") {
59 res.nb_tests += 1;
60 res.nb_errors += check_kill_decl(&mut lines, p);
61 }
62 }
63 res
64 }