2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-14 17:45:20 +01:00
|
|
|
require "exceptions"
|
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe "Exception" do
|
|
|
|
describe MultipleVersionsInstalledError do
|
|
|
|
subject {
|
|
|
|
described_class.new <<~EOS
|
|
|
|
foo has multiple installed versions
|
|
|
|
Run `brew uninstall --force foo` to remove all versions.
|
|
|
|
EOS
|
|
|
|
}
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) {
|
|
|
|
is_expected.to eq <<~EOS
|
|
|
|
foo has multiple installed versions
|
|
|
|
Run `brew uninstall --force foo` to remove all versions.
|
|
|
|
EOS
|
|
|
|
}
|
|
|
|
end
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe NoSuchKegError do
|
|
|
|
subject { described_class.new("foo") }
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to eq("No such keg: #{HOMEBREW_CELLAR}/foo") }
|
|
|
|
end
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe FormulaValidationError do
|
|
|
|
subject(:error) { described_class.new("foo", "sha257", "magic") }
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) {
|
|
|
|
expect(error.to_s).to eq(%q(invalid attribute for formula 'foo': sha257 ("magic")))
|
|
|
|
}
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe FormulaUnavailableError do
|
|
|
|
subject(:error) { described_class.new("foo") }
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe "#dependent_s" do
|
|
|
|
it "returns nil if there is no dependent" do
|
|
|
|
expect(error.dependent_s).to be nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil if it depended on by itself" do
|
|
|
|
error.dependent = "foo"
|
|
|
|
expect(error.dependent_s).to be nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a string if there is a dependent" do
|
|
|
|
error.dependent = "foobar"
|
|
|
|
expect(error.dependent_s).to eq(" (dependency of foobar)")
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
end
|
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
context "without a dependent" do
|
|
|
|
its(:to_s) { is_expected.to eq('No available formula with the name "foo".') }
|
2017-02-14 17:45:20 +01:00
|
|
|
end
|
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
context "with a dependent" do
|
|
|
|
before do
|
|
|
|
error.dependent = "foobar"
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) {
|
|
|
|
expect(error.to_s).to eq('No available formula with the name "foo" (dependency of foobar).')
|
|
|
|
}
|
2017-02-14 17:45:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe TapFormulaUnavailableError do
|
|
|
|
subject { described_class.new(tap, "foo") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:tap) { double(Tap, user: "u", repo: "r", to_s: "u/r", installed?: false) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to match(%r{Please tap it and then try again: brew tap u/r}) }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe FormulaClassUnavailableError do
|
|
|
|
subject(:error) { described_class.new("foo", "foo.rb", "Foo", list) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:mod) do
|
|
|
|
Module.new do
|
|
|
|
class Bar < Requirement; end
|
2020-11-30 16:27:49 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
class Baz < Formula; end
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
end
|
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
context "no classes" do
|
|
|
|
let(:list) { [] }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) {
|
|
|
|
expect(error.to_s).to match(/Expected to find class Foo, but found no classes\./)
|
|
|
|
}
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
context "class not derived from Formula" do
|
|
|
|
let(:list) { [mod.const_get(:Bar)] }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) {
|
|
|
|
expect(error.to_s).to match(/Expected to find class Foo, but only found: Bar \(not derived from Formula!\)\./)
|
|
|
|
}
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
context "class derived from Formula" do
|
|
|
|
let(:list) { [mod.const_get(:Baz)] }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to match(/Expected to find class Foo, but only found: Baz\./) }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
end
|
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe FormulaUnreadableError do
|
|
|
|
subject { described_class.new("foo", formula_error) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:formula_error) { LoadError.new("bar") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to eq("foo: bar") }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe TapUnavailableError do
|
|
|
|
subject { described_class.new("foo") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to eq("No available tap foo.\n") }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe TapAlreadyTappedError do
|
|
|
|
subject { described_class.new("foo") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to eq("Tap foo already tapped.\n") }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe BuildError do
|
|
|
|
subject { described_class.new(formula, "badprg", %w[arg1 arg2], {}) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:formula) { double(Formula, name: "foo") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to eq("Failed executing: badprg arg1 arg2") }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe OperationInProgressError do
|
|
|
|
subject { described_class.new("foo") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to match(/Operation already in progress for foo/) }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe FormulaInstallationAlreadyAttemptedError do
|
|
|
|
subject { described_class.new(formula) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:formula) { double(Formula, full_name: "foo/bar") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to eq("Formula installation already attempted: foo/bar") }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe FormulaConflictError do
|
|
|
|
subject { described_class.new(formula, [conflict]) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:formula) { double(Formula, full_name: "foo/qux") }
|
|
|
|
let(:conflict) { double(name: "bar", reason: "I decided to") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to match(/Please `brew unlink bar` before continuing\./) }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe CompilerSelectionError do
|
|
|
|
subject { described_class.new(formula) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:formula) { double(Formula, full_name: "foo") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to match(/foo cannot be built with any available compilers\./) }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe CurlDownloadStrategyError do
|
|
|
|
context "file does not exist" do
|
|
|
|
subject { described_class.new("file:///tmp/foo") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to eq("File does not exist: /tmp/foo") }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
context "download failed" do
|
|
|
|
subject { described_class.new("https://brew.sh") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to eq("Download failed: https://brew.sh") }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
end
|
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe ErrorDuringExecution do
|
|
|
|
subject { described_class.new(["badprg", "arg1", "arg2"], status: status) }
|
2018-09-20 09:07:56 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:status) { instance_double(Process::Status, exitstatus: 17) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to eq("Failure while executing; `badprg arg1 arg2` exited with 17.") }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe ChecksumMismatchError do
|
|
|
|
subject { described_class.new("/file.tar.gz", hash1, hash2) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:hash1) { double(hash_type: "sha256", to_s: "deadbeef") }
|
|
|
|
let(:hash2) { double(hash_type: "sha256", to_s: "deadcafe") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to match(/SHA256 mismatch/) }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe ResourceMissingError do
|
|
|
|
subject { described_class.new(formula, resource) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:formula) { double(Formula, full_name: "bar") }
|
|
|
|
let(:resource) { double(inspect: "<resource foo>") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to eq("bar does not define resource <resource foo>") }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe DuplicateResourceError do
|
|
|
|
subject { described_class.new(resource) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:resource) { double(inspect: "<resource foo>") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to eq("Resource <resource foo> is defined more than once") }
|
|
|
|
end
|
2017-02-14 17:45:20 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe BottleFormulaUnavailableError do
|
|
|
|
subject { described_class.new("/foo.bottle.tar.gz", "foo/1.0/.brew/foo.rb") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
let(:formula) { double(Formula, full_name: "foo") }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to match(/This bottle does not contain the formula file/) }
|
|
|
|
end
|
2019-10-11 09:34:43 +02:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
describe BuildFlagsError do
|
|
|
|
subject { described_class.new(["-s"]) }
|
2019-10-11 09:34:43 +02:00
|
|
|
|
2021-01-31 14:50:29 -05:00
|
|
|
its(:to_s) { is_expected.to match(/flag:\s+-s\nrequires building tools/) }
|
|
|
|
end
|
2019-10-11 09:34:43 +02:00
|
|
|
end
|