test(xatu): simplify googletest result handling
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use googletest::matchers::{anything, contains, eq, err, is_true, ok};
|
use googletest::matchers::{contains, eq, is_true};
|
||||||
use googletest::{assert_that, expect_that, gtest};
|
use googletest::{OrFail, Result as TestResult, expect_that, gtest};
|
||||||
use status::Code;
|
use status::Code;
|
||||||
use xatu::SourceFile;
|
use xatu::SourceFile;
|
||||||
|
|
||||||
@@ -24,29 +24,26 @@ fn fixture_path(path: &str) -> PathBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[gtest]
|
#[gtest]
|
||||||
fn future_sight_reports_clean_sources_as_clean() {
|
fn future_sight_reports_clean_sources_as_clean() -> TestResult<()> {
|
||||||
let result = xatu::future_sight(vec![fixture_source("testdata/clean.nix")]);
|
let report = xatu::future_sight(vec![fixture_source("testdata/clean.nix")]).or_fail()?;
|
||||||
assert_that!(result.as_ref(), ok(anything()));
|
|
||||||
let report = result.unwrap();
|
|
||||||
|
|
||||||
expect_that!(report.is_clean(), is_true());
|
expect_that!(report.is_clean(), is_true());
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gtest]
|
#[gtest]
|
||||||
fn future_sight_rejects_parse_errors() {
|
fn future_sight_rejects_parse_errors() -> TestResult<()> {
|
||||||
let result = xatu::future_sight(vec![fixture_source("testdata/invalid.nix")]);
|
let error = xatu::future_sight(vec![fixture_source("testdata/invalid.nix")])
|
||||||
|
.err()
|
||||||
|
.or_fail()?;
|
||||||
|
|
||||||
expect_that!(result.as_ref(), err(anything()));
|
expect_that!(error.code(), eq(Code::FailedPrecondition));
|
||||||
if let Err(error) = result {
|
Ok(())
|
||||||
expect_that!(error.code(), eq(Code::FailedPrecondition));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gtest]
|
#[gtest]
|
||||||
fn future_sight_reports_deprecated_to_path_qualified_findings() {
|
fn future_sight_reports_deprecated_to_path_qualified_findings() -> TestResult<()> {
|
||||||
let result = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")]);
|
let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")]).or_fail()?;
|
||||||
assert_that!(result.as_ref(), ok(anything()));
|
|
||||||
let report = result.unwrap();
|
|
||||||
|
|
||||||
let findings = report
|
let findings = report
|
||||||
.diagnostics
|
.diagnostics
|
||||||
@@ -65,13 +62,12 @@ fn future_sight_reports_deprecated_to_path_qualified_findings() {
|
|||||||
"deprecated_to_path"
|
"deprecated_to_path"
|
||||||
)))
|
)))
|
||||||
);
|
);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gtest]
|
#[gtest]
|
||||||
fn future_sight_reports_deprecated_to_path_unqualified_findings() {
|
fn future_sight_reports_deprecated_to_path_unqualified_findings() -> TestResult<()> {
|
||||||
let result = xatu::future_sight(vec![fixture_source("testdata/lint_variants.nix")]);
|
let report = xatu::future_sight(vec![fixture_source("testdata/lint_variants.nix")]).or_fail()?;
|
||||||
assert_that!(result.as_ref(), ok(anything()));
|
|
||||||
let report = result.unwrap();
|
|
||||||
|
|
||||||
let findings = report
|
let findings = report
|
||||||
.diagnostics
|
.diagnostics
|
||||||
@@ -90,13 +86,12 @@ fn future_sight_reports_deprecated_to_path_unqualified_findings() {
|
|||||||
"deprecated_to_path"
|
"deprecated_to_path"
|
||||||
)))
|
)))
|
||||||
);
|
);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gtest]
|
#[gtest]
|
||||||
fn future_sight_reports_empty_inherit_findings() {
|
fn future_sight_reports_empty_inherit_findings() -> TestResult<()> {
|
||||||
let result = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")]);
|
let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")]).or_fail()?;
|
||||||
assert_that!(result.as_ref(), ok(anything()));
|
|
||||||
let report = result.unwrap();
|
|
||||||
|
|
||||||
let findings = report
|
let findings = report
|
||||||
.diagnostics
|
.diagnostics
|
||||||
@@ -115,4 +110,5 @@ fn future_sight_reports_empty_inherit_findings() {
|
|||||||
"empty_inherit"
|
"empty_inherit"
|
||||||
)))
|
)))
|
||||||
);
|
);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user