test(xatu): keep multiline fixtures in testdata

This commit is contained in:
2026-09-19 11:02:12 -04:00
parent 7b5559595e
commit 22e8c896c0
4 changed files with 35 additions and 16 deletions

View File

@@ -28,6 +28,10 @@ rust_test(
rust_test(
name = "xatu_test",
srcs = ["xatu_test.rs"],
data = [
"testdata/clean.nix",
"testdata/empty_inherit.nix",
],
deps = [
":xatu_lib",
"//src/status:status",

4
src/xatu/testdata/clean.nix vendored Normal file
View File

@@ -0,0 +1,4 @@
{
path = ./. + "/foo";
inherit foo;
}

3
src/xatu/testdata/empty_inherit.nix vendored Normal file
View File

@@ -0,0 +1,3 @@
{
inherit;
}

View File

@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use status::Code;
use xatu::SourceFile;
@@ -10,17 +10,28 @@ fn source_file(path: &str, source: &str) -> SourceFile {
}
}
fn testdata_source_file(path: &str) -> SourceFile {
source_file(
path,
&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(
"clean.nix",
r#"{
path = ./. + "/foo";
inherit foo;
}
"#,
)])
.expect("fixture should parse");
let report = xatu::future_sight(vec![testdata_source_file("testdata/clean.nix")])
.expect("fixture should parse");
assert!(report.is_clean());
}
@@ -71,18 +82,15 @@ fn future_sight_reports_deprecated_to_path_select_findings() {
#[test]
fn future_sight_reports_empty_inherit_findings() {
let report = xatu::future_sight(vec![source_file(
"empty_inherit.nix",
"{\n inherit;\n}\n",
)])
.expect("fixture should parse");
let report = xatu::future_sight(vec![testdata_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("empty_inherit.nix"),
PathBuf::from("testdata/empty_inherit.nix"),
);
assert_eq!(diagnostic.finding.rule_id, "empty_inherit");
}