From 4f17b9367d7535fc5308557b92e1b306662b3d3d Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 19 Oct 2023 23:48:31 +0200 Subject: [PATCH] tests.nixpkgs-check-by-name: Intermediate UndefinedAttr error --- .../nixpkgs-check-by-name/src/check_result.rs | 10 ++++++++++ pkgs/test/nixpkgs-check-by-name/src/eval.rs | 20 +++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pkgs/test/nixpkgs-check-by-name/src/check_result.rs b/pkgs/test/nixpkgs-check-by-name/src/check_result.rs index 6b1d120de8fa..f546b1285450 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/check_result.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/check_result.rs @@ -6,6 +6,10 @@ use std::io; use std::path::PathBuf; pub enum CheckError { + UndefinedAttr { + relative_package_file: PathBuf, + package_name: String, + }, WrongCallPackage { relative_package_file: PathBuf, package_name: String, @@ -64,6 +68,12 @@ impl CheckError { impl fmt::Display for CheckError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { + CheckError::UndefinedAttr { relative_package_file, package_name } => + write!( + f, + "pkgs.{package_name}: This attribute is not defined but it should be defined automatically as {}", + relative_package_file.display() + ), CheckError::WrongCallPackage { relative_package_file, package_name } => write!( f, diff --git a/pkgs/test/nixpkgs-check-by-name/src/eval.rs b/pkgs/test/nixpkgs-check-by-name/src/eval.rs index d1c5135b7d85..81cf43a381ed 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/eval.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/eval.rs @@ -116,7 +116,7 @@ pub fn check_values( let relative_package_file = structure::Nixpkgs::relative_file_for_package(package_name); let absolute_package_file = nixpkgs.path.join(&relative_package_file); - if let Some(attribute_info) = actual_files.get(package_name) { + let check_result = if let Some(attribute_info) = actual_files.get(package_name) { let valid = match &attribute_info.variant { AttributeVariant::AutoCalled => true, AttributeVariant::CallPackage { path, empty_arg } => { @@ -137,7 +137,7 @@ pub fn check_values( AttributeVariant::Other => false, }; - let check_result = if !valid { + if !valid { CheckError::WrongCallPackage { relative_package_file: relative_package_file.clone(), package_name: package_name.clone(), @@ -151,15 +151,15 @@ pub fn check_values( .into_result() } else { pass(()) - }; - write_check_result(error_writer, check_result)?; + } } else { - error_writer.write(&format!( - "pkgs.{package_name}: This attribute is not defined but it should be defined automatically as {}", - relative_package_file.display() - ))?; - continue; - } + CheckError::UndefinedAttr { + relative_package_file: relative_package_file.clone(), + package_name: package_name.clone(), + } + .into_result() + }; + write_check_result(error_writer, check_result)?; } Ok(()) }