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:
@@ -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<()> {
|
||||
|
||||
Reference in New Issue
Block a user