Add tests and fix brew typecheck
This commit is contained in:
parent
7eb3f1a314
commit
40d3ab6a5d
@ -20,7 +20,17 @@ module Cask
|
||||
|
||||
def desc; end
|
||||
|
||||
def discontinued?; end
|
||||
def deprecated?; end
|
||||
|
||||
def deprecation_date; end
|
||||
|
||||
def deprecation_reason; end
|
||||
|
||||
def disabled?; end
|
||||
|
||||
def disable_date; end
|
||||
|
||||
def disable_reason; end
|
||||
|
||||
def homepage; end
|
||||
|
||||
|
||||
89
Library/Homebrew/test/deprecate_disable_spec.rb
Normal file
89
Library/Homebrew/test/deprecate_disable_spec.rb
Normal file
@ -0,0 +1,89 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "deprecate_disable"
|
||||
|
||||
describe DeprecateDisable do
|
||||
let(:deprecated_formula) do
|
||||
instance_double(Formula, deprecated?: true, disabled?: false, deprecation_reason: :does_not_build)
|
||||
end
|
||||
let(:disabled_formula) do
|
||||
instance_double(Formula, deprecated?: false, disabled?: true, disable_reason: "is broken")
|
||||
end
|
||||
let(:deprecated_cask) do
|
||||
instance_double(Cask::Cask, deprecated?: true, disabled?: false, deprecation_reason: :discontinued)
|
||||
end
|
||||
let(:disabled_cask) do
|
||||
instance_double(Cask::Cask, deprecated?: false, disabled?: true, disable_reason: nil)
|
||||
end
|
||||
|
||||
before do
|
||||
allow(deprecated_formula).to receive(:is_a?).with(Formula).and_return(true)
|
||||
allow(deprecated_formula).to receive(:is_a?).with(Cask::Cask).and_return(false)
|
||||
allow(disabled_formula).to receive(:is_a?).with(Formula).and_return(true)
|
||||
allow(disabled_formula).to receive(:is_a?).with(Cask::Cask).and_return(false)
|
||||
allow(deprecated_cask).to receive(:is_a?).with(Formula).and_return(false)
|
||||
allow(deprecated_cask).to receive(:is_a?).with(Cask::Cask).and_return(true)
|
||||
allow(disabled_cask).to receive(:is_a?).with(Formula).and_return(false)
|
||||
allow(disabled_cask).to receive(:is_a?).with(Cask::Cask).and_return(true)
|
||||
end
|
||||
|
||||
describe "::type" do
|
||||
it "returns :deprecated if the formula is deprecated" do
|
||||
expect(described_class.type(deprecated_formula)).to eq :deprecated
|
||||
end
|
||||
|
||||
it "returns :disabled if the formula is disabled" do
|
||||
expect(described_class.type(disabled_formula)).to eq :disabled
|
||||
end
|
||||
|
||||
it "returns :deprecated if the cask is deprecated" do
|
||||
expect(described_class.type(deprecated_cask)).to eq :deprecated
|
||||
end
|
||||
|
||||
it "returns :disabled if the cask is disabled" do
|
||||
expect(described_class.type(disabled_cask)).to eq :disabled
|
||||
end
|
||||
end
|
||||
|
||||
describe "::message" do
|
||||
it "returns a deprecation message with a preset formula reason" do
|
||||
expect(described_class.message(deprecated_formula))
|
||||
.to eq "deprecated because it does not build!"
|
||||
end
|
||||
|
||||
it "returns a disable message with a custom reason" do
|
||||
expect(described_class.message(disabled_formula))
|
||||
.to eq "disabled because it is broken!"
|
||||
end
|
||||
|
||||
it "returns a deprecation message with a preset cask reason" do
|
||||
expect(described_class.message(deprecated_cask))
|
||||
.to eq "deprecated because it is discontinued upstream!"
|
||||
end
|
||||
|
||||
it "returns a deprecation message with no reason" do
|
||||
expect(described_class.message(disabled_cask))
|
||||
.to eq "disabled!"
|
||||
end
|
||||
end
|
||||
|
||||
describe "::to_reason_string_or_symbol" do
|
||||
it "returns the original string if it isn't a formula preset reason" do
|
||||
expect(described_class.to_reason_string_or_symbol("discontinued", type: :formula)).to eq "discontinued"
|
||||
end
|
||||
|
||||
it "returns the original string if it isn't a cask preset reason" do
|
||||
expect(described_class.to_reason_string_or_symbol("does_not_build", type: :cask)).to eq "does_not_build"
|
||||
end
|
||||
|
||||
it "returns a symbol if the original string is a formula preset reason" do
|
||||
expect(described_class.to_reason_string_or_symbol("does_not_build", type: :formula))
|
||||
.to eq :does_not_build
|
||||
end
|
||||
|
||||
it "returns a symbol if the original string is a cask preset reason" do
|
||||
expect(described_class.to_reason_string_or_symbol("discontinued", type: :cask))
|
||||
.to eq :discontinued
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -521,15 +521,4 @@ describe Formulary do
|
||||
expect(described_class.convert_to_string_or_symbol(":foo")).to eq :foo
|
||||
end
|
||||
end
|
||||
|
||||
describe "::convert_to_deprecate_disable_reason_string_or_symbol" do
|
||||
it "returns the original string if it isn't a preset reason" do
|
||||
expect(described_class.convert_to_deprecate_disable_reason_string_or_symbol("foo")).to eq "foo"
|
||||
end
|
||||
|
||||
it "returns a symbol if the original string is a preset reason" do
|
||||
expect(described_class.convert_to_deprecate_disable_reason_string_or_symbol("does_not_build"))
|
||||
.to eq :does_not_build
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -104,6 +104,28 @@ describe Homebrew::Livecheck::SkipConditions do
|
||||
discontinued
|
||||
end
|
||||
end,
|
||||
deprecated: Cask::Cask.new("test_deprecated") do
|
||||
version "0.0.1"
|
||||
sha256 :no_check
|
||||
|
||||
url "https://brew.sh/test-0.0.1.tgz"
|
||||
name "Test Deprecate"
|
||||
desc "Deprecated test cask"
|
||||
homepage "https://brew.sh"
|
||||
|
||||
deprecate! date: "2020-06-25", because: :discontinued
|
||||
end,
|
||||
disabled: Cask::Cask.new("test_disabled") do
|
||||
version "0.0.1"
|
||||
sha256 :no_check
|
||||
|
||||
url "https://brew.sh/test-0.0.1.tgz"
|
||||
name "Test Disable"
|
||||
desc "Disabled test cask"
|
||||
homepage "https://brew.sh"
|
||||
|
||||
disable! date: "2020-06-25", because: :discontinued
|
||||
end,
|
||||
latest: Cask::Cask.new("test_latest") do
|
||||
version :latest
|
||||
sha256 :no_check
|
||||
@ -225,7 +247,21 @@ describe Homebrew::Livecheck::SkipConditions do
|
||||
cask: {
|
||||
discontinued: {
|
||||
cask: "test_discontinued",
|
||||
status: "discontinued",
|
||||
status: "deprecated",
|
||||
meta: {
|
||||
livecheckable: false,
|
||||
},
|
||||
},
|
||||
deprecated: {
|
||||
cask: "test_deprecated",
|
||||
status: "deprecated",
|
||||
meta: {
|
||||
livecheckable: false,
|
||||
},
|
||||
},
|
||||
disabled: {
|
||||
cask: "test_disabled",
|
||||
status: "disabled",
|
||||
meta: {
|
||||
livecheckable: false,
|
||||
},
|
||||
@ -330,6 +366,20 @@ describe Homebrew::Livecheck::SkipConditions do
|
||||
end
|
||||
end
|
||||
|
||||
context "when a cask without a livecheckable is deprecated" do
|
||||
it "skips" do
|
||||
expect(skip_conditions.skip_information(casks[:deprecated]))
|
||||
.to eq(status_hashes[:cask][:deprecated])
|
||||
end
|
||||
end
|
||||
|
||||
context "when a cask without a livecheckable is disabled" do
|
||||
it "skips" do
|
||||
expect(skip_conditions.skip_information(casks[:disabled]))
|
||||
.to eq(status_hashes[:cask][:disabled])
|
||||
end
|
||||
end
|
||||
|
||||
context "when a cask without a livecheckable has `version :latest`" do
|
||||
it "skips" do
|
||||
expect(skip_conditions.skip_information(casks[:latest]))
|
||||
@ -428,7 +478,21 @@ describe Homebrew::Livecheck::SkipConditions do
|
||||
context "when a cask without a livecheckable is discontinued" do
|
||||
it "errors" do
|
||||
expect { skip_conditions.referenced_skip_information(casks[:discontinued], original_name) }
|
||||
.to raise_error(RuntimeError, "Referenced cask (test_discontinued) is skipped as discontinued")
|
||||
.to raise_error(RuntimeError, "Referenced cask (test_discontinued) is skipped as deprecated")
|
||||
end
|
||||
end
|
||||
|
||||
context "when a cask without a livecheckable is deprecated" do
|
||||
it "errors" do
|
||||
expect { skip_conditions.referenced_skip_information(casks[:deprecated], original_name) }
|
||||
.to raise_error(RuntimeError, "Referenced cask (test_deprecated) is skipped as deprecated")
|
||||
end
|
||||
end
|
||||
|
||||
context "when a cask without a livecheckable is disabled" do
|
||||
it "errors" do
|
||||
expect { skip_conditions.referenced_skip_information(casks[:disabled], original_name) }
|
||||
.to raise_error(RuntimeError, "Referenced cask (test_disabled) is skipped as disabled")
|
||||
end
|
||||
end
|
||||
|
||||
@ -537,7 +601,23 @@ describe Homebrew::Livecheck::SkipConditions do
|
||||
context "when the cask is discontinued without a livecheckable" do
|
||||
it "prints skip information" do
|
||||
expect { skip_conditions.print_skip_information(status_hashes[:cask][:discontinued]) }
|
||||
.to output("test_discontinued: discontinued\n").to_stdout
|
||||
.to output("test_discontinued: deprecated\n").to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
end
|
||||
end
|
||||
|
||||
context "when the cask is deprecated without a livecheckable" do
|
||||
it "prints skip information" do
|
||||
expect { skip_conditions.print_skip_information(status_hashes[:cask][:deprecated]) }
|
||||
.to output("test_deprecated: deprecated\n").to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
end
|
||||
end
|
||||
|
||||
context "when the cask is disabled without a livecheckable" do
|
||||
it "prints skip information" do
|
||||
expect { skip_conditions.print_skip_information(status_hashes[:cask][:disabled]) }
|
||||
.to output("test_disabled: disabled\n").to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
end
|
||||
end
|
||||
|
||||
@ -90,6 +90,12 @@
|
||||
"type": "naked"
|
||||
},
|
||||
"auto_updates": true,
|
||||
"deprecated": false,
|
||||
"deprecation_date": null,
|
||||
"deprecation_reason": null,
|
||||
"disabled": false,
|
||||
"disable_date": null,
|
||||
"disable_reason": null,
|
||||
"tap_git_head": null,
|
||||
"languages": [
|
||||
"en",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user