From 27c873af995394445eef05eaa1b95997f57e868a Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 5 Jan 2024 00:50:41 +0100 Subject: [PATCH] tests.nixpkgs-check-by-name: Deterministic ordering Makes errors for attributes deterministic so it's easier to test (also, reproducibility is always nice) --- pkgs/test/nixpkgs-check-by-name/src/eval.nix | 11 ++++++----- pkgs/test/nixpkgs-check-by-name/src/eval.rs | 6 +++--- pkgs/test/nixpkgs-check-by-name/src/ratchet.rs | 12 +++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pkgs/test/nixpkgs-check-by-name/src/eval.nix b/pkgs/test/nixpkgs-check-by-name/src/eval.nix index e75a28ddbdf7..b605a35a322a 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/eval.nix +++ b/pkgs/test/nixpkgs-check-by-name/src/eval.nix @@ -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 diff --git a/pkgs/test/nixpkgs-check-by-name/src/eval.rs b/pkgs/test/nixpkgs-check-by-name/src/eval.rs index 00bdc0bc9f39..4004841c9430 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/eval.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/eval.rs @@ -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 = 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(), })) } diff --git a/pkgs/test/nixpkgs-check-by-name/src/ratchet.rs b/pkgs/test/nixpkgs-check-by-name/src/ratchet.rs index c363f85466e9..ae0c29cb6f35 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/ratchet.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/ratchet.rs @@ -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, + /// Sorted list of attributes in package_map + pub package_names: Vec, + /// The ratchet values for all packages + pub package_map: HashMap, } 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]) + }), ) } }