tests.nixpkgs-check-by-name: Introduce result_map

Convenience function to run another validation over a successful validation result.

This will be usable in more locations in future commits, making the code
nicer.
This commit is contained in:
Silvan Mosberger 2023-12-14 03:03:04 +01:00
parent b8e4d555b4
commit e98d22851b
2 changed files with 11 additions and 7 deletions

View file

@ -86,14 +86,9 @@ pub fn check_nixpkgs<W: io::Write>(
);
Success(())
} else {
match check_structure(&nixpkgs_path)? {
Failure(errors) => Failure(errors),
Success(package_names) =>
check_structure(&nixpkgs_path)?.result_map(|package_names|
// Only if we could successfully parse the structure, we do the evaluation checks
{
eval::check_values(version, &nixpkgs_path, package_names, eval_accessible_paths)?
}
}
eval::check_values(version, &nixpkgs_path, package_names, eval_accessible_paths))?
};
match check_result {

View file

@ -58,6 +58,15 @@ impl<A> Validation<A> {
Success(value) => Success(f(value)),
}
}
/// Map a `Validation<A>` to a `Result<B>` by applying a function `A -> Result<B>`
/// only if there is a `Success` value
pub fn result_map<B>(self, f: impl FnOnce(A) -> Result<B>) -> Result<B> {
match self {
Failure(err) => Ok(Failure(err)),
Success(value) => f(value),
}
}
}
impl Validation<()> {