tests.nixpkgs-check-by-name: Minor refactor, allow more simultaneous problems

This makes it such that these two errors can both be thrown for a single
package:
- The attribute value not being a derivation
- The attribute not being a proper callPackage

The tests had to be adjusted to only throw the error they were testing
for
This commit is contained in:
Silvan Mosberger 2023-12-14 02:07:50 +01:00
parent 6a937597be
commit b8e4d555b4
3 changed files with 26 additions and 20 deletions

View File

@ -116,8 +116,18 @@ pub fn check_values(
let absolute_package_file = nixpkgs_path.join(&relative_package_file);
if let Some(attribute_info) = actual_files.get(package_name) {
let valid = match &attribute_info.variant {
AttributeVariant::AutoCalled => true,
let check_result = if !attribute_info.is_derivation {
NixpkgsProblem::NonDerivation {
relative_package_file: relative_package_file.clone(),
package_name: package_name.clone(),
}
.into()
} else {
Success(())
};
check_result.and(match &attribute_info.variant {
AttributeVariant::AutoCalled => Success(()),
AttributeVariant::CallPackage { path, empty_arg } => {
let correct_file = if let Some(call_package_path) = path {
absolute_package_file == *call_package_path
@ -131,26 +141,22 @@ pub fn check_values(
} else {
true
};
correct_file && non_empty
if correct_file && non_empty {
Success(())
} else {
NixpkgsProblem::WrongCallPackage {
relative_package_file: relative_package_file.clone(),
package_name: package_name.clone(),
}
.into()
}
}
AttributeVariant::Other => false,
};
if !valid {
NixpkgsProblem::WrongCallPackage {
AttributeVariant::Other => NixpkgsProblem::WrongCallPackage {
relative_package_file: relative_package_file.clone(),
package_name: package_name.clone(),
}
.into()
} else if !attribute_info.is_derivation {
NixpkgsProblem::NonDerivation {
relative_package_file: relative_package_file.clone(),
package_name: package_name.clone(),
}
.into()
} else {
Success(())
}
.into(),
})
} else {
NixpkgsProblem::UndefinedAttr {
relative_package_file: relative_package_file.clone(),

View File

@ -1,3 +1,3 @@
self: super: {
nonDerivation = null;
nonDerivation = self.someDrv;
}

View File

@ -1,3 +1,3 @@
self: super: {
nonDerivation = self.callPackage ({ }: { }) { };
nonDerivation = self.callPackage ({ someDrv }: someDrv) { };
}