test(xatu): use googletest matchers
This commit is contained in:
@@ -37,6 +37,7 @@ rust_test(
|
||||
deps = [
|
||||
":xatu_lib",
|
||||
"//src/status:status",
|
||||
"//third_party/crates:googletest",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use googletest::matchers::{anything, contains, eq, err, is_true, ok};
|
||||
use googletest::{assert_that, expect_that, gtest};
|
||||
use status::Code;
|
||||
use xatu::SourceFile;
|
||||
|
||||
@@ -21,51 +23,96 @@ fn fixture_path(path: &str) -> PathBuf {
|
||||
runfiles.join(workspace).join("src/xatu").join(path)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[gtest]
|
||||
fn future_sight_reports_clean_sources_as_clean() {
|
||||
let report = xatu::future_sight(vec![fixture_source("testdata/clean.nix")])
|
||||
.expect("fixture should parse");
|
||||
let result = xatu::future_sight(vec![fixture_source("testdata/clean.nix")]);
|
||||
assert_that!(result.as_ref(), ok(anything()));
|
||||
let report = result.unwrap();
|
||||
|
||||
assert!(report.is_clean());
|
||||
expect_that!(report.is_clean(), is_true());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[gtest]
|
||||
fn future_sight_rejects_parse_errors() {
|
||||
let error = xatu::future_sight(vec![fixture_source("testdata/invalid.nix")])
|
||||
.expect_err("fixture should fail to parse");
|
||||
let result = xatu::future_sight(vec![fixture_source("testdata/invalid.nix")]);
|
||||
|
||||
assert_eq!(error.code(), Code::FailedPrecondition);
|
||||
expect_that!(result.as_ref(), err(anything()));
|
||||
if let Err(error) = result {
|
||||
expect_that!(error.code(), eq(Code::FailedPrecondition));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[gtest]
|
||||
fn future_sight_reports_deprecated_to_path_qualified_findings() {
|
||||
let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")])
|
||||
.expect("fixture should parse");
|
||||
let result = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")]);
|
||||
assert_that!(result.as_ref(), ok(anything()));
|
||||
let report = result.unwrap();
|
||||
|
||||
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"
|
||||
}));
|
||||
let findings = report
|
||||
.diagnostics
|
||||
.iter()
|
||||
.map(|diagnostic| {
|
||||
(
|
||||
report.files.get(diagnostic.file_id).path.clone(),
|
||||
diagnostic.finding.rule_id,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
expect_that!(
|
||||
findings,
|
||||
contains(eq(&(
|
||||
PathBuf::from("testdata/lint_findings.nix"),
|
||||
"deprecated_to_path"
|
||||
)))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[gtest]
|
||||
fn future_sight_reports_deprecated_to_path_unqualified_findings() {
|
||||
let report = xatu::future_sight(vec![fixture_source("testdata/lint_variants.nix")])
|
||||
.expect("fixture should parse");
|
||||
let result = xatu::future_sight(vec![fixture_source("testdata/lint_variants.nix")]);
|
||||
assert_that!(result.as_ref(), ok(anything()));
|
||||
let report = result.unwrap();
|
||||
|
||||
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"
|
||||
}));
|
||||
let findings = report
|
||||
.diagnostics
|
||||
.iter()
|
||||
.map(|diagnostic| {
|
||||
(
|
||||
report.files.get(diagnostic.file_id).path.clone(),
|
||||
diagnostic.finding.rule_id,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
expect_that!(
|
||||
findings,
|
||||
contains(eq(&(
|
||||
PathBuf::from("testdata/lint_variants.nix"),
|
||||
"deprecated_to_path"
|
||||
)))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[gtest]
|
||||
fn future_sight_reports_empty_inherit_findings() {
|
||||
let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")])
|
||||
.expect("fixture should parse");
|
||||
let result = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")]);
|
||||
assert_that!(result.as_ref(), ok(anything()));
|
||||
let report = result.unwrap();
|
||||
|
||||
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"
|
||||
}));
|
||||
let findings = report
|
||||
.diagnostics
|
||||
.iter()
|
||||
.map(|diagnostic| {
|
||||
(
|
||||
report.files.get(diagnostic.file_id).path.clone(),
|
||||
diagnostic.finding.rule_id,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
expect_that!(
|
||||
findings,
|
||||
contains(eq(&(
|
||||
PathBuf::from("testdata/lint_findings.nix"),
|
||||
"empty_inherit"
|
||||
)))
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user