tests.nixpkgs-check-by-name: Intermediate PackageNonDir error
This commit is contained in:
parent
935f82267a
commit
143e267ad2
@ -8,6 +8,9 @@ use std::io;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub enum CheckError {
|
pub enum CheckError {
|
||||||
|
PackageNonDir {
|
||||||
|
relative_package_dir: PathBuf,
|
||||||
|
},
|
||||||
CaseSensitiveDuplicate {
|
CaseSensitiveDuplicate {
|
||||||
relative_shard_path: PathBuf,
|
relative_shard_path: PathBuf,
|
||||||
first: OsString,
|
first: OsString,
|
||||||
@ -89,6 +92,12 @@ impl CheckError {
|
|||||||
impl fmt::Display for CheckError {
|
impl fmt::Display for CheckError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
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 } =>
|
CheckError::CaseSensitiveDuplicate { relative_shard_path, first, second } =>
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
@ -105,69 +105,72 @@ impl Nixpkgs {
|
|||||||
let relative_package_dir =
|
let relative_package_dir =
|
||||||
PathBuf::from(format!("{BASE_SUBPATH}/{shard_name}/{package_name}"));
|
PathBuf::from(format!("{BASE_SUBPATH}/{shard_name}/{package_name}"));
|
||||||
|
|
||||||
if !package_path.is_dir() {
|
let check_result = if !package_path.is_dir() {
|
||||||
error_writer.write(&format!(
|
CheckError::PackageNonDir {
|
||||||
"{}: 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 {
|
|
||||||
relative_package_dir: relative_package_dir.clone(),
|
relative_package_dir: relative_package_dir.clone(),
|
||||||
package_name: package_name.clone(),
|
|
||||||
}
|
}
|
||||||
.into_result()
|
.into_result()
|
||||||
} else {
|
} else {
|
||||||
pass(())
|
let package_name_valid = PACKAGE_NAME_REGEX.is_match(&package_name);
|
||||||
};
|
let name_check_result = if !package_name_valid {
|
||||||
|
CheckError::InvalidPackageName {
|
||||||
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(),
|
relative_package_dir: relative_package_dir.clone(),
|
||||||
correct_relative_package_dir: correct_relative_package_dir.clone(),
|
package_name: package_name.clone(),
|
||||||
}
|
}
|
||||||
.into_result()
|
.into_result()
|
||||||
} else {
|
} else {
|
||||||
pass(())
|
pass(())
|
||||||
}
|
};
|
||||||
} else {
|
|
||||||
pass(())
|
|
||||||
};
|
|
||||||
|
|
||||||
let package_nix_path = package_path.join(PACKAGE_NIX_FILENAME);
|
let correct_relative_package_dir =
|
||||||
let package_nix_check_result = if !package_nix_path.exists() {
|
Nixpkgs::relative_dir_for_package(&package_name);
|
||||||
CheckError::PackageNixNonExistent {
|
let shard_check_result = if relative_package_dir != correct_relative_package_dir
|
||||||
relative_package_dir: relative_package_dir.clone(),
|
{
|
||||||
}
|
// Only show this error if we have a valid shard and package name
|
||||||
.into_result()
|
// Because if one of those is wrong, you should fix that first
|
||||||
} else if package_nix_path.is_dir() {
|
if shard_name_valid && package_name_valid {
|
||||||
CheckError::PackageNixDir {
|
CheckError::IncorrectShard {
|
||||||
relative_package_dir: relative_package_dir.clone(),
|
relative_package_dir: relative_package_dir.clone(),
|
||||||
}
|
correct_relative_package_dir: correct_relative_package_dir.clone(),
|
||||||
.into_result()
|
}
|
||||||
} else {
|
.into_result()
|
||||||
pass(())
|
} else {
|
||||||
};
|
pass(())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pass(())
|
||||||
|
};
|
||||||
|
|
||||||
let check_result = flatten_check_results(
|
let package_nix_path = package_path.join(PACKAGE_NIX_FILENAME);
|
||||||
[
|
let package_nix_check_result = if !package_nix_path.exists() {
|
||||||
name_check_result,
|
CheckError::PackageNixNonExistent {
|
||||||
shard_check_result,
|
relative_package_dir: relative_package_dir.clone(),
|
||||||
package_nix_check_result,
|
}
|
||||||
],
|
.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,
|
||||||
|
],
|
||||||
|
|_| (),
|
||||||
|
);
|
||||||
|
|
||||||
|
package_names.push(package_name.clone());
|
||||||
|
|
||||||
|
check_result
|
||||||
|
};
|
||||||
|
|
||||||
write_check_result(error_writer, check_result)?;
|
write_check_result(error_writer, check_result)?;
|
||||||
|
|
||||||
package_names.push(package_name.clone());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user