Skip to content

Commit

Permalink
Add tests and fix brew typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Rylan12 committed Dec 4, 2023
1 parent 052811e commit 961e6e4
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 15 deletions.
12 changes: 11 additions & 1 deletion Library/Homebrew/cask/cask.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
89 changes: 89 additions & 0 deletions Library/Homebrew/test/deprecate_disable_spec.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 0 additions & 11 deletions Library/Homebrew/test/formulary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,4 @@ def formula_json_contents(extra_items = {})
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
86 changes: 83 additions & 3 deletions Library/Homebrew/test/livecheck/skip_conditions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@
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
Expand Down Expand Up @@ -225,7 +247,21 @@
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,
},
Expand Down Expand Up @@ -330,6 +366,20 @@
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]))
Expand Down Expand Up @@ -428,7 +478,21 @@
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

Expand Down Expand Up @@ -537,7 +601,23 @@
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
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/test/support/fixtures/cask/everything.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 961e6e4

Please sign in to comment.