1 // Take a look at the license at the top of the repository in the LICENSE file.
3 use super::utils
::{show_error, TestResult}
;
6 fn check_supported_signals_decl
<'a
>(lines
: &mut impl Iterator
<Item
= &'a
str>, p
: &Path
) -> usize {
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();" {
13 "SystemExt::SUPPORTED_SIGNALS should be declared using `supported_signals()`",
23 fn check_kill_decl
<'a
>(lines
: &mut impl Iterator
<Item
= &'a
str>, p
: &Path
) -> usize {
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!");
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" {
37 show_error(p
, "`ProcessExt::kill_with` should use `convert_signal`");
46 pub fn check_signals(content
: &str, p
: &Path
) -> TestResult
{
47 let mut lines
= content
.lines();
48 let mut res
= TestResult
{
53 while let Some(line
) = lines
.next() {
54 let trimmed
= line
.trim();
55 if trimmed
.starts_with("impl SystemExt for System {") {
57 res
.nb_errors
+= check_supported_signals_decl(&mut lines
, p
);
58 } else if trimmed
.starts_with("impl ProcessExt for Process {") {
60 res
.nb_errors
+= check_kill_decl(&mut lines
, p
);