-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmode.rs
93 lines (88 loc) · 2.72 KB
/
mode.rs
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
85
86
87
88
89
90
91
92
93
use super::Error;
use crate::parser::Comments;
use crate::parser::MaybeSpanned;
use crate::Errored;
use std::fmt::Display;
use std::process::ExitStatus;
/// When to run rustfix on tests
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum RustfixMode {
/// Do not run rustfix on the test
Disabled,
/// Apply only `MachineApplicable` suggestions emitted by the test
MachineApplicable,
/// Apply all suggestions emitted by the test
Everything,
}
impl RustfixMode {
pub(crate) fn enabled(self) -> bool {
self != RustfixMode::Disabled
}
}
#[derive(Copy, Clone, Debug)]
/// Decides what is expected of each test's exit status.
pub enum Mode {
/// 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,
/// When to run rustfix on the test
rustfix: RustfixMode,
},
/// Run the tests, but always pass them as long as all annotations are satisfied and stderr files match.
Yolo {
/// When to run rustfix on the test
rustfix: RustfixMode,
},
}
impl Mode {
pub(crate) fn ok(self, status: ExitStatus) -> Result<(), Error> {
let expected = match self {
Mode::Run { exit_code } => exit_code,
Mode::Pass => 0,
Mode::Panic => 101,
Mode::Fail { .. } => 1,
Mode::Yolo { .. } => return Ok(()),
};
if status.code() == Some(expected) {
Ok(())
} else {
Err(Error::ExitStatus {
mode: self,
status,
expected,
})
}
}
pub(crate) fn maybe_override(
self,
comments: &Comments,
revision: &str,
) -> Result<MaybeSpanned<Self>, Errored> {
let mode = comments.find_one_for_revision(revision, "mode changes", |r| r.mode)?;
Ok(mode.map_or(MaybeSpanned::new_config(self), Into::into))
}
}
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: _,
rustfix: _,
} => write!(f, "fail"),
Mode::Yolo { rustfix: _ } => write!(f, "yolo"),
}
}
}