summaryrefslogtreecommitdiffstats
path: root/pkgs/pkgs-lib/tests/default.nix
blob: 5b8bc99e992d5c1fce243f87dc225a418b7a08b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Call nix-build on this file to run all tests in this directory

# This produces a link farm derivation with the original attrs
# merged on top of it.
# You can run parts of the "hierarchy" with for example:
#     nix-build -A java-properties
# See `structured` below.

{
  pkgs ? import ../../.. { },
}:
let
  inherit (pkgs.lib)
    mapAttrs
    mapAttrsToList
    isDerivation
    mergeAttrs
    foldl'
    attrValues
    recurseIntoAttrs
    ;

  structured = {
    formats = import ./formats.nix { inherit pkgs; };
    java-properties = recurseIntoAttrs {
      jdk11 = pkgs.callPackage ../formats/java-properties/test { jdk = pkgs.jdk11_headless; };
      jdk17 = pkgs.callPackage ../formats/java-properties/test { jdk = pkgs.jdk17_headless; };
      jdk = pkgs.callPackage ../formats/java-properties/test { jdk = pkgs.jdk_headless; };
    };

    libconfig = recurseIntoAttrs (import ../formats/libconfig/test { inherit pkgs; });

    hocon = recurseIntoAttrs (import ../formats/hocon/test { inherit pkgs; });
  };

  flatten =
    prefix: as:
    foldl' mergeAttrs { } (
      attrValues (
        mapAttrs (
          k: v:
          if isDerivation v then
            { "${prefix}${k}" = v; }
          else if v ? recurseForDerivations then
            flatten "${prefix}${k}-" (removeAttrs v [ "recurseForDerivations" ])
          else
            builtins.trace v throw "expected derivation or recurseIntoAttrs"
        ) as
      )
    );
in

# It has to be a link farm for inclusion in the hydra unstable jobset.
{
  formats-tests = pkgs.linkFarm "pkgs-lib-formats-tests" (
    mapAttrsToList (k: v: {
      name = k;
      path = v;
    }) (flatten "" structured)
  );
}
// structured