test(xatu): cover parse failures
This commit is contained in:
@@ -30,8 +30,12 @@ rust_test(
|
|||||||
compile_data = [
|
compile_data = [
|
||||||
"testdata/clean.nix",
|
"testdata/clean.nix",
|
||||||
"testdata/empty_inherit.nix",
|
"testdata/empty_inherit.nix",
|
||||||
|
"testdata/invalid.nix",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":xatu_lib",
|
||||||
|
"//src/status:status",
|
||||||
],
|
],
|
||||||
deps = [":xatu_lib"],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
rust_binary(
|
rust_binary(
|
||||||
|
|||||||
1
src/xatu/testdata/invalid.nix
vendored
Normal file
1
src/xatu/testdata/invalid.nix
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use status::Code;
|
||||||
use xatu::SourceFile;
|
use xatu::SourceFile;
|
||||||
|
|
||||||
fn source_file(path: &str, source: &str) -> SourceFile {
|
fn source_file(path: &str, source: &str) -> SourceFile {
|
||||||
@@ -15,7 +16,7 @@ fn future_sight_reports_clean_sources_as_clean() {
|
|||||||
"clean.nix",
|
"clean.nix",
|
||||||
include_str!("testdata/clean.nix"),
|
include_str!("testdata/clean.nix"),
|
||||||
)])
|
)])
|
||||||
.expect("source should parse");
|
.expect("fixture should parse");
|
||||||
|
|
||||||
assert!(report.is_clean());
|
assert!(report.is_clean());
|
||||||
}
|
}
|
||||||
@@ -26,7 +27,7 @@ fn future_sight_reports_empty_inherit_findings() {
|
|||||||
"empty_inherit.nix",
|
"empty_inherit.nix",
|
||||||
include_str!("testdata/empty_inherit.nix"),
|
include_str!("testdata/empty_inherit.nix"),
|
||||||
)])
|
)])
|
||||||
.expect("source should parse");
|
.expect("fixture should parse");
|
||||||
|
|
||||||
assert_eq!(1, report.diagnostics.len());
|
assert_eq!(1, report.diagnostics.len());
|
||||||
|
|
||||||
@@ -37,3 +38,14 @@ fn future_sight_reports_empty_inherit_findings() {
|
|||||||
);
|
);
|
||||||
assert_eq!("empty_inherit", diagnostic.finding.rule_id);
|
assert_eq!("empty_inherit", diagnostic.finding.rule_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn future_sight_rejects_parse_errors() {
|
||||||
|
let error = xatu::future_sight(vec![source_file(
|
||||||
|
"invalid.nix",
|
||||||
|
include_str!("testdata/invalid.nix"),
|
||||||
|
)])
|
||||||
|
.expect_err("fixture should fail to parse");
|
||||||
|
|
||||||
|
assert_eq!(Code::FailedPrecondition, error.code());
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user