test(xatu): inline finding assertions
This commit is contained in:
@@ -21,20 +21,10 @@ fn fixture_path(path: &str) -> PathBuf {
|
||||
runfiles.join(workspace).join("src/xatu").join(path)
|
||||
}
|
||||
|
||||
fn fixture_report(path: &str) -> xatu::Report {
|
||||
xatu::future_sight(vec![fixture_source(path)]).expect("fixture should parse")
|
||||
}
|
||||
|
||||
fn has_finding(report: &xatu::Report, path: &str, rule_id: &str) -> bool {
|
||||
report.diagnostics.iter().any(|diagnostic| {
|
||||
report.files.get(diagnostic.file_id).path.as_path() == Path::new(path)
|
||||
&& diagnostic.finding.rule_id == rule_id
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn future_sight_reports_clean_sources_as_clean() {
|
||||
let report = fixture_report("testdata/clean.nix");
|
||||
let report = xatu::future_sight(vec![fixture_source("testdata/clean.nix")])
|
||||
.expect("fixture should parse");
|
||||
|
||||
assert!(report.is_clean());
|
||||
}
|
||||
@@ -49,33 +39,33 @@ fn future_sight_rejects_parse_errors() {
|
||||
|
||||
#[test]
|
||||
fn future_sight_reports_deprecated_to_path_qualified_findings() {
|
||||
let report = fixture_report("testdata/lint_findings.nix");
|
||||
let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")])
|
||||
.expect("fixture should parse");
|
||||
|
||||
assert!(has_finding(
|
||||
&report,
|
||||
"testdata/lint_findings.nix",
|
||||
"deprecated_to_path",
|
||||
));
|
||||
assert!(report.diagnostics.iter().any(|diagnostic| {
|
||||
report.files.get(diagnostic.file_id).path.as_path() == Path::new("testdata/lint_findings.nix")
|
||||
&& diagnostic.finding.rule_id == "deprecated_to_path"
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn future_sight_reports_deprecated_to_path_unqualified_findings() {
|
||||
let report = fixture_report("testdata/lint_variants.nix");
|
||||
let report = xatu::future_sight(vec![fixture_source("testdata/lint_variants.nix")])
|
||||
.expect("fixture should parse");
|
||||
|
||||
assert!(has_finding(
|
||||
&report,
|
||||
"testdata/lint_variants.nix",
|
||||
"deprecated_to_path",
|
||||
));
|
||||
assert!(report.diagnostics.iter().any(|diagnostic| {
|
||||
report.files.get(diagnostic.file_id).path.as_path() == Path::new("testdata/lint_variants.nix")
|
||||
&& diagnostic.finding.rule_id == "deprecated_to_path"
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn future_sight_reports_empty_inherit_findings() {
|
||||
let report = fixture_report("testdata/lint_findings.nix");
|
||||
let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")])
|
||||
.expect("fixture should parse");
|
||||
|
||||
assert!(has_finding(
|
||||
&report,
|
||||
"testdata/lint_findings.nix",
|
||||
"empty_inherit",
|
||||
));
|
||||
assert!(report.diagnostics.iter().any(|diagnostic| {
|
||||
report.files.get(diagnostic.file_id).path.as_path() == Path::new("testdata/lint_findings.nix")
|
||||
&& diagnostic.finding.rule_id == "empty_inherit"
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user