about summary refs log tree commit diff
path: root/nixos/tests/replace-dependencies/guest.nix
blob: f022f1728599559f53ae5d70908fc548ecc808c3 (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# This needs to be run in a NixOS test, because Hydra cannot do IFD.
let
  pkgs = import ../../.. { };
  inherit (pkgs)
    runCommand
    writeShellScriptBin
    replaceDependency
    replaceDependencies
    ;
  inherit (pkgs.lib) escapeShellArg;
  mkCheckOutput =
    name: test: output:
    runCommand name { } ''
      actualOutput="$(${escapeShellArg "${test}/bin/test"})"
      if [ "$(${escapeShellArg "${test}/bin/test"})" != ${escapeShellArg output} ]; then
        echo >&2 "mismatched output: expected \""${escapeShellArg output}"\", got \"$actualOutput\""
        exit 1
      fi
      touch "$out"
    '';
  oldDependency = writeShellScriptBin "dependency" ''
    echo "got old dependency"
  '';
  oldDependency-ca = oldDependency.overrideAttrs { __contentAddressed = true; };
  newDependency = writeShellScriptBin "dependency" ''
    echo "got new dependency"
  '';
  newDependency-ca = newDependency.overrideAttrs { __contentAddressed = true; };
  basic = writeShellScriptBin "test" ''
    ${oldDependency}/bin/dependency
  '';
  basic-ca = writeShellScriptBin "test" ''
    ${oldDependency-ca}/bin/dependency
  '';
  transitive = writeShellScriptBin "test" ''
    ${basic}/bin/test
  '';
  weirdDependency = writeShellScriptBin "dependency" ''
    echo "got weird dependency"
    ${basic}/bin/test
  '';
  oldDependency1 = writeShellScriptBin "dependency1" ''
    echo "got old dependency 1"
  '';
  newDependency1 = writeShellScriptBin "dependency1" ''
    echo "got new dependency 1"
  '';
  oldDependency2 = writeShellScriptBin "dependency2" ''
    ${oldDependency1}/bin/dependency1
      echo "got old dependency 2"
  '';
  newDependency2 = writeShellScriptBin "dependency2" ''
    ${oldDependency1}/bin/dependency1
      echo "got new dependency 2"
  '';
  deep = writeShellScriptBin "test" ''
    ${oldDependency2}/bin/dependency2
  '';
in
{
  replacedependency-basic = mkCheckOutput "replacedependency-basic" (replaceDependency {
    drv = basic;
    inherit oldDependency newDependency;
  }) "got new dependency";

  replacedependency-basic-old-ca = mkCheckOutput "replacedependency-basic" (replaceDependency {
    drv = basic-ca;
    oldDependency = oldDependency-ca;
    inherit newDependency;
  }) "got new dependency";

  replacedependency-basic-new-ca = mkCheckOutput "replacedependency-basic" (replaceDependency {
    drv = basic;
    inherit oldDependency;
    newDependency = newDependency-ca;
  }) "got new dependency";

  replacedependency-transitive = mkCheckOutput "replacedependency-transitive" (replaceDependency {
    drv = transitive;
    inherit oldDependency newDependency;
  }) "got new dependency";

  replacedependency-weird =
    mkCheckOutput "replacedependency-weird"
      (replaceDependency {
        drv = basic;
        inherit oldDependency;
        newDependency = weirdDependency;
      })
      ''
        got weird dependency
        got old dependency'';

  replacedependencies-precedence = mkCheckOutput "replacedependencies-precedence" (replaceDependencies
    {
      drv = basic;
      replacements = [ { inherit oldDependency newDependency; } ];
      cutoffPackages = [ oldDependency ];
    }
  ) "got new dependency";

  replacedependencies-self = mkCheckOutput "replacedependencies-self" (replaceDependencies {
    drv = basic;
    replacements = [
      {
        inherit oldDependency;
        newDependency = oldDependency;
      }
    ];
  }) "got old dependency";

  replacedependencies-deep-order1 =
    mkCheckOutput "replacedependencies-deep-order1"
      (replaceDependencies {
        drv = deep;
        replacements = [
          {
            oldDependency = oldDependency1;
            newDependency = newDependency1;
          }
          {
            oldDependency = oldDependency2;
            newDependency = newDependency2;
          }
        ];
      })
      ''
        got new dependency 1
        got new dependency 2'';

  replacedependencies-deep-order2 =
    mkCheckOutput "replacedependencies-deep-order2"
      (replaceDependencies {
        drv = deep;
        replacements = [
          {
            oldDependency = oldDependency2;
            newDependency = newDependency2;
          }
          {
            oldDependency = oldDependency1;
            newDependency = newDependency1;
          }
        ];
      })
      ''
        got new dependency 1
        got new dependency 2'';
}