test(xatu): inline short future sight fixtures
This commit is contained in:
@@ -28,13 +28,6 @@ rust_test(
|
|||||||
rust_test(
|
rust_test(
|
||||||
name = "xatu_test",
|
name = "xatu_test",
|
||||||
srcs = ["xatu_test.rs"],
|
srcs = ["xatu_test.rs"],
|
||||||
data = [
|
|
||||||
"testdata/clean.nix",
|
|
||||||
"testdata/deprecated_to_path_ident.nix",
|
|
||||||
"testdata/deprecated_to_path_select.nix",
|
|
||||||
"testdata/empty_inherit.nix",
|
|
||||||
"testdata/invalid.nix",
|
|
||||||
],
|
|
||||||
deps = [
|
deps = [
|
||||||
":xatu_lib",
|
":xatu_lib",
|
||||||
"//src/status:status",
|
"//src/status:status",
|
||||||
|
|||||||
1
src/xatu/testdata/clean.nix
vendored
1
src/xatu/testdata/clean.nix
vendored
@@ -1 +0,0 @@
|
|||||||
{ inherit foo; }
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
toPath x
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
builtins.toPath x
|
|
||||||
1
src/xatu/testdata/empty_inherit.nix
vendored
1
src/xatu/testdata/empty_inherit.nix
vendored
@@ -1 +0,0 @@
|
|||||||
{ inherit; }
|
|
||||||
1
src/xatu/testdata/invalid.nix
vendored
1
src/xatu/testdata/invalid.nix
vendored
@@ -1 +0,0 @@
|
|||||||
{
|
|
||||||
@@ -1,29 +1,21 @@
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use status::Code;
|
use status::Code;
|
||||||
use xatu::SourceFile;
|
use xatu::SourceFile;
|
||||||
|
|
||||||
fn source_file(path: &str) -> SourceFile {
|
fn source_file(path: &str, source: &str) -> SourceFile {
|
||||||
SourceFile {
|
SourceFile {
|
||||||
path: PathBuf::from(path),
|
path: PathBuf::from(path),
|
||||||
source: std::fs::read_to_string(testdata_path(path)).expect("fixture should be readable"),
|
source: source.to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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]
|
#[test]
|
||||||
fn future_sight_reports_clean_sources_as_clean() {
|
fn future_sight_reports_clean_sources_as_clean() {
|
||||||
let report = xatu::future_sight(vec![source_file("testdata/clean.nix")])
|
let report = xatu::future_sight(vec![source_file(
|
||||||
|
"clean.nix",
|
||||||
|
"{ value = builtins.toString x; inherit foo; }",
|
||||||
|
)])
|
||||||
.expect("fixture should parse");
|
.expect("fixture should parse");
|
||||||
|
|
||||||
assert!(report.is_clean());
|
assert!(report.is_clean());
|
||||||
@@ -31,15 +23,15 @@ fn future_sight_reports_clean_sources_as_clean() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn future_sight_rejects_parse_errors() {
|
fn future_sight_rejects_parse_errors() {
|
||||||
let error = xatu::future_sight(vec![source_file("testdata/invalid.nix")])
|
let error = xatu::future_sight(vec![source_file("invalid.nix", "{")])
|
||||||
.expect_err("fixture should fail to parse");
|
.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_ident_findings() {
|
fn future_sight_reports_deprecated_to_path_ident_findings() {
|
||||||
let report = xatu::future_sight(vec![source_file("testdata/deprecated_to_path_ident.nix")])
|
let report = xatu::future_sight(vec![source_file("deprecated_to_path_ident.nix", "toPath x")])
|
||||||
.expect("fixture should parse");
|
.expect("fixture should parse");
|
||||||
|
|
||||||
assert_eq!(report.diagnostics.len(), 1);
|
assert_eq!(report.diagnostics.len(), 1);
|
||||||
@@ -47,29 +39,32 @@ fn future_sight_reports_deprecated_to_path_ident_findings() {
|
|||||||
let diagnostic = &report.diagnostics[0];
|
let diagnostic = &report.diagnostics[0];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
report.files.get(diagnostic.file_id).path,
|
report.files.get(diagnostic.file_id).path,
|
||||||
PathBuf::from("testdata/deprecated_to_path_ident.nix"),
|
PathBuf::from("deprecated_to_path_ident.nix"),
|
||||||
);
|
);
|
||||||
assert_eq!(diagnostic.finding.rule_id, "deprecated_to_path");
|
assert_eq!(diagnostic.finding.rule_id, "deprecated_to_path");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn future_sight_reports_deprecated_to_path_select_findings() {
|
fn future_sight_reports_deprecated_to_path_select_findings() {
|
||||||
let report = xatu::future_sight(vec![source_file("testdata/deprecated_to_path_select.nix")])
|
let report = xatu::future_sight(vec![source_file(
|
||||||
.expect("fixture should parse");
|
"deprecated_to_path_select.nix",
|
||||||
|
"builtins.toPath x",
|
||||||
|
)])
|
||||||
|
.expect("fixture should parse");
|
||||||
|
|
||||||
assert_eq!(report.diagnostics.len(), 1);
|
assert_eq!(report.diagnostics.len(), 1);
|
||||||
|
|
||||||
let diagnostic = &report.diagnostics[0];
|
let diagnostic = &report.diagnostics[0];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
report.files.get(diagnostic.file_id).path,
|
report.files.get(diagnostic.file_id).path,
|
||||||
PathBuf::from("testdata/deprecated_to_path_select.nix"),
|
PathBuf::from("deprecated_to_path_select.nix"),
|
||||||
);
|
);
|
||||||
assert_eq!(diagnostic.finding.rule_id, "deprecated_to_path");
|
assert_eq!(diagnostic.finding.rule_id, "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![source_file("testdata/empty_inherit.nix")])
|
let report = xatu::future_sight(vec![source_file("empty_inherit.nix", "{ inherit; }")])
|
||||||
.expect("fixture should parse");
|
.expect("fixture should parse");
|
||||||
|
|
||||||
assert_eq!(report.diagnostics.len(), 1);
|
assert_eq!(report.diagnostics.len(), 1);
|
||||||
@@ -77,7 +72,7 @@ fn future_sight_reports_empty_inherit_findings() {
|
|||||||
let diagnostic = &report.diagnostics[0];
|
let diagnostic = &report.diagnostics[0];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
report.files.get(diagnostic.file_id).path,
|
report.files.get(diagnostic.file_id).path,
|
||||||
PathBuf::from("testdata/empty_inherit.nix"),
|
PathBuf::from("empty_inherit.nix"),
|
||||||
);
|
);
|
||||||
assert_eq!(diagnostic.finding.rule_id, "empty_inherit");
|
assert_eq!(diagnostic.finding.rule_id, "empty_inherit");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user