diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-20 01:54:03 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-24 01:18:09 +0200 |
commit | 83b887504c9a4aaa4e25f89bbf3dc19074fba29e (patch) | |
tree | 4fef6755569d70906b73dcfabd07ed994925efb8 /pkgs/test | |
parent | bb89ca72dfd79d88f7e3de2460c96a0255ebac11 (diff) | |
download | nixpkgs-83b887504c9a4aaa4e25f89bbf3dc19074fba29e.tar nixpkgs-83b887504c9a4aaa4e25f89bbf3dc19074fba29e.tar.gz nixpkgs-83b887504c9a4aaa4e25f89bbf3dc19074fba29e.tar.bz2 nixpkgs-83b887504c9a4aaa4e25f89bbf3dc19074fba29e.tar.lz nixpkgs-83b887504c9a4aaa4e25f89bbf3dc19074fba29e.tar.xz nixpkgs-83b887504c9a4aaa4e25f89bbf3dc19074fba29e.tar.zst nixpkgs-83b887504c9a4aaa4e25f89bbf3dc19074fba29e.zip |
tests.nixpkgs-check-by-name: Support for combining check results
Diffstat (limited to 'pkgs/test')
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/check_result.rs | 12 | ||||
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/structure.rs | 21 |
2 files changed, 24 insertions, 9 deletions
diff --git a/pkgs/test/nixpkgs-check-by-name/src/check_result.rs b/pkgs/test/nixpkgs-check-by-name/src/check_result.rs index b970c7d6306..818ba1a9afd 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/check_result.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/check_result.rs @@ -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, diff --git a/pkgs/test/nixpkgs-check-by-name/src/structure.rs b/pkgs/test/nixpkgs-check-by-name/src/structure.rs index 2f225ecd2ec..d1655dc2e3f 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/structure.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/structure.rs @@ -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), + ) } }); |