mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-31 17:23:34 +00:00
tests.nixpkgs-check-by-name: Deterministic ordering
Makes errors for attributes deterministic so it's easier to test (also, reproducibility is always nice)
This commit is contained in:
parent
2a8f469348
commit
27c873af99
@ -76,14 +76,15 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
attrInfos = builtins.listToAttrs (map (name: {
|
||||
inherit name;
|
||||
value =
|
||||
attrInfos = map (name: [
|
||||
name
|
||||
(
|
||||
if ! pkgs ? ${name} then
|
||||
{ Missing = null; }
|
||||
else
|
||||
{ Existing = attrInfo name pkgs.${name}; };
|
||||
}) attrs);
|
||||
{ Existing = attrInfo name pkgs.${name}; }
|
||||
)
|
||||
]) attrs;
|
||||
|
||||
in
|
||||
attrInfos
|
||||
|
@ -6,7 +6,6 @@ use std::path::Path;
|
||||
|
||||
use anyhow::Context;
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
use tempfile::NamedTempFile;
|
||||
@ -119,7 +118,7 @@ pub fn check_values(
|
||||
anyhow::bail!("Failed to run command {command:?}");
|
||||
}
|
||||
// Parse the resulting JSON value
|
||||
let attributes: HashMap<String, ByNameAttribute> = serde_json::from_slice(&result.stdout)
|
||||
let attributes: Vec<(String, ByNameAttribute)> = serde_json::from_slice(&result.stdout)
|
||||
.context(format!(
|
||||
"Failed to deserialise {}",
|
||||
String::from_utf8_lossy(&result.stdout)
|
||||
@ -201,6 +200,7 @@ pub fn check_values(
|
||||
));
|
||||
|
||||
Ok(check_result.map(|elems| ratchet::Nixpkgs {
|
||||
packages: elems.into_iter().collect(),
|
||||
package_names,
|
||||
package_map: elems.into_iter().collect(),
|
||||
}))
|
||||
}
|
||||
|
@ -10,8 +10,10 @@ use std::collections::HashMap;
|
||||
/// The ratchet value for the entirety of Nixpkgs.
|
||||
#[derive(Default)]
|
||||
pub struct Nixpkgs {
|
||||
/// The ratchet values for each package in `pkgs/by-name`
|
||||
pub packages: HashMap<String, Package>,
|
||||
/// Sorted list of attributes in package_map
|
||||
pub package_names: Vec<String>,
|
||||
/// The ratchet values for all packages
|
||||
pub package_map: HashMap<String, Package>,
|
||||
}
|
||||
|
||||
impl Nixpkgs {
|
||||
@ -20,9 +22,9 @@ impl Nixpkgs {
|
||||
validation::sequence_(
|
||||
// We only loop over the current attributes,
|
||||
// we don't need to check ones that were removed
|
||||
to.packages
|
||||
.into_iter()
|
||||
.map(|(name, attr_to)| Package::compare(&name, from.packages.get(&name), &attr_to)),
|
||||
to.package_names.into_iter().map(|name| {
|
||||
Package::compare(&name, from.package_map.get(&name), &to.package_map[&name])
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user