diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-20 00:55:55 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-24 01:15:58 +0200 |
commit | 935f82267a84a69a7aa66b2b849fc57f15d24685 (patch) | |
tree | fb959e309ea2efbeaae0deded56a4ec0b2ed01b6 /pkgs/test | |
parent | e7d9cc96ed0f8edeb52a2dbeefdcf00e4aedf8ee (diff) |
tests.nixpkgs-check-by-name: Intermediate CaseSensitiveDuplicate error
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 | 33 |
2 files changed, 33 insertions, 12 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 ff90ea7c50921..2bceadbf807ce 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/check_result.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/check_result.rs @@ -2,11 +2,17 @@ use crate::utils::PACKAGE_NIX_FILENAME; use crate::ErrorWriter; use itertools::{Either, Itertools}; use rnix::parser::ParseError; +use std::ffi::OsString; use std::fmt; use std::io; use std::path::PathBuf; pub enum CheckError { + CaseSensitiveDuplicate { + relative_shard_path: PathBuf, + first: OsString, + second: OsString, + }, InvalidPackageName { relative_package_dir: PathBuf, package_name: String, @@ -83,6 +89,12 @@ impl CheckError { impl fmt::Display for CheckError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { + CheckError::CaseSensitiveDuplicate { relative_shard_path, first, second } => + write!( + f, + "{}: Duplicate case-sensitive package directories {first:?} and {second:?}.", + relative_shard_path.display(), + ), CheckError::InvalidPackageName { relative_package_dir, package_name } => 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 e2d03d83a53fd..f64f80d381aa3 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/structure.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/structure.rs @@ -3,7 +3,6 @@ use crate::utils; use crate::utils::{ErrorWriter, BASE_SUBPATH, PACKAGE_NIX_FILENAME}; use lazy_static::lazy_static; use regex::Regex; -use std::collections::HashMap; use std::io; use std::path::{Path, PathBuf}; @@ -79,9 +78,28 @@ impl Nixpkgs { ))?; } - let mut unique_package_names = HashMap::new(); + let entries = utils::read_dir_sorted(&shard_path)?; + + let duplicate_check_results = entries + .iter() + .zip(entries.iter().skip(1)) + .filter(|(l, r)| { + l.file_name().to_ascii_lowercase() == r.file_name().to_ascii_lowercase() + }) + .map(|(l, r)| { + CheckError::CaseSensitiveDuplicate { + relative_shard_path: relative_shard_path.clone(), + first: l.file_name(), + second: r.file_name(), + } + .into_result::<()>() + }); + + let duplicate_check_result = flatten_check_results(duplicate_check_results, |_| ()); - for package_entry in utils::read_dir_sorted(&shard_path)? { + write_check_result(error_writer, duplicate_check_result)?; + + for package_entry in entries { let package_path = package_entry.path(); let package_name = package_entry.file_name().to_string_lossy().into_owned(); let relative_package_dir = @@ -95,15 +113,6 @@ impl Nixpkgs { continue; } - if let Some(duplicate_package_name) = - unique_package_names.insert(package_name.to_lowercase(), package_name.clone()) - { - error_writer.write(&format!( - "{}: Duplicate case-sensitive package directories \"{duplicate_package_name}\" and \"{package_name}\".", - relative_shard_path.display(), - ))?; - } - let package_name_valid = PACKAGE_NAME_REGEX.is_match(&package_name); let name_check_result = if !package_name_valid { CheckError::InvalidPackageName { |