aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cmd/install_spec.rb
blob: b819c17bee0e49670b7b78ccfedc50a85159605e (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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
describe "brew install", :integration_test do
  it "installs Formulae" do
    setup_test_formula "testball1"

    expect { brew "install", "testball1", "--head" }
      .to output(/Specify `\-\-HEAD`/).to_stderr
      .and not_to_output.to_stdout
      .and be_a_failure

    expect { brew "install", "testball1", "--HEAD" }
      .to output(/No head is defined/).to_stderr
      .and not_to_output.to_stdout
      .and be_a_failure

    expect { brew "install", "testball1", "--devel" }
      .to output(/No devel block/).to_stderr
      .and not_to_output.to_stdout
      .and be_a_failure

    expect { brew "install", "testball1" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    expect { brew "install", "testball1" }
      .to output(/testball1\-0\.1 already installed/).to_stderr
      .and not_to_output.to_stdout
      .and be_a_success

    expect { brew "install", "macruby" }
      .to output(/MacRuby is not packaged/).to_stderr
      .and not_to_output.to_stdout
      .and be_a_failure

    expect { brew "install", "formula" }
      .to output(/No available formula/).to_stderr
      .and output(/Searching for similarly named formulae/).to_stdout
      .and be_a_failure

    expect { brew "install", "testball" }
      .to output(/This similarly named formula was found/).to_stdout
      .and output(/No available formula/).to_stderr
      .and be_a_failure

    setup_test_formula "testball2"
    expect { brew "install", "testball" }
      .to output(/These similarly named formulae were found/).to_stdout
      .and output(/No available formula/).to_stderr
      .and be_a_failure

    install_and_rename_coretap_formula "testball1", "testball2"
    expect { brew "install", "testball2" }
      .to output(/testball1 already installed, it's just not migrated/).to_stderr
      .and output(/You can migrate formula with `brew migrate testball2`/).to_stdout
      .and be_a_success
  end

  specify "install failures" do
    path = setup_test_formula "testball1", <<-EOS.undent
      version "1.0"
    EOS

    expect { brew "install", "testball1" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    FileUtils.rm path
    setup_test_formula "testball1", <<-EOS.undent
      version "2.0"

      devel do
        url "#{Formulary.factory("testball1").stable.url}"
        sha256 "#{TESTBALL_SHA256}"
        version "3.0"
      end
    EOS

    expect { brew "install", "testball1" }
      .to output(/`brew upgrade testball1`/).to_stderr
      .and not_to_output.to_stdout
      .and be_a_failure

    expect { brew "unlink", "testball1" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    expect { brew "install", "testball1", "--devel" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/3\.0}).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    expect { brew "unlink", "testball1" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/3\.0}).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    expect { brew "install", "testball1" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/2\.0}).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    shutup do
      expect { brew "switch", "testball1", "3.0" }.to be_a_success
    end

    expect { brew "install", "testball1" }
      .to output(/already installed, however linked version is/).to_stderr
      .and output(/`brew switch testball1 2.0`/).to_stdout
      .and be_a_success

    expect { brew "unlink", "testball1" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/3\.0}).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    expect { brew "install", "testball1" }
      .to output(/just not linked/).to_stderr
      .and not_to_output.to_stdout
      .and be_a_success
  end

  it "can install keg-only Formulae" do
    path_keg_only = setup_test_formula "testball1", <<-EOS.undent
      version "1.0"

      keg_only "test reason"
    EOS

    expect { brew "install", "testball1" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    FileUtils.rm path_keg_only
    setup_test_formula "testball1", <<-EOS.undent
      version "2.0"

      keg_only "test reason"
    EOS

    expect { brew "install", "testball1" }
      .to output(/keg-only and another version is linked to opt/).to_stderr
      .and output(/Use `brew install --force`/).to_stdout
      .and be_a_success

    expect { brew "install", "testball1", "--force" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/2\.0}).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success
  end

  it "can install HEAD Formulae" do
    repo_path = HOMEBREW_CACHE.join("repo")
    repo_path.join("bin").mkpath

    repo_path.cd do
      shutup do
        system "git", "init"
        system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
        FileUtils.touch "bin/something.bin"
        FileUtils.touch "README"
        system "git", "add", "--all"
        system "git", "commit", "-m", "Initial repo commit"
      end
    end

    setup_test_formula "testball1", <<-EOS.undent
      version "1.0"

      head "file://#{repo_path}", :using => :git

      def install
        prefix.install Dir["*"]
      end
    EOS

    # Ignore dependencies, because we'll try to resolve requirements in build.rb
    # and there will be the git requirement, but we cannot instantiate git
    # formula since we only have testball1 formula.
    expect { brew "install", "testball1", "--HEAD", "--ignore-dependencies" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/HEAD\-d5eb689}).to_stdout
      .and output(/Cloning into/).to_stderr
      .and be_a_success

    expect { brew "install", "testball1", "--HEAD", "--ignore-dependencies" }
      .to output(/testball1\-HEAD\-d5eb689 already installed/).to_stderr
      .and not_to_output.to_stdout
      .and be_a_success

    expect { brew "unlink", "testball1" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/HEAD\-d5eb689}).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    expect { brew "install", "testball1" }
      .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success
  end

  it "ignores invalid options" do
    setup_test_formula "testball1"
    expect { brew "install", "testball1", "--with-fo" }
      .to output(/testball1: this formula has no \-\-with\-fo option so it will be ignored!/).to_stderr
      .and output(/Downloading file/).to_stdout
      .and be_a_success
  end

  it "succeeds when a non-fatal requirement isn't satisfied" do
    setup_test_formula "testball1", <<-EOS.undent
      class NonFatalRequirement < Requirement
        satisfy { false }
      end

      depends_on NonFatalRequirement
    EOS

    expect { brew "install", "testball1" }
      .to output(/NonFatalRequirement unsatisfied!/).to_stderr
      .and output(/built in/).to_stdout
      .and be_a_success
  end

  it "fails when a fatal requirement isn't satisfied" do
    setup_test_formula "testball1", <<-EOS.undent
      class FatalRequirement < Requirement
        fatal true
        satisfy { false }
      end

      depends_on FatalRequirement
    EOS

    expect { brew "install", "testball1" }
      .to output(/FatalRequirement unsatisfied!/).to_stderr
      .and not_to_output.to_stdout
      .and be_a_failure
  end
end