tests.nixpkgs-check-by-name: Support for combining check results

This commit is contained in:
Silvan Mosberger 2023-10-20 01:54:03 +02:00
parent bb89ca72df
commit 83b887504c
2 changed files with 24 additions and 9 deletions

View File

@ -1,5 +1,6 @@
use crate::utils::PACKAGE_NIX_FILENAME;
use crate::ErrorWriter;
use itertools::concat;
use itertools::{Either, Itertools};
use rnix::parser::ParseError;
use std::ffi::OsString;
@ -245,6 +246,17 @@ pub fn pass<A>(value: A) -> CheckResult<A> {
pub type CheckResult<A> = anyhow::Result<Either<Vec<CheckError>, A>>;
pub fn sequence_check_results<A>(first: CheckResult<()>, second: CheckResult<A>) -> CheckResult<A> {
match (first?, second?) {
(Either::Right(_), Either::Right(right_value)) => pass(right_value),
(Either::Left(errors), Either::Right(_)) => Ok(Either::Left(errors)),
(Either::Right(_), Either::Left(errors)) => Ok(Either::Left(errors)),
(Either::Left(errors_l), Either::Left(errors_r)) => {
Ok(Either::Left(concat([errors_l, errors_r])))
}
}
}
pub fn flatten_check_results<I, O>(
check_results: impl IntoIterator<Item = CheckResult<I>>,
value_transform: impl Fn(Vec<I>) -> O,

View File

@ -1,4 +1,6 @@
use crate::check_result::{flatten_check_results, pass, write_check_result, CheckError};
use crate::check_result::{
flatten_check_results, pass, sequence_check_results, write_check_result, CheckError,
};
use crate::utils;
use crate::utils::{ErrorWriter, BASE_SUBPATH, PACKAGE_NIX_FILENAME};
use lazy_static::lazy_static;
@ -67,7 +69,7 @@ impl Nixpkgs {
// we can't check for any other errors if it's a file, since there's no subdirectories to check
} else {
let shard_name_valid = SHARD_NAME_REGEX.is_match(&shard_name);
let shard_name_valid_check_result = if !shard_name_valid {
let check_result = if !shard_name_valid {
CheckError::InvalidShardName {
relative_shard_path: relative_shard_path.clone(),
shard_name: shard_name.clone(),
@ -77,8 +79,6 @@ impl Nixpkgs {
pass(())
};
write_check_result(error_writer, shard_name_valid_check_result)?;
let entries = utils::read_dir_sorted(&shard_path)?;
let duplicate_check_results = entries
@ -96,10 +96,10 @@ impl Nixpkgs {
.into_result::<()>()
});
let duplicate_check_result =
flatten_check_results(duplicate_check_results, |_| ());
write_check_result(error_writer, duplicate_check_result)?;
let check_result = sequence_check_results(
check_result,
flatten_check_results(duplicate_check_results, |_| ()),
);
let check_results = entries.into_iter().map(|package_entry| {
let package_path = package_entry.path();
@ -170,7 +170,10 @@ impl Nixpkgs {
}
});
flatten_check_results(check_results, |x| x)
sequence_check_results(
check_result,
flatten_check_results(check_results, |x| x),
)
}
});