test(xatu): organize lint fixtures
This commit is contained in:
@@ -30,7 +30,9 @@ rust_test(
|
|||||||
srcs = ["xatu_test.rs"],
|
srcs = ["xatu_test.rs"],
|
||||||
data = [
|
data = [
|
||||||
"testdata/clean.nix",
|
"testdata/clean.nix",
|
||||||
"testdata/empty_inherit.nix",
|
"testdata/invalid.nix",
|
||||||
|
"testdata/lint_findings.nix",
|
||||||
|
"testdata/lint_variants.nix",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":xatu_lib",
|
":xatu_lib",
|
||||||
|
|||||||
4
src/xatu/testdata/clean.nix
vendored
4
src/xatu/testdata/clean.nix
vendored
@@ -1,4 +1,6 @@
|
|||||||
|
{ pkgs }:
|
||||||
|
|
||||||
{
|
{
|
||||||
path = ./. + "/foo";
|
path = ./. + "/foo";
|
||||||
inherit foo;
|
inherit pkgs;
|
||||||
}
|
}
|
||||||
|
|||||||
3
src/xatu/testdata/empty_inherit.nix
vendored
3
src/xatu/testdata/empty_inherit.nix
vendored
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
inherit;
|
|
||||||
}
|
|
||||||
4
src/xatu/testdata/invalid.nix
vendored
Normal file
4
src/xatu/testdata/invalid.nix
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{ pkgs }:
|
||||||
|
|
||||||
|
{
|
||||||
|
inherit pkgs;
|
||||||
6
src/xatu/testdata/lint_findings.nix
vendored
Normal file
6
src/xatu/testdata/lint_findings.nix
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{ src }:
|
||||||
|
|
||||||
|
{
|
||||||
|
inherit;
|
||||||
|
path = builtins.toPath src;
|
||||||
|
}
|
||||||
5
src/xatu/testdata/lint_variants.nix
vendored
Normal file
5
src/xatu/testdata/lint_variants.nix
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{ src }:
|
||||||
|
|
||||||
|
{
|
||||||
|
path = toPath src;
|
||||||
|
}
|
||||||
@@ -21,58 +21,61 @@ fn fixture_path(path: &str) -> PathBuf {
|
|||||||
runfiles.join(workspace).join("src/xatu").join(path)
|
runfiles.join(workspace).join("src/xatu").join(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fixture_report(path: &str) -> xatu::Report {
|
||||||
|
xatu::future_sight(vec![fixture_source(path)]).expect("fixture should parse")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn has_finding(report: &xatu::Report, path: &str, rule_id: &str) -> bool {
|
||||||
|
report.diagnostics.iter().any(|diagnostic| {
|
||||||
|
report.files.get(diagnostic.file_id).path.as_path() == Path::new(path)
|
||||||
|
&& diagnostic.finding.rule_id == rule_id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
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 report = fixture_report("testdata/clean.nix");
|
||||||
.expect("fixture should parse");
|
|
||||||
|
|
||||||
assert!(report.is_clean());
|
assert!(report.is_clean());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn future_sight_rejects_parse_errors() {
|
fn future_sight_rejects_parse_errors() {
|
||||||
let error = xatu::future_sight(vec![SourceFile {
|
let error = xatu::future_sight(vec![fixture_source("testdata/invalid.nix")])
|
||||||
path: PathBuf::from("invalid.nix"),
|
.expect_err("fixture should fail to parse");
|
||||||
source: "{\n".to_owned(),
|
|
||||||
}])
|
|
||||||
.expect_err("fixture should fail to parse");
|
|
||||||
|
|
||||||
assert_eq!(error.code(), Code::FailedPrecondition);
|
assert_eq!(error.code(), Code::FailedPrecondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn future_sight_reports_deprecated_to_path_findings() {
|
fn future_sight_reports_deprecated_to_path_qualified_findings() {
|
||||||
let report = xatu::future_sight(vec![
|
let report = fixture_report("testdata/lint_findings.nix");
|
||||||
SourceFile {
|
|
||||||
path: PathBuf::from("deprecated_to_path_ident.nix"),
|
|
||||||
source: "toPath x\n".to_owned(),
|
|
||||||
},
|
|
||||||
SourceFile {
|
|
||||||
path: PathBuf::from("deprecated_to_path_select.nix"),
|
|
||||||
source: "builtins.toPath x\n".to_owned(),
|
|
||||||
},
|
|
||||||
])
|
|
||||||
.expect("fixture should parse");
|
|
||||||
|
|
||||||
assert!(report.diagnostics.iter().any(|diagnostic| {
|
assert!(has_finding(
|
||||||
report.files.get(diagnostic.file_id).path.as_path()
|
&report,
|
||||||
== Path::new("deprecated_to_path_ident.nix")
|
"testdata/lint_findings.nix",
|
||||||
&& diagnostic.finding.rule_id == "deprecated_to_path"
|
"deprecated_to_path",
|
||||||
}));
|
));
|
||||||
assert!(report.diagnostics.iter().any(|diagnostic| {
|
}
|
||||||
report.files.get(diagnostic.file_id).path.as_path()
|
|
||||||
== Path::new("deprecated_to_path_select.nix")
|
#[test]
|
||||||
&& diagnostic.finding.rule_id == "deprecated_to_path"
|
fn future_sight_reports_deprecated_to_path_unqualified_findings() {
|
||||||
}));
|
let report = fixture_report("testdata/lint_variants.nix");
|
||||||
|
|
||||||
|
assert!(has_finding(
|
||||||
|
&report,
|
||||||
|
"testdata/lint_variants.nix",
|
||||||
|
"deprecated_to_path",
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn future_sight_reports_empty_inherit_findings() {
|
fn future_sight_reports_empty_inherit_findings() {
|
||||||
let report = xatu::future_sight(vec![fixture_source("testdata/empty_inherit.nix")])
|
let report = fixture_report("testdata/lint_findings.nix");
|
||||||
.expect("fixture should parse");
|
|
||||||
|
|
||||||
assert!(report.diagnostics.iter().any(|diagnostic| {
|
assert!(has_finding(
|
||||||
report.files.get(diagnostic.file_id).path.as_path() == Path::new("testdata/empty_inherit.nix")
|
&report,
|
||||||
&& diagnostic.finding.rule_id == "empty_inherit"
|
"testdata/lint_findings.nix",
|
||||||
}));
|
"empty_inherit",
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user