diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-12-14 03:03:04 +0100 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-12-14 03:21:41 +0100 |
commit | e98d22851b67a6125683f80735e4bc1042252aef (patch) | |
tree | 84710686b65dfa0f1c3a02198ce0dfc776a89a17 /pkgs/test | |
parent | b8e4d555b4936adf93510c9e333798eecf32b5e7 (diff) |
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.
Diffstat (limited to 'pkgs/test')
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/main.rs | 9 | ||||
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/validation.rs | 9 |
2 files changed, 11 insertions, 7 deletions
diff --git a/pkgs/test/nixpkgs-check-by-name/src/main.rs b/pkgs/test/nixpkgs-check-by-name/src/main.rs index 4cabf8f446f56..567da00333e6c 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/main.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/main.rs @@ -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 { diff --git a/pkgs/test/nixpkgs-check-by-name/src/validation.rs b/pkgs/test/nixpkgs-check-by-name/src/validation.rs index e727938515218..b14bfb92eb2e3 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/validation.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/validation.rs @@ -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<()> { |