From 1af843da11506a8acad964b61a6e81d8f014781e Mon Sep 17 00:00:00 2001 From: alexion Date: Sat, 19 Sep 2026 15:06:49 -0400 Subject: [PATCH] test(xatu): return fixture load failures --- src/xatu/xatu_test.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/xatu/xatu_test.rs b/src/xatu/xatu_test.rs index d718826..01fe746 100644 --- a/src/xatu/xatu_test.rs +++ b/src/xatu/xatu_test.rs @@ -5,27 +5,27 @@ use googletest::{OrFail, expect_that, gtest}; use status::Code; use xatu::SourceFile; -fn fixture_source(path: &str) -> SourceFile { - SourceFile { +fn fixture_source(path: &str) -> googletest::Result { + Ok(SourceFile { path: PathBuf::from(path), - source: std::fs::read_to_string(fixture_path(path)).expect("fixture should be readable"), - } + source: std::fs::read_to_string(fixture_path(path)?).or_fail()?, + }) } -fn fixture_path(path: &str) -> PathBuf { +fn fixture_path(path: &str) -> googletest::Result { if Path::new(path).exists() { - return PathBuf::from(path); + return Ok(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"); + let runfiles = PathBuf::from(std::env::var("TEST_SRCDIR").or_fail()?); + let workspace = std::env::var("TEST_WORKSPACE").or_fail()?; - runfiles.join(workspace).join("src/xatu").join(path) + Ok(runfiles.join(workspace).join("src/xatu").join(path)) } #[gtest] fn future_sight_reports_clean_sources_as_clean() -> googletest::Result<()> { - let report = xatu::future_sight(vec![fixture_source("testdata/clean.nix")]).or_fail()?; + let report = xatu::future_sight(vec![fixture_source("testdata/clean.nix")?]).or_fail()?; expect_that!(report.is_clean(), is_true()); Ok(()) @@ -33,7 +33,7 @@ fn future_sight_reports_clean_sources_as_clean() -> googletest::Result<()> { #[gtest] fn future_sight_rejects_parse_errors() -> googletest::Result<()> { - let error = xatu::future_sight(vec![fixture_source("testdata/invalid.nix")]) + let error = xatu::future_sight(vec![fixture_source("testdata/invalid.nix")?]) .err() .or_fail()?; @@ -43,7 +43,7 @@ fn future_sight_rejects_parse_errors() -> googletest::Result<()> { #[gtest] fn future_sight_reports_deprecated_to_path_qualified_findings() -> googletest::Result<()> { - let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")]).or_fail()?; + let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")?]).or_fail()?; let findings = report .diagnostics @@ -67,7 +67,7 @@ fn future_sight_reports_deprecated_to_path_qualified_findings() -> googletest::R #[gtest] fn future_sight_reports_deprecated_to_path_unqualified_findings() -> googletest::Result<()> { - let report = xatu::future_sight(vec![fixture_source("testdata/lint_variants.nix")]).or_fail()?; + let report = xatu::future_sight(vec![fixture_source("testdata/lint_variants.nix")?]).or_fail()?; let findings = report .diagnostics @@ -91,7 +91,7 @@ fn future_sight_reports_deprecated_to_path_unqualified_findings() -> googletest: #[gtest] fn future_sight_reports_empty_inherit_findings() -> googletest::Result<()> { - let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")]).or_fail()?; + let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")?]).or_fail()?; let findings = report .diagnostics