diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-20 01:15:18 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-24 01:15:58 +0200 |
commit | b7ace0198cfc971a887358bdc8871c6f5c31cfb4 (patch) | |
tree | 2fa5ee744cbee3be48fdf0d3cdacff653c2c6a67 /pkgs/test | |
parent | 143e267ad24e7872ed8adede446d2a9f95e4c409 (diff) |
tests.nixpkgs-check-by-name: Intermediate InvalidShardName error
Diffstat (limited to 'pkgs/test')
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/check_result.rs | 10 | ||||
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/structure.rs | 37 |
2 files changed, 31 insertions, 16 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 28d48fb597833..ad3d949dcb49d 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/check_result.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/check_result.rs @@ -8,6 +8,10 @@ use std::io; use std::path::PathBuf; pub enum CheckError { + InvalidShardName { + relative_shard_path: PathBuf, + shard_name: String, + }, PackageNonDir { relative_package_dir: PathBuf, }, @@ -92,6 +96,12 @@ impl CheckError { impl fmt::Display for CheckError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { + CheckError::InvalidShardName { relative_shard_path, shard_name } => + write!( + f, + "{}: Invalid directory name \"{shard_name}\", must be at most 2 ASCII characters consisting of a-z, 0-9, \"-\" or \"_\".", + relative_shard_path.display() + ), CheckError::PackageNonDir { relative_package_dir } => write!( f, diff --git a/pkgs/test/nixpkgs-check-by-name/src/structure.rs b/pkgs/test/nixpkgs-check-by-name/src/structure.rs index e50f2113e6335..fed70c97b090f 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/structure.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/structure.rs @@ -71,12 +71,17 @@ impl Nixpkgs { } let shard_name_valid = SHARD_NAME_REGEX.is_match(&shard_name); - if !shard_name_valid { - error_writer.write(&format!( - "{}: Invalid directory name \"{shard_name}\", must be at most 2 ASCII characters consisting of a-z, 0-9, \"-\" or \"_\".", - relative_shard_path.display() - ))?; - } + let shard_name_valid_check_result = if !shard_name_valid { + CheckError::InvalidShardName { + relative_shard_path: relative_shard_path.clone(), + shard_name: shard_name.clone(), + } + .into_result() + } else { + pass(()) + }; + + write_check_result(error_writer, shard_name_valid_check_result)?; let entries = utils::read_dir_sorted(&shard_path)?; @@ -99,13 +104,13 @@ impl Nixpkgs { write_check_result(error_writer, duplicate_check_result)?; - for package_entry in entries { + let check_results = entries.into_iter().map(|package_entry| { let package_path = package_entry.path(); let package_name = package_entry.file_name().to_string_lossy().into_owned(); let relative_package_dir = PathBuf::from(format!("{BASE_SUBPATH}/{shard_name}/{package_name}")); - let check_result = if !package_path.is_dir() { + if !package_path.is_dir() { CheckError::PackageNonDir { relative_package_dir: relative_package_dir.clone(), } @@ -156,21 +161,21 @@ impl Nixpkgs { pass(()) }; - let check_result = flatten_check_results( + flatten_check_results( [ name_check_result, shard_check_result, package_nix_check_result, ], - |_| (), - ); - - package_names.push(package_name.clone()); + |_| package_name.clone(), + ) + } + }); - check_result - }; + let check_result = flatten_check_results(check_results, |x| x); - write_check_result(error_writer, check_result)?; + if let Some(shard_package_names) = write_check_result(error_writer, check_result)? { + package_names.extend(shard_package_names) } } |