use std::path::Path;
use stern4rust::source_reader::SourceReader;
const RULE: &str = "readable-source";
fn root() -> &'static Path {
Path::new(env!("CARGO_MANIFEST_DIR"))
}
#[test]
fn read_of_a_file_that_does_not_exist_names_the_readable_source_rule() {
let found = SourceReader::read(root(), &root().join("src/there_is_no_such_file.rs"));
let offence = found.expect_err("expected an offence");
assert_eq!(offence.rule, RULE);
assert!(
offence.description.contains("could not be read"),
"got {}",
offence.description
);
}
#[test]
fn read_of_a_file_that_does_not_exist_returns_an_offence() {
let found = SourceReader::read(root(), &root().join("src/there_is_no_such_file.rs"));
assert!(found.is_err());
}
#[test]
fn read_of_a_readable_file_reports_the_path_relative_to_the_root() {
let found = SourceReader::read(root(), &root().join("src/lib.rs"));
assert_eq!(found.expect("readable").relative_path(), "src/lib.rs");
}
#[test]
fn read_of_a_readable_file_returns_its_contents() {
let found = SourceReader::read(root(), &root().join("src/lib.rs"));
assert!(
found
.expect("readable")
.contents()
.contains("pub mod rule;")
);
}