diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-20 01:03:48 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-24 01:15:58 +0200 |
commit | 143e267ad24e7872ed8adede446d2a9f95e4c409 (patch) | |
tree | bd5c39bc378c4c6af99d151254ac359fba0f11c7 /pkgs/test | |
parent | 935f82267a84a69a7aa66b2b849fc57f15d24685 (diff) |
tests.nixpkgs-check-by-name: Intermediate PackageNonDir error
Diffstat (limited to 'pkgs/test')
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/check_result.rs | 9 | ||||
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/structure.rs | 101 |
2 files changed, 61 insertions, 49 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 2bceadbf807ce..28d48fb597833 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,9 @@ use std::io; use std::path::PathBuf; pub enum CheckError { + PackageNonDir { + relative_package_dir: PathBuf, + }, CaseSensitiveDuplicate { relative_shard_path: PathBuf, first: OsString, @@ -89,6 +92,12 @@ impl CheckError { impl fmt::Display for CheckError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { + CheckError::PackageNonDir { relative_package_dir } => + write!( + f, + "{}: This path is a file, but it should be a directory.", + relative_package_dir.display(), + ), CheckError::CaseSensitiveDuplicate { relative_shard_path, first, second } => 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 f64f80d381aa3..e50f2113e6335 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/structure.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/structure.rs @@ -105,69 +105,72 @@ impl Nixpkgs { let relative_package_dir = PathBuf::from(format!("{BASE_SUBPATH}/{shard_name}/{package_name}")); - if !package_path.is_dir() { - error_writer.write(&format!( - "{}: This path is a file, but it should be a directory.", - relative_package_dir.display(), - ))?; - continue; - } - - let package_name_valid = PACKAGE_NAME_REGEX.is_match(&package_name); - let name_check_result = if !package_name_valid { - CheckError::InvalidPackageName { + let check_result = if !package_path.is_dir() { + CheckError::PackageNonDir { relative_package_dir: relative_package_dir.clone(), - package_name: package_name.clone(), } .into_result() } else { - pass(()) - }; + let package_name_valid = PACKAGE_NAME_REGEX.is_match(&package_name); + let name_check_result = if !package_name_valid { + CheckError::InvalidPackageName { + relative_package_dir: relative_package_dir.clone(), + package_name: package_name.clone(), + } + .into_result() + } else { + pass(()) + }; + + let correct_relative_package_dir = + Nixpkgs::relative_dir_for_package(&package_name); + let shard_check_result = if relative_package_dir != correct_relative_package_dir + { + // Only show this error if we have a valid shard and package name + // Because if one of those is wrong, you should fix that first + if shard_name_valid && package_name_valid { + CheckError::IncorrectShard { + relative_package_dir: relative_package_dir.clone(), + correct_relative_package_dir: correct_relative_package_dir.clone(), + } + .into_result() + } else { + pass(()) + } + } else { + pass(()) + }; - let correct_relative_package_dir = Nixpkgs::relative_dir_for_package(&package_name); - let shard_check_result = if relative_package_dir != correct_relative_package_dir { - // Only show this error if we have a valid shard and package name - // Because if one of those is wrong, you should fix that first - if shard_name_valid && package_name_valid { - CheckError::IncorrectShard { + let package_nix_path = package_path.join(PACKAGE_NIX_FILENAME); + let package_nix_check_result = if !package_nix_path.exists() { + CheckError::PackageNixNonExistent { + relative_package_dir: relative_package_dir.clone(), + } + .into_result() + } else if package_nix_path.is_dir() { + CheckError::PackageNixDir { relative_package_dir: relative_package_dir.clone(), - correct_relative_package_dir: correct_relative_package_dir.clone(), } .into_result() } else { pass(()) - } - } else { - pass(()) - }; + }; - let package_nix_path = package_path.join(PACKAGE_NIX_FILENAME); - let package_nix_check_result = if !package_nix_path.exists() { - CheckError::PackageNixNonExistent { - relative_package_dir: relative_package_dir.clone(), - } - .into_result() - } else if package_nix_path.is_dir() { - CheckError::PackageNixDir { - relative_package_dir: relative_package_dir.clone(), - } - .into_result() - } else { - pass(()) - }; + let check_result = flatten_check_results( + [ + name_check_result, + shard_check_result, + package_nix_check_result, + ], + |_| (), + ); - let check_result = flatten_check_results( - [ - name_check_result, - shard_check_result, - package_nix_check_result, - ], - |_| (), - ); + package_names.push(package_name.clone()); - write_check_result(error_writer, check_result)?; + check_result + }; - package_names.push(package_name.clone()); + write_check_result(error_writer, check_result)?; } } |