refactor(natu): rename xatu
This commit was merged in pull request #97.
This commit is contained in:
105
src/natu/natu_test.rs
Normal file
105
src/natu/natu_test.rs
Normal file
@@ -0,0 +1,105 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use googletest::matchers::{contains, eq, is_true};
|
||||
use googletest::{OrFail, expect_that, gtest};
|
||||
use status::Code;
|
||||
use natu::SourceFile;
|
||||
|
||||
fn fixture_source(path: &str) -> googletest::Result<SourceFile> {
|
||||
Ok(SourceFile {
|
||||
path: PathBuf::from(path),
|
||||
source: std::fs::read_to_string(fixture_path(path)?).or_fail()?,
|
||||
})
|
||||
}
|
||||
|
||||
fn fixture_path(path: &str) -> googletest::Result<PathBuf> {
|
||||
if Path::new(path).exists() {
|
||||
return Ok(PathBuf::from(path));
|
||||
}
|
||||
|
||||
let runfiles = PathBuf::from(std::env::var("TEST_SRCDIR").or_fail()?);
|
||||
let workspace = std::env::var("TEST_WORKSPACE").or_fail()?;
|
||||
|
||||
Ok(runfiles.join(workspace).join("src/natu").join(path))
|
||||
}
|
||||
|
||||
#[gtest]
|
||||
fn natu_accepts_clean_source() -> googletest::Result<()> {
|
||||
let report = natu::future_sight(vec![fixture_source("testdata/clean.nix")?]).or_fail()?;
|
||||
|
||||
expect_that!(report.is_clean(), is_true());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[gtest]
|
||||
fn natu_rejects_invalid_source() -> googletest::Result<()> {
|
||||
let error = natu::future_sight(vec![fixture_source("testdata/invalid.nix")?])
|
||||
.err()
|
||||
.or_fail()?;
|
||||
|
||||
expect_that!(error.code(), eq(Code::FailedPrecondition));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[gtest]
|
||||
fn natu_reports_out_of_order_let_bindings() -> googletest::Result<()> {
|
||||
let report = natu::future_sight(vec![fixture_source("testdata/lint_findings.nix")?]).or_fail()?;
|
||||
|
||||
let let_order_count = report
|
||||
.diagnostics
|
||||
.iter()
|
||||
.filter(|diagnostic| diagnostic.finding.rule_id == "let_order")
|
||||
.count();
|
||||
expect_that!(let_order_count, eq(4));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[gtest]
|
||||
fn natu_reports_unquoted_uri() -> googletest::Result<()> {
|
||||
let report = natu::future_sight(vec![fixture_source("testdata/lint_findings.nix")?]).or_fail()?;
|
||||
|
||||
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"),
|
||||
"unquoted_uri"
|
||||
)))
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[gtest]
|
||||
fn natu_reports_manual_inherit() -> googletest::Result<()> {
|
||||
let report = natu::future_sight(vec![fixture_source("testdata/lint_findings.nix")?]).or_fail()?;
|
||||
|
||||
let manual_inherit_count = report
|
||||
.diagnostics
|
||||
.iter()
|
||||
.filter(|diagnostic| diagnostic.finding.rule_id == "manual_inherit")
|
||||
.count();
|
||||
expect_that!(manual_inherit_count, eq(1));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[gtest]
|
||||
fn natu_reports_manual_inherit_from() -> googletest::Result<()> {
|
||||
let report = natu::future_sight(vec![fixture_source("testdata/lint_findings.nix")?]).or_fail()?;
|
||||
|
||||
let manual_inherit_from_count = report
|
||||
.diagnostics
|
||||
.iter()
|
||||
.filter(|diagnostic| diagnostic.finding.rule_id == "manual_inherit_from")
|
||||
.count();
|
||||
expect_that!(manual_inherit_from_count, eq(1));
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user