Files
dev/src/xatu/xatu_test.rs

89 lines
2.2 KiB
Rust

use std::path::PathBuf;
use status::Code;
use xatu::SourceFile;
fn source_file(path: &str, source: &str) -> SourceFile {
SourceFile {
path: PathBuf::from(path),
source: source.to_owned(),
}
}
#[test]
fn future_sight_reports_clean_sources_as_clean() {
let report = xatu::future_sight(vec![source_file(
"clean.nix",
r#"{
path = ./. + "/foo";
inherit foo;
}
"#,
)])
.expect("fixture should parse");
assert!(report.is_clean());
}
#[test]
fn future_sight_rejects_parse_errors() {
let error = xatu::future_sight(vec![source_file("invalid.nix", "{\n")])
.expect_err("fixture should fail to parse");
assert_eq!(error.code(), Code::FailedPrecondition);
}
#[test]
fn future_sight_reports_deprecated_to_path_ident_findings() {
let report = xatu::future_sight(vec![source_file(
"deprecated_to_path_ident.nix",
"toPath x\n",
)])
.expect("fixture should parse");
assert_eq!(report.diagnostics.len(), 1);
let diagnostic = &report.diagnostics[0];
assert_eq!(
report.files.get(diagnostic.file_id).path,
PathBuf::from("deprecated_to_path_ident.nix"),
);
assert_eq!(diagnostic.finding.rule_id, "deprecated_to_path");
}
#[test]
fn future_sight_reports_deprecated_to_path_select_findings() {
let report = xatu::future_sight(vec![source_file(
"deprecated_to_path_select.nix",
"builtins.toPath x\n",
)])
.expect("fixture should parse");
assert_eq!(report.diagnostics.len(), 1);
let diagnostic = &report.diagnostics[0];
assert_eq!(
report.files.get(diagnostic.file_id).path,
PathBuf::from("deprecated_to_path_select.nix"),
);
assert_eq!(diagnostic.finding.rule_id, "deprecated_to_path");
}
#[test]
fn future_sight_reports_empty_inherit_findings() {
let report = xatu::future_sight(vec![source_file(
"empty_inherit.nix",
"{\n inherit;\n}\n",
)])
.expect("fixture should parse");
assert_eq!(report.diagnostics.len(), 1);
let diagnostic = &report.diagnostics[0];
assert_eq!(
report.files.get(diagnostic.file_id).path,
PathBuf::from("empty_inherit.nix"),
);
assert_eq!(diagnostic.finding.rule_id, "empty_inherit");
}