test(xatu): return fixture load failures
This commit is contained in:
@@ -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<SourceFile> {
|
||||
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<PathBuf> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user