about summary refs log tree commit diff
path: root/pkgs/test
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2024-01-10 19:21:07 +0100
committerSilvan Mosberger <silvan.mosberger@tweag.io>2024-01-10 19:29:27 +0100
commitcbff02834f3c0a1daa3502566fcf19433f9ca214 (patch)
tree94f9488a6ddd842f53d5f9403ef0dbc800bf78b5 /pkgs/test
parent57afdc545bdc9894754c51265ab993da556915e4 (diff)
downloadnixlib-cbff02834f3c0a1daa3502566fcf19433f9ca214.tar
nixlib-cbff02834f3c0a1daa3502566fcf19433f9ca214.tar.gz
nixlib-cbff02834f3c0a1daa3502566fcf19433f9ca214.tar.bz2
nixlib-cbff02834f3c0a1daa3502566fcf19433f9ca214.tar.lz
nixlib-cbff02834f3c0a1daa3502566fcf19433f9ca214.tar.xz
nixlib-cbff02834f3c0a1daa3502566fcf19433f9ca214.tar.zst
nixlib-cbff02834f3c0a1daa3502566fcf19433f9ca214.zip
tests.nixpkgs-check-by-name: Sort the eval validation results
Not that important, but nice.
Also adds a nice test case show-casing the two current ratchet checks at
once.
Diffstat (limited to 'pkgs/test')
-rw-r--r--pkgs/test/nixpkgs-check-by-name/src/eval.nix51
-rw-r--r--pkgs/test/nixpkgs-check-by-name/tests/sorted-order/all-packages.nix6
-rw-r--r--pkgs/test/nixpkgs-check-by-name/tests/sorted-order/default.nix1
-rw-r--r--pkgs/test/nixpkgs-check-by-name/tests/sorted-order/expected4
-rw-r--r--pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/a/a/package.nix1
-rw-r--r--pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/c/c/package.nix1
6 files changed, 40 insertions, 24 deletions
diff --git a/pkgs/test/nixpkgs-check-by-name/src/eval.nix b/pkgs/test/nixpkgs-check-by-name/src/eval.nix
index f13dbd167a00..87c54b6444ee 100644
--- a/pkgs/test/nixpkgs-check-by-name/src/eval.nix
+++ b/pkgs/test/nixpkgs-check-by-name/src/eval.nix
@@ -79,34 +79,37 @@ let
         };
       };
 
-  byNameAttrs = map (name: [
-    name
-    {
-      ByName =
-        if ! pkgs ? ${name} then
-          { Missing = null; }
-        else
-          { Existing = attrInfo name pkgs.${name}; };
-    }
-  ]) attrs;
+  byNameAttrs = builtins.listToAttrs (map (name: {
+    inherit name;
+    value.ByName =
+      if ! pkgs ? ${name} then
+        { Missing = null; }
+      else
+        { Existing = attrInfo name pkgs.${name}; };
+  }) attrs);
 
   # Information on all attributes that exist but are not in pkgs/by-name.
   # We need this to enforce pkgs/by-name for new packages
-  nonByNameAttrs = map (name:
+  nonByNameAttrs = builtins.mapAttrs (name: value:
     let
-      output = attrInfo name pkgs.${name};
+      output = attrInfo name value;
       result = builtins.tryEval (builtins.deepSeq output null);
     in
-    [
-      name
-      {
-        NonByName =
-          if result.success then
-            { EvalSuccess = output; }
-          else
-            { EvalFailure = null; };
-      }
-    ]
-  ) (builtins.attrNames (builtins.removeAttrs pkgs attrs));
+    {
+      NonByName =
+        if result.success then
+          { EvalSuccess = output; }
+        else
+          { EvalFailure = null; };
+    }
+  ) (builtins.removeAttrs pkgs attrs);
+
+  # All attributes
+  attributes = byNameAttrs // nonByNameAttrs;
 in
-byNameAttrs ++ nonByNameAttrs
+# We output them in the form [ [ <name> <value> ] ]` such that the Rust side
+# doesn't need to sort them again to get deterministic behavior (good for testing)
+map (name: [
+  name
+  attributes.${name}
+]) (builtins.attrNames attributes)
diff --git a/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/all-packages.nix b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/all-packages.nix
new file mode 100644
index 000000000000..688f52b9358f
--- /dev/null
+++ b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/all-packages.nix
@@ -0,0 +1,6 @@
+self: super: {
+  a = self.callPackage ./pkgs/by-name/a/a/package.nix { };
+  b = self.callPackage ({ someDrv }: someDrv) { };
+  c = self.callPackage ./pkgs/by-name/c/c/package.nix { };
+  d = self.callPackage ({ someDrv }: someDrv) { };
+}
diff --git a/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/default.nix b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/default.nix
new file mode 100644
index 000000000000..af25d1450122
--- /dev/null
+++ b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/default.nix
@@ -0,0 +1 @@
+import ../mock-nixpkgs.nix { root = ./.; }
diff --git a/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/expected b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/expected
new file mode 100644
index 000000000000..349e9ad47c41
--- /dev/null
+++ b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/expected
@@ -0,0 +1,4 @@
+pkgs.a: This attribute is manually defined (most likely in pkgs/top-level/all-packages.nix), which is only allowed if the definition is of the form `pkgs.callPackage pkgs/by-name/a/a/package.nix { ... }` with a non-empty second argument.
+pkgs.b: This is a new top-level package of the form `callPackage ... { }`. Please define it in pkgs/by-name/b/b/package.nix instead. See `pkgs/by-name/README.md` for more details. Since the second `callPackage` argument is `{ }`, no manual `callPackage` (e.g. in `pkgs/top-level/all-packages.nix`) is needed anymore.
+pkgs.c: This attribute is manually defined (most likely in pkgs/top-level/all-packages.nix), which is only allowed if the definition is of the form `pkgs.callPackage pkgs/by-name/c/c/package.nix { ... }` with a non-empty second argument.
+pkgs.d: This is a new top-level package of the form `callPackage ... { }`. Please define it in pkgs/by-name/d/d/package.nix instead. See `pkgs/by-name/README.md` for more details. Since the second `callPackage` argument is `{ }`, no manual `callPackage` (e.g. in `pkgs/top-level/all-packages.nix`) is needed anymore.
diff --git a/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/a/a/package.nix b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/a/a/package.nix
new file mode 100644
index 000000000000..a1b92efbbadb
--- /dev/null
+++ b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/a/a/package.nix
@@ -0,0 +1 @@
+{ someDrv }: someDrv
diff --git a/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/c/c/package.nix b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/c/c/package.nix
new file mode 100644
index 000000000000..a1b92efbbadb
--- /dev/null
+++ b/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/pkgs/by-name/c/c/package.nix
@@ -0,0 +1 @@
+{ someDrv }: someDrv