tests.nixpkgs-check-by-name: Intermediate ShardNonDir error

This commit is contained in:
Silvan Mosberger 2023-10-20 01:25:05 +02:00
parent b7ace0198c
commit 571eaed155
2 changed files with 101 additions and 92 deletions

View file

@ -8,6 +8,9 @@ use std::io;
use std::path::PathBuf;
pub enum CheckError {
ShardNonDir {
relative_shard_path: PathBuf,
},
InvalidShardName {
relative_shard_path: PathBuf,
shard_name: String,
@ -96,6 +99,12 @@ impl CheckError {
impl fmt::Display for CheckError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CheckError::ShardNonDir { relative_shard_path } =>
write!(
f,
"{}: This is a file, but it should be a directory.",
relative_shard_path.display(),
),
CheckError::InvalidShardName { relative_shard_path, shard_name } =>
write!(
f,

View file

@ -61,15 +61,13 @@ impl Nixpkgs {
continue;
}
if !shard_path.is_dir() {
error_writer.write(&format!(
"{}: This is a file, but it should be a directory.",
relative_shard_path.display(),
))?;
// we can't check for any other errors if it's a file, since there's no subdirectories to check
continue;
let check_result = if !shard_path.is_dir() {
CheckError::ShardNonDir {
relative_shard_path: relative_shard_path.clone(),
}
.into_result()
// 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 {
CheckError::InvalidShardName {
@ -129,14 +127,15 @@ impl Nixpkgs {
let correct_relative_package_dir =
Nixpkgs::relative_dir_for_package(&package_name);
let shard_check_result = if relative_package_dir != correct_relative_package_dir
{
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(),
correct_relative_package_dir: correct_relative_package_dir
.clone(),
}
.into_result()
} else {
@ -172,7 +171,8 @@ impl Nixpkgs {
}
});
let check_result = flatten_check_results(check_results, |x| x);
flatten_check_results(check_results, |x| x)
};
if let Some(shard_package_names) = write_check_result(error_writer, check_result)? {
package_names.extend(shard_package_names)