mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-17 19:21:04 +00:00
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:
parent
b8e4d555b4
commit
e98d22851b
|
@ -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 {
|
||||
|
|
|
@ -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<()> {
|
||||
|
|
Loading…
Reference in a new issue