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