Skip to content

Commit f027e04

Browse files
committed
rust: compiler recoginze ignore is verbose about the reason
1 parent e496b6f commit f027e04

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

rust/bear/src/semantic/interpreters/combinators.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ mod test {
8686
let input = any_execution();
8787

8888
match sut.recognize(&input) {
89-
Recognition::Ignored => assert!(true),
89+
Recognition::Ignored(_) => assert!(true),
9090
_ => assert!(false),
9191
}
9292
}
@@ -121,8 +121,8 @@ mod test {
121121
fn recognize(&self, _: &Execution) -> Recognition<CompilerCall> {
122122
match self {
123123
MockTool::Recognize => Recognition::Success(any_compiler_call()),
124-
MockTool::RecognizeIgnored => Recognition::Ignored,
125-
MockTool::RecognizeFailed => Recognition::Error(String::from("problem")),
124+
MockTool::RecognizeIgnored => Recognition::Ignored("reason".into()),
125+
MockTool::RecognizeFailed => Recognition::Error("problem".into()),
126126
MockTool::NotRecognize => Recognition::Unknown,
127127
}
128128
}

rust/bear/src/semantic/interpreters/ignore.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,30 @@ use std::path::PathBuf;
55

66
use super::super::{CompilerCall, Execution, Interpreter, Recognition};
77

8+
const COREUTILS_MESSAGE: &str = "coreutils executable";
9+
const COMPILER_MESSAGE: &str = "compiler specified in config to ignore";
10+
811
/// A tool to ignore a command execution by executable name.
912
pub(super) struct IgnoreByPath {
1013
executables: HashSet<PathBuf>,
14+
reason: String,
1115
}
1216

1317
impl IgnoreByPath {
1418
pub(super) fn new() -> Self {
1519
let executables = COREUTILS_FILES.iter().map(PathBuf::from).collect();
16-
Self { executables }
20+
Self {
21+
executables,
22+
reason: COREUTILS_MESSAGE.into(),
23+
}
1724
}
1825

1926
pub(super) fn from(compilers: &[PathBuf]) -> Self {
2027
let executables = compilers.iter().cloned().collect();
21-
Self { executables }
28+
Self {
29+
executables,
30+
reason: COMPILER_MESSAGE.into(),
31+
}
2232
}
2333
}
2434

@@ -32,7 +42,7 @@ impl Default for IgnoreByPath {
3242
impl Interpreter for IgnoreByPath {
3343
fn recognize(&self, execution: &Execution) -> Recognition<CompilerCall> {
3444
if self.executables.contains(&execution.executable) {
35-
Recognition::Ignored
45+
Recognition::Ignored(self.reason.clone())
3646
} else {
3747
Recognition::Unknown
3848
}
@@ -166,8 +176,9 @@ mod test {
166176
environment: HashMap::new(),
167177
};
168178
let sut = IgnoreByPath::new();
179+
let result = sut.recognize(&input);
169180

170-
assert_eq!(Recognition::Ignored, sut.recognize(&input))
181+
assert!(matches!(result, Recognition::Ignored(_)));
171182
}
172183

173184
#[test]

rust/bear/src/semantic/interpreters/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ mod test {
127127
let interpreter = create_interpreter(&config);
128128
let input = any_execution();
129129

130-
match interpreter.recognize(&input) {
131-
Recognition::Ignored => assert!(true),
132-
_ => assert!(false),
133-
}
130+
let result = interpreter.recognize(&input);
131+
132+
assert_eq!(
133+
result,
134+
Recognition::Ignored("compiler specified in config to ignore".into())
135+
);
134136
}
135137
}

rust/bear/src/semantic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub enum Recognition<T> {
8989
/// The command was recognized and the semantic was identified.
9090
Success(T),
9191
/// The command was recognized, but the semantic was ignored.
92-
Ignored,
92+
Ignored(String),
9393
/// The command was recognized, but the semantic was broken.
9494
Error(String),
9595
/// The command was not recognized.

0 commit comments

Comments
 (0)