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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
use super::Error;
use super::Errors;
use crate::parser::Comments;
use std::fmt::Display;
use std::process::ExitStatus;
#[derive(Copy, Clone, Debug)]
/// Decides what is expected of each test's exit status.
pub enum Mode {
/// The test fails with an error, but passes after running rustfix
Fix,
/// The test passes a full execution of the rustc driver
Pass,
/// The test produces an executable binary that can get executed on the host
Run {
/// The expected exit code
exit_code: i32,
},
/// The rustc driver panicked
Panic,
/// The rustc driver emitted an error
Fail {
/// Whether failing tests must have error patterns. Set to false if you just care about .stderr output.
require_patterns: bool,
},
/// Run the tests, but always pass them as long as all annotations are satisfied and stderr files match.
Yolo,
}
impl Mode {
pub(crate) fn ok(self, status: ExitStatus) -> Errors {
let expected = match self {
Mode::Run { exit_code } => exit_code,
Mode::Pass => 0,
Mode::Panic => 101,
Mode::Fail { .. } => 1,
Mode::Fix | Mode::Yolo => return vec![],
};
if status.code() == Some(expected) {
vec![]
} else {
vec![Error::ExitStatus {
mode: self,
status,
expected,
}]
}
}
pub(crate) fn maybe_override(
self,
comments: &Comments,
revision: &str,
errors: &mut Vec<Error>,
) -> Self {
comments
.find_one_for_revision(
revision,
|r| r.mode.as_ref(),
|&(_, line)| {
errors.push(Error::InvalidComment {
msg: "multiple mode changes found".into(),
line,
})
},
)
.map(|&(mode, _)| mode)
.unwrap_or(self)
}
}
impl Display for Mode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Mode::Run { exit_code } => write!(f, "run({exit_code})"),
Mode::Pass => write!(f, "pass"),
Mode::Panic => write!(f, "panic"),
Mode::Fail {
require_patterns: _,
} => write!(f, "fail"),
Mode::Yolo => write!(f, "yolo"),
Mode::Fix => write!(f, "fix"),
}
}
}
|