notes: 2.3.0 -> 2.3.1 (#352950)
[NixPkgs.git] / nixos / tests / replace-dependencies / guest.nix
blobf022f1728599559f53ae5d70908fc548ecc808c3
1 # This needs to be run in a NixOS test, because Hydra cannot do IFD.
2 let
3   pkgs = import ../../.. { };
4   inherit (pkgs)
5     runCommand
6     writeShellScriptBin
7     replaceDependency
8     replaceDependencies
9     ;
10   inherit (pkgs.lib) escapeShellArg;
11   mkCheckOutput =
12     name: test: output:
13     runCommand name { } ''
14       actualOutput="$(${escapeShellArg "${test}/bin/test"})"
15       if [ "$(${escapeShellArg "${test}/bin/test"})" != ${escapeShellArg output} ]; then
16         echo >&2 "mismatched output: expected \""${escapeShellArg output}"\", got \"$actualOutput\""
17         exit 1
18       fi
19       touch "$out"
20     '';
21   oldDependency = writeShellScriptBin "dependency" ''
22     echo "got old dependency"
23   '';
24   oldDependency-ca = oldDependency.overrideAttrs { __contentAddressed = true; };
25   newDependency = writeShellScriptBin "dependency" ''
26     echo "got new dependency"
27   '';
28   newDependency-ca = newDependency.overrideAttrs { __contentAddressed = true; };
29   basic = writeShellScriptBin "test" ''
30     ${oldDependency}/bin/dependency
31   '';
32   basic-ca = writeShellScriptBin "test" ''
33     ${oldDependency-ca}/bin/dependency
34   '';
35   transitive = writeShellScriptBin "test" ''
36     ${basic}/bin/test
37   '';
38   weirdDependency = writeShellScriptBin "dependency" ''
39     echo "got weird dependency"
40     ${basic}/bin/test
41   '';
42   oldDependency1 = writeShellScriptBin "dependency1" ''
43     echo "got old dependency 1"
44   '';
45   newDependency1 = writeShellScriptBin "dependency1" ''
46     echo "got new dependency 1"
47   '';
48   oldDependency2 = writeShellScriptBin "dependency2" ''
49     ${oldDependency1}/bin/dependency1
50       echo "got old dependency 2"
51   '';
52   newDependency2 = writeShellScriptBin "dependency2" ''
53     ${oldDependency1}/bin/dependency1
54       echo "got new dependency 2"
55   '';
56   deep = writeShellScriptBin "test" ''
57     ${oldDependency2}/bin/dependency2
58   '';
61   replacedependency-basic = mkCheckOutput "replacedependency-basic" (replaceDependency {
62     drv = basic;
63     inherit oldDependency newDependency;
64   }) "got new dependency";
66   replacedependency-basic-old-ca = mkCheckOutput "replacedependency-basic" (replaceDependency {
67     drv = basic-ca;
68     oldDependency = oldDependency-ca;
69     inherit newDependency;
70   }) "got new dependency";
72   replacedependency-basic-new-ca = mkCheckOutput "replacedependency-basic" (replaceDependency {
73     drv = basic;
74     inherit oldDependency;
75     newDependency = newDependency-ca;
76   }) "got new dependency";
78   replacedependency-transitive = mkCheckOutput "replacedependency-transitive" (replaceDependency {
79     drv = transitive;
80     inherit oldDependency newDependency;
81   }) "got new dependency";
83   replacedependency-weird =
84     mkCheckOutput "replacedependency-weird"
85       (replaceDependency {
86         drv = basic;
87         inherit oldDependency;
88         newDependency = weirdDependency;
89       })
90       ''
91         got weird dependency
92         got old dependency'';
94   replacedependencies-precedence = mkCheckOutput "replacedependencies-precedence" (replaceDependencies
95     {
96       drv = basic;
97       replacements = [ { inherit oldDependency newDependency; } ];
98       cutoffPackages = [ oldDependency ];
99     }
100   ) "got new dependency";
102   replacedependencies-self = mkCheckOutput "replacedependencies-self" (replaceDependencies {
103     drv = basic;
104     replacements = [
105       {
106         inherit oldDependency;
107         newDependency = oldDependency;
108       }
109     ];
110   }) "got old dependency";
112   replacedependencies-deep-order1 =
113     mkCheckOutput "replacedependencies-deep-order1"
114       (replaceDependencies {
115         drv = deep;
116         replacements = [
117           {
118             oldDependency = oldDependency1;
119             newDependency = newDependency1;
120           }
121           {
122             oldDependency = oldDependency2;
123             newDependency = newDependency2;
124           }
125         ];
126       })
127       ''
128         got new dependency 1
129         got new dependency 2'';
131   replacedependencies-deep-order2 =
132     mkCheckOutput "replacedependencies-deep-order2"
133       (replaceDependencies {
134         drv = deep;
135         replacements = [
136           {
137             oldDependency = oldDependency2;
138             newDependency = newDependency2;
139           }
140           {
141             oldDependency = oldDependency1;
142             newDependency = newDependency1;
143           }
144         ];
145       })
146       ''
147         got new dependency 1
148         got new dependency 2'';