pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / test / overriding.nix
bloba9fa482e4e588344f3a907134f5039f2ac505db7
1 { lib, pkgs, stdenvNoCC }:
3 let
4   tests =
5     let
6       p = pkgs.python3Packages.xpybutil.overridePythonAttrs (_: { dontWrapPythonPrograms = true; });
7     in
8     {
9       overridePythonAttrs = {
10         expr = !lib.hasInfix "wrapPythonPrograms" p.postFixup;
11         expected = true;
12       };
13       repeatedOverrides-pname = {
14         expr = repeatedOverrides.pname == "a-better-hello-with-blackjack";
15         expected = true;
16       };
17       repeatedOverrides-entangled-pname = {
18         expr = repeatedOverrides.entangled.pname == "a-better-figlet-with-blackjack";
19         expected = true;
20       };
21       overriding-using-only-attrset = {
22         expr = (pkgs.hello.overrideAttrs { pname = "hello-overriden"; }).pname == "hello-overriden";
23         expected = true;
24       };
25       overriding-using-only-attrset-no-final-attrs = {
26         name = "overriding-using-only-attrset-no-final-attrs";
27         expr = ((stdenvNoCC.mkDerivation { pname = "hello-no-final-attrs"; }).overrideAttrs { pname = "hello-no-final-attrs-overridden"; }).pname == "hello-no-final-attrs-overridden";
28         expected = true;
29       };
30       buildGoModule-overrideAttrs = {
31         expr = lib.all (
32           attrPath:
33           let
34             attrPathPretty = lib.concatStringsSep "." attrPath;
35             valueNative = lib.getAttrFromPath attrPath pet_0_4_0;
36             valueOverridden = lib.getAttrFromPath attrPath pet_0_4_0-overridden;
37           in
38           lib.warnIfNot
39             (valueNative == valueOverridden)
40             "pet_0_4_0.${attrPathPretty} (${valueNative}) does not equal pet_0_4_0-overridden.${attrPathPretty} (${valueOverridden})"
41             true
42         ) [
43           [ "drvPath" ]
44           [ "name" ]
45           [ "pname" ]
46           [ "version" ]
47           [ "vendorHash" ]
48           [ "goModules" "drvPath" ]
49           [ "goModules" "name" ]
50           [ "goModules" "outputHash" ]
51         ];
52         expected = true;
53       };
54       buildGoModule-goModules-overrideAttrs = {
55         expr = pet-foo.goModules.FOO == "foo";
56         expected = true;
57       };
58       buildGoModule-goModules-overrideAttrs-vendored = {
59         expr = lib.isString pet-vendored.drvPath;
60         expected = true;
61       };
62     };
64   addEntangled = origOverrideAttrs: f:
65     origOverrideAttrs (
66       lib.composeExtensions f (self: super: {
67         passthru = super.passthru // {
68           entangled = super.passthru.entangled.overrideAttrs f;
69           overrideAttrs = addEntangled self.overrideAttrs;
70         };
71       })
72     );
74   entangle = pkg1: pkg2: pkg1.overrideAttrs (self: super: {
75     passthru = super.passthru // {
76       entangled = pkg2;
77       overrideAttrs = addEntangled self.overrideAttrs;
78     };
79   });
81   example = entangle pkgs.hello pkgs.figlet;
83   overrides1 = example.overrideAttrs (_: super: { pname = "a-better-${super.pname}"; });
85   repeatedOverrides = overrides1.overrideAttrs (_: super: { pname = "${super.pname}-with-blackjack"; });
87   pet_0_3_4 = pkgs.buildGoModule rec {
88     pname = "pet";
89     version = "0.3.4";
91     src = pkgs.fetchFromGitHub {
92       owner = "knqyf263";
93       repo = "pet";
94       rev = "v${version}";
95       hash = "sha256-Gjw1dRrgM8D3G7v6WIM2+50r4HmTXvx0Xxme2fH9TlQ=";
96     };
98     vendorHash = "sha256-ciBIR+a1oaYH+H1PcC8cD8ncfJczk1IiJ8iYNM+R6aA=";
100     meta = {
101       description = "Simple command-line snippet manager, written in Go";
102       homepage = "https://github.com/knqyf263/pet";
103       license = lib.licenses.mit;
104       maintainers = with lib.maintainers; [ kalbasit ];
105     };
106   };
108   pet_0_4_0 = pkgs.buildGoModule rec {
109     pname = "pet";
110     version = "0.4.0";
112     src = pkgs.fetchFromGitHub {
113       owner = "knqyf263";
114       repo = "pet";
115       rev = "v${version}";
116       hash = "sha256-gVTpzmXekQxGMucDKskGi+e+34nJwwsXwvQTjRO6Gdg=";
117     };
119     vendorHash = "sha256-dUvp7FEW09V0xMuhewPGw3TuAic/sD7xyXEYviZ2Ivs=";
121     meta = {
122       description = "Simple command-line snippet manager, written in Go";
123       homepage = "https://github.com/knqyf263/pet";
124       license = lib.licenses.mit;
125       maintainers = with lib.maintainers; [ kalbasit ];
126     };
127   };
129   pet_0_4_0-overridden = pet_0_3_4.overrideAttrs (finalAttrs: previousAttrs: {
130   version = "0.4.0";
132   src = pkgs.fetchFromGitHub {
133     inherit (previousAttrs.src) owner repo;
134     rev = "v${finalAttrs.version}";
135     hash = "sha256-gVTpzmXekQxGMucDKskGi+e+34nJwwsXwvQTjRO6Gdg=";
136   };
138   vendorHash = "sha256-dUvp7FEW09V0xMuhewPGw3TuAic/sD7xyXEYviZ2Ivs=";
139   });
141   pet-foo = pet_0_3_4.overrideAttrs (
142     finalAttrs: previousAttrs: {
143       passthru = previousAttrs.passthru // {
144         overrideModAttrs = lib.composeExtensions previousAttrs.passthru.overrideModAttrs (
145           finalModAttrs: previousModAttrs: {
146             FOO = "foo";
147           }
148         );
149       };
150     }
151   );
153   pet-vendored = pet-foo.overrideAttrs { vendorHash = null; };
156 stdenvNoCC.mkDerivation {
157   name = "test-overriding";
158   passthru = { inherit tests; };
159   buildCommand = ''
160     touch $out
161   '' + lib.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs (name: t: "([[ ${lib.boolToString t.expr} == ${lib.boolToString t.expected} ]] && echo '${name} success') || (echo '${name} fail' && exit 1)") tests));