test(xatu): cover future sight findings
This commit was merged in pull request #74.
This commit is contained in:
@@ -24,6 +24,20 @@ rust_test(
|
|||||||
deps = [":xatu_lib"],
|
deps = [":xatu_lib"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
rust_test(
|
||||||
|
name = "xatu_test",
|
||||||
|
srcs = ["xatu_test.rs"],
|
||||||
|
data = [
|
||||||
|
"testdata/clean.nix",
|
||||||
|
"testdata/empty_inherit.nix",
|
||||||
|
"testdata/invalid.nix",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":xatu_lib",
|
||||||
|
"//src/status:status",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
rust_binary(
|
rust_binary(
|
||||||
name = "xatu",
|
name = "xatu",
|
||||||
crate_name = "xatu_cli",
|
crate_name = "xatu_cli",
|
||||||
|
|||||||
1
src/xatu/testdata/clean.nix
vendored
Normal file
1
src/xatu/testdata/clean.nix
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{ inherit foo; }
|
||||||
1
src/xatu/testdata/empty_inherit.nix
vendored
Normal file
1
src/xatu/testdata/empty_inherit.nix
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{ inherit; }
|
||||||
1
src/xatu/testdata/invalid.nix
vendored
Normal file
1
src/xatu/testdata/invalid.nix
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{
|
||||||
53
src/xatu/xatu_test.rs
Normal file
53
src/xatu/xatu_test.rs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use status::Code;
|
||||||
|
use xatu::SourceFile;
|
||||||
|
|
||||||
|
fn source_file(path: &str) -> SourceFile {
|
||||||
|
SourceFile {
|
||||||
|
path: PathBuf::from(path),
|
||||||
|
source: std::fs::read_to_string(testdata_path(path)).expect("fixture should be readable"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn testdata_path(path: &str) -> PathBuf {
|
||||||
|
if Path::new(path).exists() {
|
||||||
|
return PathBuf::from(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let runfiles = PathBuf::from(std::env::var("TEST_SRCDIR").expect("TEST_SRCDIR should be set"));
|
||||||
|
let workspace = std::env::var("TEST_WORKSPACE").expect("TEST_WORKSPACE should be set");
|
||||||
|
|
||||||
|
runfiles.join(workspace).join("src/xatu").join(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn future_sight_reports_clean_sources_as_clean() {
|
||||||
|
let report = xatu::future_sight(vec![source_file("testdata/clean.nix")])
|
||||||
|
.expect("fixture should parse");
|
||||||
|
|
||||||
|
assert!(report.is_clean());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn future_sight_rejects_parse_errors() {
|
||||||
|
let error = xatu::future_sight(vec![source_file("testdata/invalid.nix")])
|
||||||
|
.expect_err("fixture should fail to parse");
|
||||||
|
|
||||||
|
assert_eq!(error.code(), Code::FailedPrecondition);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn future_sight_reports_empty_inherit_findings() {
|
||||||
|
let report = xatu::future_sight(vec![source_file("testdata/empty_inherit.nix")])
|
||||||
|
.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("testdata/empty_inherit.nix"),
|
||||||
|
);
|
||||||
|
assert_eq!(diagnostic.finding.rule_id, "empty_inherit");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user