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