testing_conventions/
violation.rs1use std::path::PathBuf;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct Violation {
8 pub file: PathBuf,
9 pub line: usize,
11 pub rule: &'static str,
13 pub message: String,
14}
15
16pub fn rendered(violation: &Violation) -> String {
18 format!(
19 "{}:{}: {} — {}",
20 violation.file.display(),
21 violation.line,
22 violation.rule,
23 violation.message
24 )
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30
31 #[test]
32 fn a_violation_renders_its_file_line_rule_and_message() {
33 let rendering = rendered(&Violation {
34 file: PathBuf::from("src/widget.rs"),
35 line: 12,
36 rule: "no-monkeypatch",
37 message: "patches `os.environ`".to_string(),
38 });
39
40 assert_eq!(
41 rendering,
42 "src/widget.rs:12: no-monkeypatch — patches `os.environ`"
43 );
44 }
45}