repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/livecheck/regex_parentheses_spec.rb
Library/Homebrew/test/rubocops/livecheck/regex_parentheses_spec.rb
# frozen_string_literal: true require "rubocops/livecheck" RSpec.describe RuboCop::Cop::FormulaAudit::LivecheckRegexParentheses do subject(:cop) { described_class.new } it "reports an offense when the `regex` call in the `livecheck` block does not use parentheses" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable regex %r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.t}i ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/LivecheckRegexParentheses: The `regex` call should always use parentheses. end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable regex(%r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.t}i) end end RUBY end it "reports no offenses when the `regex` call in the `livecheck` block uses parentheses" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable regex(%r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.t}i) end end RUBY end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/livecheck/url_symbol_spec.rb
Library/Homebrew/test/rubocops/livecheck/url_symbol_spec.rb
# frozen_string_literal: true require "rubocops/livecheck" RSpec.describe RuboCop::Cop::FormulaAudit::LivecheckUrlSymbol do subject(:cop) { described_class.new } it "reports an offense when the `url` specified in the `livecheck` block is identical to a formula URL" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url "https://brew.sh/foo-1.0.tgz" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/LivecheckUrlSymbol: Use `url :stable` end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable end end RUBY end it "reports no offenses when the `url` specified in the `livecheck` block is not identical to a formula URL" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url "https://brew.sh/foo/releases/" end end RUBY end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/livecheck/regex_case_insensitive_spec.rb
Library/Homebrew/test/rubocops/livecheck/regex_case_insensitive_spec.rb
# frozen_string_literal: true require "rubocops/livecheck" RSpec.describe RuboCop::Cop::FormulaAudit::LivecheckRegexCaseInsensitive do subject(:cop) { described_class.new } it "reports an offense when the `regex` is not case-insensitive" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable regex(%r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.t}) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/LivecheckRegexCaseInsensitive: Regexes should be case-insensitive unless sensitivity is explicitly required for proper matching. end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable regex(%r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.t}i) end end RUBY end it "reports no offenses when the `regex` is case-insensitive" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable regex(%r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.t}i) end end RUBY end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/livecheck/regex_if_page_match_spec.rb
Library/Homebrew/test/rubocops/livecheck/regex_if_page_match_spec.rb
# frozen_string_literal: true require "rubocops/livecheck" RSpec.describe RuboCop::Cop::FormulaAudit::LivecheckRegexIfPageMatch do subject(:cop) { described_class.new } it "reports an offense when there is no `regex` for `strategy :page_match`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do ^^^^^^^^^^^^ FormulaAudit/LivecheckRegexIfPageMatch: A `regex` is required if `strategy :page_match` is present. url :stable strategy :page_match end end RUBY end it "reports no offenses when a `regex` is specified for `strategy :page_match`" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable strategy :page_match regex(%r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.t}i) end end RUBY end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/livecheck/regex_extension_spec.rb
Library/Homebrew/test/rubocops/livecheck/regex_extension_spec.rb
# frozen_string_literal: true require "rubocops/livecheck" RSpec.describe RuboCop::Cop::FormulaAudit::LivecheckRegexExtension do subject(:cop) { described_class.new } it "reports an offense when the `regex` does not use `\\.t` for archive file extensions" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable regex(%r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.tgz}i) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/LivecheckRegexExtension: Use `\\.t` instead of `\\.tgz` end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable regex(%r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.t}i) end end RUBY end it "reports no offenses when the `regex` uses `\\.t` for archive file extensions" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable regex(%r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.t}i) end end RUBY end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/deprecate_disable/date_spec.rb
Library/Homebrew/test/rubocops/deprecate_disable/date_spec.rb
# frozen_string_literal: true require "rubocops/deprecate_disable" RSpec.describe RuboCop::Cop::FormulaAudit::DeprecateDisableDate do subject(:cop) { described_class.new } context "when auditing `deprecate!`" do it "reports and corrects an offense if `date` is not ISO 8601 compliant" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! date: "June 25, 2020" ^^^^^^^^^^^^^^^ FormulaAudit/DeprecateDisableDate: Use `2020-06-25` to comply with ISO 8601 end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! date: "2020-06-25" end RUBY end it "reports and corrects an offense if `date` is not ISO 8601 compliant (with `reason`)" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken", date: "June 25, 2020" ^^^^^^^^^^^^^^^ FormulaAudit/DeprecateDisableDate: Use `2020-06-25` to comply with ISO 8601 end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken", date: "2020-06-25" end RUBY end it "reports no offenses if `date` is ISO 8601 compliant" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! date: "2020-06-25" end RUBY end it "reports no offenses if `date` is ISO 8601 compliant (with `reason`)" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken", date: "2020-06-25" end RUBY end it "reports no offenses if no `date` is specified" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! end RUBY end it "reports no offenses if no `date` is specified (with `reason`)" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken" end RUBY end end context "when auditing `disable!`" do it "reports and corrects an offense if `date` is not ISO 8601 compliant" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! date: "June 25, 2020" ^^^^^^^^^^^^^^^ FormulaAudit/DeprecateDisableDate: Use `2020-06-25` to comply with ISO 8601 end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! date: "2020-06-25" end RUBY end it "reports and corrects an offense if `date` is not ISO 8601 compliant (with `reason`)" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken", date: "June 25, 2020" ^^^^^^^^^^^^^^^ FormulaAudit/DeprecateDisableDate: Use `2020-06-25` to comply with ISO 8601 end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken", date: "2020-06-25" end RUBY end it "reports no offenses if `date` is ISO 8601 compliant" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! date: "2020-06-25" end RUBY end it "reports no offenses if `date` is ISO 8601 compliant (with `reason`)" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken", date: "2020-06-25" end RUBY end it "reports no offenses if no `date` is specified" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! end RUBY end it "reports no offenses if no `date` is specified (with `reason`)" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken" end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/deprecate_disable/reason_spec.rb
Library/Homebrew/test/rubocops/deprecate_disable/reason_spec.rb
# frozen_string_literal: true require "rubocops/deprecate_disable" RSpec.describe RuboCop::Cop::FormulaAudit::DeprecateDisableReason do subject(:cop) { described_class.new } context "when auditing `deprecate!`" do it "reports no offenses if `reason` is acceptable" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken" end RUBY end it "reports no offenses if `reason` is acceptable as a symbol" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: :does_not_build end RUBY end it "reports no offenses if `reason` is acceptable (with `date`)" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! date: "2020-08-28", because: "is broken" end RUBY end it "reports no offenses if `reason` is acceptable as a symbol (with `date`)" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! date: "2020-08-28", because: :does_not_build end RUBY end it "reports an offense if `reason` is absent" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! ^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Add a reason for deprecation: `deprecate! because: "..."` end RUBY end it "reports an offense if `reason` is absent (with `date`)" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! date: "2020-08-28" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Add a reason for deprecation: `deprecate! because: "..."` end RUBY end it "reports and corrects an offense if `reason` starts with 'it'" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "it is broken" ^^^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not start the reason with `it` end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken" end RUBY end it "reports and corrects an offense if `reason` starts with 'it' (with `date`)" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! date: "2020-08-28", because: "it is broken" ^^^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not start the reason with `it` end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! date: "2020-08-28", because: "is broken" end RUBY end it "reports and corrects an offense if `reason` ends with a period" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken." ^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not end the reason with a punctuation mark end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken" end RUBY end it "reports and corrects an offense if `reason` ends with an exclamation point" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken!" ^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not end the reason with a punctuation mark end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken" end RUBY end it "reports and corrects an offense if `reason` ends with a question mark" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken?" ^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not end the reason with a punctuation mark end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! because: "is broken" end RUBY end it "reports and corrects an offense if `reason` ends with a period (with `date`)" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! date: "2020-08-28", because: "is broken." ^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not end the reason with a punctuation mark end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecate! date: "2020-08-28", because: "is broken" end RUBY end end context "when auditing `disable!`" do it "reports no offenses if `reason` is acceptable" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken" end RUBY end it "reports no offenses if `reason` is acceptable as a symbol" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: :does_not_build end RUBY end it "reports no offenses if `reason` is acceptable (with `date`)" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! date: "2020-08-28", because: "is broken" end RUBY end it "reports no offenses if `reason` is acceptable as a symbol (with `date`)" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! date: "2020-08-28", because: :does_not_build end RUBY end it "reports an offense if `reason` is absent" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! ^^^^^^^^ FormulaAudit/DeprecateDisableReason: Add a reason for disabling: `disable! because: "..."` end RUBY end it "reports an offense if `reason` is absent (with `date`)" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! date: "2020-08-28" ^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Add a reason for disabling: `disable! because: "..."` end RUBY end it "reports and corrects an offense if `reason` starts with 'it'" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "it is broken" ^^^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not start the reason with `it` end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken" end RUBY end it "reports and corrects an offense if `reason` starts with 'it' (with `date`)" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! date: "2020-08-28", because: "it is broken" ^^^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not start the reason with `it` end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! date: "2020-08-28", because: "is broken" end RUBY end it "reports and corrects an offense if `reason` ends with a period" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken." ^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not end the reason with a punctuation mark end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken" end RUBY end it "reports and corrects an offense if `reason` ends with an exclamation point" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken!" ^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not end the reason with a punctuation mark end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken" end RUBY end it "reports and corrects an offense if `reason` ends with a question mark" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken?" ^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not end the reason with a punctuation mark end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! because: "is broken" end RUBY end it "reports and corrects an offense if `reason` ends with a period (with `date`)" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! date: "2020-08-28", because: "is broken." ^^^^^^^^^^^^ FormulaAudit/DeprecateDisableReason: Do not end the reason with a punctuation mark end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! date: "2020-08-28", because: "is broken" end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/checksum/checksum_spec.rb
Library/Homebrew/test/rubocops/checksum/checksum_spec.rb
# frozen_string_literal: true require "rubocops/checksum" RSpec.describe RuboCop::Cop::FormulaAudit::Checksum do subject(:cop) { described_class.new } context "when auditing spec checksums" do it "reports an offense if a checksum is empty" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' stable do url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz" sha256 "" ^^ FormulaAudit/Checksum: `sha256` is empty resource "foo-package" do url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz" sha256 "" ^^ FormulaAudit/Checksum: `sha256` is empty end end end RUBY end it "reports an offense if a checksum is not 64 characters" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' stable do url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz" sha256 "5cf6e1ae0a645b426c0474cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9ad" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Checksum: `sha256` should be 64 characters resource "foo-package" do url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz" sha256 "5cf6e1ae0a645b426c047aaa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Checksum: `sha256` should be 64 characters end end end RUBY end it "reports an offense if a checksum contains invalid characters" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' stable do url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz" sha256 "5cf6e1ae0a645b426c0k7cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9a" ^ FormulaAudit/Checksum: `sha256` contains invalid characters resource "foo-package" do url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz" sha256 "5cf6e1ae0a645b426x047aa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea9" ^ FormulaAudit/Checksum: `sha256` contains invalid characters end end end RUBY end it "reports an offense if a checksum is not 64 characters in a bottle block without cellar" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' bottle do sha256 catalina: "5cf6e1ae0a645b426c0474cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9ad" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Checksum: `sha256` should be 64 characters end end RUBY end it "reports an offense if a checksum is not 64 characters in a bottle block" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' bottle do sha256 cellar: :any, catalina: "5cf6e1ae0a645b426c0474cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9ad" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Checksum: `sha256` should be 64 characters end end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/checksum/checksum_case_spec.rb
Library/Homebrew/test/rubocops/checksum/checksum_case_spec.rb
# frozen_string_literal: true require "rubocops/checksum" RSpec.describe RuboCop::Cop::FormulaAudit::ChecksumCase do subject(:cop) { described_class.new } context "when auditing spec checksums" do it "reports an offense if a checksum contains uppercase letters" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' stable do url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz" sha256 "5cf6e1ae0A645b426c0a7cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9a" ^ FormulaAudit/ChecksumCase: `sha256` should be lowercase resource "foo-package" do url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz" sha256 "5cf6e1Ae0a645b426b047aa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea9" ^ FormulaAudit/ChecksumCase: `sha256` should be lowercase end end end RUBY end it "reports and corrects an offense if a checksum outside a `stable` block contains uppercase letters" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' resource "foo-outside" do url "https://github.com/foo-lang/foo-outside/archive/0.18.0.tar.gz" sha256 "A4cc7cd3f7d1605ffa1ac5755cf6e1ae0a645b426b047a6a39a8b2268ddc7ea9" ^ FormulaAudit/ChecksumCase: `sha256` should be lowercase end stable do url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz" sha256 "5cf6e1ae0a645b426c0a7cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9a" resource "foo-package" do url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz" sha256 "5cf6e1ae0a645b426b047aa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea9" end end end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' resource "foo-outside" do url "https://github.com/foo-lang/foo-outside/archive/0.18.0.tar.gz" sha256 "a4cc7cd3f7d1605ffa1ac5755cf6e1ae0a645b426b047a6a39a8b2268ddc7ea9" end stable do url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz" sha256 "5cf6e1ae0a645b426c0a7cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9a" resource "foo-package" do url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz" sha256 "5cf6e1ae0a645b426b047aa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea9" end end end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/desc_spec.rb
Library/Homebrew/test/rubocops/cask/desc_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::Desc, :config do it "does not start with an article" do expect_no_offenses <<~RUBY cask "foo" do desc "Bar program" end RUBY expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foo' do desc 'A bar program' ^ Description shouldn't start with an article. end RUBY expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foo' do desc 'The bar program' ^^^ Description shouldn't start with an article. end RUBY expect_correction <<~RUBY cask 'foo' do desc 'Bar program' end RUBY end it "does not start with the cask name" do expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foobar' do desc 'Foo bar program' ^^^^^^^ Description shouldn't start with the cask name. end RUBY expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foobar' do desc 'Foo-Bar program' ^^^^^^^ Description shouldn't start with the cask name. end RUBY expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foo-bar' do desc 'Foo bar program' ^^^^^^^ Description shouldn't start with the cask name. end RUBY expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foo-bar' do desc 'Foo-Bar program' ^^^^^^^ Description shouldn't start with the cask name. end RUBY expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foo-bar' do desc 'Foo Bar' ^^^^^^^ Description shouldn't start with the cask name. end RUBY end it "does not contain the platform" do expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foo-bar' do desc 'macOS status bar monitor' ^^^^^ Description shouldn't contain the platform. end RUBY expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foo-bar' do desc 'Toggles dark mode on macOS Catalina' ^^^^^ Description shouldn't contain the platform. end RUBY expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foo-bar' do desc 'Better input source switcher for OS X' ^^^^ Description shouldn't contain the platform. end RUBY expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foo-bar' do desc 'Media Manager for Mac OS X' ^^^^^^^^ Description shouldn't contain the platform. end RUBY expect_no_offenses <<~RUBY cask 'foo' do desc 'Application for managing macOS virtual machines' end RUBY expect_offense <<~RUBY cask 'foo' do desc 'Application for managing macOS virtual machines on macOS' ^^^^^ Description shouldn't contain the platform. end RUBY expect_offense <<~RUBY cask 'foo' do desc 'Description with a 🍺 symbol' ^ Description shouldn't contain Unicode emojis or symbols. end RUBY expect_no_offenses <<~RUBY cask 'foo' do desc 'MAC address changer' end RUBY end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/on_system_conditionals_spec.rb
Library/Homebrew/test/rubocops/cask/on_system_conditionals_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::OnSystemConditionals, :config do context "when auditing `postflight` stanzas" do it "accepts when there are no `on_*` blocks" do expect_no_offenses <<~CASK cask 'foo' do postflight do foobar end end CASK end it "reports an offense it contains an `on_intel` block" do expect_offense <<~CASK cask 'foo' do postflight do on_intel do ^^^^^^^^ Instead of using `on_intel` in `postflight do`, use `if Hardware::CPU.intel?`. foobar end end end CASK # FIXME: Infinite loop alternating between `if Hardware::CPU.intel?` and `on_intel do`. expect_correction <<~CASK, loop: false cask 'foo' do postflight do if Hardware::CPU.intel? foobar end end end CASK end it "reports an offense when it contains an `on_monterey` block" do expect_offense <<~CASK cask 'foo' do postflight do on_monterey do ^^^^^^^^^^^ Instead of using `on_monterey` in `postflight do`, use `if MacOS.version == :monterey`. foobar end end end CASK # FIXME: Infinite loop alternating between `if MacOS.version == :monterey` and `on_monterey do`. expect_correction <<~CASK, loop: false cask 'foo' do postflight do if MacOS.version == :monterey foobar end end end CASK end it "reports an offense when it contains an `on_monterey :or_older` block" do expect_offense <<~CASK cask 'foo' do postflight do on_monterey :or_older do ^^^^^^^^^^^^^^^^^^^^^ Instead of using `on_monterey :or_older` in `postflight do`, use `if MacOS.version <= :monterey`. foobar end end end CASK # FIXME: Infinite loop alternating between `if MacOS.version <= :monterey` and `on_monterey :or_older do`. expect_correction <<~CASK, loop: false cask 'foo' do postflight do if MacOS.version <= :monterey foobar end end end CASK end end context "when auditing `sha256` stanzas inside `on_arch` blocks" do it "accepts when there are no `on_arch` blocks" do expect_no_offenses <<~CASK cask 'foo' do sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94" end CASK end it "accepts when the `sha256` stanza is used with keyword arguments" do expect_no_offenses <<~CASK cask 'foo' do sha256 arm: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94", intel: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" end CASK end it "reports an offense when `sha256` has identical values for different architectures" do expect_offense <<~CASK cask 'foo' do sha256 arm: "5f42cb017dd07270409eaee7c3b4a164ffa7c0f21d85c65840c4f81aab21d457", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sha256 values for different architectures should not be identical. intel: "5f42cb017dd07270409eaee7c3b4a164ffa7c0f21d85c65840c4f81aab21d457" end CASK end it "accepts when there is only one `on_arch` block" do expect_no_offenses <<~CASK cask 'foo' do on_intel do sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94" end end CASK end it "reports an offense when `sha256` is specified in all `on_arch` blocks" do expect_offense <<~CASK cask 'foo' do on_intel do sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94" end on_arm do ^^^^^^^^^ Use `sha256 arm: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b", intel: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"` instead of nesting the `sha256` stanzas in `on_intel` and `on_arm` blocks sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" end end CASK expect_correction <<~CASK cask 'foo' do #{" "} sha256 arm: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b", intel: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94" end CASK end it "accepts when there is also a `version` stanza inside the `on_arch` blocks" do expect_no_offenses <<~CASK cask 'foo' do on_intel do version "1.0.0" sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94" end on_arm do version "2.0.0" sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" end end CASK end it "accepts when there is also a `version` stanza inside only a single `on_arch` block" do expect_no_offenses <<~CASK cask 'foo' do on_intel do version "2.0.0" sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94" end on_arm do sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" end end CASK end end context "when auditing loose `Hardware::CPU` method calls" do it "reports an offense when `Hardware::CPU.arm?` is used" do expect_offense <<~CASK cask 'foo' do if Hardware::CPU.arm? && other_condition ^^^^^^^^^^^^^^^^^^ Instead of `Hardware::CPU.arm?`, use `on_arm` and `on_intel` blocks. sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94" else sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" end end CASK end it "reports an offense when `Hardware::CPU.intel?` is used" do expect_offense <<~CASK cask 'foo' do if Hardware::CPU.intel? && other_condition ^^^^^^^^^^^^^^^^^^^^ Instead of `Hardware::CPU.intel?`, use `on_arm` and `on_intel` blocks. sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94" else sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" end end CASK end it "reports an offense when `Hardware::CPU.arch` is used" do expect_offense <<~'CASK' cask 'foo' do version "1.2.3" sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94" url "https://example.com/foo-#{version}-#{Hardware::CPU.arch}.zip" ^^^^^^^^^^^^^^^^^^ Instead of `Hardware::CPU.arch`, use `on_arm` and `on_intel` blocks. end CASK end end context "when auditing loose `MacOS.version` method calls" do it "reports an offense when `MacOS.version ==` is used" do expect_offense <<~CASK cask 'foo' do if MacOS.version == :catalina ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Instead of `if MacOS.version == :catalina`, use `on_catalina do`. version "1.0.0" else version "2.0.0" end end CASK end it "reports an offense when `MacOS.version <=` is used" do expect_offense <<~CASK cask 'foo' do if MacOS.version <= :catalina ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Instead of `if MacOS.version <= :catalina`, use `on_catalina :or_older do`. version "1.0.0" else version "2.0.0" end end CASK end it "reports an offense when `MacOS.version >=` is used" do expect_offense <<~CASK cask 'foo' do if MacOS.version >= :catalina ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Instead of `if MacOS.version >= :catalina`, use `on_catalina :or_newer do`. version "1.0.0" else version "2.0.0" end end CASK end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/uninstall_methods_order_spec.rb
Library/Homebrew/test/rubocops/cask/uninstall_methods_order_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::UninstallMethodsOrder, :config do context "with uninstall blocks" do context "when methods are incorrectly ordered" do it "detects and corrects ordering offenses in the uninstall block when each method contains a single item" do expect_offense(<<~CASK) cask 'foo' do uninstall quit: "com.example.foo", ^^^^ `quit` method out of order launchctl: "com.example.foo" ^^^^^^^^^ `launchctl` method out of order end CASK expect_correction(<<~CASK) cask 'foo' do uninstall launchctl: "com.example.foo", quit: "com.example.foo" end CASK end it "detects and corrects ordering offenses in the uninstall block when methods contain arrays" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall delete: [ ^^^^^^ `delete` method out of order "/usr/local/bin/foo", "/usr/local/bin/foobar", ], script: { ^^^^^^ `script` method out of order executable: "/usr/local/bin/foo", sudo: false, }, pkgutil: "org.foo.bar" ^^^^^^^ `pkgutil` method out of order end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall script: { executable: "/usr/local/bin/foo", sudo: false, }, pkgutil: "org.foo.bar", delete: [ "/usr/local/bin/foo", "/usr/local/bin/foobar", ] end CASK end end context "when methods are correctly ordered" do it "does not report an offense" do expect_no_offenses(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall script: { executable: "/usr/local/bin/foo", sudo: false, }, pkgutil: "org.foo.bar", delete: [ "/usr/local/bin/foo", "/usr/local/bin/foobar", ] end CASK end context "when methods are correctly ordered and on_upgrade is present" do it "ignores on_upgrade when checking method order" do expect_no_offenses(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall quit: "com.example.foo", signal: ["TERM", "com.example.foo"], on_upgrade: [:quit, :signal], script: { executable: "/usr/local/bin/foo", sudo: false, }, pkgutil: "org.foo.bar", delete: [ "/usr/local/bin/foo", "/usr/local/bin/foobar", ] end CASK end end context "when on_upgrade is fully useless (no quit: or signal:)" do it "registers offense and autocorrects to remove on_upgrade when 1 other key exists" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall pkgutil: "org.foo.bar", on_upgrade: :quit ^^^^^^^^^^ `on_upgrade` has no effect without matching `uninstall quit:` or `uninstall signal:` directives end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall pkgutil: "org.foo.bar" end CASK end end it "registers offense and autocorrects to remove on_upgrade when between other keys" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall login_item: "FooApp", on_upgrade: :quit, ^^^^^^^^^^ `on_upgrade` has no effect without matching `uninstall quit:` or `uninstall signal:` directives pkgutil: "org.foo.bar" end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall login_item: "FooApp", pkgutil: "org.foo.bar" end CASK end end it "registers offense but does not autocorrect when on_upgrade is the only key" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall on_upgrade: :quit ^^^^^^^^^^ `on_upgrade` has no effect without matching `uninstall quit:` or `uninstall signal:` directives end CASK end context "when only on_upgrade is present" do it "registers offense but does not autocorrect" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall on_upgrade: :quit ^^^^^^^^^^ `on_upgrade` has no effect without matching `uninstall quit:` or `uninstall signal:` directives end CASK end end context "when on_upgrade includes symbols without matching directives" do it "registers offense on the value but does not autocorrect" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall quit: "com.example.foo", on_upgrade: [:quit, :signal] ^^^^^^^^^^^^^^^^ `on_upgrade` lists :signal without matching `uninstall` directives end CASK end end context "when on_upgrade matches available directives (quit: or signal:)" do it "does not register offense for :quit, :signal, or [:quit, :signal]" do expect_no_offenses(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall quit: "com.example.app", on_upgrade: :quit end CASK expect_no_offenses(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall signal: [["TERM", "com.example.app"]], on_upgrade: :signal end CASK expect_no_offenses(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall quit: "com.example.foo", signal: ["TERM", "com.example.foo"], on_upgrade: [:quit, :signal] end CASK end end context "with a single method" do it "does not report an offense when a single item is present in the method" do expect_no_offenses(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall delete: "/usr/local/bin/foo" end CASK end it "does not report an offense when the method contains an array" do expect_no_offenses(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall pkgutil: [ "org.foo.bar", "org.foobar.bar", ] end CASK end end end context "with zap blocks" do context "when methods are incorrectly ordered" do it "detects and corrects ordering offenses in the zap block when each method contains a single item" do expect_offense(<<~CASK) cask 'foo' do zap rmdir: "/Library/Foo", ^^^^^ `rmdir` method out of order trash: "com.example.foo" ^^^^^ `trash` method out of order end CASK expect_correction(<<~CASK) cask 'foo' do zap trash: "com.example.foo", rmdir: "/Library/Foo" end CASK end it "detects and corrects ordering offenses in the zap block when methods contain arrays" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap delete: [ "~/Library/Application Support/Foo", "~/Library/Application Support/Bar", ], rmdir: "~/Library/Application Support", ^^^^^ `rmdir` method out of order trash: "~/Library/Application Support/FooBar" ^^^^^ `trash` method out of order end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap delete: [ "~/Library/Application Support/Foo", "~/Library/Application Support/Bar", ], trash: "~/Library/Application Support/FooBar", rmdir: "~/Library/Application Support" end CASK end end context "when methods are correctly ordered" do it "does not report an offense" do expect_no_offenses(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap delete: [ "~/Library/Application Support/Bar", "~/Library/Application Support/Foo", ], trash: "~/Library/Application Support/FooBar", rmdir: "~/Library/Application Support" end CASK end end context "with a single method" do it "does not report an offense when a single item is present in the method" do expect_no_offenses(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: "~/Library/Application Support/FooBar" end CASK end it "does not report an offense when the method contains an array" do expect_no_offenses(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: [ "~/Library/Application Support/FooBar", "~/Library/Application Support/FooBarBar", ] end CASK end end end context "with both uninstall and zap blocks" do context "when both uninstall and zap methods are incorrectly ordered" do it "detects offenses and auto-corrects to the correct order" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall delete: [ ^^^^^^ `delete` method out of order "/usr/local/bin/foo", "/usr/local/bin/foobar", ], script: { ^^^^^^ `script` method out of order executable: "/usr/local/bin/foo", sudo: false, }, pkgutil: "org.foo.bar" ^^^^^^^ `pkgutil` method out of order zap delete: [ "~/Library/Application Support/Bar", "~/Library/Application Support/Foo", ], rmdir: "~/Library/Application Support", ^^^^^ `rmdir` method out of order trash: "~/Library/Application Support/FooBar" ^^^^^ `trash` method out of order end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall script: { executable: "/usr/local/bin/foo", sudo: false, }, pkgutil: "org.foo.bar", delete: [ "/usr/local/bin/foo", "/usr/local/bin/foobar", ] zap delete: [ "~/Library/Application Support/Bar", "~/Library/Application Support/Foo", ], trash: "~/Library/Application Support/FooBar", rmdir: "~/Library/Application Support" end CASK end end context "when uninstall and zap methods are correctly ordered" do it "does not report an offense" do expect_no_offenses(<<~CASK) cask 'foo' do uninstall early_script: { executable: "foo.sh", args: ["--unattended"], }, launchctl: "com.example.foo", quit: "com.example.foo", signal: ["TERM", "com.example.foo"], login_item: "FooApp", kext: "com.example.foo", script: { executable: "foo.sh", args: ["--unattended"], }, pkgutil: "com.example.foo", delete: "~/Library/Preferences/com.example.foo", trash: "~/Library/Preferences/com.example.foo", rmdir: "~/Library/Foo" zap early_script: { executable: "foo.sh", args: ["--unattended"], }, launchctl: "com.example.foo", quit: "com.example.foo", signal: ["TERM", "com.example.foo"], login_item: "FooApp", kext: "com.example.foo", script: { executable: "foo.sh", args: ["--unattended"], }, pkgutil: "com.example.foo", delete: "~/Library/Preferences/com.example.foo", trash: "~/Library/Preferences/com.example.foo", rmdir: "~/Library/Foo" end CASK end end end context "when in-line comments are present" do it "keeps associated comments when auto-correcting" do expect_offense <<~CASK cask 'foo' do uninstall quit: "com.example.foo", # comment on same line ^^^^ `quit` method out of order launchctl: "com.example.foo" ^^^^^^^^^ `launchctl` method out of order end CASK expect_correction <<~CASK cask 'foo' do uninstall launchctl: "com.example.foo", quit: "com.example.foo" # comment on same line end CASK end end context "when methods are inside an `on_os` block" do it "detects and corrects offenses within OS-specific blocks" do expect_offense <<~CASK cask "foo" do on_catalina do uninstall trash: "com.example.foo", ^^^^^ `trash` method out of order launchctl: "com.example.foo" ^^^^^^^^^ `launchctl` method out of order end on_ventura do uninstall quit: "com.example.foo", ^^^^ `quit` method out of order launchctl: "com.example.foo" ^^^^^^^^^ `launchctl` method out of order end end CASK expect_correction <<~CASK cask "foo" do on_catalina do uninstall launchctl: "com.example.foo", trash: "com.example.foo" end on_ventura do uninstall launchctl: "com.example.foo", quit: "com.example.foo" end end CASK end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/shared_filelist_glob_spec.rb
Library/Homebrew/test/rubocops/cask/shared_filelist_glob_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::SharedFilelistGlob, :config do it "reports an offense when a zap trash array includes an .sfl2 or .sfl3 file" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: ["~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/org.mozilla.firefox.sfl2"] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a glob (*) instead of a specific version (ie. sfl2) for trashing Shared File List paths end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: ["~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/org.mozilla.firefox.sfl*"] end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/discontinued_spec.rb
Library/Homebrew/test/rubocops/cask/discontinued_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::Discontinued, :config do it "reports no offenses when there is no `caveats` stanza" do expect_no_offenses <<~CASK cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg", verified: "example.com/download/" end CASK end it "reports no offenses when there is a `caveats` stanza without `discontinued`" do expect_no_offenses <<~CASK cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg", verified: "example.com/download/" caveats do files_in_usr_local end end CASK end it "reports an offense when there is a `caveats` stanza with `discontinued` and other caveats" do expect_offense <<~CASK cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg", verified: "example.com/download/" caveats do discontinued ^^^^^^^^^^^^ Use `deprecate!` instead of `caveats { discontinued }`. files_in_usr_local end end CASK end it "corrects `caveats { discontinued }` to `deprecate!`" do expect_offense <<~CASK cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg", verified: "example.com/download/" caveats do ^^^^^^^^^^ Use `deprecate!` instead of `caveats { discontinued }`. discontinued end end CASK expect_correction <<~CASK cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg", verified: "example.com/download/" deprecate! date: "#{Date.today}", because: :discontinued end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/homepage_url_styling_spec.rb
Library/Homebrew/test/rubocops/cask/homepage_url_styling_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::HomepageUrlStyling, :config do it "accepts a homepage URL ending with a slash" do expect_no_offenses <<~CASK cask 'foo' do homepage 'https://foo.brew.sh/' end CASK end it "accepts a homepage URL with a path" do expect_no_offenses <<~CASK cask 'foo' do homepage 'https://foo.brew.sh/path' end CASK end it "reports an offense when the homepage URL does not end with a slash and has no path" do expect_offense <<~CASK cask 'foo' do homepage 'https://foo.brew.sh' ^^^^^^^^^^^^^^^^^^^^^ 'https://foo.brew.sh' must have a slash after the domain. end CASK expect_correction <<~CASK cask 'foo' do homepage 'https://foo.brew.sh/' end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/stanza_order_spec.rb
Library/Homebrew/test/rubocops/cask/stanza_order_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::StanzaOrder, :config do it "accepts a sole stanza" do expect_no_offenses <<~CASK cask 'foo' do version :latest end CASK end it "accepts when all stanzas are in order" do expect_no_offenses <<~CASK cask 'foo' do arch arm: "arm", intel: "x86_64" folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" version :latest sha256 :no_check foo = "bar" end CASK end it "reports an offense when stanzas are out of order" do expect_offense <<~CASK cask 'foo' do sha256 :no_check ^^^^^^^^^^^^^^^^ `sha256` stanza out of order version :latest ^^^^^^^^^^^^^^^ `version` stanza out of order end CASK expect_correction <<~CASK cask 'foo' do version :latest sha256 :no_check end CASK end it "reports an offense when an `arch` stanza is out of order" do expect_offense <<~CASK cask 'foo' do os macos: ">= :big_sur" ^^^^^^^^^^^^^^^^^^^^^^^ `os` stanza out of order version :latest ^^^^^^^^^^^^^^^ `version` stanza out of order sha256 :no_check ^^^^^^^^^^^^^^^^ `sha256` stanza out of order arch arm: "arm", intel: "x86_64" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `arch` stanza out of order end CASK expect_correction <<~CASK cask 'foo' do arch arm: "arm", intel: "x86_64" os macos: ">= :big_sur" version :latest sha256 :no_check end CASK end it "reports an offense when an `on_arch_conditional` variable assignment is out of order" do expect_offense <<~CASK cask 'foo' do arch arm: "arm", intel: "x86_64" sha256 :no_check ^^^^^^^^^^^^^^^^ `sha256` stanza out of order version :latest folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `on_arch_conditional` stanza out of order end CASK expect_correction <<~CASK cask 'foo' do arch arm: "arm", intel: "x86_64" folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" version :latest sha256 :no_check end CASK end it "reports an offense when an `on_arch_conditional` variable assignment is above an `arch` stanza" do expect_offense <<~CASK cask 'foo' do folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `on_arch_conditional` stanza out of order arch arm: "arm", intel: "x86_64" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `arch` stanza out of order version :latest sha256 :no_check end CASK expect_correction <<~CASK cask 'foo' do arch arm: "arm", intel: "x86_64" folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" version :latest sha256 :no_check end CASK end it "reports an offense when multiple stanzas are out of order" do expect_offense <<~CASK cask 'foo' do url 'https://foo.brew.sh/foo.zip' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `url` stanza out of order uninstall :quit => 'com.example.foo', ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `uninstall` stanza out of order :kext => 'com.example.foo.kext' version :latest ^^^^^^^^^^^^^^^ `version` stanza out of order app 'Foo.app' sha256 :no_check ^^^^^^^^^^^^^^^^ `sha256` stanza out of order end CASK expect_correction <<~CASK cask 'foo' do version :latest sha256 :no_check url 'https://foo.brew.sh/foo.zip' app 'Foo.app' uninstall :quit => 'com.example.foo', :kext => 'com.example.foo.kext' end CASK end it "does not reorder multiple stanzas of the same type" do expect_offense <<~CASK cask 'foo' do name 'Foo' ^^^^^^^^^^ `name` stanza out of order url 'https://foo.brew.sh/foo.zip' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `url` stanza out of order name 'FancyFoo' ^^^^^^^^^^^^^^^ `name` stanza out of order version :latest ^^^^^^^^^^^^^^^ `version` stanza out of order app 'Foo.app' ^^^^^^^^^^^^^ `app` stanza out of order sha256 :no_check ^^^^^^^^^^^^^^^^ `sha256` stanza out of order name 'FunkyFoo' ^^^^^^^^^^^^^^^ `name` stanza out of order end CASK expect_correction <<~CASK cask 'foo' do version :latest sha256 :no_check url 'https://foo.brew.sh/foo.zip' name 'Foo' name 'FancyFoo' name 'FunkyFoo' app 'Foo.app' end CASK end it "keeps associated comments when auto-correcting" do expect_offense <<~CASK cask 'foo' do version :latest # comment with an empty line between # comment directly above postflight do ^^^^^^^^^^^^^ `postflight` stanza out of order puts 'We have liftoff!' end sha256 :no_check # comment on same line ^^^^^^^^^^^^^^^^ `sha256` stanza out of order end CASK expect_correction <<~CASK, loop: false cask 'foo' do version :latest sha256 :no_check # comment on same line # comment with an empty line between # comment directly above postflight do puts 'We have liftoff!' end end CASK end it "reports an offense when an `on_arch_conditional` variable assignment with a comment is out of order" do expect_offense <<~CASK cask 'foo' do version :latest ^^^^^^^^^^^^^^^ `version` stanza out of order sha256 :no_check ^^^^^^^^^^^^^^^^ `sha256` stanza out of order # comment with an empty line between # comment directly above postflight do ^^^^^^^^^^^^^ `postflight` stanza out of order puts 'We have liftoff!' end folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" # comment on same line ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `on_arch_conditional` stanza out of order end CASK expect_correction <<~CASK cask 'foo' do folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" # comment on same line version :latest sha256 :no_check # comment with an empty line between # comment directly above postflight do puts 'We have liftoff!' end end CASK end shared_examples "caveats" do it "reports an offense when a `caveats` stanza is out of order" do # Indent all except the first line. interpolated_caveats = caveats.lines.map { |l| " #{l}" }.join.strip expect_offense <<~CASK cask 'foo' do name 'Foo' ^^^^^^^^^^ `name` stanza out of order url 'https://foo.brew.sh/foo.zip' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `url` stanza out of order #{interpolated_caveats} version :latest ^^^^^^^^^^^^^^^ `version` stanza out of order app 'Foo.app' sha256 :no_check ^^^^^^^^^^^^^^^^ `sha256` stanza out of order end CASK # Remove offense annotations. corrected_caveats = interpolated_caveats.gsub(/\n\s*\^+\s+.*$/, "") expect_correction <<~CASK cask 'foo' do version :latest sha256 :no_check url 'https://foo.brew.sh/foo.zip' name 'Foo' app 'Foo.app' #{corrected_caveats} end CASK end end context "when caveats is a one-line string" do let(:caveats) do <<~CAVEATS caveats 'This is a one-line caveat.' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `caveats` stanza out of order CAVEATS end include_examples "caveats" end context "when caveats is a heredoc" do let(:caveats) do <<~CAVEATS caveats <<~EOS ^^^^^^^^^^^^^^ `caveats` stanza out of order This is a multiline caveat. Let's hope it doesn't cause any problems! EOS CAVEATS end include_examples "caveats" end context "when caveats is a block" do let(:caveats) do <<~CAVEATS caveats do ^^^^^^^^^^ `caveats` stanza out of order puts 'This is a multiline caveat.' puts "Let's hope it doesn't cause any problems!" end CAVEATS end include_examples "caveats" end it "reports an offense when the `postflight` stanza is out of order" do expect_offense <<~CASK cask 'foo' do name 'Foo' ^^^^^^^^^^ `name` stanza out of order url 'https://foo.brew.sh/foo.zip' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `url` stanza out of order postflight do ^^^^^^^^^^^^^ `postflight` stanza out of order puts 'We have liftoff!' end version :latest ^^^^^^^^^^^^^^^ `version` stanza out of order app 'Foo.app' sha256 :no_check ^^^^^^^^^^^^^^^^ `sha256` stanza out of order end CASK expect_correction <<~CASK cask 'foo' do version :latest sha256 :no_check url 'https://foo.brew.sh/foo.zip' name 'Foo' app 'Foo.app' postflight do puts 'We have liftoff!' end end CASK end it "supports `on_arch` blocks and their contents" do expect_offense <<~CASK cask 'foo' do on_intel do ^^^^^^^^^^^ `on_intel` stanza out of order url "https://foo.brew.sh/foo-intel.zip" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `url` stanza out of order version :latest ^^^^^^^^^^^^^^^ `version` stanza out of order sha256 :no_check ^^^^^^^^^^^^^^^^ `sha256` stanza out of order end on_arm do ^^^^^^^^^ `on_arm` stanza out of order version :latest sha256 :no_check url "https://foo.brew.sh/foo-arm.zip" end end CASK expect_correction <<~CASK cask 'foo' do on_arm do version :latest sha256 :no_check url "https://foo.brew.sh/foo-arm.zip" end on_intel do version :latest sha256 :no_check url "https://foo.brew.sh/foo-intel.zip" end end CASK end it "registers an offense when `on_os` stanzas and their contents are out of order" do expect_offense <<~CASK cask "foo" do on_ventura do ^^^^^^^^^^^^^ `on_ventura` stanza out of order sha256 "abc123" ^^^^^^^^^^^^^^^ `sha256` stanza out of order version :latest ^^^^^^^^^^^^^^^ `version` stanza out of order url "https://foo.brew.sh/foo-ventura.zip" end on_catalina do ^^^^^^^^^^^^^^ `on_catalina` stanza out of order sha256 "def456" ^^^^^^^^^^^^^^^ `sha256` stanza out of order version "0.7" ^^^^^^^^^^^^^ `version` stanza out of order url "https://foo.brew.sh/foo-catalina.zip" end on_sequoia do ^^^^^^^^^^^^^ `on_sequoia` stanza out of order version :latest sha256 "ghi789" url "https://foo.brew.sh/foo-sequoia.zip" end on_big_sur do ^^^^^^^^^^^^^ `on_big_sur` stanza out of order sha256 "jkl012" ^^^^^^^^^^^^^^^ `sha256` stanza out of order version :latest ^^^^^^^^^^^^^^^ `version` stanza out of order url "https://foo.brew.sh/foo-big-sur.zip" end end CASK expect_correction <<~CASK cask "foo" do on_catalina do version "0.7" sha256 "def456" url "https://foo.brew.sh/foo-catalina.zip" end on_big_sur do version :latest sha256 "jkl012" url "https://foo.brew.sh/foo-big-sur.zip" end on_ventura do version :latest sha256 "abc123" url "https://foo.brew.sh/foo-ventura.zip" end on_sequoia do version :latest sha256 "ghi789" url "https://foo.brew.sh/foo-sequoia.zip" end end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/variables_spec.rb
Library/Homebrew/test/rubocops/cask/variables_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::Variables, :config do it "accepts when there are no variables" do expect_no_offenses <<~CASK cask "foo" do version :latest end CASK end it "accepts when there is an `arch` stanza" do expect_no_offenses <<~CASK cask "foo" do arch arm: "darwin-arm64", intel: "darwin" end CASK end it "accepts an `on_arch_conditional` variable" do expect_no_offenses <<~CASK cask "foo" do folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" end CASK end it "reports an offense for an `arch` variable using strings" do expect_offense <<~CASK cask 'foo' do arch = Hardware::CPU.intel? ? "darwin" : "darwin-arm64" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `arch arm: "darwin-arm64", intel: "darwin"` instead of `arch = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"`. end CASK expect_correction <<~CASK cask 'foo' do arch arm: "darwin-arm64", intel: "darwin" end CASK end it "reports an offense for an `arch` variable using symbols" do expect_offense <<~CASK cask 'foo' do arch = Hardware::CPU.intel? ? :darwin : :darwin_arm64 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `arch arm: :darwin_arm64, intel: :darwin` instead of `arch = Hardware::CPU.intel? ? :darwin : :darwin_arm64`. end CASK expect_correction <<~CASK cask 'foo' do arch arm: :darwin_arm64, intel: :darwin end CASK end it "reports an offense for an `arch` variable with an empty string" do expect_offense <<~CASK cask 'foo' do arch = Hardware::CPU.intel? ? "" : "arm64" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `arch arm: "arm64"` instead of `arch = Hardware::CPU.intel? ? "" : "arm64"`. end CASK expect_correction <<~CASK cask 'foo' do arch arm: "arm64" end CASK end it "reports an offense for a non-`arch` variable using strings" do expect_offense <<~CASK cask 'foo' do folder = Hardware::CPU.intel? ? "darwin" : "darwin-arm64" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` instead of `folder = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"`. end CASK expect_correction <<~CASK cask 'foo' do folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" end CASK end it "reports an offense for a non-`arch` variable with an empty string" do expect_offense <<~CASK cask 'foo' do folder = Hardware::CPU.intel? ? "amd64" : "" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `folder = on_arch_conditional intel: "amd64"` instead of `folder = Hardware::CPU.intel? ? "amd64" : ""`. end CASK expect_correction <<~CASK cask 'foo' do folder = on_arch_conditional intel: "amd64" end CASK end it "reports an offense for consecutive `arch` and non-`arch` variables" do expect_offense <<~CASK cask 'foo' do arch = Hardware::CPU.arm? ? "darwin-arm64" : "darwin" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `arch arm: "darwin-arm64", intel: "darwin"` instead of `arch = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"`. folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` instead of `folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"`. end CASK expect_correction <<~CASK cask 'foo' do arch arm: "darwin-arm64", intel: "darwin" folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" end CASK end it "reports an offense for two consecutive non-`arch` variables" do expect_offense <<~CASK cask 'foo' do folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` instead of `folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"`. platform = Hardware::CPU.intel? ? "darwin": "darwin-arm64" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` instead of `platform = Hardware::CPU.intel? ? "darwin": "darwin-arm64"`. end CASK expect_correction <<~CASK cask 'foo' do folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin" end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/url_spec.rb
Library/Homebrew/test/rubocops/cask/url_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::Url, :config do it "allows regular `url` blocks in homebrew-cask" do expect_no_offenses <<~CASK, "/homebrew-cask/Casks/f/foo.rb" cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg", verified: "example.com/download/" end CASK end it "does not allow `url do` blocks in homebrew-cask" do expect_offense <<~CASK, "/homebrew-cask/Casks/f/foo.rb" cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg" do |url| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `url "..." do` blocks in Homebrew/homebrew-cask. url end end CASK end it "allows regular `url` blocks in a non-homebrew-cask tap" do expect_no_offenses <<~CASK, "/homebrew-tap/Casks/f/foo.rb" cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg", verified: "example.com/download/" end CASK end it "allows `url do` blocks in a non-homebrew-cask tap" do expect_no_offenses <<~CASK, "/homebrew-tap/Casks/f/foo.rb" cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg" do |url| url end end CASK end it "accepts a `verified` value that does not start with a protocol" do expect_no_offenses <<~CASK cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg", verified: "example.com/download/" end CASK end it "reports an offense for a `verified` value that starts with a protocol" do expect_offense <<~CASK cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg", verified: "https://example.com/download/" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Verified URL parameter value should not contain a URL scheme. end CASK expect_correction <<~CASK cask "foo" do url "https://example.com/download/foo-v1.2.0.dmg", verified: "example.com/download/" end CASK end context "when then URL does not have a path and ends with a /" do it "accepts a `verified` value ending with a /" do expect_no_offenses <<~CASK cask "foo" do url "https://example.org/", verified: "example.org/" end CASK end it "reports an offense for a `verified` value not ending a /" do expect_offense <<~CASK cask "foo" do url "https://example.org/", verified: "example.org" ^^^^^^^^^^^^^ Verified URL parameter value should end with a /. end CASK expect_correction <<~CASK cask "foo" do url "https://example.org/", verified: "example.org/" end CASK end end context "when the URL has a path and does not end with a /" do it "accepts a `verified` value with one path component" do expect_no_offenses <<~CASK cask "foo" do url "https://github.com/Foo", verified: "github.com/Foo" end CASK end it "accepts a `verified` value with two path components" do expect_no_offenses <<~CASK cask "foo" do url "https://github.com/foo/foo.git", verified: "github.com/foo/foo" end CASK end end context "when the url ends with a /" do it "accepts a `verified` value ending with a /" do expect_no_offenses <<~CASK cask "foo" do url "https://github.com/", verified: "github.com/" end CASK end it "reports an offense for a `verified` value not ending with a /" do expect_offense <<~CASK cask "foo" do url "https://github.com/", verified: "github.com" ^^^^^^^^^^^^ Verified URL parameter value should end with a /. end CASK expect_correction <<~CASK cask "foo" do url "https://github.com/", verified: "github.com/" end CASK end end it "accepts a `verified` value with a path ending with a /" do expect_no_offenses <<~CASK cask "foo" do url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg", verified: "github.com/Foo/foo/" end CASK end context "when the URL uses interpolation" do it "accepts a `verified` value with a path ending with a /" do expect_no_offenses <<~CASK cask "foo" do version "1.2.3" url "Cask/Url: https://example.com/download/foo-v\#{version}.dmg", verified: "example.com/download/" end CASK end end it "reports an offense for a `verified` value with a path component that doesn't end with a /" do expect_offense <<~CASK cask "foo" do url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg", verified: "github.com/Foo/foo" ^^^^^^^^^^^^^^^^^^^^ Verified URL parameter value should end with a /. end CASK expect_correction <<~CASK cask "foo" do url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg", verified: "github.com/Foo/foo/" end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb
Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do it "reports an offense when a single `zap trash` path is specified in an array" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: ["~/Library/Application Support/Foo"] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid single-element arrays by removing the [] end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: "~/Library/Application Support/Foo" end CASK end it "reports an offense when the `zap` stanza paths are not in alphabetical order" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: [ ^ The array elements should be ordered alphabetically "/Library/Application Support/Foo", "/Library/Application Support/Baz", "~/Library/Application Support/Foo", "~/.dotfiles/thing", "~/Library/Application Support/Bar", ], rmdir: [ ^ The array elements should be ordered alphabetically "/Applications/foo/nested/blah", "/Applications/foo/", ] end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: [ "/Library/Application Support/Baz", "/Library/Application Support/Foo", "~/.dotfiles/thing", "~/Library/Application Support/Bar", "~/Library/Application Support/Foo", ], rmdir: [ "/Applications/foo/", "/Applications/foo/nested/blah", ] end CASK end it "autocorrects alphabetization in zap trash paths with interpolation" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: [ ^ The array elements should be ordered alphabetically "~/Library/Application Support/Foo", "~/Library/Application Support/Bar\#{version.major}", ] end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: [ "~/Library/Application Support/Bar\#{version.major}", "~/Library/Application Support/Foo", ] end CASK end it "reports an offense when a single cask is specified in an array" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" conflicts_with cask: ["bar"] ^^^^^^^ Avoid single-element arrays by removing the [] end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" conflicts_with cask: "bar" end CASK end it "reports an offense when a single cask is specified in a multi-line array" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" conflicts_with cask: [ ^ Avoid single-element arrays by removing the [] "bar" ] end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" conflicts_with cask: "bar" end CASK end it "autocorrects alphabetization in `conflicts_with` methods" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" conflicts_with cask: [ ^ The array elements should be ordered alphabetically "something", "other", ] end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" conflicts_with cask: [ "other", "something", ] end CASK end it "autocorrects alphabetization in `uninstall` methods" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall pkgutil: [ ^ The array elements should be ordered alphabetically "something", "other", ], script: [ "ordered", "differently", ] end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall pkgutil: [ "other", "something", ], script: [ "ordered", "differently", ] end CASK end it "ignores `uninstall` methods with commands" do expect_no_offenses(<<~CASK) cask "foo" do url "https://example.com/foo.zip" uninstall script: { args: ["--mode=something", "--another-mode"], executable: "thing", } end CASK end it "moves comments when autocorrecting" do expect_offense(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: [ ^ The array elements should be ordered alphabetically # comment related to foo "~/Library/Application Support/Foo", # a really long comment related to Zoo # and the Zoo comment continues "~/Library/Application Support/Zoo", "~/Library/Application Support/Bar", "~/Library/Application Support/Baz", # in-line comment ] end CASK expect_correction(<<~CASK) cask "foo" do url "https://example.com/foo.zip" zap trash: [ "~/Library/Application Support/Bar", "~/Library/Application Support/Baz", # in-line comment # comment related to foo "~/Library/Application Support/Foo", # a really long comment related to Zoo # and the Zoo comment continues "~/Library/Application Support/Zoo", ] end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/deprecate_disable_unsigned_reason_spec.rb
Library/Homebrew/test/rubocops/cask/deprecate_disable_unsigned_reason_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::DeprecateDisableUnsignedReason, :config do it "flags and autocorrects deprecate! with :unsigned" do expect_offense <<~CASK cask "foo" do deprecate! date: "2024-01-01", because: :unsigned ^^^^^^^^^ Use `:fails_gatekeeper_check` instead of `:unsigned` for deprecate!/disable! reason. end CASK expect_correction <<~CASK cask "foo" do deprecate! date: "2024-01-01", because: :fails_gatekeeper_check end CASK end it "flags and autocorrects disable! with :unsigned" do expect_offense <<~CASK cask "bar" do disable! because: :unsigned ^^^^^^^^^ Use `:fails_gatekeeper_check` instead of `:unsigned` for deprecate!/disable! reason. end CASK expect_correction <<~CASK cask "bar" do disable! because: :fails_gatekeeper_check end CASK end it "ignores other reasons" do expect_no_offenses <<~CASK cask "baz" do deprecate! date: "2024-01-01", because: :discontinued disable! because: :no_longer_available end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/no_autobump.rb
Library/Homebrew/test/rubocops/cask/no_autobump.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::NoAutobump, :config do it "reports no offenses if `reason` is acceptable" do expect_no_offenses <<~CASK cask 'foo' do no_autobump! because: "some reason" end CASK end it "reports no offenses if `reason` is acceptable as a symbol" do expect_no_offenses <<~CASK cask 'foo' do no_autobump! because: :bumped_by_upstream end CASK end it "reports an offense if `reason` is absent" do expect_offense <<~CASK cask 'foo' do no_autobump! ^^^^^^^^^^^ Add a reason for exclusion from autobump: `no_autobump! because: "..."` end CASK end it "reports an offense is `reason` should not be set manually" do expect_offense <<~CASK cask 'foo' do no_autobump! because: :extract_plist ^^^^^^^^^^^^^^ `:extract_plist` reason should not be used directly end CASK end it "reports and corrects an offense if `reason` starts with 'it'" do expect_offense <<~CASK cask 'foo' do no_autobump! because: "it does something" ^^^^^^^^^^^^^^^^^^^ Do not start the reason with `it` end CASK expect_correction <<~CASK cask 'foo' do no_autobump! because: "does something" end CASK end it "reports and corrects an offense if `reason` ends with a period" do expect_offense <<~CASK cask 'foo' do no_autobump! because: "does something." ^^^^^^^^^^^^^^^^^ Do not end the reason with a punctuation mark end CASK expect_correction <<~CASK cask 'foo' do no_autobump! because: "does something" end CASK end it "reports and corrects an offense if `reason` ends with an exclamation point" do expect_offense <<~CASK cask 'foo' do no_autobump! because: "does something!" ^^^^^^^^^^^^^^^^^ Do not end the reason with a punctuation mark end CASK expect_correction <<~CASK cask 'foo' do no_autobump! because: "does something" end CASK end it "reports and corrects an offense if `reason` ends with a question mark" do expect_offense <<~CASK cask 'foo' do no_autobump! because: "does something?" ^^^^^^^^^^^^^^^^^ Do not end the reason with a punctuation mark end CASK expect_correction <<~CASK cask 'foo' do no_autobump! because: "does something" end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/stanza_grouping_spec.rb
Library/Homebrew/test/rubocops/cask/stanza_grouping_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::StanzaGrouping, :config do it "accepts a sole stanza" do expect_no_offenses <<~CASK cask 'foo' do version :latest end CASK end it "accepts correctly grouped stanzas" do expect_no_offenses <<~CASK cask 'foo' do version :latest sha256 :no_check end CASK end it "accepts correctly grouped stanzas and variable assignments" do expect_no_offenses <<~CASK cask 'foo' do arch arm: "arm64", intel: "x86_64" folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" os macos: ">= :big_sur" version :latest sha256 :no_check end CASK end it "reports an offense when a stanza is grouped incorrectly" do expect_offense <<~CASK cask 'foo' do version :latest ^{} stanzas within the same group should have no lines between them sha256 :no_check end CASK expect_correction <<~CASK cask 'foo' do version :latest sha256 :no_check end CASK end it "reports an offense for an incorrectly grouped `arch` stanza" do expect_offense <<~CASK cask 'foo' do arch arm: "arm64", intel: "x86_64" version :latest ^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line sha256 :no_check end CASK expect_correction <<~CASK cask 'foo' do arch arm: "arm64", intel: "x86_64" version :latest sha256 :no_check end CASK end it "reports an offense for an incorrectly grouped variable assignment" do expect_offense <<~CASK cask 'foo' do arch arm: "arm64", intel: "x86_64" folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" version :latest ^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line sha256 :no_check end CASK expect_correction <<~CASK cask 'foo' do arch arm: "arm64", intel: "x86_64" folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" version :latest sha256 :no_check end CASK end it "reports an offense for multiple incorrectly grouped stanzas" do expect_offense <<~CASK cask 'foo' do version :latest sha256 :no_check url 'https://foo.brew.sh/foo.zip' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line ^{} stanzas within the same group should have no lines between them name 'Foo' ^{} stanzas within the same group should have no lines between them homepage 'https://foo.brew.sh' app 'Foo.app' uninstall :quit => 'com.example.foo', ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line :kext => 'com.example.foo.kextextension' end CASK expect_correction <<~CASK cask 'foo' do version :latest sha256 :no_check url 'https://foo.brew.sh/foo.zip' name 'Foo' homepage 'https://foo.brew.sh' app 'Foo.app' uninstall :quit => 'com.example.foo', :kext => 'com.example.foo.kextextension' end CASK end it "reports an offense for multiple incorrectly grouped stanzas and variable assignments" do expect_offense <<~CASK cask 'foo' do arch arm: "arm64", intel: "x86_64" folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" ^{} stanzas within the same group should have no lines between them platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin" version :latest ^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line sha256 :no_check url 'https://foo.brew.sh/foo.zip' ^{} stanzas within the same group should have no lines between them name 'Foo' ^{} stanzas within the same group should have no lines between them homepage 'https://foo.brew.sh' app 'Foo.app' uninstall :quit => 'com.example.foo', ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line :kext => 'com.example.foo.kextextension' end CASK expect_correction <<~CASK cask 'foo' do arch arm: "arm64", intel: "x86_64" folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin" version :latest sha256 :no_check url 'https://foo.brew.sh/foo.zip' name 'Foo' homepage 'https://foo.brew.sh' app 'Foo.app' uninstall :quit => 'com.example.foo', :kext => 'com.example.foo.kextextension' end CASK end shared_examples "caveats" do it "reports an offense for an incorrectly grouped `caveats` stanza" do # Indent all except the first line. interpolated_caveats = caveats.strip expect_offense <<~CASK cask 'foo' do version :latest sha256 :no_check url 'https://foo.brew.sh/foo.zip' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line name 'Foo' app 'Foo.app' ^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line #{interpolated_caveats} end CASK # Remove offense annotations. corrected_caveats = interpolated_caveats.gsub(/\n\s*\^+\s+.*$/, "") expect_correction <<~CASK cask 'foo' do version :latest sha256 :no_check url 'https://foo.brew.sh/foo.zip' name 'Foo' app 'Foo.app' #{corrected_caveats} end CASK end end context "when `caveats` is a one-line string" do let(:caveats) do <<~CAVEATS caveats 'This is a one-line caveat.' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line CAVEATS end include_examples "caveats" end context "when `caveats` is a heredoc" do let(:caveats) do <<~CAVEATS caveats <<~EOS ^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line This is a multiline caveat. Let's hope it doesn't cause any problems! EOS CAVEATS end include_examples "caveats" end context "when `caveats` is a block" do let(:caveats) do <<~CAVEATS caveats do ^^^^^^^^^^^^ stanza groups should be separated by a single empty line puts 'This is a multiline caveat.' puts "Let's hope it doesn't cause any problems!" end CAVEATS end include_examples "caveats" end it "reports an offense for an incorrectly grouped `postflight` stanza" do expect_offense <<~CASK cask 'foo' do version :latest sha256 :no_check url 'https://foo.brew.sh/foo.zip' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line name 'Foo' app 'Foo.app' ^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line postflight do ^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line puts 'We have liftoff!' end end CASK expect_correction <<~CASK cask 'foo' do version :latest sha256 :no_check url 'https://foo.brew.sh/foo.zip' name 'Foo' app 'Foo.app' postflight do puts 'We have liftoff!' end end CASK end it "reports an offense for incorrectly grouped comments" do expect_offense <<~CASK cask 'foo' do version :latest sha256 :no_check # comment with an empty line between ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line # comment directly above postflight do puts 'We have liftoff!' end url 'https://foo.brew.sh/foo.zip' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line name 'Foo' app 'Foo.app' ^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line end CASK expect_correction <<~CASK cask 'foo' do version :latest sha256 :no_check # comment with an empty line between # comment directly above postflight do puts 'We have liftoff!' end url 'https://foo.brew.sh/foo.zip' name 'Foo' app 'Foo.app' end CASK end it "reports an offense for incorrectly grouped comments and variable assignments" do expect_offense <<~CASK cask 'foo' do arch arm: "arm64", intel: "x86_64" folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" # comment with an empty line between ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line version :latest sha256 :no_check # comment directly above postflight do puts 'We have liftoff!' end url 'https://foo.brew.sh/foo.zip' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line name 'Foo' app 'Foo.app' ^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line end CASK expect_correction <<~CASK cask 'foo' do arch arm: "arm64", intel: "x86_64" folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" # comment with an empty line between version :latest sha256 :no_check # comment directly above postflight do puts 'We have liftoff!' end url 'https://foo.brew.sh/foo.zip' name 'Foo' app 'Foo.app' end CASK end it "reports an offense for incorrectly grouped stanzas in `on_*` blocks" do expect_offense <<~CASK cask 'foo' do on_arm do version "1.0.2" ^{} stanzas within the same group should have no lines between them sha256 :no_check end on_intel do version "0.9.8" sha256 :no_check url "https://foo.brew.sh/foo-intel.zip" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line end end CASK expect_correction <<~CASK cask 'foo' do on_arm do version "1.0.2" sha256 :no_check end on_intel do version "0.9.8" sha256 :no_check url "https://foo.brew.sh/foo-intel.zip" end end CASK end it "reports an offense for incorrectly grouped stanzas with comments in `on_*` blocks" do expect_offense <<~CASK cask 'foo' do on_arm do version "1.0.2" ^{} stanzas within the same group should have no lines between them sha256 :no_check # comment on same line end on_intel do version "0.9.8" sha256 :no_check end end CASK expect_correction <<~CASK cask 'foo' do on_arm do version "1.0.2" sha256 :no_check # comment on same line end on_intel do version "0.9.8" sha256 :no_check end end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/url_legacy_comma_separators_spec.rb
Library/Homebrew/test/rubocops/cask/url_legacy_comma_separators_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::UrlLegacyCommaSeparators, :config do it "accepts a simple `version` interpolation" do expect_no_offenses <<~'CASK' cask 'foo' do version '1.1' url 'https://foo.brew.sh/foo-#{version}.dmg' end CASK end it "accepts an interpolation using `version.csv`" do expect_no_offenses <<~'CASK' cask 'foo' do version '1.1,111' url 'https://foo.brew.sh/foo-#{version.csv.first}.dmg' end CASK end it "reports an offense for an interpolation using `version.before_comma`" do expect_offense <<~'CASK' cask 'foo' do version '1.1,111' url 'https://foo.brew.sh/foo-#{version.before_comma}.dmg' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `version.csv.first` instead of `version.before_comma` and `version.csv.second` instead of `version.after_comma`. end CASK expect_correction <<~'CASK' cask 'foo' do version '1.1,111' url 'https://foo.brew.sh/foo-#{version.csv.first}.dmg' end CASK end it "reports an offense for an interpolation using `version.after_comma`" do expect_offense <<~'CASK' cask 'foo' do version '1.1,111' url 'https://foo.brew.sh/foo-#{version.after_comma}.dmg' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `version.csv.first` instead of `version.before_comma` and `version.csv.second` instead of `version.after_comma`. end CASK expect_correction <<~'CASK' cask 'foo' do version '1.1,111' url 'https://foo.brew.sh/foo-#{version.csv.second}.dmg' end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/cask/no_overrides_spec.rb
Library/Homebrew/test/rubocops/cask/no_overrides_spec.rb
# frozen_string_literal: true require "rubocops/rubocop-cask" RSpec.describe RuboCop::Cop::Cask::NoOverrides, :config do it "accepts when there are no `on_*` blocks" do expect_no_offenses <<~CASK cask 'foo' do version '1.2.3' url 'https://brew.sh/foo.pkg' name 'Foo' end CASK end it "accepts when there are no top-level standalone stanzas" do expect_no_offenses <<~CASK cask 'foo' do on_sequoia :or_later do version :latest end end CASK end it "accepts non-overridable stanzas in `on_*` blocks" do expect_no_offenses <<~CASK cask 'foo' do version '1.2.3' on_arm do binary "foo-\#{version}-arm64" end app "foo-\#{version}.app" binary "foo-\#{version}" end CASK end it "accepts `arch` and `version` interpolations in strings in `on_*` blocks" do expect_no_offenses <<~CASK cask 'foo' do arch arm: "arm64", intel: "x86" version '1.2.3' on_sequoia :or_later do sha256 "aaa" url "https://brew.sh/foo-\#{version}-\#{arch}.pkg" end end CASK end it "accepts `version` interpolations with method calls in strings in `on_*` blocks" do expect_no_offenses <<~CASK cask 'foo' do version '0.99,123.3' on_sequoia :or_later do url "https://brew.sh/foo-\#{version.csv.first}-\#{version.csv.second}.pkg" end end CASK end it "accepts `arch` interpolations in regexes in `on_*` blocks" do expect_no_offenses <<~CASK cask 'foo' do arch arm: "arm64", intel: "x86" version '0.99,123.3' on_sequoia :or_later do url "https://brew.sh/foo-\#{arch}-\#{version.csv.first}-\#{version.csv.last}.pkg" livecheck do url "https://brew.sh/foo/releases.html" regex(/href=.*?foo[._-]v?(\d+(?:.\d+)+)-\#{arch}.pkg/i) end end end CASK end it "ignores contents of single-line `livecheck` blocks in `on_*` blocks" do expect_no_offenses <<~CASK cask 'foo' do on_intel do livecheck do url 'https://brew.sh/foo' # Livecheck should be allowed since it's a different "kind" of URL. end version '1.2.3' end on_arm do version '2.3.4' end url 'https://brew.sh/foo.pkg' sha256 "bbb" end CASK end it "ignores contents of multi-line `livecheck` blocks in `on_*` blocks" do expect_no_offenses <<~CASK cask 'foo' do on_intel do livecheck do url 'https://brew.sh/foo' # Livecheck should be allowed since it's a different "kind" of URL. strategy :sparkle end version '1.2.3' end on_arm do version '2.3.4' end url 'https://brew.sh/foo.pkg' sha256 "bbb" end CASK end it "accepts `on_*` blocks that don't override upper-level stanzas" do expect_no_offenses <<~CASK cask "foo" do version "1.2.3" on_big_sur :or_older do sha256 "bbb" url "https://brew.sh/legacy/foo-2.3.4.dmg" end on_monterey :or_newer do sha256 "aaa" url "https://brew.sh/foo-2.3.4.dmg" end end CASK end it "reports an offense when `on_*` blocks override a single upper-level stanza" do expect_offense <<~CASK cask 'foo' do version '2.3.4' ^^^^^^^^^^^^^^^ Do not use a top-level `version` stanza as the default. Add it to an `on_{system}` block instead. Use `:or_older` or `:or_newer` to specify a range of macOS versions. on_sequoia :or_older do version '1.2.3' end url 'https://brew.sh/foo-2.3.4.dmg' end CASK end it "reports an offense when `on_*` blocks override multiple upper-level stanzas" do expect_offense <<~CASK cask "foo" do version "1.2.3" sha256 "aaa" ^^^^^^^^^^^^ Do not use a top-level `sha256` stanza as the default. Add it to an `on_{system}` block instead. Use `:or_older` or `:or_newer` to specify a range of macOS versions. url "https://brew.sh/foo-2.3.4.dmg" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use a top-level `url` stanza as the default. Add it to an `on_{system}` block instead. Use `:or_older` or `:or_newer` to specify a range of macOS versions. on_big_sur :or_older do sha256 "bbb" url "https://brew.sh/legacy/foo-2.3.4.dmg" end end CASK end it "accepts when there is a top-level `depends_on macos:` stanza" do expect_no_offenses <<~CASK cask 'foo' do version '1.2.3' url 'https://brew.sh/foo.pkg' depends_on macos: ">= :sequoia" name 'Foo' end CASK end it "reports an offense when `on_*` blocks contain the samne `depends_on macos:` stanza" do expect_offense <<~CASK cask 'foo' do version '1.2.3' on_sequoia :or_newer do sha256 "aaa" url "https://brew.sh/foo-mac.dmg" depends_on macos: ">= :sequoia" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use a `depends_on macos:` stanza inside an `on_{system}` block. Add it once to specify the oldest macOS supported by any version in the cask. end on_arm do sha256 "bbb" url "https://brew.sh/foo-arm.dmg" depends_on macos: ">= :sequoia" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use a `depends_on macos:` stanza inside an `on_{system}` block. Add it once to specify the oldest macOS supported by any version in the cask. end name 'Foo' end CASK end it "accepts when multiple `on_*` blocks contain different `depends_on macos:` stanzas" do expect_no_offenses <<~CASK cask "foo" do version "1.2.3" on_arm do depends_on macos: ">= :monterey" end on_intel do depends_on macos: ">= :ventura" end sha256 "aaa" url "https://brew.sh/foo-mac.dmg" name 'Foo' end CASK end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/class/test_present.rb
Library/Homebrew/test/rubocops/class/test_present.rb
# frozen_string_literal: true require "rubocops/class" RSpec.describe RuboCop::Cop::FormulaAuditStrict::TestPresent do subject(:cop) { described_class.new } it "reports an offense when there is no test block" do expect_offense(<<~RUBY) class Foo < Formula ^^^^^^^^^^^^^^^^^^^ A `test do` test block should be added url 'https://brew.sh/foo-1.0.tgz' end RUBY end it "reports no offenses when there is no test block and formula is disabled" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' disable! date: "2024-07-03", because: :unsupported end RUBY end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/class/class_name_spec.rb
Library/Homebrew/test/rubocops/class/class_name_spec.rb
# frozen_string_literal: true require "rubocops/class" RSpec.describe RuboCop::Cop::FormulaAudit::ClassName do subject(:cop) { described_class.new } let(:corrected_source) do <<~RUBY class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' end RUBY end it "reports and corrects an offense when using ScriptFileFormula" do expect_offense(<<~RUBY) class Foo < ScriptFileFormula ^^^^^^^^^^^^^^^^^ FormulaAudit/ClassName: `ScriptFileFormula` is deprecated, use `Formula` instead url 'https://brew.sh/foo-1.0.tgz' end RUBY expect_correction(corrected_source) end it "reports and corrects an offense when using GithubGistFormula" do expect_offense(<<~RUBY) class Foo < GithubGistFormula ^^^^^^^^^^^^^^^^^ FormulaAudit/ClassName: `GithubGistFormula` is deprecated, use `Formula` instead url 'https://brew.sh/foo-1.0.tgz' end RUBY expect_correction(corrected_source) end it "reports and corrects an offense when using AmazonWebServicesFormula" do expect_offense(<<~RUBY) class Foo < AmazonWebServicesFormula ^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ClassName: `AmazonWebServicesFormula` is deprecated, use `Formula` instead url 'https://brew.sh/foo-1.0.tgz' end RUBY expect_correction(corrected_source) end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/class/test_spec.rb
Library/Homebrew/test/rubocops/class/test_spec.rb
# frozen_string_literal: true require "rubocops/class" RSpec.describe RuboCop::Cop::FormulaAudit::Test do subject(:cop) { described_class.new } it "reports and corrects an offense when /usr/local/bin is found in test calls" do expect_offense(<<~'RUBY') class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' test do system "/usr/local/bin/test" ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Test: Use `#{bin}` instead of `/usr/local/bin` in `system` end end RUBY expect_correction(<<~'RUBY') class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' test do system "#{bin}/test" end end RUBY end it "reports and corrects an offense when passing 0 as the second parameter to shell_output" do expect_offense(<<~'RUBY') class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' test do shell_output("#{bin}/test", 0) ^ FormulaAudit/Test: Passing 0 to `shell_output` is redundant end end RUBY expect_correction(<<~'RUBY') class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' test do shell_output("#{bin}/test") end end RUBY end it "reports an offense when there is an empty test block" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' test do ^^^^^^^ FormulaAudit/Test: `test do` should not be empty end end RUBY end it "reports an offense when test is falsely true" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' test do ^^^^^^^ FormulaAudit/Test: `test do` should contain a real test true end end RUBY end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/python_versions_spec.rb
Library/Homebrew/test/rubocops/text/python_versions_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::PythonVersions do subject(:cop) { described_class.new } context "when auditing Python versions" do it "reports no offenses for Python with no dependency" do expect_no_offenses(<<~RUBY) class Foo < Formula def install puts "python@3.8" end end RUBY end it "reports no offenses for unversioned Python references" do expect_no_offenses(<<~RUBY) class Foo < Formula depends_on "python@3.9" def install puts "python" end end RUBY end it "reports no offenses for Python with no version" do expect_no_offenses(<<~RUBY) class Foo < Formula depends_on "python@3.9" def install puts "python3" end end RUBY end it "reports no offenses when a Python reference matches its dependency" do expect_no_offenses(<<~RUBY) class Foo < Formula depends_on "python@3.9" def install puts "python@3.9" end end RUBY end it "reports no offenses when a Python reference matches its dependency without `@`" do expect_no_offenses(<<~RUBY) class Foo < Formula depends_on "python@3.9" def install puts "python3.9" end end RUBY end it "reports no offenses when a Python reference matches its two-digit dependency" do expect_no_offenses(<<~RUBY) class Foo < Formula depends_on "python@3.10" def install puts "python@3.10" end end RUBY end it "reports no offenses when a Python reference matches its two-digit dependency without `@`" do expect_no_offenses(<<~RUBY) class Foo < Formula depends_on "python@3.10" def install puts "python3.10" end end RUBY end it "reports and corrects Python references with mismatched versions" do expect_offense(<<~RUBY) class Foo < Formula depends_on "python@3.9" def install puts "python@3.8" ^^^^^^^^^^^^ FormulaAudit/PythonVersions: References to `python@3.8` should match the specified python dependency (`python@3.9`) end end RUBY expect_correction(<<~RUBY) class Foo < Formula depends_on "python@3.9" def install puts "python@3.9" end end RUBY end it "reports and corrects Python references with mismatched versions without `@`" do expect_offense(<<~RUBY) class Foo < Formula depends_on "python@3.9" def install puts "python3.8" ^^^^^^^^^^^ FormulaAudit/PythonVersions: References to `python3.8` should match the specified python dependency (`python3.9`) end end RUBY expect_correction(<<~RUBY) class Foo < Formula depends_on "python@3.9" def install puts "python3.9" end end RUBY end it "reports and corrects Python references with mismatched two-digit versions" do expect_offense(<<~RUBY) class Foo < Formula depends_on "python@3.11" def install puts "python@3.10" ^^^^^^^^^^^^^ FormulaAudit/PythonVersions: References to `python@3.10` should match the specified python dependency (`python@3.11`) end end RUBY expect_correction(<<~RUBY) class Foo < Formula depends_on "python@3.11" def install puts "python@3.11" end end RUBY end it "reports and corrects Python references with mismatched two-digit versions without `@`" do expect_offense(<<~RUBY) class Foo < Formula depends_on "python@3.11" def install puts "python3.10" ^^^^^^^^^^^^ FormulaAudit/PythonVersions: References to `python3.10` should match the specified python dependency (`python3.11`) end end RUBY expect_correction(<<~RUBY) class Foo < Formula depends_on "python@3.11" def install puts "python3.11" end end RUBY end it "reports no offenses for multiple non-runtime Python dependencies" do expect_no_offenses(<<~RUBY) class Foo < Formula depends_on "python@3.9" => :build depends_on "python@3.10" => :test def install puts "python3.9" end test do puts "python3.10" end end RUBY end it "reports and corrects Python references that mismatch single non-runtime Python dependency" do expect_offense(<<~RUBY) class Foo < Formula depends_on "python@3.9" => :build def install puts "python@3.8" ^^^^^^^^^^^^ FormulaAudit/PythonVersions: References to `python@3.8` should match the specified python dependency (`python@3.9`) end end RUBY expect_correction(<<~RUBY) class Foo < Formula depends_on "python@3.9" => :build def install puts "python@3.9" end end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/on_system_conditionals_spec.rb
Library/Homebrew/test/rubocops/text/on_system_conditionals_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::OnSystemConditionals do subject(:cop) { described_class.new } context "when auditing OS conditionals" do it "reports an offense when `OS.linux?` is used on Formula class" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" if OS.linux? ^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of `if OS.linux?`, use `on_linux do`. url 'https://brew.sh/linux-1.0.tgz' else url 'https://brew.sh/linux-1.0.tgz' end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" on_linux do url 'https://brew.sh/linux-1.0.tgz' end on_macos do url 'https://brew.sh/linux-1.0.tgz' end end RUBY end it "reports an offense when `OS.mac?` is used on Formula class" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" if OS.mac? ^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of `if OS.mac?`, use `on_macos do`. url 'https://brew.sh/mac-1.0.tgz' else url 'https://brew.sh/linux-1.0.tgz' end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" on_macos do url 'https://brew.sh/mac-1.0.tgz' end on_linux do url 'https://brew.sh/linux-1.0.tgz' end end RUBY end it "reports an offense when `on_macos` is used in install method" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install on_macos do ^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_macos` in `def install`, use `if OS.mac?`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install if OS.mac? true end end end RUBY end it "reports an offense when `on_linux` is used in install method" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install on_linux do ^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_linux` in `def install`, use `if OS.linux?`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install if OS.linux? true end end end RUBY end it "reports an offense when `on_macos` is used in test block" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' test do on_macos do ^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_macos` in `test do`, use `if OS.mac?`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' test do if OS.mac? true end end end RUBY end end context "when auditing Hardware::CPU conditionals" do it "reports an offense when `Hardware::CPU.arm?` is used on Formula class" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" if Hardware::CPU.arm? ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of `if Hardware::CPU.arm?`, use `on_arm do`. url 'https://brew.sh/linux-1.0.tgz' else url 'https://brew.sh/linux-1.0.tgz' end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" on_arm do url 'https://brew.sh/linux-1.0.tgz' end on_intel do url 'https://brew.sh/linux-1.0.tgz' end end RUBY end it "reports an offense when `Hardware::CPU.intel?` is used on Formula class" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" if Hardware::CPU.intel? ^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of `if Hardware::CPU.intel?`, use `on_intel do`. url 'https://brew.sh/mac-1.0.tgz' else url 'https://brew.sh/linux-1.0.tgz' end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" on_intel do url 'https://brew.sh/mac-1.0.tgz' end on_arm do url 'https://brew.sh/linux-1.0.tgz' end end RUBY end it "reports an offense when `on_intel` is used in install method" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install on_intel do ^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_intel` in `def install`, use `if Hardware::CPU.intel?`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install if Hardware::CPU.intel? true end end end RUBY end it "reports an offense when `on_arm` is used in install method" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install on_arm do ^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_arm` in `def install`, use `if Hardware::CPU.arm?`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install if Hardware::CPU.arm? true end end end RUBY end it "reports an offense when `on_intel` is used in test block" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' test do on_intel do ^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_intel` in `test do`, use `if Hardware::CPU.intel?`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' test do if Hardware::CPU.intel? true end end end RUBY end end context "when auditing MacOS.version conditionals" do it "reports an offense when `MacOS.version ==` is used on Formula class" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" if MacOS.version == :monterey ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of `if MacOS.version == :monterey`, use `on_monterey do`. url 'https://brew.sh/linux-1.0.tgz' end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" on_monterey do url 'https://brew.sh/linux-1.0.tgz' end end RUBY end it "reports an offense when `MacOS.version <=` is used on Formula class" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" if MacOS.version <= :monterey ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of `if MacOS.version <= :monterey`, use `on_system :linux, macos: :monterey_or_older do`. url 'https://brew.sh/mac-1.0.tgz' end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" on_system :linux, macos: :monterey_or_older do url 'https://brew.sh/mac-1.0.tgz' end end RUBY end it "reports an offense when `MacOS.version <` is used on Formula class" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" if MacOS.version < :monterey ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of `if MacOS.version < :monterey`, use `on_system do`. url 'https://brew.sh/mac-1.0.tgz' end end RUBY end it "reports an offense when `MacOS.version >=` is used on Formula class" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" if MacOS.version >= :monterey ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of `if MacOS.version >= :monterey`, use `on_monterey :or_newer do`. url 'https://brew.sh/mac-1.0.tgz' else url 'https://brew.sh/linux-1.0.tgz' end end RUBY end it "reports an offense when `MacOS.version >` is used on Formula class" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" if MacOS.version > :monterey ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of `if MacOS.version > :monterey`, use `on_monterey do`. url 'https://brew.sh/mac-1.0.tgz' end end RUBY end it "reports an offense when `on_monterey` is used in install method" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install on_monterey do ^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_monterey` in `def install`, use `if MacOS.version == :monterey`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install if MacOS.version == :monterey true end end end RUBY end it "reports an offense when `on_monterey :or_older` is used in install method" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install on_monterey :or_older do ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_monterey :or_older` in `def install`, use `if MacOS.version <= :monterey`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install if MacOS.version <= :monterey true end end end RUBY end it "reports an offense when `on_monterey :or_newer` is used in install method" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install on_monterey :or_newer do ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_monterey :or_newer` in `def install`, use `if MacOS.version >= :monterey`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install if MacOS.version >= :monterey true end end end RUBY end it "reports an offense when `on_system :linux, macos: :monterey_or_newer` is used in install method" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install on_system :linux, macos: :monterey_or_newer do ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_system :linux, macos: :monterey_or_newer` in `def install`, use `if OS.linux? || MacOS.version >= :monterey`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install if OS.linux? || MacOS.version >= :monterey true end end end RUBY end it "reports an offense when `on_monterey` is used in test block" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' test do on_monterey do ^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_monterey` in `test do`, use `if MacOS.version == :monterey`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' test do if MacOS.version == :monterey true end end end RUBY end it "reports an offense when `on_system :linux, macos: :monterey` is used in test block" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' test do on_system :linux, macos: :monterey do ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OnSystemConditionals: Instead of using `on_system :linux, macos: :monterey` in `test do`, use `if OS.linux? || MacOS.version == :monterey`. true end end end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' test do if OS.linux? || MacOS.version == :monterey true end end end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/license_arrays_spec.rb
Library/Homebrew/test/rubocops/text/license_arrays_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::LicenseArrays do subject(:cop) { described_class.new } context "when auditing license arrays" do it "reports no offenses for license strings" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license "MIT" end RUBY end it "reports no offenses for license symbols" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license :public_domain end RUBY end it "reports no offenses for license hashes" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license any_of: ["MIT", "0BSD"] end RUBY end it "reports and corrects use of a license array" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license ["MIT", "0BSD"] ^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/LicenseArrays: Use `license any_of: ["MIT", "0BSD"]` instead of `license ["MIT", "0BSD"]` end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license any_of: ["MIT", "0BSD"] end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/macos_on_linux_spec.rb
Library/Homebrew/test/rubocops/text/macos_on_linux_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::MacOSOnLinux do subject(:cop) { described_class.new } it "reports an offense when `MacOS` is used in the `Formula` class" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" if MacOS::Xcode.version >= "12.0" ^^^^^ FormulaAudit/MacOSOnLinux: Don't use `MacOS` where it could be called on Linux. url 'https://brew.sh/linux-1.0.tgz' end end RUBY end it "reports an offense when `MacOS` is used in a `resource` block" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/linux-1.0.tgz' resource "foo" do url "https://brew.sh/linux-1.0.tgz" if MacOS::full_version >= "12.0" ^^^^^ FormulaAudit/MacOSOnLinux: Don't use `MacOS` where it could be called on Linux. end end RUBY end it "reports an offense when `MacOS` is used in an `on_linux` block" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" on_linux do if MacOS::Xcode.version >= "12.0" ^^^^^ FormulaAudit/MacOSOnLinux: Don't use `MacOS` where it could be called on Linux. url 'https://brew.sh/linux-1.0.tgz' end end end RUBY end it "reports an offense when `MacOS` is used in an `on_arm` block" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" on_arm do if MacOS::Xcode.version >= "12.0" ^^^^^ FormulaAudit/MacOSOnLinux: Don't use `MacOS` where it could be called on Linux. url 'https://brew.sh/linux-1.0.tgz' end end end RUBY end it "reports an offense when `MacOS` is used in an `on_intel` block" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" on_intel do if MacOS::Xcode.version >= "12.0" ^^^^^ FormulaAudit/MacOSOnLinux: Don't use `MacOS` where it could be called on Linux. url 'https://brew.sh/linux-1.0.tgz' end end end RUBY end it "reports no offenses when `MacOS` is used in an `on_macos` block" do expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" on_macos do if MacOS::Xcode.version >= "12.0" url 'https://brew.sh/linux-1.0.tgz' end end end RUBY end it "reports no offenses when `MacOS` is used in an `on_ventura` block" do expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" on_ventura :or_older do if MacOS::Xcode.version >= "12.0" url 'https://brew.sh/linux-1.0.tgz' end end end RUBY end it "reports no offenses when `MacOS` is used in the `install` method" do expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/linux-1.0.tgz' def install MacOS.version end end RUBY end it "reports no offenses when `MacOS` is used in the `test` block" do expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/linux-1.0.tgz' test do MacOS.version end end RUBY end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/mpi_check_spec.rb
Library/Homebrew/test/rubocops/text/mpi_check_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::MpiCheck do subject(:cop) { described_class.new } context "when auditing MPI dependencies" do it "reports and corrects an offense when using depends_on \"mpich\" in homebrew/core" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' depends_on "mpich" ^^^^^^^^^^^^^^^^^^ FormulaAudit/MpiCheck: Formulae in homebrew/core should use `depends_on "open-mpi"` instead of `depends_on "mpich"`. end RUBY expect_correction(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' depends_on "open-mpi" end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/shell_variables_spec.rb
Library/Homebrew/test/rubocops/text/shell_variables_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::ShellVariables do subject(:cop) { described_class.new } context "when auditing shell variables" do it "reports and corrects unexpanded shell variables in `Utils.popen`" do expect_offense(<<~RUBY) class Foo < Formula def install Utils.popen "SHELL=bash foo" ^^^^^^^^^^^^^^^^ FormulaAudit/ShellVariables: Use `Utils.popen({ "SHELL" => "bash" }, "foo")` instead of `Utils.popen "SHELL=bash foo"` end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install Utils.popen({ "SHELL" => "bash" }, "foo") end end RUBY end it "reports and corrects unexpanded shell variables in `Utils.safe_popen_read`" do expect_offense(<<~RUBY) class Foo < Formula def install Utils.safe_popen_read "SHELL=bash foo" ^^^^^^^^^^^^^^^^ FormulaAudit/ShellVariables: Use `Utils.safe_popen_read({ "SHELL" => "bash" }, "foo")` instead of `Utils.safe_popen_read "SHELL=bash foo"` end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install Utils.safe_popen_read({ "SHELL" => "bash" }, "foo") end end RUBY end it "reports and corrects unexpanded shell variables in `Utils.safe_popen_write`" do expect_offense(<<~RUBY) class Foo < Formula def install Utils.safe_popen_write "SHELL=bash foo" ^^^^^^^^^^^^^^^^ FormulaAudit/ShellVariables: Use `Utils.safe_popen_write({ "SHELL" => "bash" }, "foo")` instead of `Utils.safe_popen_write "SHELL=bash foo"` end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install Utils.safe_popen_write({ "SHELL" => "bash" }, "foo") end end RUBY end it "reports and corrects unexpanded shell variables while preserving string interpolation" do expect_offense(<<~'RUBY') class Foo < Formula def install Utils.popen "SHELL=bash #{bin}/foo" ^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ShellVariables: Use `Utils.popen({ "SHELL" => "bash" }, "#{bin}/foo")` instead of `Utils.popen "SHELL=bash #{bin}/foo"` end end RUBY expect_correction(<<~'RUBY') class Foo < Formula def install Utils.popen({ "SHELL" => "bash" }, "#{bin}/foo") end end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/option_declarations_spec.rb
Library/Homebrew/test/rubocops/text/option_declarations_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::OptionDeclarations do subject(:cop) { described_class.new } context "when auditing options" do it "reports an offense when `build.without?` is used in homebrew/core" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install build.without? "bar" ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OptionDeclarations: Formulae in homebrew/core should not use `build.without?`. end end RUBY end it "reports an offense when `build.with?` is used in homebrew/core" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install build.with? "bar" ^^^^^^^^^^^^^^^^^ FormulaAudit/OptionDeclarations: Formulae in homebrew/core should not use `build.with?`. end end RUBY end it "reports an offense when `build.without?` is used for a conditional dependency" do expect_offense(<<~RUBY) class Foo < Formula depends_on "bar" if build.without?("baz") ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OptionDeclarations: Use `:optional` or `:recommended` instead of `if build.without?("baz")` end RUBY end it "reports an offense when `build.with?` is used for a conditional dependency" do expect_offense(<<~RUBY) class Foo < Formula depends_on "bar" if build.with?("baz") ^^^^^^^^^^^^^^^^^^ FormulaAudit/OptionDeclarations: Use `:optional` or `:recommended` instead of `if build.with?("baz")` end RUBY end it "reports an offense when `build.without?` is used with `unless`" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def post_install return unless build.without? "bar" ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OptionDeclarations: Use `if build.with? "bar"` instead of `unless build.without? "bar"` end end RUBY end it "reports an offense when `build.with?` is used with `unless`" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def post_install return unless build.with? "bar" ^^^^^^^^^^^^^^^^^ FormulaAudit/OptionDeclarations: Use `if build.without? "bar"` instead of `unless build.with? "bar"` end end RUBY end it "reports an offense when `build.with?` is negated" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def post_install return if !build.with? "bar" ^^^^^^^^^^^^^^^^^^ FormulaAudit/OptionDeclarations: Instead of negating `build.with?`, use `build.without?` end end RUBY end it "reports an offense when `build.without?` is negated" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def post_install return if !build.without? "bar" ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OptionDeclarations: Instead of negating `build.without?`, use `build.with?` end end RUBY end it "reports an offense when a `build.without?` conditional is unnecessary" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def post_install return if build.without? "--without-bar" ^^^^^^^^^^^^^^^ FormulaAudit/OptionDeclarations: Instead of duplicating `without`, use `build.without? "bar"` to check for "--without-bar" end end RUBY end it "reports an offense when a `build.with?` conditional is unnecessary" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def post_install return if build.with? "--with-bar" ^^^^^^^^^^^^ FormulaAudit/OptionDeclarations: Instead of duplicating `with`, use `build.with? "bar"` to check for '--with-bar' end end RUBY end it "reports an offense when `build.include?` is used" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def post_install return if build.include? "foo" ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/OptionDeclarations: `build.include?` is deprecated end end RUBY end it "reports an offense when `def option` is used" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def options ^^^^^^^^^^^ FormulaAudit/OptionDeclarations: Use new-style option definitions [["--bar", "desc"]] end end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/make_check_spec.rb
Library/Homebrew/test/rubocops/text/make_check_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAuditStrict::MakeCheck do subject(:cop) { described_class.new } let(:path) { HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-core" } before do path.mkpath (path/"style_exceptions").mkpath end def setup_style_exceptions (path/"style_exceptions/make_check_allowlist.json").write <<~JSON [ "bar" ] JSON end it "reports an offense when formulae in homebrew/core run build-time checks" do setup_style_exceptions expect_offense(<<~RUBY, "#{path}/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' system "make", "-j1", "test" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAuditStrict/MakeCheck: Formulae in homebrew/core (except e.g. cryptography, libraries) should not run build-time checks end RUBY end it "reports no offenses when exempted formulae in homebrew/core run build-time checks" do setup_style_exceptions expect_no_offenses(<<~RUBY, "#{path}/Formula/bar.rb") class Bar < Formula desc "bar" url 'https://brew.sh/bar-1.0.tgz' system "make", "-j1", "test" end RUBY end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/safe_popen_commands_spec.rb
Library/Homebrew/test/rubocops/text/safe_popen_commands_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::SafePopenCommands do subject(:cop) { described_class.new } context "when auditing popen commands" do it "reports and corrects `Utils.popen_read` usage" do expect_offense(<<~RUBY) class Foo < Formula def install Utils.popen_read "foo" ^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/SafePopenCommands: Use `Utils.safe_popen_read` instead of `Utils.popen_read` end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install Utils.safe_popen_read "foo" end end RUBY end it "reports and corrects `Utils.popen_write` usage" do expect_offense(<<~RUBY) class Foo < Formula def install Utils.popen_write "foo" ^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/SafePopenCommands: Use `Utils.safe_popen_write` instead of `Utils.popen_write` end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install Utils.safe_popen_write "foo" end end RUBY end it "does not report an offense when `Utils.popen_read` is used in a test block" do expect_no_offenses(<<~RUBY) class Foo < Formula def install; end test do Utils.popen_read "foo" end end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/comments_spec.rb
Library/Homebrew/test/rubocops/text/comments_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::Comments do subject(:cop) { described_class.new } context "when auditing comment text" do it "reports an offense when commented cmake calls exist" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' # system "cmake", ".", *std_cmake_args ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Comments: Please remove default template comments end RUBY end it "reports an offense when default template comments exist" do expect_offense(<<~RUBY) class Foo < Formula # PLEASE REMOVE ^^^^^^^^^^^^^^^ FormulaAudit/Comments: Please remove default template comments desc "foo" url 'https://brew.sh/foo-1.0.tgz' end RUBY end it "reports an offense when `depends_on` is commented" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' # depends_on "foo" ^^^^^^^^^^^^^^^^^^ FormulaAudit/Comments: Commented-out dependency "foo" end RUBY end it "reports an offense if citation tags are present" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' # cite Howell_2009: ^^^^^^^^^^^^^^^^^^^ FormulaAudit/Comments: Formulae in homebrew/core should not use `cite` comments # doi "10.111/222.x" ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Comments: Formulae in homebrew/core should not use `doi` comments # tag "software" ^^^^^^^^^^^^^^^^ FormulaAudit/Comments: Formulae in homebrew/core should not use `tag` comments end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/strict_spec.rb
Library/Homebrew/test/rubocops/text/strict_spec.rb
# frozen_string_literal: true require "rubocops/text" RSpec.describe RuboCop::Cop::FormulaAuditStrict::Text do subject(:cop) { described_class.new } context "when auditing formula text in homebrew/core" do it "reports an offense if `env :userpaths` is present" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" env :userpaths ^^^^^^^^^^^^^^ FormulaAuditStrict/Text: `env :userpaths` in homebrew/core formulae is deprecated end RUBY end it "reports an offense if `env :std` is present in homebrew/core" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" env :std ^^^^^^^^ FormulaAuditStrict/Text: `env :std` in homebrew/core formulae is deprecated end RUBY end it %Q(reports an offense if "\#{share}/<formula name>" is present) do expect_offense(<<~'RUBY', "/homebrew-core/Formula/foo.rb") class Foo < Formula def install ohai "#{share}/foo" ^^^^^^^^^^^^^^ FormulaAuditStrict/Text: Use `#{pkgshare}` instead of `#{share}/foo` end end RUBY expect_offense(<<~'RUBY', "/homebrew-core/Formula/foo.rb") class Foo < Formula def install ohai "#{share}/foo/bar" ^^^^^^^^^^^^^^^^^^ FormulaAuditStrict/Text: Use `#{pkgshare}` instead of `#{share}/foo` end end RUBY expect_offense(<<~'RUBY', "/homebrew-core/Formula/foolibc++.rb") class Foolibcxx < Formula def install ohai "#{share}/foolibc++" ^^^^^^^^^^^^^^^^^^^^ FormulaAuditStrict/Text: Use `#{pkgshare}` instead of `#{share}/foolibc++` end end RUBY end it 'reports an offense if `share/"<formula name>"` is present' do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula def install ohai share/"foo" ^^^^^^^^^^^ FormulaAuditStrict/Text: Use `pkgshare` instead of `share/"foo"` end end RUBY expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula def install ohai share/"foo/bar" ^^^^^^^^^^^^^^^ FormulaAuditStrict/Text: Use `pkgshare` instead of `share/"foo"` end end RUBY expect_offense(<<~RUBY, "/homebrew-core/Formula/foolibc++.rb") class Foolibcxx < Formula def install ohai share/"foolibc++" ^^^^^^^^^^^^^^^^^ FormulaAuditStrict/Text: Use `pkgshare` instead of `share/"foolibc++"` end end RUBY end it %Q(reports no offenses if "\#{share}/<directory name>" doesn't match formula name) do expect_no_offenses(<<~'RUBY', "/homebrew-core/Formula/foo.rb") class Foo < Formula def install ohai "#{share}/foo-bar" end end RUBY end it 'reports no offenses if `share/"<formula name>"` is not present' do expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula def install ohai share/"foo-bar" end end RUBY expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula def install ohai share/"bar" end end RUBY expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula def install ohai share/"bar/foo" end end RUBY end it %Q(reports no offenses if formula name appears after "\#{share}/<directory name>") do expect_no_offenses(<<~'RUBY', "/homebrew-core/Formula/foo.rb") class Foo < Formula def install ohai "#{share}/bar/foo" end end RUBY end context "for interpolated bin paths" do it 'reports an offense & autocorrects if "\#{bin}/<formula_name>" or other dashed binaries too are present' do expect_offense(<<~'RUBY', "/homebrew-core/Formula/foo.rb") class Foo < Formula test do system "#{bin}/foo", "-v" ^^^^^^^^^^^^ FormulaAuditStrict/Text: Use `bin/"foo"` instead of `"#{bin}/foo"` system "#{bin}/foo-bar", "-v" ^^^^^^^^^^^^^^^^ FormulaAuditStrict/Text: Use `bin/"foo-bar"` instead of `"#{bin}/foo-bar"` end end RUBY expect_correction(<<~RUBY) class Foo < Formula test do system bin/"foo", "-v" system bin/"foo-bar", "-v" end end RUBY end it 'does not report an offense if \#{bin}/foo and then a space and more text' do expect_no_offenses(<<~'RUBY', "/homebrew-core/Formula/foo.rb") class Foo < Formula test do shell_output("#{bin}/foo --version") assert_match "help", shell_output("#{bin}/foo-something --help 2>&1") assert_match "OK", shell_output("#{bin}/foo-something_else --check 2>&1") end end RUBY end end it 'does not report an offense if "\#{bin}/foo" is in a word array' do expect_no_offenses(<<~'RUBY', "/homebrew-core/Formula/foo.rb") class Foo < Formula test do cmd = %W[ #{bin}/foo version ] assert_match version.to_s, shell_output(cmd) end end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/std_npm_args_spec.rb
Library/Homebrew/test/rubocops/text/std_npm_args_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::StdNpmArgs do subject(:cop) { described_class.new } context "when auditing node formulae" do it "reports an offense when `npm install` is called without std_npm_args arguments" do expect_offense(<<~RUBY) class Foo < Formula def install system "npm", "install" ^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use `std_npm_args` for npm install end end RUBY end it "reports and corrects an offense when using local_npm_install_args" do expect_offense(<<~RUBY) class Foo < Formula def install system "npm", "install", *Language::Node.local_npm_install_args, "--production" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use `std_npm_args` instead of `local_npm_install_args`. end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install system "npm", "install", *std_npm_args(prefix: false), "--production" end end RUBY end it "reports and corrects an offense when using std_npm_install_args with libexec" do expect_offense(<<~RUBY) class Foo < Formula def install system "npm", "install", *Language::Node.std_npm_install_args(libexec), "--production" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use `std_npm_args` instead of `std_npm_install_args`. end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install system "npm", "install", *std_npm_args, "--production" end end RUBY end it "reports and corrects an offense when using std_npm_install_args without libexec" do expect_offense(<<~RUBY) class Foo < Formula def install system "npm", "install", *Language::Node.std_npm_install_args(buildpath), "--production" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use `std_npm_args` instead of `std_npm_install_args`. end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install system "npm", "install", *std_npm_args(prefix: buildpath), "--production" end end RUBY end it "does not report an offense when using std_npm_args" do expect_no_offenses(<<~RUBY) class Foo < Formula def install system "npm", "install", *std_npm_args end end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/miscellaneous_spec.rb
Library/Homebrew/test/rubocops/text/miscellaneous_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::Miscellaneous do subject(:cop) { described_class.new } context "when auditing formula miscellany" do it "reports an offense for unneeded `FileUtils` usage" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' FileUtils.mv "hello" ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: No need for `FileUtils.` before `mv` end RUBY end it "reports an offense for long `inreplace` block variable names" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' inreplace "foo" do |longvar| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: `inreplace <filenames> do |s|` is preferred over `|longvar|`. somerandomCall(longvar) end end RUBY end it "reports an offense for invalid `rebuild` numbers" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' bottle do rebuild 0 ^^^^^^^^^ FormulaAudit/Miscellaneous: `rebuild 0` should be removed sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sonoma end end RUBY end it "reports an offense when a useless `fails_with :llvm` is used" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' bottle do sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sonoma end fails_with :llvm do ^^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: `fails_with :llvm` is now a no-op and should be removed build 2335 cause "foo" end end RUBY end it "reports an offense when `def test` is used" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def test ^^^^^^^^ FormulaAudit/Miscellaneous: Use new-style test definitions (`test do`) assert_equals "1", "1" end end RUBY end it "reports an offense when `skip_clean` is used" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' skip_clean :all ^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: `skip_clean :all` is deprecated; brew no longer strips symbols. Pass explicit paths to prevent Homebrew from removing empty folders. end RUBY end it "reports an offense when `install_name_tool` is called" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' system "install_name_tool", "-id" ^^^^^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: Use ruby-macho instead of calling "install_name_tool" end RUBY end it "reports an offense when `depends_on` is called with an instance" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' depends_on FOO::BAR.new ^^^^^^^^^^^^ FormulaAudit/Miscellaneous: `depends_on` can take requirement classes instead of instances end RUBY end it "reports an offense when `Dir` is called without a globbing argument" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' rm_rf Dir["src/{llvm,test,librustdoc,etc/snapshot.pyc}"] rm_rf Dir["src/snapshot.pyc"] ^^^^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: `Dir(["src/snapshot.pyc"])` is unnecessary; just use `src/snapshot.pyc` end RUBY end it "reports an offense when executing a system command for which there is a Ruby FileUtils equivalent" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' system "mkdir", "foo" ^^^^^^^ FormulaAudit/Miscellaneous: Use the `mkdir` Ruby method instead of `system "mkdir", "foo"` end RUBY end it "reports an offense when top-level functions are defined outside of a class body" do expect_offense(<<~RUBY) def test ^^^^^^^^ FormulaAudit/Miscellaneous: Define method `test` in the class body, not at the top-level nil end class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' end RUBY end it 'reports an offense when `man+"man8"` is used' do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install man1.install man+"man8" => "faad.1" ^^^^^^ FormulaAudit/Miscellaneous: `man+"man8"` should be `man8` end end RUBY end it "reports an offense when a hard-coded `gcc` is referenced" do expect_offense(<<~'RUBY') class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install system "/usr/bin/gcc", "foo" ^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: Use `#{ENV.cc}` instead of hard-coding `gcc` end end RUBY end it "reports an offense when a hard-coded `g++` is referenced" do expect_offense(<<~'RUBY') class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install system "/usr/bin/g++", "-o", "foo", "foo.cc" ^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: Use `#{ENV.cxx}` instead of hard-coding `g++` end end RUBY end it "reports an offense when a hard-coded `c++` is set as COMPILER_PATH" do expect_offense(<<~'RUBY') class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install ENV["COMPILER_PATH"] = "/usr/bin/c++" ^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: Use `#{ENV.cxx}` instead of hard-coding `c++` end end RUBY end it "reports an offense when a hard-coded `gcc` is set as COMPILER_PATH" do expect_offense(<<~'RUBY') class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install ENV["COMPILER_PATH"] = "/usr/bin/gcc" ^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: Use `#{ENV.cc}` instead of hard-coding `gcc` end end RUBY end it "reports an offense when the formula path shortcut `man` could be used" do expect_offense(<<~'RUBY') class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install mv "#{share}/man", share ^^^^ FormulaAudit/Miscellaneous: `#{share}/man` should be `#{man}` end end RUBY end it "reports an offense when the formula path shortcut `libexec` could be used" do expect_offense(<<~'RUBY') class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install mv "#{prefix}/libexec", share ^^^^^^^^ FormulaAudit/Miscellaneous: `#{prefix}/libexec` should be `#{libexec}` end end RUBY end it "reports an offense when the formula path shortcut `info` could be used" do expect_offense(<<~'RUBY') class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install system "./configure", "--INFODIR=#{prefix}/share/info" ^^^^^^^^^^^ FormulaAudit/Miscellaneous: `#{prefix}/share/info` should be `#{info}` end end RUBY end it "reports an offense when the formula path shortcut `man8` could be used" do expect_offense(<<~'RUBY') class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install system "./configure", "--MANDIR=#{prefix}/share/man/man8" ^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: `#{prefix}/share/man/man8` should be `#{man8}` end end RUBY end it "reports an offense when unvendored lua modules are used" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' depends_on "lpeg" => :lua51 ^^^^^^ FormulaAudit/Miscellaneous: lua modules should be vendored rather than using deprecated `depends_on "lpeg" => :lua51` end RUBY end it "reports an offense when `export` is used to set environment variables" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' system "export", "var=value" ^^^^^^^^ FormulaAudit/Miscellaneous: Use `ENV` instead of invoking `export` to modify the environment end RUBY end it "reports an offense when dependencies with invalid options are used" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' depends_on "foo" => "with-bar" ^^^^^^^^^^ FormulaAudit/Miscellaneous: Dependency 'foo' should not use option `with-bar` end RUBY end it "reports an offense when dependencies with invalid options are used in an array" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' depends_on "httpd" => [:build, :test] depends_on "foo" => [:optional, "with-bar"] ^^^^^^^^^^ FormulaAudit/Miscellaneous: Dependency 'foo' should not use option `with-bar` depends_on "icu4c" => [:optional, "c++11"] ^^^^^^^ FormulaAudit/Miscellaneous: Dependency 'icu4c' should not use option `c++11` end RUBY end it "reports an offense when `build.head?` could be used instead of checking `version`" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' if version == "HEAD" ^^^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: Use `build.head?` instead of inspecting `version` foo() end end RUBY end it "reports an offense when `ARGV.include? (--HEAD)` is used" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' test do head = ARGV.include? "--HEAD" ^^^^ FormulaAudit/Miscellaneous: Use `build.with?` or `build.without?` instead of `ARGV` to check options ^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: Use `if build.head?` instead end end RUBY end it "reports an offense when `needs :openmp` is used" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' needs :openmp ^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: `needs :openmp` should be replaced with `depends_on "gcc"` end RUBY end it "reports an offense when `MACOS_VERSION` is used" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' test do version = MACOS_VERSION ^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: Use `MacOS.version` instead of `MACOS_VERSION` end end RUBY end it "reports an offense when `build.with?` is used for a conditional dependency" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' depends_on "foo" if build.with? "foo" ^^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: Replace `depends_on "foo" if build.with? "foo"` with `depends_on "foo" => :optional` end RUBY end it "reports an offense when `build.without?` is used for a negated conditional dependency" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' depends_on :foo unless build.without? "foo" ^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: Replace `depends_on :foo unless build.without? "foo"` with `depends_on :foo => :recommended` end RUBY end it "reports an offense when `build.include?` is used for a negated conditional dependency" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' depends_on :foo unless build.include? "without-foo" ^^^^^^^^^^^^^^^ FormulaAudit/Miscellaneous: Replace `depends_on :foo unless build.include? "without-foo"` with `depends_on :foo => :recommended` end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/assert_statements_spec.rb
Library/Homebrew/test/rubocops/text/assert_statements_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::AssertStatements do subject(:cop) { described_class.new } context "when auditing formula assertions" do it "reports an offense when assert ... include is used" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' assert File.read("inbox").include?("Sample message 1") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/AssertStatements: Use `assert_match` instead of `assert ...include?` end RUBY end it "reports an offense when assert ... exist? is used without a negation" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' assert File.exist? "default.ini" ^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/AssertStatements: Use `assert_path_exists <path_to_file>` instead of `assert File.exist? "default.ini"` end RUBY end it "reports an offense when assert ... exist? is used with a negation" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' assert !File.exist?("default.ini") ^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/AssertStatements: Use `refute_path_exists <path_to_file>` instead of `assert !File.exist?("default.ini")` end RUBY end it "reports an offense when assert ... executable? is used without a negation" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' assert File.executable? f ^^^^^^^^^^^^^^^^^^ FormulaAudit/AssertStatements: Use `assert_predicate <path_to_file>, :executable?` instead of `assert File.executable? f` end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/text/licenses_spec.rb
Library/Homebrew/test/rubocops/text/licenses_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::Licenses do subject(:cop) { described_class.new } context "when auditing licenses" do it "reports no offenses for license strings" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license "MIT" end RUBY end it "reports no offenses for license symbols" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license :public_domain end RUBY end it "reports no offenses for license hashes" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license any_of: ["MIT", "0BSD"] end RUBY end it "reports no offenses for license exceptions" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license "MIT" => { with: "LLVM-exception" } end RUBY end it "reports no offenses for multiline nested license hashes" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license any_of: [ "MIT", all_of: ["0BSD", "Zlib"], ] end RUBY end it "reports no offenses for multiline nested license hashes with exceptions" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license any_of: [ "MIT", all_of: ["0BSD", "Zlib"], "GPL-2.0-only" => { with: "LLVM-exception" }, ] end RUBY end it "reports an offense for nested license hashes on a single line" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' license any_of: ["MIT", all_of: ["0BSD", "Zlib"]] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Licenses: Split nested license declarations onto multiple lines end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/lines/class_inheritance_spec.rb
Library/Homebrew/test/rubocops/lines/class_inheritance_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::ClassInheritance do subject(:cop) { described_class.new } context "when auditing formula class inheritance" do it "reports an offense when not using spaces for class inheritance" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo<Formula ^^^^^^^ FormulaAudit/ClassInheritance: Use a space in class inheritance: class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/lines/quictls_check_spec.rb
Library/Homebrew/test/rubocops/lines/quictls_check_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::QuicTLSCheck do subject(:cop) { described_class.new } context "when auditing formula dependencies" do it "reports an offense when a formula depends on `quictls`" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' depends_on "quictls" ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/QuicTLSCheck: Formulae in homebrew/core should use `depends_on "openssl@3"` instead of `depends_on "quictls"`. end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb
Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit do describe RuboCop::Cop::FormulaAudit::GenerateCompletionsDSL do subject(:cop) { described_class.new } it "reports an offense when writing to a shell completions file directly" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula name "foo" def install (bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "bash") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/GenerateCompletionsDSL: Use `generate_completions_from_executable(bin/"foo", "completions", shells: [:bash])` instead of `(bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "bash")`. end end RUBY expect_correction(<<~RUBY) class Foo < Formula name "foo" def install generate_completions_from_executable(bin/"foo", "completions", shells: [:bash]) end end RUBY end it "reports an offense when writing to a shell completions file differing from the formula name" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo-cli.rb") class FooCli < Formula name "foo-cli" def install (bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "bash") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/GenerateCompletionsDSL: Use `generate_completions_from_executable(bin/"foo", "completions", base_name: "foo", shells: [:bash])` instead of `(bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "bash")`. end end RUBY expect_correction(<<~RUBY) class FooCli < Formula name "foo-cli" def install generate_completions_from_executable(bin/"foo", "completions", base_name: "foo", shells: [:bash]) end end RUBY end it "reports an offense when writing to a shell completions file using an arg for the shell parameter" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula name "foo" def install (bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "--shell=bash") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/GenerateCompletionsDSL: Use `generate_completions_from_executable(bin/"foo", "completions", shells: [:bash], shell_parameter_format: :arg)` instead of `(bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "--shell=bash")`. end end RUBY expect_correction(<<~RUBY) class Foo < Formula name "foo" def install generate_completions_from_executable(bin/"foo", "completions", shells: [:bash], shell_parameter_format: :arg) end end RUBY end it "reports an offense when writing to a shell completions file using a custom flag for the shell parameter" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula name "foo" def install (bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "--completion-script-bash") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/GenerateCompletionsDSL: Use `generate_completions_from_executable(bin/"foo", "completions", shells: [:bash], shell_parameter_format: "--completion-script-")` instead of `(bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "--completion-script-bash")`. end end RUBY expect_correction(<<~RUBY) class Foo < Formula name "foo" def install generate_completions_from_executable(bin/"foo", "completions", shells: [:bash], shell_parameter_format: "--completion-script-") end end RUBY end it "reports an offense when writing to a completions file indirectly" do expect_offense(<<~RUBY) class Foo < Formula name "foo" def install output = Utils.safe_popen_read(bin/"foo", "completions", "bash") (bash_completion/"foo").write output ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/GenerateCompletionsDSL: Use `generate_completions_from_executable` DSL instead of `(bash_completion/"foo").write output`. end end RUBY end end describe RuboCop::Cop::FormulaAudit::SingleGenerateCompletionsDSLCall do subject(:cop) { described_class.new } it "reports an offense when using multiple #generate_completions_from_executable calls for different shells" do expect_offense(<<~RUBY) class Foo < Formula name "foo" def install generate_completions_from_executable(bin/"foo", "completions", shells: [:bash]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/SingleGenerateCompletionsDSLCall: Use a single `generate_completions_from_executable` call combining all specified shells. generate_completions_from_executable(bin/"foo", "completions", shells: [:zsh]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/SingleGenerateCompletionsDSLCall: Use a single `generate_completions_from_executable` call combining all specified shells. generate_completions_from_executable(bin/"foo", "completions", shells: [:fish]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/SingleGenerateCompletionsDSLCall: Use `generate_completions_from_executable(bin/"foo", "completions")` instead of `generate_completions_from_executable(bin/"foo", "completions", shells: [:fish])`. end end RUBY expect_correction(<<~RUBY) class Foo < Formula name "foo" def install generate_completions_from_executable(bin/"foo", "completions") end end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/urls/git_strict_spec.rb
Library/Homebrew/test/rubocops/urls/git_strict_spec.rb
# frozen_string_literal: true require "rubocops/urls" RSpec.describe RuboCop::Cop::FormulaAuditStrict::GitUrls do subject(:cop) { described_class.new } context "when a git URL is used" do it "reports no offenses with both a tag and a revision" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", tag: "v1.0.0", revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" end RUBY end it "reports no offenses with both a tag, revision and `shallow` before" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", shallow: false, tag: "v1.0.0", revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" end RUBY end it "reports no offenses with both a tag, revision and `shallow` after" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", tag: "v1.0.0", revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", shallow: false end RUBY end it "reports an offense with no `tag`" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAuditStrict/GitUrls: Formulae in homebrew/core should specify a tag for Git URLs revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" end RUBY end it "reports an offense with no `tag` and `shallow`" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAuditStrict/GitUrls: Formulae in homebrew/core should specify a tag for Git URLs revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", shallow: false end RUBY end it "reports no offenses with missing arguments in `head`" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://foo.com" head do url "https://github.com/foo/bar.git" end end RUBY end it "reports no offenses for non-core taps" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url "https://github.com/foo/bar.git" end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/urls/pypi_spec.rb
Library/Homebrew/test/rubocops/urls/pypi_spec.rb
# frozen_string_literal: true require "rubocops/urls" RSpec.describe RuboCop::Cop::FormulaAudit::PyPiUrls do subject(:cop) { described_class.new } context "when a pypi URL is used" do it "reports an offense for pypi.python.org urls" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url "https://pypi.python.org/packages/source/foo/foo-0.1.tar.gz" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/PyPiUrls: Use the "Source" URL found on the PyPI downloads page (https://pypi.org/project/foo/#files) end RUBY end it "reports an offense for short file.pythonhosted.org urls" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url "https://files.pythonhosted.org/packages/source/f/foo/foo-0.1.tar.gz" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/PyPiUrls: Use the "Source" URL found on the PyPI downloads page (https://pypi.org/project/foo/#files) end RUBY end it "reports no offenses for long file.pythonhosted.org urls" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url "https://files.pythonhosted.org/packages/a0/b1/a01b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f/foo-0.1.tar.gz" end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/urls/git_spec.rb
Library/Homebrew/test/rubocops/urls/git_spec.rb
# frozen_string_literal: true require "rubocops/urls" RSpec.describe RuboCop::Cop::FormulaAudit::GitUrls do subject(:cop) { described_class.new } context "when a git URL is used" do it "reports no offenses with a non-git URL" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://foo.com" end RUBY end it "reports no offenses with both a tag and a revision" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", tag: "v1.0.0", revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" end RUBY end it "reports no offenses with both a tag, revision and `shallow` before" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", shallow: false, tag: "v1.0.0", revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" end RUBY end it "reports no offenses with both a tag, revision and `shallow` after" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", tag: "v1.0.0", revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", shallow: false end RUBY end it "reports an offense with no `revision`" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/GitUrls: Formulae in homebrew/core should specify a revision for Git URLs tag: "v1.0.0" end RUBY end it "reports an offense with no `revision` and `shallow`" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/GitUrls: Formulae in homebrew/core should specify a revision for Git URLs shallow: false, tag: "v1.0.0" end RUBY end it "reports no offenses with no `tag`" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" end RUBY end it "reports no offenses with no `tag` and `shallow`" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://github.com/foo/bar.git", revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", shallow: false end RUBY end it "reports no offenses with missing arguments in `head`" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula desc "foo" url "https://foo.com" head do url "https://github.com/foo/bar.git" end end RUBY end it "reports no offenses for non-core taps" do expect_no_offenses(<<~RUBY) class Foo < Formula desc "foo" url "https://github.com/foo/bar.git" end RUBY end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/mac_spec.rb
Library/Homebrew/test/os/mac_spec.rb
# frozen_string_literal: true require "locale" require "os/mac" RSpec.describe OS::Mac do describe "::languages" do it "returns a list of all languages" do expect(described_class.languages).not_to be_empty end end describe "::language" do it "returns the first item from #languages" do expect(described_class.language).to eq(described_class.languages.first) end end describe "::sdk_path" do let(:clt_sdk_path) { Pathname("/tmp/clt/MacOS.sdk") } let(:clt_sdk) { OS::Mac::SDK.new(MacOSVersion.new("26"), clt_sdk_path, :clt) } let(:xcode_sdk_path) { Pathname("/tmp/xcode/MacOS.sdk") } let(:xcode_sdk) { OS::Mac::SDK.new(MacOSVersion.new("26"), xcode_sdk_path, :xcode) } before do allow_any_instance_of(OS::Mac::CLTSDKLocator).to receive(:sdk_if_applicable).and_return(clt_sdk) allow_any_instance_of(OS::Mac::XcodeSDKLocator).to receive(:sdk_if_applicable).and_return(xcode_sdk) end it "returns the Xcode SDK path on Xcode-only systems" do allow(OS::Mac::Xcode).to receive(:installed?).and_return(true) allow(OS::Mac::CLT).to receive(:installed?).and_return(false) expect(described_class.sdk_path).to eq(xcode_sdk_path) end it "returns the CLT SDK path on CLT-only systems" do allow(OS::Mac::Xcode).to receive(:installed?).and_return(false) allow(OS::Mac::CLT).to receive(:installed?).and_return(true) expect(described_class.sdk_path).to eq(clt_sdk_path) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/os_spec.rb
Library/Homebrew/test/os/os_spec.rb
# frozen_string_literal: true RSpec.describe OS do describe "::kernel_version" do it "is not NULL" do expect(described_class.kernel_version).not_to be_null end end describe "::kernel_name" do it "returns Linux on Linux", :needs_linux do expect(described_class.kernel_name).to eq "Linux" end it "returns Darwin on macOS", :needs_macos do expect(described_class.kernel_name).to eq "Darwin" end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/linux_spec.rb
Library/Homebrew/test/os/linux_spec.rb
# frozen_string_literal: true require "locale" require "os/linux" RSpec.describe OS::Linux do describe "::languages", :needs_linux do it "returns a list of all languages" do expect(described_class.languages).not_to be_empty end end describe "::language", :needs_linux do it "returns the first item from #languages" do expect(described_class.language).to eq(described_class.languages.first) end end describe "::'os_version'", :needs_linux do it "returns the OS version" do expect(described_class.os_version).not_to be_empty end end describe "::'wsl?'" do it "returns the WSL state" do expect(described_class.wsl?).to be(false) end end describe "::'wsl_version'", :needs_linux do it "returns the WSL version" do expect(described_class.wsl_version).to match(Version::NULL) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/mac/sdk_spec.rb
Library/Homebrew/test/os/mac/sdk_spec.rb
# frozen_string_literal: true RSpec.describe OS::Mac::CLTSDKLocator do subject(:locator) { described_class.new } let(:big_sur_sdk) { OS::Mac::SDK.new(MacOSVersion.new("11"), "/some/path/MacOSX.sdk", :clt) } let(:catalina_sdk) { OS::Mac::SDK.new(MacOSVersion.new("10.15"), "/some/path/MacOSX10.15.sdk", :clt) } specify "#sdk_for" do allow(locator).to receive(:all_sdks).and_return([big_sur_sdk, catalina_sdk]) expect(locator.sdk_for(MacOSVersion.new("11"))).to eq(big_sur_sdk) expect(locator.sdk_for(MacOSVersion.new("10.15"))).to eq(catalina_sdk) expect { locator.sdk_for(MacOSVersion.new("10.14")) }.to raise_error(described_class::NoSDKError) end describe "#sdk_if_applicable" do before do allow(locator).to receive(:all_sdks).and_return([big_sur_sdk, catalina_sdk]) end it "returns the requested SDK" do expect(locator.sdk_if_applicable(MacOSVersion.new("11"))).to eq(big_sur_sdk) expect(locator.sdk_if_applicable(MacOSVersion.new("10.15"))).to eq(catalina_sdk) end it "returns the latest SDK if the requested version is not found" do expect(locator.sdk_if_applicable(MacOSVersion.new("10.14"))).to eq(big_sur_sdk) expect(locator.sdk_if_applicable(MacOSVersion.new("12"))).to eq(big_sur_sdk) end it "returns the SDK matching the OS version if no version is specified" do allow(OS::Mac).to receive(:version).and_return(MacOSVersion.new("10.15")) expect(locator.sdk_if_applicable).to eq(catalina_sdk) end it "returns the latest SDK on older OS versions when there's no matching SDK" do allow(OS::Mac).to receive(:version).and_return(MacOSVersion.new("10.14")) expect(locator.sdk_if_applicable).to eq(big_sur_sdk) end it "returns nil if the OS is newer than all SDKs" do allow(OS::Mac).to receive(:version).and_return(MacOSVersion.new("12")) expect(locator.sdk_if_applicable).to be_nil end end describe "#all_sdks" do let(:big_sur_sdk_prefix) { TEST_FIXTURE_DIR/"sdks/big_sur" } let(:malformed_sdk_prefix) { TEST_FIXTURE_DIR/"sdks/malformed" } it "reads the SDKSettings.json version of unversioned SDKs folders" do allow(locator).to receive(:sdk_prefix).and_return(big_sur_sdk_prefix.to_s) sdks = locator.all_sdks expect(sdks.count).to eq(1) sdk = sdks.first expect(sdk.path).to eq(big_sur_sdk_prefix/"MacOSX.sdk") expect(sdk.version).to eq(MacOSVersion.new("11")) expect(sdk.source).to eq(:clt) end it "rejects malformed sdks" do allow(locator).to receive(:sdk_prefix).and_return(malformed_sdk_prefix.to_s) expect(locator.all_sdks).to be_empty end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/mac/pkgconfig_spec.rb
Library/Homebrew/test/os/mac/pkgconfig_spec.rb
# frozen_string_literal: true # These tests assume the needed SDKs are correctly installed, i.e. `brew doctor` passes. # The CLT version installed should be the latest available for the running OS. # The tests do not check other OS versions beyond than the one the tests are being run on. # # It is not possible to automatically check the following libraries for version updates: # # - libedit (incorrect LIBEDIT_MAJOR/MINOR in histedit.h) # - uuid (not a standalone library) # # Additionally, libffi version detection cannot be performed on systems running Mojave or earlier. # TODO: we no longer support Mojave or earlier, so we can fix this now. # # For indeterminable cases, consult https://opensource.apple.com for the version used. RSpec.describe "pkg-config", :needs_ci, type: :system do def pc_version(library) path = HOMEBREW_LIBRARY_PATH/"os/mac/pkgconfig/#{MacOS.version}/#{library}.pc" version = File.foreach(path) .lazy .grep(/^Version:\s*?(.+)$/) { Regexp.last_match(1) } .first .strip if (match = version.match(/^\${(.+?)}$/)) version = File.foreach(path) .lazy .grep(/^#{match.captures.first}\s*?=\s*?(.+)$/) { Regexp.last_match(1) } .first .strip end version end let(:sdk) { MacOS.sdk_path } it "returns the correct version for bzip2" do version = File.foreach("#{sdk}/usr/include/bzlib.h") .lazy .grep(%r{^\s*bzip2/libbzip2 version (\S+) of }) { Regexp.last_match(1) } .first expect(pc_version("bzip2")).to eq(version) end it "returns the correct version for expat" do version = File.foreach("#{sdk}/usr/include/expat.h") .lazy .grep(/^#define XML_(MAJOR|MINOR|MICRO)_VERSION (\d+)$/) do { Regexp.last_match(1).downcase => Regexp.last_match(2) } end .reduce(:merge!) version = "#{version["major"]}.#{version["minor"]}.#{version["micro"]}" expect(pc_version("expat")).to eq(version) end it "returns the correct version for libcurl" do version = File.foreach("#{sdk}/usr/include/curl/curlver.h") .lazy .grep(/^#define LIBCURL_VERSION "(.*?)"$/) { Regexp.last_match(1) } .first expect(pc_version("libcurl")).to eq(version) end it "returns the correct version for libexslt" do version = File.foreach("#{sdk}/usr/include/libexslt/exsltconfig.h") .lazy .grep(/^#define LIBEXSLT_VERSION (\d+)$/) { Regexp.last_match(1) } .first .rjust(6, "0") version = "#{version[-6..-5].to_i}.#{version[-4..-3].to_i}.#{version[-2..].to_i}" expect(pc_version("libexslt")).to eq(version) end it "returns the correct version for libffi" do version = File.foreach("#{sdk}/usr/include/ffi/ffi.h") .lazy .grep(/^\s*libffi (\S+)\s+(?:- Copyright |$)/) { Regexp.last_match(1) } .first skip "Cannot detect system libffi version." if version == "PyOBJC" expect(pc_version("libffi")).to eq(version) end it "returns the correct version for libxml-2.0" do version = File.foreach("#{sdk}/usr/include/libxml2/libxml/xmlversion.h") .lazy .grep(/^#define LIBXML_DOTTED_VERSION "(.*?)"$/) { Regexp.last_match(1) } .first expect(pc_version("libxml-2.0")).to eq(version) end it "returns the correct version for libxslt" do version = File.foreach("#{sdk}/usr/include/libxslt/xsltconfig.h") .lazy .grep(/^#define LIBXSLT_DOTTED_VERSION "(.*?)"$/) { Regexp.last_match(1) } .first expect(pc_version("libxslt")).to eq(version) end it "returns the correct version for ncurses" do version = File.foreach("#{sdk}/usr/include/ncurses.h") .lazy .grep(/^#define NCURSES_VERSION_(MAJOR|MINOR|PATCH) (\d+)$/) do { Regexp.last_match(1).downcase => Regexp.last_match(2) } end .reduce(:merge!) version = "#{version["major"]}.#{version["minor"]}.#{version["patch"]}" expect(pc_version("ncurses")).to eq(version) expect(pc_version("ncursesw")).to eq(version) end it "returns the correct version for sqlite3" do version = File.foreach("#{sdk}/usr/include/sqlite3.h") .lazy .grep(/^#define SQLITE_VERSION\s+?"(.*?)"$/) { Regexp.last_match(1) } .first expect(pc_version("sqlite3")).to eq(version) end it "returns the correct version for zlib" do version = File.foreach("#{sdk}/usr/include/zlib.h") .lazy .grep(/^#define ZLIB_VERSION "(.*?)"$/) { Regexp.last_match(1) } .first expect(pc_version("zlib")).to eq(version) end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/mac/dependency_collector_spec.rb
Library/Homebrew/test/os/mac/dependency_collector_spec.rb
# frozen_string_literal: true require "dependency_collector" RSpec.describe DependencyCollector do alias_matcher :need_tar_xz_dependency, :be_tar_needs_xz_dependency subject(:collector) { described_class.new } specify "Resource dependency from a '.xz' URL" do resource = Resource.new resource.url("https://brew.sh/foo.tar.xz") expect(collector.add(resource)).to be_nil end specify "Resource dependency from a '.zip' URL" do resource = Resource.new resource.url("https://brew.sh/foo.zip") expect(collector.add(resource)).to be_nil end specify "Resource dependency from a '.bz2' URL" do resource = Resource.new resource.url("https://brew.sh/foo.tar.bz2") expect(collector.add(resource)).to be_nil end specify "Resource dependency from a '.git' URL" do resource = Resource.new resource.url("git://brew.sh/foo/bar.git") expect(collector.add(resource)).to be_nil end specify "Resource dependency from a Subversion URL" do resource = Resource.new resource.url("svn://brew.sh/foo/bar") expect(collector.add(resource)).to eq(Dependency.new("subversion", [:build, :test, :implicit])) end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/mac/keg_spec.rb
Library/Homebrew/test/os/mac/keg_spec.rb
# frozen_string_literal: true require "keg" RSpec.describe Keg do include FileUtils subject(:keg) { described_class.new(keg_path) } describe "#mach_o_files" do let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" } before { (keg_path/"lib").mkpath } after { keg.unlink } it "skips hardlinks" do cp dylib_path("i386"), keg_path/"lib/i386.dylib" ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" keg.link expect(keg.mach_o_files.count).to eq(1) end it "isn't confused by symlinks" do cp dylib_path("i386"), keg_path/"lib/i386.dylib" ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" ln_s keg_path/"lib/i386.dylib", keg_path/"lib/i386_symlink.dylib" keg.link expect(keg.mach_o_files.count).to eq(1) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/mac/formula_spec.rb
Library/Homebrew/test/os/mac/formula_spec.rb
# frozen_string_literal: true require "test/support/fixtures/testball" require "formula" RSpec.describe Formula do describe "#uses_from_macos" do before do allow(OS).to receive(:mac?).and_return(true) allow(OS::Mac).to receive(:version).and_return(MacOSVersion.from_symbol(:sonoma)) end it "adds a macOS dependency to all specs if the OS version meets requirements" do f = formula "foo" do url "foo-1.0" uses_from_macos("foo", since: :big_sur) end expect(f.class.stable.deps).to be_empty expect(f.class.head.deps).to be_empty expect(f.class.stable.declared_deps).not_to be_empty expect(f.class.head.declared_deps).not_to be_empty expect(f.class.stable.declared_deps.first.name).to eq("foo") expect(f.class.head.declared_deps.first.name).to eq("foo") end it "adds a dependency to any spec if the OS version doesn't meet requirements" do f = formula "foo" do url "foo-1.0" uses_from_macos("foo", since: :tahoe) end expect(f.class.stable.deps).not_to be_empty expect(f.class.head.deps).not_to be_empty expect(f.class.stable.deps.first.name).to eq("foo") expect(f.class.head.deps.first.name).to eq("foo") expect(f.class.stable.declared_deps).not_to be_empty expect(f.class.head.declared_deps).not_to be_empty end end describe "#on_macos" do it "adds a dependency on macos only" do f = formula do homepage "https://brew.sh" url "https://brew.sh/test-0.1.tbz" sha256 TEST_SHA256 depends_on "hello_both" on_macos do depends_on "hello_macos" end on_linux do depends_on "hello_linux" end end expect(f.class.stable.deps[0].name).to eq("hello_both") expect(f.class.stable.deps[1].name).to eq("hello_macos") expect(f.class.stable.deps[2]).to be_nil end it "adds a patch on Mac only" do f = formula do homepage "https://brew.sh" url "https://brew.sh/test-0.1.tbz" sha256 TEST_SHA256 patch do on_macos do url "patch_macos" end on_linux do url "patch_linux" end end end expect(f.patchlist.length).to eq(1) expect(f.patchlist.first.strip).to eq(:p1) expect(f.patchlist.first.url).to eq("patch_macos") end it "uses on_macos within a resource block" do f = formula do homepage "https://brew.sh" url "https://brew.sh/test-0.1.tbz" sha256 TEST_SHA256 resource "test_resource" do on_macos do url "resource_macos" end end end expect(f.resources.length).to eq(1) expect(f.resources.first.url).to eq("resource_macos") end end describe "#shared_library" do it "generates a shared library string" do f = Testball.new expect(f.shared_library("foobar")).to eq("foobar.dylib") expect(f.shared_library("foobar", 2)).to eq("foobar.2.dylib") expect(f.shared_library("foobar", nil)).to eq("foobar.dylib") expect(f.shared_library("foobar", "*")).to eq("foobar{,.*}.dylib") expect(f.shared_library("*")).to eq("*.dylib") expect(f.shared_library("*", 2)).to eq("*.2.dylib") expect(f.shared_library("*", nil)).to eq("*.dylib") expect(f.shared_library("*", "*")).to eq("*.dylib") end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/mac/reinstall_spec.rb
Library/Homebrew/test/os/mac/reinstall_spec.rb
# typed: false # frozen_string_literal: true require "reinstall" require "extend/os/mac/pkgconf" RSpec.describe Homebrew::Reinstall do describe ".reinstall_pkgconf_if_needed!" do let(:formula) { instance_double(Formula) } let(:formula_installer) do instance_double(FormulaInstaller, formula:, prelude_fetch: true, prelude: true, fetch: true) end let(:context) { instance_double(described_class::InstallationContext, formula_installer:) } before do allow(Formula).to receive(:[]).with("pkgconf").and_return(formula) allow(Homebrew::Install).to receive(:fetch_formulae).with([formula_installer]) allow(described_class).to receive(:build_install_context).and_return(context) end context "when there is no macOS SDK mismatch" do it "does nothing" do allow(Homebrew::Pkgconf).to receive(:macos_sdk_mismatch).and_return(nil) expect(described_class).not_to receive(:reinstall_formula) described_class.reinstall_pkgconf_if_needed! end end context "when dry_run is true" do it "prints a warning and does not reinstall" do allow(Homebrew::Pkgconf).to receive_messages( macos_sdk_mismatch: :mismatch, mismatch_warning_message: "warning", ) expect(described_class).not_to receive(:reinstall_formula) expect(described_class).to receive(:opoo).with(/would be reinstalled/) described_class.reinstall_pkgconf_if_needed!(dry_run: true) end end context "when there is a mismatch and reinstall succeeds" do it "reinstalls pkgconf and prints success" do allow(Homebrew::Pkgconf).to receive(:macos_sdk_mismatch).and_return(:mismatch) expect(described_class).to receive(:reinstall_formula).with(context) expect(described_class).to receive(:ohai).with(/Reinstalled pkgconf/) described_class.reinstall_pkgconf_if_needed! end end context "when reinstall_formula raises an error" do it "rescues and prints the mismatch warning" do allow(Homebrew::Pkgconf).to receive_messages( macos_sdk_mismatch: :mismatch, mismatch_warning_message: "warning", ) allow(described_class).to receive(:reinstall_formula).and_raise(RuntimeError) expect(described_class).to receive(:ofail).with("warning") described_class.reinstall_pkgconf_if_needed! end end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/mac/diagnostic_spec.rb
Library/Homebrew/test/os/mac/diagnostic_spec.rb
# frozen_string_literal: true require "diagnostic" RSpec.describe Homebrew::Diagnostic::Checks do subject(:checks) { described_class.new } specify "#check_for_unsupported_macos" do ENV.delete("HOMEBREW_DEVELOPER") macos_version = MacOSVersion.new("30") allow(OS::Mac).to receive_messages(version: macos_version, full_version: macos_version) allow(OS::Mac.version).to receive_messages(outdated_release?: false, prerelease?: true) expect(checks.check_for_unsupported_macos) .to match("We do not provide support for this pre-release version.") end specify "#check_if_xcode_needs_clt_installed" do macos_version = MacOSVersion.new("11") allow(OS::Mac).to receive_messages(version: macos_version, full_version: macos_version) allow(OS::Mac::Xcode).to receive_messages(installed?: true, version: "8.0", without_clt?: true) expect(checks.check_if_xcode_needs_clt_installed) .to match("Xcode alone is not sufficient on Big Sur") end describe "#check_if_supported_sdk_available" do let(:macos_version) { MacOSVersion.new("11") } before do allow(DevelopmentTools).to receive(:installed?).and_return(true) allow(OS::Mac).to receive(:version).and_return(macos_version) allow(OS::Mac::CLT).to receive(:below_minimum_version?).and_return(false) allow(OS::Mac::Xcode).to receive(:below_minimum_version?).and_return(false) end it "doesn't trigger when a valid SDK is present" do allow(OS::Mac).to receive_messages(sdk: OS::Mac::SDK.new( macos_version, "/some/path/MacOSX.sdk", :clt )) expect(checks.check_if_supported_sdk_available).to be_nil end it "triggers when a valid SDK is not present on CLT systems" do allow(OS::Mac).to receive_messages(sdk: nil, sdk_locator: OS::Mac::CLT.sdk_locator) expect(checks.check_if_supported_sdk_available) .to include("Your Command Line Tools (CLT) does not support macOS #{macos_version}") end it "triggers when a valid SDK is not present on Xcode systems" do allow(OS::Mac).to receive_messages(sdk: nil, sdk_locator: OS::Mac::Xcode.sdk_locator) expect(checks.check_if_supported_sdk_available) .to include("Your Xcode does not support macOS #{macos_version}") end end describe "#check_broken_sdks" do it "doesn't trigger when SDK versions are as expected" do allow(OS::Mac).to receive(:sdk_locator).and_return(OS::Mac::CLT.sdk_locator) allow_any_instance_of(OS::Mac::CLTSDKLocator).to receive(:all_sdks).and_return([ OS::Mac::SDK.new(MacOSVersion.new("11"), "/some/path/MacOSX.sdk", :clt), OS::Mac::SDK.new(MacOSVersion.new("10.15"), "/some/path/MacOSX10.15.sdk", :clt), ]) expect(checks.check_broken_sdks).to be_nil end it "triggers when the CLT SDK version doesn't match the folder name" do allow_any_instance_of(OS::Mac::CLTSDKLocator).to receive(:all_sdks).and_return([ OS::Mac::SDK.new(MacOSVersion.new("10.14"), "/some/path/MacOSX10.15.sdk", :clt), ]) expect(checks.check_broken_sdks) .to include("SDKs in your Command Line Tools (CLT) installation do not match the SDK folder names") end it "triggers when the Xcode SDK version doesn't match the folder name" do allow(OS::Mac).to receive(:sdk_locator).and_return(OS::Mac::Xcode.sdk_locator) allow_any_instance_of(OS::Mac::XcodeSDKLocator).to receive(:all_sdks).and_return([ OS::Mac::SDK.new(MacOSVersion.new("10.14"), "/some/path/MacOSX10.15.sdk", :xcode), ]) expect(checks.check_broken_sdks) .to include("The contents of the SDKs in your Xcode installation do not match the SDK folder names") end end describe "#check_pkgconf_macos_sdk_mismatch" do let(:pkg_config_formula) { instance_double(Formula, any_version_installed?: true) } let(:tab) { instance_double(Tab, built_on: { "os_version" => "13" }) } before do allow(Formulary).to receive(:factory_stub).with("pkgconf").and_return(pkg_config_formula) allow(Tab).to receive(:for_formula).with(pkg_config_formula).and_return(tab) end it "doesn't trigger when pkgconf is not installed" do allow(Formulary).to receive(:factory_stub).with("pkgconf").and_raise(FormulaUnavailableError.new("pkgconf")) expect(checks.check_pkgconf_macos_sdk_mismatch).to be_nil end it "doesn't trigger when no versions are installed" do allow(pkg_config_formula).to receive(:any_version_installed?).and_return(false) expect(checks.check_pkgconf_macos_sdk_mismatch).to be_nil end it "doesn't trigger when built_on information is missing" do allow(tab).to receive(:built_on).and_return(nil) expect(checks.check_pkgconf_macos_sdk_mismatch).to be_nil end it "doesn't trigger when os_version information is missing" do allow(tab).to receive(:built_on).and_return({ "cpu_family" => "x86_64" }) expect(checks.check_pkgconf_macos_sdk_mismatch).to be_nil end it "doesn't trigger when versions match" do current_version = MacOS.version.to_s allow(tab).to receive(:built_on).and_return({ "os_version" => current_version }) expect(checks.check_pkgconf_macos_sdk_mismatch).to be_nil end it "triggers when built_on version differs from current macOS version" do allow(MacOS).to receive(:version).and_return(MacOSVersion.new("14")) allow(tab).to receive(:built_on).and_return({ "os_version" => "13" }) expect(checks.check_pkgconf_macos_sdk_mismatch).to include("brew reinstall pkgconf") end end describe "#check_cask_quarantine_support" do it "returns nil when quarantine is available" do allow(Cask::Quarantine).to receive(:check_quarantine_support).and_return([:quarantine_available, nil]) expect(checks.check_cask_quarantine_support).to be_nil end it "returns error when xattr is broken" do allow(Cask::Quarantine).to receive(:check_quarantine_support).and_return([:xattr_broken, nil]) expect(checks.check_cask_quarantine_support) .to match("there's no working version of `xattr` on this system") end it "returns error when swift is not available" do allow(Cask::Quarantine).to receive(:check_quarantine_support).and_return([:no_swift, nil]) expect(checks.check_cask_quarantine_support) .to match("there's no available version of `swift` on this system") end it "returns error when swift is broken due to missing CLT" do allow(Cask::Quarantine).to receive(:check_quarantine_support).and_return([:swift_broken_clt, nil]) expect(checks.check_cask_quarantine_support) .to match("Swift is not working due to missing Command Line Tools") end it "returns error when swift compilation failed" do allow(Cask::Quarantine).to receive(:check_quarantine_support).and_return([:swift_compilation_failed, nil]) expect(checks.check_cask_quarantine_support) .to match("Swift compilation failed") end it "returns error when swift runtime error occurs" do allow(Cask::Quarantine).to receive(:check_quarantine_support).and_return([:swift_runtime_error, nil]) expect(checks.check_cask_quarantine_support) .to match("Swift runtime error") end it "returns error when swift is not executable" do allow(Cask::Quarantine).to receive(:check_quarantine_support).and_return([:swift_not_executable, nil]) expect(checks.check_cask_quarantine_support) .to match("Swift is not executable") end it "returns error when swift returns unexpected error" do allow(Cask::Quarantine).to receive(:check_quarantine_support).and_return([:swift_unexpected_error, "whoopsie"]) expect(checks.check_cask_quarantine_support) .to match("whoopsie") end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/mac/formula_installer_spec.rb
Library/Homebrew/test/os/mac/formula_installer_spec.rb
# frozen_string_literal: true require "formula_installer" require "test/support/fixtures/testball" RSpec.describe FormulaInstaller do include FileUtils subject(:keg) { described_class.new(keg_path) } describe "#fresh_install" do subject(:formula_installer) { described_class.new(Testball.new) } it "is true by default" do formula = Testball.new expect(formula_installer.fresh_install?(formula)).to be true end it "is false in developer mode" do formula = Testball.new allow(Homebrew::EnvConfig).to receive_messages(developer?: true) expect(formula_installer.fresh_install?(formula)).to be false end it "is false on outdated releases" do formula = Testball.new allow(OS::Mac.version).to receive_messages(outdated_release?: true) expect(formula_installer.fresh_install?(formula)).to be false end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/mac/mach_spec.rb
Library/Homebrew/test/os/mac/mach_spec.rb
# frozen_string_literal: true RSpec.describe MachOShim do describe "Pathname tests" do specify "fat dylib" do pn = dylib_path("fat") expect(pn).to be_universal expect(pn).not_to be_i386 expect(pn).not_to be_x86_64 expect(pn).not_to be_ppc7400 expect(pn).not_to be_ppc64 expect(pn).to be_dylib expect(pn).not_to be_mach_o_executable expect(pn).not_to be_text_executable expect(pn.arch).to eq(:universal) end specify "i386 dylib" do pn = dylib_path("i386") expect(pn).not_to be_universal expect(pn).to be_i386 expect(pn).not_to be_x86_64 expect(pn).not_to be_ppc7400 expect(pn).not_to be_ppc64 expect(pn).to be_dylib expect(pn).not_to be_mach_o_executable expect(pn).not_to be_text_executable expect(pn).not_to be_mach_o_bundle end specify "x86_64 dylib" do pn = dylib_path("x86_64") expect(pn).not_to be_universal expect(pn).not_to be_i386 expect(pn).to be_x86_64 expect(pn).not_to be_ppc7400 expect(pn).not_to be_ppc64 expect(pn).to be_dylib expect(pn).not_to be_mach_o_executable expect(pn).not_to be_text_executable expect(pn).not_to be_mach_o_bundle end specify "Mach-O executable" do pn = MachOPathname.wrap("#{TEST_FIXTURE_DIR}/mach/a.out") expect(pn).to be_universal expect(pn).not_to be_i386 expect(pn).not_to be_x86_64 expect(pn).not_to be_ppc7400 expect(pn).not_to be_ppc64 expect(pn).not_to be_dylib expect(pn).to be_mach_o_executable expect(pn).not_to be_text_executable expect(pn).not_to be_mach_o_bundle end specify "fat bundle" do pn = bundle_path("fat") expect(pn).to be_universal expect(pn).not_to be_i386 expect(pn).not_to be_x86_64 expect(pn).not_to be_ppc7400 expect(pn).not_to be_ppc64 expect(pn).not_to be_dylib expect(pn).not_to be_mach_o_executable expect(pn).not_to be_text_executable expect(pn).to be_mach_o_bundle end specify "i386 bundle" do pn = bundle_path("i386") expect(pn).not_to be_universal expect(pn).to be_i386 expect(pn).not_to be_x86_64 expect(pn).not_to be_ppc7400 expect(pn).not_to be_ppc64 expect(pn).not_to be_dylib expect(pn).not_to be_mach_o_executable expect(pn).not_to be_text_executable expect(pn).to be_mach_o_bundle end specify "x86_64 bundle" do pn = bundle_path("x86_64") expect(pn).not_to be_universal expect(pn).not_to be_i386 expect(pn).to be_x86_64 expect(pn).not_to be_ppc7400 expect(pn).not_to be_ppc64 expect(pn).not_to be_dylib expect(pn).not_to be_mach_o_executable expect(pn).not_to be_text_executable expect(pn).to be_mach_o_bundle end specify "non-Mach-O" do pn = MachOPathname.wrap("#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz") expect(pn).not_to be_universal expect(pn).not_to be_i386 expect(pn).not_to be_x86_64 expect(pn).not_to be_ppc7400 expect(pn).not_to be_ppc64 expect(pn).not_to be_dylib expect(pn).not_to be_mach_o_executable expect(pn).not_to be_text_executable expect(pn).not_to be_mach_o_bundle expect(pn.arch).to eq(:dunno) end end describe "text executables" do let(:pn) { MachOPathname.wrap(HOMEBREW_PREFIX/"an_executable") } after { pn.unlink } specify "simple shebang" do pn.write "#!/bin/sh" expect(pn).not_to be_universal expect(pn).not_to be_i386 expect(pn).not_to be_x86_64 expect(pn).not_to be_ppc7400 expect(pn).not_to be_ppc64 expect(pn).not_to be_dylib expect(pn).not_to be_mach_o_executable expect(pn).to be_text_executable expect(pn.archs).to eq([]) expect(pn.arch).to eq(:dunno) end specify "shebang with options" do pn.write "#! /usr/bin/perl -w" expect(pn).not_to be_universal expect(pn).not_to be_i386 expect(pn).not_to be_x86_64 expect(pn).not_to be_ppc7400 expect(pn).not_to be_ppc64 expect(pn).not_to be_dylib expect(pn).not_to be_mach_o_executable expect(pn).to be_text_executable expect(pn.archs).to eq([]) expect(pn.arch).to eq(:dunno) end specify "malformed shebang" do pn.write " #!" expect(pn).not_to be_universal expect(pn).not_to be_i386 expect(pn).not_to be_x86_64 expect(pn).not_to be_ppc7400 expect(pn).not_to be_ppc64 expect(pn).not_to be_dylib expect(pn).not_to be_mach_o_executable expect(pn).not_to be_text_executable expect(pn.archs).to eq([]) expect(pn.arch).to eq(:dunno) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/linux/pathname_spec.rb
Library/Homebrew/test/os/linux/pathname_spec.rb
# frozen_string_literal: true require "extend/pathname" RSpec.describe Pathname do let(:elf_dir) { ELFPathname.wrap("#{TEST_FIXTURE_DIR}/elf") } let(:sho) { ELFPathname.wrap(elf_dir/"libforty.so.0") } let(:sho_without_runpath_rpath) { ELFPathname.wrap(elf_dir/"libhello.so.0") } let(:exec) { ELFPathname.wrap(elf_dir/"hello_with_rpath") } def patch_elfs mktmpdir do |tmp_dir| %w[c.elf].each do |elf| FileUtils.cp(elf_dir/elf, tmp_dir/elf) yield ELFPathname.wrap(tmp_dir/elf) end end end describe "#interpreter" do it "returns interpreter" do expect(exec.interpreter).to eq "/lib64/ld-linux-x86-64.so.2" expect(sho.interpreter).to be_nil end end describe "#rpath" do it "returns rpath" do expect(sho.rpath).to eq "runpath" expect(exec.rpath).to eq "@@HOMEBREW_PREFIX@@/lib" expect(sho_without_runpath_rpath.rpath).to be_nil end end describe "#patch!" do let(:placeholder_prefix) { "@@HOMEBREW_PREFIX@@" } let(:short_prefix) { "/home/dwarf" } let(:standard_prefix) { "/home/linuxbrew/.linuxbrew" } let(:long_prefix) { "/home/organized/very organized/litter/more organized than/your words can describe" } let(:prefixes) { [short_prefix, standard_prefix, long_prefix].map { |prefix| ELFPathname.wrap(prefix) } } # file is copied as modified_elf to avoid caching issues it "only interpreter" do prefixes.each do |new_prefix| patch_elfs do |elf| interpreter = elf.interpreter.gsub(placeholder_prefix, new_prefix) elf.patch!(interpreter:) modified_elf = ELFPathname.wrap(elf.dirname/"mod.#{elf.basename}") FileUtils.cp(elf, modified_elf) expect(modified_elf.interpreter).to eq interpreter expect(modified_elf.rpath).to eq "@@HOMEBREW_PREFIX@@/lib" end end end it "only rpath" do prefixes.each do |new_prefix| patch_elfs do |elf| rpath = elf.rpath.gsub(placeholder_prefix, new_prefix) elf.patch!(rpath:) modified_elf = ELFPathname.wrap(elf.dirname/"mod.#{elf.basename}") FileUtils.cp(elf, modified_elf) expect(modified_elf.interpreter).to eq "@@HOMEBREW_PREFIX@@/lib/ld.so" expect(modified_elf.rpath).to eq rpath end end end it "both" do prefixes.each do |new_prefix| patch_elfs do |elf| interpreter = elf.interpreter.gsub(placeholder_prefix, new_prefix) rpath = elf.rpath.gsub(placeholder_prefix, new_prefix) elf.patch!(interpreter:, rpath:) modified_elf = ELFPathname.wrap(elf.dirname/"mod.#{elf.basename}") FileUtils.cp(elf, modified_elf) expect(modified_elf.interpreter).to eq interpreter expect(modified_elf.rpath).to eq rpath end end end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/linux/dependency_collector_spec.rb
Library/Homebrew/test/os/linux/dependency_collector_spec.rb
# frozen_string_literal: true require "dependency_collector" RSpec.describe DependencyCollector do alias_matcher :be_a_build_requirement, :be_build subject(:collector) { described_class.new } describe "#add" do let(:resource) { Resource.new } context "when xz, unzip and bzip2 are not available" do it "creates a resource dependency from a '.xz' URL" do resource.url("https://brew.sh/foo.xz") allow_any_instance_of(Object).to receive(:which).with("xz") expect(collector.add(resource)).to eq(Dependency.new("xz", [:build, :test, :implicit])) end it "creates a resource dependency from a '.zip' URL" do resource.url("https://brew.sh/foo.zip") allow_any_instance_of(Object).to receive(:which).with("unzip") expect(collector.add(resource)).to eq(Dependency.new("unzip", [:build, :test, :implicit])) end it "creates a resource dependency from a '.bz2' URL" do resource.url("https://brew.sh/foo.tar.bz2") allow_any_instance_of(Object).to receive(:which).with("bzip2") expect(collector.add(resource)).to eq(Dependency.new("bzip2", [:build, :test, :implicit])) end end context "when xz, zip and bzip2 are available" do it "does not create a resource dependency from a '.xz' URL" do resource.url("https://brew.sh/foo.xz") allow_any_instance_of(Object).to receive(:which).with("xz").and_return(Pathname.new("foo")) expect(collector.add(resource)).to be_nil end it "does not create a resource dependency from a '.zip' URL" do resource.url("https://brew.sh/foo.zip") allow_any_instance_of(Object).to receive(:which).with("unzip").and_return(Pathname.new("foo")) expect(collector.add(resource)).to be_nil end it "does not create a resource dependency from a '.bz2' URL" do resource.url("https://brew.sh/foo.tar.bz2") allow_any_instance_of(Object).to receive(:which).with("bzip2").and_return(Pathname.new("foo")) expect(collector.add(resource)).to be_nil end end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/linux/libstdcxx_spec.rb
Library/Homebrew/test/os/linux/libstdcxx_spec.rb
# frozen_string_literal: true require "os/linux/libstdcxx" RSpec.describe OS::Linux::Libstdcxx do describe "::below_ci_version?" do it "returns false when system version matches CI version" do allow(described_class).to receive(:system_version).and_return(Version.new(OS::LINUX_LIBSTDCXX_CI_VERSION)) expect(described_class.below_ci_version?).to be false end it "returns true when system version cannot be detected" do allow(described_class).to receive(:system_version).and_return(Version::NULL) expect(described_class.below_ci_version?).to be true end end describe "::system_version" do let(:tmpdir) { mktmpdir } let(:libstdcxx) { tmpdir/described_class::SONAME } let(:soversion) { Version.new(described_class::SOVERSION.to_s) } before do tmpdir.mkpath described_class.instance_variable_set(:@system_version, nil) allow(described_class).to receive(:system_path).and_return(libstdcxx) end after do FileUtils.rm_rf(tmpdir) end it "returns NULL when unable to find system path" do allow(described_class).to receive(:system_path).and_return(nil) expect(described_class.system_version).to be Version::NULL end it "returns full version from filename" do full_version = Version.new("#{soversion}.0.999") libstdcxx_real = libstdcxx.sub_ext(".#{full_version}") FileUtils.touch libstdcxx_real FileUtils.ln_s libstdcxx_real, libstdcxx expect(described_class.system_version).to eq full_version end it "returns major version when non-standard libstdc++ filename without full version" do FileUtils.touch libstdcxx expect(described_class.system_version).to eq soversion end it "returns major version when non-standard libstdc++ filename with unexpected realpath" do libstdcxx_real = tmpdir/"libstdc++.so.real" FileUtils.touch libstdcxx_real FileUtils.ln_s libstdcxx_real, libstdcxx expect(described_class.system_version).to eq soversion end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/linux/ld_spec.rb
Library/Homebrew/test/os/linux/ld_spec.rb
# frozen_string_literal: true require "os/linux/ld" require "tmpdir" RSpec.describe OS::Linux::Ld do let(:diagnostics) do <<~EOS path.prefix="/usr" path.sysconfdir="/usr/local/etc" path.system_dirs[0x0]="/lib64" path.system_dirs[0x1]="/var/lib" EOS end describe "::system_ld_so" do let(:ld_so) { "/lib/ld-linux.so.3" } before do allow(File).to receive(:executable?).and_return(false) described_class.instance_variable_set(:@system_ld_so, nil) end it "returns the path to a known dynamic linker" do allow(File).to receive(:executable?).with(ld_so).and_return(true) expect(described_class.system_ld_so).to eq(Pathname(ld_so)) end it "returns nil when there is no known dynamic linker" do expect(described_class.system_ld_so).to be_nil end end describe "::sysconfdir" do it "returns path.sysconfdir" do allow(described_class).to receive(:ld_so_diagnostics).and_return(diagnostics) expect(described_class.sysconfdir).to eq("/usr/local/etc") expect(described_class.sysconfdir(brewed: false)).to eq("/usr/local/etc") end it "returns fallback on blank diagnostics" do allow(described_class).to receive(:ld_so_diagnostics).and_return("") expect(described_class.sysconfdir).to eq("/etc") expect(described_class.sysconfdir(brewed: false)).to eq("/etc") end end describe "::system_dirs" do it "returns all path.system_dirs" do allow(described_class).to receive(:ld_so_diagnostics).and_return(diagnostics) expect(described_class.system_dirs).to eq(["/lib64", "/var/lib"]) expect(described_class.system_dirs(brewed: false)).to eq(["/lib64", "/var/lib"]) end it "returns an empty array on blank diagnostics" do allow(described_class).to receive(:ld_so_diagnostics).and_return("") expect(described_class.system_dirs).to eq([]) expect(described_class.system_dirs(brewed: false)).to eq([]) end end describe "::library_paths" do ld_etc = Pathname("") before do ld_etc = Pathname(Dir.mktmpdir("homebrew-tests-ld-etc-", Dir.tmpdir)) FileUtils.mkdir [ld_etc/"subdir1", ld_etc/"subdir2"] (ld_etc/"ld.so.conf").write <<~EOS # This line is a comment include #{ld_etc}/subdir1/*.conf # This is an end-of-line comment, should be ignored # subdir2 is an empty directory include #{ld_etc}/subdir2/*.conf /a/b/c /d/e/f # Indentation on this line should be ignored /a/b/c # Duplicate entry should be ignored EOS (ld_etc/"subdir1/1-1.conf").write <<~EOS /foo/bar /baz/qux EOS (ld_etc/"subdir1/1-2.conf").write <<~EOS /g/h/i EOS # Empty files (or files containing only whitespace) should be ignored (ld_etc/"subdir1/1-3.conf").write "\n\t\n\t\n" (ld_etc/"subdir1/1-4.conf").write "" end after do FileUtils.rm_rf ld_etc end it "parses library paths successfully" do expect(described_class.library_paths(ld_etc/"ld.so.conf")).to eq(%w[/foo/bar /baz/qux /g/h/i /a/b/c /d/e/f]) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/linux/formula_spec.rb
Library/Homebrew/test/os/linux/formula_spec.rb
# frozen_string_literal: true require "test/support/fixtures/testball" require "formula" RSpec.describe Formula do describe "#uses_from_macos" do before do allow(OS).to receive(:mac?).and_return(false) end it "acts like #depends_on" do f = formula "foo" do url "foo-1.0" uses_from_macos("foo") end expect(f.class.stable.deps.first.name).to eq("foo") expect(f.class.head.deps.first.name).to eq("foo") end it "ignores OS version specifications" do f = formula "foo" do url "foo-1.0" uses_from_macos "foo", since: :sequoia end expect(f.class.stable.deps.first.name).to eq("foo") expect(f.class.head.deps.first.name).to eq("foo") end end describe "#on_linux" do it "adds a dependency on Linux only" do f = formula do homepage "https://brew.sh" url "https://brew.sh/test-0.1.tbz" sha256 TEST_SHA256 depends_on "hello_both" on_macos do depends_on "hello_macos" end on_linux do depends_on "hello_linux" end end expect(f.class.stable.deps[0].name).to eq("hello_both") expect(f.class.stable.deps[1].name).to eq("hello_linux") expect(f.class.stable.deps[2]).to be_nil end it "adds a patch on Linux only" do f = formula do homepage "https://brew.sh" url "https://brew.sh/test-0.1.tbz" sha256 TEST_SHA256 patch do on_macos do url "patch_macos" end on_linux do url "patch_linux" end end end expect(f.patchlist.length).to eq(1) expect(f.patchlist.first.strip).to eq(:p1) expect(f.patchlist.first.url).to eq("patch_linux") end it "uses on_linux within a resource block" do f = formula do homepage "https://brew.sh" url "https://brew.sh/test-0.1.tbz" sha256 TEST_SHA256 resource "test_resource" do on_linux do url "on_linux" end end end expect(f.resources.length).to eq(1) expect(f.resources.first.url).to eq("on_linux") end end describe "#shared_library" do it "generates a shared library string" do f = Testball.new expect(f.shared_library("foobar")).to eq("foobar.so") expect(f.shared_library("foobar", 2)).to eq("foobar.so.2") expect(f.shared_library("foobar", nil)).to eq("foobar.so") expect(f.shared_library("foobar", "*")).to eq("foobar.so{,.*}") expect(f.shared_library("*")).to eq("*.so{,.*}") expect(f.shared_library("*", 2)).to eq("*.so.2") expect(f.shared_library("*", nil)).to eq("*.so{,.*}") expect(f.shared_library("*", "*")).to eq("*.so{,.*}") end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/linux/diagnostic_spec.rb
Library/Homebrew/test/os/linux/diagnostic_spec.rb
# frozen_string_literal: true require "diagnostic" RSpec.describe Homebrew::Diagnostic::Checks do subject(:checks) { described_class.new } specify "#check_supported_architecture" do allow(Hardware::CPU).to receive(:type).and_return(:arm64) expect(checks.check_supported_architecture) .to match(/Your CPU architecture .+ is not supported/) end specify "#check_glibc_minimum_version" do allow(OS::Linux::Glibc).to receive(:below_minimum_version?).and_return(true) expect(checks.check_glibc_minimum_version) .to match(/Your system glibc .+ is too old/) end specify "#check_kernel_minimum_version" do allow(OS::Linux::Kernel).to receive(:below_minimum_version?).and_return(true) expect(checks.check_kernel_minimum_version) .to match(/Your Linux kernel .+ is too old/) end specify "#check_for_symlinked_home" do allow(File).to receive(:symlink?).with("/home").and_return(true) expect(checks.check_for_symlinked_home) .to match(%r{Your /home directory is a symlink}) end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/linux/formula_installer_spec.rb
Library/Homebrew/test/os/linux/formula_installer_spec.rb
# frozen_string_literal: true require "formula_installer" require "test/support/fixtures/testball" RSpec.describe FormulaInstaller do include FileUtils subject(:keg) { described_class.new(keg_path) } describe "#fresh_install" do subject(:formula_installer) { described_class.new(Testball.new) } it "is true by default" do formula = Testball.new expect(formula_installer.fresh_install?(formula)).to be true end it "is false in developer mode" do formula = Testball.new allow(Homebrew::EnvConfig).to receive_messages(developer?: true) expect(formula_installer.fresh_install?(formula)).to be false end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/os/linux/elf_spec.rb
Library/Homebrew/test/os/linux/elf_spec.rb
# frozen_string_literal: true RSpec.describe OS::Linux::Elf do describe "::expand_elf_dst" do it "expands tokens that are not wrapped in curly braces" do str = "$ORIGIN/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "/opt/homebrew/bin/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) end it "expands tokens that are wrapped in curly braces" do str = "${ORIGIN}/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "/opt/homebrew/bin/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) str = "${ORIGIN}new/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "/opt/homebrew/binnew/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) end it "expands multiple occurrences of token" do str = "${ORIGIN}/../..$ORIGIN/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "/opt/homebrew/bin/../../opt/homebrew/bin/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) end it "rejects and passes through tokens containing additional characters" do str = "$ORIGINAL/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "$ORIGINAL/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) str = "$ORIGIN_/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "$ORIGIN_/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) str = "$ORIGIN_STORY/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "$ORIGIN_STORY/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) str = "${ORIGINAL}/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "${ORIGINAL}/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) str = "${ORIGIN_}/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "${ORIGIN_}/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) str = "${ORIGIN_STORY}/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "${ORIGIN_STORY}/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) end it "rejects and passes through tokens with mismatched curly braces" do str = "${ORIGIN/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "${ORIGIN/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) str = "$ORIGIN}/../lib" ref = "ORIGIN" repl = "/opt/homebrew/bin" expected = "$ORIGIN}/../lib" expect(described_class.expand_elf_dst(str, ref, repl)).to eq(expected) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/extend/blank_spec.rb
Library/Homebrew/test/extend/blank_spec.rb
# frozen_string_literal: true require "extend/blank" RSpec.describe Object do let(:empty_true) do Class.new(described_class) do # This API is intentionally non-ideal for testing. # rubocop:disable Naming/PredicateMethod def empty? 0 end # rubocop:enable Naming/PredicateMethod end end let(:empty_false) do Class.new(described_class) do def empty? false end end end let(:blank) { [empty_true.new, nil, false, "", " ", " \n\t \r ", " ", "\u00a0", [], {}] } let(:present) { [empty_false.new, described_class.new, true, 0, 1, "a", [nil], { nil => 0 }, Time.now] } describe ".blank?" do it "checks if an object is blank" do blank.each { |v| expect(v.blank?).to be true } present.each { |v| expect(v.blank?).to be false } end it "checks if an object is blank with bundled string encodings" do Encoding.list.reject(&:dummy?).each do |encoding| expect(" ".encode(encoding).blank?).to be true expect("a".encode(encoding).blank?).to be false end end end describe ".present?" do it "checks if an object is present" do blank.each { |v| expect(v.present?).to be false } present.each { |v| expect(v.present?).to be true } end end describe ".presence" do it "returns the object if present, or nil" do blank.each { |v| expect(v.presence).to be_nil } present.each { |v| expect(v.presence).to be v } end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/extend/array_spec.rb
Library/Homebrew/test/extend/array_spec.rb
# frozen_string_literal: true require "extend/array" RSpec.describe Array do describe ".to_sentence" do it "converts a plain array to a sentence" do expect([].to_sentence).to eq("") expect(["one"].to_sentence).to eq("one") expect(["one", "two"].to_sentence).to eq("one and two") expect(["one", "two", "three"].to_sentence).to eq("one, two and three") end it "converts an array to a sentence with a custom connector" do expect(["one", "two", "three"].to_sentence(words_connector: " ")).to eq("one two and three") expect(["one", "two", "three"].to_sentence(words_connector: " & ")).to eq("one & two and three") end it "converts an array to a sentence with a custom last word connector" do expect(["one", "two", "three"].to_sentence(last_word_connector: ", and also ")) .to eq("one, two, and also three") expect(["one", "two", "three"].to_sentence(last_word_connector: " ")).to eq("one, two three") expect(["one", "two", "three"].to_sentence(last_word_connector: " and ")).to eq("one, two and three") end it "converts an array to a sentence with a custom two word connector" do expect(["one", "two"].to_sentence(two_words_connector: " ")).to eq("one two") end it "creates a new string" do elements = ["one"] expect(elements.to_sentence.object_id).not_to eq(elements[0].object_id) end it "converts a non-String to a sentence" do # rubocop:todo RSpec/AggregateExamples expect([1].to_sentence).to eq("1") end it "converts an array with blank elements to a sentence" do # rubocop:todo RSpec/AggregateExamples expect([nil, "one", "", "two", "three"].to_sentence).to eq(", one, , two and three") end it "does not return a frozen string" do # rubocop:todo RSpec/AggregateExamples expect([""].to_sentence).not_to be_frozen expect(["one"].to_sentence).not_to be_frozen expect(["one", "two"].to_sentence).not_to be_frozen expect(["one", "two", "three"].to_sentence).not_to be_frozen end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/extend/kernel_spec.rb
Library/Homebrew/test/extend/kernel_spec.rb
# frozen_string_literal: true RSpec.describe Kernel do let(:dir) { mktmpdir } describe "#interactive_shell" do let(:shell) { dir/"myshell" } it "starts an interactive shell session" do File.write shell, <<~SH #!/bin/sh echo called > "#{dir}/called" SH FileUtils.chmod 0755, shell ENV["SHELL"] = shell expect { interactive_shell }.not_to raise_error expect(dir/"called").to exist end end describe "#with_custom_locale" do it "temporarily overrides the system locale" do ENV["LC_ALL"] = "en_US.UTF-8" with_custom_locale("C") do expect(ENV.fetch("LC_ALL")).to eq("C") end expect(ENV.fetch("LC_ALL")).to eq("en_US.UTF-8") end end describe "#which" do let(:cmd) { dir/"foo" } before { FileUtils.touch cmd } it "returns the first executable that is found" do cmd.chmod 0744 expect(which(File.basename(cmd), File.dirname(cmd))).to eq(cmd) end it "skips non-executables" do expect(which(File.basename(cmd), File.dirname(cmd))).to be_nil end it "skips malformed path and doesn't fail" do # 'which' should not fail if a path is malformed # see https://github.com/Homebrew/legacy-homebrew/issues/32789 for an example cmd.chmod 0744 # ~~ will fail because ~foo resolves to foo's home and there is no '~' user path = ["~~", File.dirname(cmd)].join(File::PATH_SEPARATOR) expect(which(File.basename(cmd), path)).to eq(cmd) end end specify "#which_editor" do ENV["HOMEBREW_EDITOR"] = "vemate -w" ENV["HOMEBREW_PATH"] = dir editor = "#{dir}/vemate" FileUtils.touch editor FileUtils.chmod 0755, editor expect(which_editor).to eq("vemate -w") end specify "#disk_usage_readable" do expect(disk_usage_readable(1)).to eq("1B") expect(disk_usage_readable(999)).to eq("999B") expect(disk_usage_readable(1000)).to eq("1KB") expect(disk_usage_readable(1025)).to eq("1KB") expect(disk_usage_readable(4_404_020)).to eq("4.4MB") expect(disk_usage_readable(4_509_715_660)).to eq("4.5GB") end describe "#number_readable" do it "returns a string with thousands separators" do expect(number_readable(1)).to eq("1") expect(number_readable(1_000)).to eq("1,000") expect(number_readable(1_000_000)).to eq("1,000,000") end end specify "#truncate_text_to_approximate_size" do glue = "\n[...snip...]\n" # hard-coded copy from truncate_text_to_approximate_size n = 20 long_s = "x" * 40 s = truncate_text_to_approximate_size(long_s, n) expect(s.length).to eq(n) expect(s).to match(/^x+#{Regexp.escape(glue)}x+$/) s = truncate_text_to_approximate_size(long_s, n, front_weight: 0.0) expect(s).to eq(glue + ("x" * (n - glue.length))) s = truncate_text_to_approximate_size(long_s, n, front_weight: 1.0) expect(s).to eq(("x" * (n - glue.length)) + glue) end describe "#with_env" do it "sets environment variables within the block" do expect(ENV.fetch("PATH")).not_to eq("/bin") with_env(PATH: "/bin") do expect(ENV.fetch("PATH", nil)).to eq("/bin") end end it "restores ENV after the block" do with_env(PATH: "/bin") do expect(ENV.fetch("PATH", nil)).to eq("/bin") end path = ENV.fetch("PATH", nil) expect(path).not_to be_nil expect(path).not_to eq("/bin") end it "restores ENV if an exception is raised" do expect do with_env(PATH: "/bin") do raise StandardError, "boom" end end.to raise_error(StandardError) path = ENV.fetch("PATH", nil) expect(path).not_to be_nil expect(path).not_to eq("/bin") end end describe "#tap_and_name_comparison" do describe "both strings are only names" do it "alphabetizes the strings" do expect(%w[a b].sort(&tap_and_name_comparison)).to eq(%w[a b]) expect(%w[b a].sort(&tap_and_name_comparison)).to eq(%w[a b]) end end describe "both strings include tap" do it "alphabetizes the strings" do expect(%w[a/z/z b/z/z].sort(&tap_and_name_comparison)).to eq(%w[a/z/z b/z/z]) expect(%w[b/z/z a/z/z].sort(&tap_and_name_comparison)).to eq(%w[a/z/z b/z/z]) expect(%w[z/a/z z/b/z].sort(&tap_and_name_comparison)).to eq(%w[z/a/z z/b/z]) expect(%w[z/b/z z/a/z].sort(&tap_and_name_comparison)).to eq(%w[z/a/z z/b/z]) expect(%w[z/z/a z/z/b].sort(&tap_and_name_comparison)).to eq(%w[z/z/a z/z/b]) expect(%w[z/z/b z/z/a].sort(&tap_and_name_comparison)).to eq(%w[z/z/a z/z/b]) end end describe "only one string includes tap" do it "prefers the string without tap" do expect(%w[a/z/z z].sort(&tap_and_name_comparison)).to eq(%w[z a/z/z]) expect(%w[z a/z/z].sort(&tap_and_name_comparison)).to eq(%w[z a/z/z]) end end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/extend/pathname/write_mkpath_extension_spec.rb
Library/Homebrew/test/extend/pathname/write_mkpath_extension_spec.rb
# frozen_string_literal: true require "extend/pathname/write_mkpath_extension" # Use a copy of Pathname with the WriteMkpathExtension prepended to avoid affecting the original class for all tests class PathnameCopy < Pathname PathnameCopy.prepend WriteMkpathExtension end RSpec.describe WriteMkpathExtension do let(:file_content) { "sample contents" } it "creates parent directories if they do not exist" do mktmpdir do |tmpdir| file = PathnameCopy.new(tmpdir/"foo/bar/baz.txt") expect(file.dirname).not_to exist file.write(file_content) expect(file).to exist expect(file.read).to eq(file_content) end end it "raises if file exists and not in append mode or with offset" do mktmpdir do |tmpdir| file = PathnameCopy.new(tmpdir/"file.txt") file.write(file_content) expect { file.write("new content") }.to raise_error(RuntimeError, /Will not overwrite/) end end it "allows overwrite if offset is provided" do mktmpdir do |tmpdir| file = PathnameCopy.new(tmpdir/"file.txt") file.write(file_content) expect do file.write("change", 0) end.not_to raise_error expect(file.read).to eq("change contents") end end it "allows append mode ('a')" do mktmpdir do |tmpdir| file = PathnameCopy.new(tmpdir/"file.txt") file.write(file_content) expect do file.write(" appended", mode: "a") end.not_to raise_error expect(file.read).to eq("#{file_content} appended") end end it "allows append mode ('a+')" do mktmpdir do |tmpdir| file = PathnameCopy.new(tmpdir/"file.txt") file.write(file_content) expect do file.write(" again", mode: "a+") end.not_to raise_error expect(file.read).to include("again") end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cli/parser_spec.rb
Library/Homebrew/test/cli/parser_spec.rb
# frozen_string_literal: true require_relative "../../cli/parser" RSpec.describe Homebrew::CLI::Parser do before { stub_const("Cmd", Class.new(Homebrew::AbstractCommand)) } describe "test switch options" do subject(:parser) do described_class.new(Cmd) do switch "--more-verbose", description: "Flag for higher verbosity" switch "--pry", env: :pry switch "--foo", env: :foo switch "--bar", env: :bar switch "--hidden", hidden: true end end before do allow(Homebrew::EnvConfig).to receive(:pry?).and_return(true) allow(ENV).to receive(:fetch).and_call_original allow(ENV).to receive(:fetch).with("HOMEBREW_FOO", nil).and_return("") allow(ENV).to receive(:fetch).with("HOMEBREW_BAR", nil).and_return("1") end context "when using binary options" do subject(:parser) do described_class.new(Cmd) do switch "--[no-]positive" end end it "does not create no_positive?" do args = parser.parse(["--no-positive"]) expect { args.no_positive? }.to raise_error(NoMethodError) end it "sets the positive name to false if the negative switch is passed" do args = parser.parse(["--no-positive"]) expect(args).not_to be_positive end it "sets the positive name to true if the positive switch is passed" do args = parser.parse(["--positive"]) expect(args).to be_positive end it "does not set the positive name if the positive switch is not passed" do args = parser.parse([]) expect(args.positive?).to be_nil end end context "when using negative options" do subject(:parser) do described_class.new(Cmd) do switch "--no-positive" end end it "does not set the positive name" do args = parser.parse(["--no-positive"]) expect { args.positive? }.to raise_error(NoMethodError) end it "fails when using the positive name" do expect do parser.parse(["--positive"]) end.to raise_error(/invalid option/) end it "sets the negative name to true if the negative switch is passed" do args = parser.parse(["--no-positive"]) expect(args.no_positive?).to be true end end context "when `ignore_invalid_options` is true" do it "passes through invalid options" do args = parser.parse(["-v", "named-arg", "--not-a-valid-option"], ignore_invalid_options: true) expect(args.remaining).to eq ["named-arg", "--not-a-valid-option"] expect(args.named).to be_empty end end it "parses short option" do args = parser.parse(["-v"]) expect(args).to be_verbose end it "parses a single valid option" do args = parser.parse(["--verbose"]) expect(args).to be_verbose end it "parses a valid option along with few unnamed args" do args = parser.parse(%w[--verbose unnamed args]) expect(args).to be_verbose expect(args.named).to eq %w[unnamed args] end it "parses a single option and checks other options to be false" do args = parser.parse(["--verbose"]) expect(args).to be_verbose expect(args.more_verbose?).to be false end it "sets the correct value for a hidden switch" do args = parser.parse([]) expect(args.hidden?).to be false end it "raises an exception and outputs help text when an invalid option is passed" do expect { parser.parse(["--random"]) }.to raise_error(OptionParser::InvalidOption, /--random/) .and output(/Usage: brew/).to_stderr end it "maps environment var to an option" do args = parser.parse([]) expect(args.pry?).to be true expect(args.foo?).to be false expect(args.bar?).to be true end end describe "test long flag options" do subject(:parser) do described_class.new(Cmd) do flag "--filename=", description: "Name of the file" comma_array "--files", description: "Comma-separated filenames" flag "--hidden=", hidden: true comma_array "--hidden-array", hidden: true end end it "parses a long flag option with its argument" do args = parser.parse(["--filename=random.txt"]) expect(args.filename).to eq "random.txt" end it "raises an exception when a flag's required value is not passed" do expect { parser.parse(["--filename"]) }.to raise_error(OptionParser::MissingArgument, /--filename/) end it "parses a comma array flag option" do args = parser.parse(["--files=random1.txt,random2.txt"]) expect(args.files).to eq %w[random1.txt random2.txt] end it "sets the correct value for hidden flags" do args = parser.parse(["--hidden=foo", "--hidden-array=bar,baz"]) expect(args.hidden).to eq "foo" expect(args.hidden_array).to eq %w[bar baz] end end describe "test short flag options" do subject(:parser) do described_class.new(Cmd) do flag "-f", "--filename=", description: "Name of the file" end end it "parses a short flag option with its argument" do args = parser.parse(["--filename=random.txt"]) expect(args.filename).to eq "random.txt" expect(args.f).to eq "random.txt" end end describe "test constraints for flag options" do subject(:parser) do described_class.new(Cmd) do flag "--flag1=" flag "--flag2=", depends_on: "--flag1=" flag "--flag3=" conflicts "--flag1", "--flag3" end end it "raises exception on depends_on constraint violation" do expect { parser.parse(["--flag2=flag2"]) }.to raise_error(Homebrew::CLI::OptionConstraintError) end it "raises exception for conflict violation" do expect { parser.parse(["--flag1=flag1", "--flag3=flag3"]) }.to raise_error(Homebrew::CLI::OptionConflictError) end it "raises no exception" do args = parser.parse(["--flag1=flag1", "--flag2=flag2"]) expect(args.flag1).to eq "flag1" expect(args.flag2).to eq "flag2" end it "raises no exception for optional dependency" do args = parser.parse(["--flag3=flag3"]) expect(args.flag3).to eq "flag3" end end describe "test invalid constraints" do subject(:parser) do described_class.new(Cmd) do flag "--flag1=" flag "--flag2=", depends_on: "--flag1=" conflicts "--flag1", "--flag2" end end it "raises exception due to invalid constraints" do expect { parser.parse([]) }.to raise_error(Homebrew::CLI::InvalidConstraintError) end end describe "test constraints for switch options" do subject(:parser) do described_class.new(Cmd) do switch "-a", "--switch-a", env: "switch_a" switch "-b", "--switch-b", env: "switch_b" switch "--switch-c", depends_on: "--switch-a" conflicts "--switch-a", "--switch-b" end end it "raises exception on depends_on constraint violation" do expect { parser.parse(["--switch-c"]) }.to raise_error(Homebrew::CLI::OptionConstraintError) end it "raises exception for conflict violation" do expect { parser.parse(["-ab"]) }.to raise_error(Homebrew::CLI::OptionConflictError) end it "raises no exception" do args = parser.parse(["--switch-a", "--switch-c"]) expect(args.switch_a?).to be true expect(args.switch_c?).to be true end it "raises no exception for optional dependency" do args = parser.parse(["--switch-b"]) expect(args.switch_b?).to be true end it "prioritizes cli arguments over env vars when they conflict" do without_partial_double_verification do allow(Homebrew::EnvConfig).to receive_messages(switch_a?: true, switch_b?: false) end args = parser.parse(["--switch-b"]) expect(args.switch_a?).to be false expect(args).to be_switch_b end it "raises an exception on constraint violation when both are env vars" do without_partial_double_verification do allow(Homebrew::EnvConfig).to receive_messages(switch_a?: true, switch_b?: true) end expect { parser.parse([]) }.to raise_error(Homebrew::CLI::OptionConflictError) end end describe "test immutability of args" do subject(:parser) do described_class.new(Cmd) do switch "-a", "--switch-a" switch "-b", "--switch-b" end end it "raises exception when arguments were already parsed" do parser.parse(["--switch-a"]) expect { parser.parse(["--switch-b"]) }.to raise_error(RuntimeError, /Arguments were already parsed!/) end end describe "test inferrability of args" do subject(:parser) do described_class.new(Cmd) do switch "--switch-a" switch "--switch-b" switch "--foo-switch" flag "--flag-foo=" comma_array "--comma-array-foo" end end it "parses a valid switch that uses `_` instead of `-`" do args = parser.parse(["--switch_a"]) expect(args).to be_switch_a end it "parses a valid flag that uses `_` instead of `-`" do args = parser.parse(["--flag_foo=foo.txt"]) expect(args.flag_foo).to eq "foo.txt" end it "parses a valid comma_array that uses `_` instead of `-`" do args = parser.parse(["--comma_array_foo=foo.txt,bar.txt"]) expect(args.comma_array_foo).to eq %w[foo.txt bar.txt] end it "raises an error when option is ambiguous" do expect { parser.parse(["--switch"]) }.to raise_error(RuntimeError, /ambiguous option: --switch/) end it "inferrs the option from an abbreviated name" do args = parser.parse(["--foo"]) expect(args).to be_foo_switch end end describe "test argv extensions" do subject(:parser) do described_class.new(Cmd) do switch "--foo" flag "--bar" switch "-s" end end it "#options_only" do args = parser.parse(["--foo", "--bar=value", "-v", "-s", "a", "b", "cdefg"]) expect(args.options_only).to eq %w[--verbose --foo --bar=value -s] end it "#flags_only" do args = parser.parse(["--foo", "--bar=value", "-v", "-s", "a", "b", "cdefg"]) expect(args.flags_only).to eq %w[--verbose --foo --bar=value] end it "#named returns an array of non-option arguments" do args = parser.parse(["foo", "-v", "-s"]) expect(args.named).to eq ["foo"] end it "#named returns an empty array when there are no named arguments" do args = parser.parse([]) expect(args.named).to be_empty end end describe "usage banner generation" do it "includes `[options]` if more than two non-global options are available" do parser = described_class.new(Cmd) do switch "--foo" switch "--baz" switch "--bar" end expect(parser.generate_help_text).to match(/\[options\]/) end it "includes individual options if less than two non-global options are available" do parser = described_class.new(Cmd) do switch "--foo" switch "--bar" end expect(parser.generate_help_text).to match(/\[--foo\] \[--bar\]/) end it "formats flags correctly when less than two non-global options are available" do parser = described_class.new(Cmd) do flag "--foo" flag "--bar=" end expect(parser.generate_help_text).to match(/\[--foo\] \[--bar=\]/) end it "formats comma arrays correctly when less than two non-global options are available" do parser = described_class.new(Cmd) do comma_array "--foo" end expect(parser.generate_help_text).to match(/\[--foo=\]/) end it "does not include hidden options" do parser = described_class.new(Cmd) do switch "--foo", hidden: true end expect(parser.generate_help_text).not_to match(/\[--foo\]/) end it "doesn't include `[options]` if non non-global options are available" do parser = described_class.new(Cmd) expect(parser.generate_help_text).not_to match(/\[options\]/) end it "includes a description" do parser = described_class.new(Cmd) do description <<~EOS This command does something EOS end expect(parser.generate_help_text).to match(/This command does something/) end it "allows the usage banner to be overridden" do parser = described_class.new(Cmd) do usage_banner "`test` [foo] <bar>" end expect(parser.generate_help_text).to match(/test \[foo\] bar/) end it "allows a usage banner and a description to be overridden" do parser = described_class.new(Cmd) do usage_banner "`test` [foo] <bar>" description <<~EOS This command does something EOS end expect(parser.generate_help_text).to match(/test \[foo\] bar/) expect(parser.generate_help_text).to match(/This command does something/) end it "shows the correct usage for no named argument" do parser = described_class.new(Cmd) do named_args :none end expect(parser.generate_help_text).to match(/^Usage: [^\[]+$/s) end it "shows the correct usage for a single typed argument" do parser = described_class.new(Cmd) do named_args :formula, number: 1 end expect(parser.generate_help_text).to match(/^Usage: .* formula$/s) end it "shows the correct usage for a subcommand argument with a maximum" do parser = described_class.new(Cmd) do named_args %w[off on], max: 1 end expect(parser.generate_help_text).to match(/^Usage: .* \[subcommand\]$/s) end it "shows the correct usage for multiple typed argument with no maximum or minimum" do parser = described_class.new(Cmd) do named_args [:tap, :command] end expect(parser.generate_help_text).to match(/^Usage: .* \[tap|command ...\]$/s) end it "shows the correct usage for a subcommand argument with a minimum of 1" do parser = described_class.new(Cmd) do named_args :installed_formula, min: 1 end expect(parser.generate_help_text).to match(/^Usage: .* installed_formula \[...\]$/s) end it "shows the correct usage for a subcommand argument with a minimum greater than 1" do parser = described_class.new(Cmd) do named_args :installed_formula, min: 2 end expect(parser.generate_help_text).to match(/^Usage: .* installed_formula ...$/s) end end describe "named_args" do let(:parser_none) do described_class.new(Cmd) do named_args :none end end let(:parser_number) do described_class.new(Cmd) do named_args number: 1 end end it "doesn't allow :none passed with a number" do expect do described_class.new(Cmd) do named_args :none, number: 1 end end.to raise_error(ArgumentError, /Do not specify both `number`, `min` or `max` with `named_args :none`/) end it "doesn't allow number and min" do expect do described_class.new(Cmd) do named_args number: 1, min: 1 end end.to raise_error(ArgumentError, /Do not specify both `number` and `min` or `max`/) end it "doesn't accept fewer than the passed number of arguments" do expect { parser_number.parse([]) }.to raise_error(Homebrew::CLI::NumberOfNamedArgumentsError) end it "doesn't accept more than the passed number of arguments" do expect { parser_number.parse(["foo", "bar"]) }.to raise_error(Homebrew::CLI::NumberOfNamedArgumentsError) end it "accepts the passed number of arguments" do expect { parser_number.parse(["foo"]) }.not_to raise_error end it "doesn't accept any arguments with :none" do expect { parser_none.parse(["foo"]) } .to raise_error(Homebrew::CLI::MaxNamedArgumentsError, /This command does not take named arguments/) end it "accepts no arguments with :none" do expect { parser_none.parse([]) }.not_to raise_error end it "displays the correct error message with no arg types and min" do parser = described_class.new(Cmd) do named_args min: 2 end expect { parser.parse([]) }.to raise_error( Homebrew::CLI::MinNamedArgumentsError, /This command requires at least 2 named arguments/ ) end it "displays the correct error message with no arg types and number" do parser = described_class.new(Cmd) do named_args number: 2 end expect { parser.parse([]) }.to raise_error( Homebrew::CLI::NumberOfNamedArgumentsError, /This command requires exactly 2 named arguments/ ) end it "displays the correct error message with no arg types and max" do parser = described_class.new(Cmd) do named_args max: 1 end expect { parser.parse(%w[foo bar]) }.to raise_error( Homebrew::CLI::MaxNamedArgumentsError, /This command does not take more than 1 named argument/ ) end it "displays the correct error message with an array of strings" do parser = described_class.new(Cmd) do named_args %w[on off], number: 1 end expect { parser.parse([]) }.to raise_error( Homebrew::CLI::NumberOfNamedArgumentsError, /This command requires exactly 1 subcommand/ ) end it "displays the correct error message with an array of symbols" do parser = described_class.new(Cmd) do named_args [:formula, :cask], min: 1 end expect { parser.parse([]) }.to raise_error( Homebrew::CLI::MinNamedArgumentsError, /This command requires at least 1 formula or cask argument/ ) end it "displays the correct error message with an array of symbols and max" do parser = described_class.new(Cmd) do named_args [:formula, :cask], max: 1 end expect { parser.parse(%w[foo bar]) }.to raise_error( Homebrew::CLI::MaxNamedArgumentsError, /This command does not take more than 1 formula or cask argument/ ) end it "accepts commands with :command" do parser = described_class.new(Cmd) do named_args :command end expect { parser.parse(["--prefix", "--version"]) }.not_to raise_error end it "doesn't accept invalid options with :command" do parser = described_class.new(Cmd) do named_args :command end expect { parser.parse(["--not-a-command"]) }.to raise_error(OptionParser::InvalidOption, /--not-a-command/) end end describe "--cask on linux", :needs_linux do context "without --formula switch" do subject(:parser) do described_class.new(Cmd) do switch "--cask" end end # Developers want to be able to use `audit` and `bump` # commands for formulae and casks on Linux. it "succeeds for developer commands" do require "dev-cmd/cat" args = Homebrew::DevCmd::Cat.new(["--cask", "cask_name"]).args expect(args.cask?).to be(true) end end context "with conflicting --formula switch" do subject(:parser) do described_class.new(Cmd) do switch "--cask" switch "--formula" conflicts "--cask", "--formula" end end it "throws an error when both defined" do expect { parser.parse(["--cask", "--formula"]) } .to raise_exception Homebrew::CLI::OptionConflictError end end end describe "--formula on linux", :needs_linux do it "doesn't set --formula when not defined" do parser = described_class.new(Cmd) args = parser.parse([]) expect(args.respond_to?(:formula?)).to be(false) end it "doesn't set --formula when defined" do parser = described_class.new(Cmd) do switch "--formula" end args = parser.parse([]) expect(args.formula?).to be(false) end it "does not set --formula to true when --cask" do parser = described_class.new(Cmd) do switch "--cask" end args = parser.parse([]) expect(args.respond_to?(:formula?)).to be(false) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cli/named_args_spec.rb
Library/Homebrew/test/cli/named_args_spec.rb
# frozen_string_literal: true require "cli/named_args" RSpec.describe Homebrew::CLI::NamedArgs do def setup_unredable_formula(name) error = FormulaUnreadableError.new(name, RuntimeError.new("testing")) allow(Formulary).to receive(:factory).with(name, any_args).and_raise(error) end def setup_unredable_cask(name) error = Cask::CaskUnreadableError.new(name, "testing") allow(Cask::CaskLoader).to receive(:load).with(name, any_args).and_raise(error) config = instance_double(Cask::Config) allow(Cask::Config).to receive(:from_args).and_return(config) end let(:foo) do formula "foo" do url "https://brew.sh" version "1.0" end end let(:bar) do formula "bar" do url "https://brew.sh" version "1.0" end end let(:baz) do Cask::CaskLoader::FromContentLoader.new(+<<~RUBY, tap: CoreCaskTap.instance).load(config: nil) cask "baz" do version "1.0" end RUBY end let(:foo_cask) do Cask::CaskLoader::FromContentLoader.new(+<<~RUBY, tap: CoreCaskTap.instance).load(config: nil) cask "foo" do version "1.0" end RUBY end describe "#to_formulae" do it "returns formulae" do stub_formula_loader foo, call_original: true stub_formula_loader bar expect(described_class.new("foo", "bar").to_formulae).to eq [foo, bar] end it "raises an error when a Formula is unavailable" do expect { described_class.new("mxcl").to_formulae }.to raise_error FormulaUnavailableError end it "returns an empty array when there are no Formulae" do expect(described_class.new.to_formulae).to be_empty end end describe "#to_formulae_and_casks" do it "returns formulae and casks", :needs_macos do stub_formula_loader foo, call_original: true stub_cask_loader baz, call_original: true expect(described_class.new("foo", "baz").to_formulae_and_casks).to eq [foo, baz] end context "when both formula and cask are present" do before do stub_formula_loader foo stub_cask_loader foo_cask end it "returns formula by default" do expect(described_class.new("foo").to_formulae_and_casks).to eq [foo] end it "returns formula if loading formula only" do expect(described_class.new("foo").to_formulae_and_casks(only: :formula)).to eq [foo] end it "returns cask if loading cask only" do expect(described_class.new("foo").to_formulae_and_casks(only: :cask)).to eq [foo_cask] end end context "when a non-core formula and a core cask are present" do let(:non_core_formula) do formula "foo", tap: Tap.fetch("some/tap") do url "https://brew.sh" version "1.0" end end before do stub_formula_loader non_core_formula, "foo" stub_cask_loader foo_cask end it "returns the cask by default" do expect(described_class.new("foo").to_formulae_and_casks).to eq [foo_cask] end it "returns formula if loading formula only" do expect(described_class.new("foo").to_formulae_and_casks(only: :formula)).to eq [non_core_formula] end it "returns cask if loading cask only" do expect(described_class.new("foo").to_formulae_and_casks(only: :cask)).to eq [foo_cask] end end context "when both formula and cask are unreadable" do before do setup_unredable_formula "foo" setup_unredable_cask "foo" end it "raises an error" do expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaUnreadableError) end it "raises an error if loading formula only" do expect { described_class.new("foo").to_formulae_and_casks(only: :formula) } .to raise_error(FormulaUnreadableError) end it "raises an error if loading cask only" do expect { described_class.new("foo").to_formulae_and_casks(only: :cask) } .to raise_error(Cask::CaskUnreadableError) end end it "raises an error when neither formula nor cask is present" do expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaOrCaskUnavailableError) end it "returns formula when formula is present and cask is unreadable", :needs_macos do stub_formula_loader foo setup_unredable_cask "foo" expect(described_class.new("foo").to_formulae_and_casks).to eq [foo] expect { described_class.new("foo").to_formulae_and_casks }.to output(/Failed to load cask: foo/).to_stderr end it "returns cask when formula is unreadable and cask is present", :needs_macos do setup_unredable_formula "foo" stub_cask_loader foo_cask expect(described_class.new("foo").to_formulae_and_casks).to eq [foo_cask] expect { described_class.new("foo").to_formulae_and_casks }.to output(/Failed to load formula: foo/).to_stderr end it "raises an error when formula is absent and cask is unreadable", :needs_macos do setup_unredable_cask "foo" expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(Cask::CaskUnreadableError) end it "raises an error when formula is unreadable and cask is absent" do setup_unredable_formula "foo" expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaUnreadableError) end end describe "#to_resolved_formulae" do it "returns resolved formulae" do allow(Formulary).to receive(:resolve).and_return(foo, bar) expect(described_class.new("foo", "bar").to_resolved_formulae).to eq [foo, bar] end end describe "#to_resolved_formulae_to_casks" do it "returns resolved formulae, as well as casks", :needs_macos do allow(Formulary).to receive(:resolve).and_call_original allow(Formulary).to receive(:resolve).with("foo", any_args).and_return foo stub_cask_loader baz, call_original: true resolved_formulae, casks = described_class.new("foo", "baz").to_resolved_formulae_to_casks expect(resolved_formulae).to eq [foo] expect(casks).to eq [baz] end end describe "#to_casks" do it "returns casks" do stub_cask_loader baz expect(described_class.new("baz").to_casks).to eq [baz] end end describe "#to_kegs" do before do (HOMEBREW_CELLAR/"foo/1.0").mkpath (HOMEBREW_CELLAR/"foo/2.0").mkpath (HOMEBREW_CELLAR/"bar/1.0").mkpath end it "resolves kegs with #resolve_kegs" do expect(described_class.new("foo", "bar").to_kegs.map(&:name)).to eq ["foo", "foo", "bar"] end it "resolves kegs with multiple versions with #resolve_keg" do expect(described_class.new("foo").to_kegs.map { |k| k.version.version.to_s }.sort).to eq ["1.0", "2.0"] end it "when there are no matching kegs returns an empty array" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new.to_kegs).to be_empty end it "raises an error when a Keg is unavailable" do expect { described_class.new("baz").to_kegs }.to raise_error NoSuchKegError end context "when a keg specifies a tap" do let(:tab) { instance_double(Tab, tap: Tap.fetch("user", "repo")) } before do allow_any_instance_of(Keg).to receive(:tab).and_return(tab) end it "returns kegs if no tap is specified" do stub_formula_loader bar, "user/repo/bar" expect(described_class.new("bar").to_kegs.map(&:name)).to eq ["bar"] end it "returns kegs if the tap is specified" do stub_formula_loader bar, "user/repo/bar" expect(described_class.new("user/repo/bar").to_kegs.map(&:name)).to eq ["bar"] end it "raises an error if there is no tap match" do stub_formula_loader bar, "other/tap/bar" expect { described_class.new("other/tap/bar").to_kegs }.to raise_error(NoSuchKegError, %r{from tap other/tap}) end end end describe "#to_default_kegs" do before do (HOMEBREW_CELLAR/"foo/1.0").mkpath (HOMEBREW_CELLAR/"bar/1.0").mkpath linked_path = (HOMEBREW_CELLAR/"foo/2.0") linked_path.mkpath Keg.new(linked_path).link end it "resolves kegs with #resolve_default_keg" do expect(described_class.new("foo", "bar").to_default_kegs.map(&:name)).to eq ["foo", "bar"] end it "resolves the default keg" do expect(described_class.new("foo").to_default_kegs.map { |k| k.version.version.to_s }).to eq ["2.0"] end it "when there are no matching kegs returns an empty array" do expect(described_class.new.to_default_kegs).to be_empty end end describe "#to_latest_kegs" do before do (HOMEBREW_CELLAR/"foo/1.0").mkpath (HOMEBREW_CELLAR/"foo/2.0").mkpath (HOMEBREW_CELLAR/"bar/1.0").mkpath (HOMEBREW_CELLAR/"baz/HEAD-1").mkpath head2 = HOMEBREW_CELLAR/"baz/HEAD-2" head2.mkpath (head2/"INSTALL_RECEIPT.json").write (TEST_FIXTURE_DIR/"receipt.json").read end it "resolves the latest kegs with #resolve_latest_keg" do latest_kegs = described_class.new("foo", "bar", "baz").to_latest_kegs expect(latest_kegs.map(&:name)).to eq ["foo", "bar", "baz"] expect(latest_kegs.map { |k| k.version.version.to_s }).to eq ["2.0", "1.0", "HEAD-2"] end it "when there are no matching kegs returns an empty array" do expect(described_class.new.to_latest_kegs).to be_empty end end describe "#to_kegs_to_casks" do before do (HOMEBREW_CELLAR/"foo/1.0").mkpath end it "returns kegs, as well as casks", :needs_macos do stub_cask_loader baz, call_original: true kegs, casks = described_class.new("foo", "baz").to_kegs_to_casks expect(kegs.map(&:name)).to eq ["foo"] expect(casks).to eq [baz] end end describe "#homebrew_tap_cask_names" do it "returns an array of casks from homebrew-cask" do expect(described_class.new("foo", "homebrew/cask/local-caffeine").homebrew_tap_cask_names) .to eq ["homebrew/cask/local-caffeine"] end it "returns an empty array when there are no matching casks" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new("foo").homebrew_tap_cask_names).to be_empty end end describe "#to_paths" do let(:existing_path) { mktmpdir } let(:formula_path) { Pathname("/path/to/foo.rb") } let(:cask_path) { Pathname("/path/to/baz.rb") } before do allow(formula_path).to receive(:exist?).and_return(true) allow(cask_path).to receive(:exist?).and_return(true) allow(Formulary).to receive(:path).and_call_original allow(Cask::CaskLoader).to receive(:path).and_call_original end it "returns taps, cask formula and existing paths", :needs_macos do expect(Formulary).to receive(:path).with("foo").and_return(formula_path) expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_path) expect(described_class.new("homebrew/core", "foo", "baz", existing_path.to_s).to_paths) .to eq [Tap.fetch("homebrew/core").path, formula_path, cask_path, existing_path] end it "returns both cask and formula paths if they exist", :needs_macos do expect(Formulary).to receive(:path).with("foo").and_return(formula_path) expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_path) expect(described_class.new("foo", "baz").to_paths).to eq [formula_path, cask_path] end it "returns only formulae when `only: :formula` is specified" do expect(Formulary).to receive(:path).with("foo").and_return(formula_path) expect(described_class.new("foo", "baz").to_paths(only: :formula)).to eq [formula_path, Formulary.path("baz")] end it "returns only casks when `only: :cask` is specified" do expect(Cask::CaskLoader).to receive(:path).with("foo").and_return(cask_path) expect(described_class.new("foo", "baz").to_paths(only: :cask)).to eq [cask_path, Cask::CaskLoader.path("baz")] end end describe "#to_taps" do it "returns taps" do taps = described_class.new("homebrew/foo", "bar/baz") expect(taps.to_taps.map(&:name)).to eq %w[homebrew/foo bar/baz] end it "raises an error for invalid tap" do taps = described_class.new("homebrew/foo", "barbaz") expect { taps.to_taps }.to raise_error(Tap::InvalidNameError, /Invalid tap name/) end end describe "#to_installed_taps" do before do (HOMEBREW_REPOSITORY/"Library/Taps/homebrew/homebrew-foo").mkpath end it "returns installed taps" do taps = described_class.new("homebrew/foo") expect(taps.to_installed_taps.map(&:name)).to eq %w[homebrew/foo] end it "raises an error for uninstalled tap" do taps = described_class.new("homebrew/foo", "bar/baz") expect { taps.to_installed_taps }.to raise_error(TapUnavailableError) end it "raises an error for invalid tap" do taps = described_class.new("homebrew/foo", "barbaz") expect { taps.to_installed_taps }.to raise_error(Tap::InvalidNameError, /Invalid tap name/) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/lha_spec.rb
Library/Homebrew/test/unpack_strategy/lha_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Lha do let(:path) { TEST_FIXTURE_DIR/"test.lha" } include_examples "UnpackStrategy::detect" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/uncompressed_spec.rb
Library/Homebrew/test/unpack_strategy/uncompressed_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Uncompressed do let(:path) do (mktmpdir/"test").tap do |path| FileUtils.touch path end end include_examples "UnpackStrategy::detect" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/subversion_spec.rb
Library/Homebrew/test/unpack_strategy/subversion_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Subversion, :needs_svn do let(:repo) { mktmpdir } let(:working_copy) { mktmpdir } let(:path) { working_copy } before do safe_system "svnadmin", "create", repo safe_system "svn", "checkout", "file://#{repo}", working_copy FileUtils.touch working_copy/"test" system "svn", "add", working_copy/"test" system "svn", "commit", working_copy, "-m", "Add `test` file." end include_examples "UnpackStrategy::detect" include_examples "#extract", children: ["test"] context "when the directory name contains an '@' symbol" do let(:working_copy) { mktmpdir(["", "@1.2.3"]) } include_examples "#extract", children: ["test"] end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/lzip_spec.rb
Library/Homebrew/test/unpack_strategy/lzip_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Lzip do let(:path) { TEST_FIXTURE_DIR/"test.lz" } include_examples "UnpackStrategy::detect" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/cvs_spec.rb
Library/Homebrew/test/unpack_strategy/cvs_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Cvs do let(:repo) do mktmpdir.tap do |repo| FileUtils.touch repo/"test" (repo/"CVS").mkpath end end let(:path) { repo } include_examples "UnpackStrategy::detect" include_examples "#extract", children: ["CVS", "test"] end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/directory_spec.rb
Library/Homebrew/test/unpack_strategy/directory_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Directory do let(:path) do mktmpdir.tap do |path| FileUtils.touch path/"file" FileUtils.ln_s "file", path/"symlink" FileUtils.ln path/"file", path/"hardlink" FileUtils.mkdir path/"folder" FileUtils.ln_s "folder", path/"folderSymlink" end end let(:unpack_dir) { mktmpdir } shared_examples "extract directory" do |move:| subject(:strategy) { described_class.new(path, move:) } it "does not follow symlinks" do strategy.extract(to: unpack_dir) expect(unpack_dir/"symlink").to be_a_symlink end it "does not follow top level symlinks to directories" do strategy.extract(to: unpack_dir) expect(unpack_dir/"folderSymlink").to be_a_symlink end it "preserves permissions of contained files" do FileUtils.chmod 0644, path/"file" strategy.extract(to: unpack_dir) expect((unpack_dir/"file").stat.mode & 0777).to eq 0644 end it "preserves permissions of contained subdirectories" do FileUtils.mkdir unpack_dir/"folder" FileUtils.chmod 0755, unpack_dir/"folder" FileUtils.chmod 0700, path/"folder" strategy.extract(to: unpack_dir) expect((unpack_dir/"folder").stat.mode & 0777).to eq 0700 end it "preserves permissions of the destination directory" do FileUtils.chmod 0700, path FileUtils.chmod 0755, unpack_dir strategy.extract(to: unpack_dir) expect(unpack_dir.stat.mode & 0777).to eq 0755 end it "preserves mtime of contained files and directories" do FileUtils.mkdir unpack_dir/"folder" FileUtils.touch path/"folder", mtime: Time.utc(2000, 1, 2, 3, 4, 5, 678999), nocreate: true mtimes = path.children.to_h { |child| [child.basename, child.lstat.mtime] } strategy.extract(to: unpack_dir) expect(unpack_dir.children.to_h { |child| [child.basename, child.lstat.mtime] }).to eq mtimes end it "preserves unrelated destination files and subdirectories" do FileUtils.touch unpack_dir/"existing_file" FileUtils.mkdir unpack_dir/"existing_folder" strategy.extract(to: unpack_dir) expect(unpack_dir/"existing_file").to be_a_file expect(unpack_dir/"existing_folder").to be_a_directory end it "overwrites destination files/symlinks with source files/symlinks" do FileUtils.mkdir unpack_dir/"existing_folder" FileUtils.ln_s unpack_dir/"existing_folder", unpack_dir/"symlink" (unpack_dir/"file").write "existing contents" strategy.extract(to: unpack_dir) expect((unpack_dir/"file").read).to be_empty expect((unpack_dir/"symlink").readlink).to eq Pathname("file") end it "fails when overwriting a directory with a file" do FileUtils.mkdir unpack_dir/"file" expect { strategy.extract(to: unpack_dir) }.to raise_error(/Is a directory|cannot overwrite directory/i) end it "fails when overwriting a nested directory with a file" do FileUtils.touch path/"folder/nested" FileUtils.mkdir_p unpack_dir/"folder/nested" expect { strategy.extract(to: unpack_dir) }.to raise_error(/Is a directory|cannot overwrite directory/i) end end context "with `move: false`" do include_examples "extract directory", move: false end context "with `move: true`" do include_examples "extract directory", move: true it "preserves hardlinks" do strategy.extract(to: unpack_dir) expect((unpack_dir/"file").stat.ino).to eq (unpack_dir/"hardlink").stat.ino end # NOTE: We don't test `move: false` because system cp behaviour is inconsistent, # e.g. Ventura cp does not error but Sequoia and Linux cp will error it "fails when overwriting a file with a directory" do FileUtils.touch unpack_dir/"folder" expect { strategy.extract(to: unpack_dir) }.to raise_error(/cannot overwrite non-directory/i) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/dmg_spec.rb
Library/Homebrew/test/unpack_strategy/dmg_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Dmg, :needs_macos do describe "#mount" do let(:path) { TEST_FIXTURE_DIR/"cask/container.dmg" } include_examples "UnpackStrategy::detect" include_examples "#extract", children: ["container"] end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/zstd_spec.rb
Library/Homebrew/test/unpack_strategy/zstd_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Zstd do let(:path) { TEST_FIXTURE_DIR/"cask/container.tar.zst" } it "is correctly detected" do # `UnpackStrategy.detect(path)` for a `.tar.XXX` file returns either `UnpackStrategy::Tar` if # the host's `tar` is able to extract that compressed file or `UnpackStrategy::XXX` otherwise, # such as `UnpackStrategy::Zstd`. On macOS `UnpackStrategy.detect("container.tar.zst")` # returns `UnpackStrategy::Zstd` and on Ubuntu 22.04 it returns `UnpackStrategy::Tar`, # because the host's version of `tar` is recent enough and `zstd` is installed. expect(UnpackStrategy.detect(path)).to(be_a(described_class).or(be_a(UnpackStrategy::Tar))) end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/git_spec.rb
Library/Homebrew/test/unpack_strategy/git_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Git do let(:repo) do mktmpdir.tap do |repo| system "git", "-C", repo, "init" FileUtils.touch repo/"test" system "git", "-C", repo, "add", "test" system "git", "-C", repo, "commit", "-m", "Add `test` file." end end let(:path) { repo } include_examples "UnpackStrategy::detect" include_examples "#extract", children: [".git", "test"] end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/p7zip_spec.rb
Library/Homebrew/test/unpack_strategy/p7zip_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::P7Zip do let(:path) { TEST_FIXTURE_DIR/"cask/container.7z" } include_examples "UnpackStrategy::detect" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/xz_spec.rb
Library/Homebrew/test/unpack_strategy/xz_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Xz do let(:path) { TEST_FIXTURE_DIR/"cask/container.xz" } include_examples "UnpackStrategy::detect" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/shared_examples.rb
Library/Homebrew/test/unpack_strategy/shared_examples.rb
# frozen_string_literal: true require "unpack_strategy" RSpec.shared_examples "UnpackStrategy::detect" do it "is correctly detected" do expect(UnpackStrategy.detect(path)).to be_a described_class end end RSpec.shared_examples "#extract" do |children: []| specify "#extract" do mktmpdir do |unpack_dir| described_class.new(path).extract(to: unpack_dir) expect(unpack_dir.children(false).map(&:to_s)).to match_array children end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/rar_spec.rb
Library/Homebrew/test/unpack_strategy/rar_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Rar do let(:path) { TEST_FIXTURE_DIR/"cask/container.rar" } include_examples "UnpackStrategy::detect" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/zip_spec.rb
Library/Homebrew/test/unpack_strategy/zip_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Zip do let(:path) { TEST_FIXTURE_DIR/"cask/MyFancyApp.zip" } include_examples "UnpackStrategy::detect" context "when unzip is available", :needs_unzip do include_examples "#extract", children: ["MyFancyApp"] end context "when ZIP archive is corrupted" do let(:path) do (mktmpdir/"test.zip").tap do |path| FileUtils.touch path end end include_examples "UnpackStrategy::detect" end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/bzip2_spec.rb
Library/Homebrew/test/unpack_strategy/bzip2_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Bzip2 do let(:path) { TEST_FIXTURE_DIR/"cask/container.bz2" } include_examples "UnpackStrategy::detect" include_examples "#extract", children: ["container"] end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/bazaar_spec.rb
Library/Homebrew/test/unpack_strategy/bazaar_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Bazaar do let(:repo) do mktmpdir.tap do |repo| FileUtils.touch repo/"test" (repo/".bzr").mkpath end end let(:path) { repo } include_examples "UnpackStrategy::detect" include_examples "#extract", children: ["test"] end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/tar_spec.rb
Library/Homebrew/test/unpack_strategy/tar_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Tar do let(:path) { TEST_FIXTURE_DIR/"cask/container.tar.gz" } include_examples "UnpackStrategy::detect" include_examples "#extract", children: ["container"] context "when TAR archive is corrupted" do let(:path) do (mktmpdir/"test.tar").tap do |path| FileUtils.touch path end end include_examples "UnpackStrategy::detect" end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/gzip_spec.rb
Library/Homebrew/test/unpack_strategy/gzip_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Gzip do let(:path) { TEST_FIXTURE_DIR/"cask/container.gz" } include_examples "UnpackStrategy::detect" include_examples "#extract", children: ["container"] end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/jar_spec.rb
Library/Homebrew/test/unpack_strategy/jar_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Jar, :needs_unzip do let(:path) { TEST_FIXTURE_DIR/"test.jar" } include_examples "UnpackStrategy::detect" include_examples "#extract", children: ["test.jar"] end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/xar_spec.rb
Library/Homebrew/test/unpack_strategy/xar_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Xar, :needs_macos do let(:path) { TEST_FIXTURE_DIR/"cask/container.xar" } include_examples "UnpackStrategy::detect" include_examples "#extract", children: ["container"] end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/unpack_strategy/mercurial_spec.rb
Library/Homebrew/test/unpack_strategy/mercurial_spec.rb
# frozen_string_literal: true require_relative "shared_examples" RSpec.describe UnpackStrategy::Mercurial do let(:repo) do mktmpdir.tap do |repo| (repo/".hg").mkpath end end let(:path) { repo } include_examples "UnpackStrategy::detect" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/language/java_spec.rb
Library/Homebrew/test/language/java_spec.rb
# frozen_string_literal: true require "language/java" RSpec.describe Language::Java do let(:f) do formula("openjdk") do url "openjdk" version "15.0.1" end end let(:expected_home) do if OS.mac? f.opt_libexec/"openjdk.jdk/Contents/Home" else f.opt_libexec end end before do allow(Formula).to receive(:[]).and_return(f) allow(f).to receive_messages(any_version_installed?: true, any_installed_version: f.version) end describe "::java_home" do it "returns valid JAVA_HOME if version is specified" do java_home = described_class.java_home("1.8+") expect(java_home).to eql(expected_home) end it "returns valid JAVA_HOME if version is not specified" do java_home = described_class.java_home expect(java_home).to eql(expected_home) end end describe "::java_home_env" do it "returns java_home path if version specified" do java_home_env = described_class.java_home_env("1.8+") expect(java_home_env[:JAVA_HOME]).to eql(expected_home.to_s) end it "returns java_home path if version is not specified" do java_home_env = described_class.java_home_env expect(java_home_env[:JAVA_HOME]).to eql(expected_home.to_s) end end describe "::overridable_java_home_env" do it "returns java_home path if version specified" do overridable_java_home_env = described_class.overridable_java_home_env("1.8+") expect(overridable_java_home_env[:JAVA_HOME]).to eql("${JAVA_HOME:-#{expected_home}}") end it "returns java_home path if version is not specified" do overridable_java_home_env = described_class.overridable_java_home_env expect(overridable_java_home_env[:JAVA_HOME]).to eql("${JAVA_HOME:-#{expected_home}}") end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/language/python_spec.rb
Library/Homebrew/test/language/python_spec.rb
# frozen_string_literal: true require "language/python" RSpec.describe Language::Python, :needs_python do describe "#major_minor_version" do it "returns a Version for Python 2" do expect(described_class).to receive(:major_minor_version).and_return(Version) described_class.major_minor_version("python") end end describe "#site_packages" do it "gives a different location between PyPy and Python 2" do expect(described_class.site_packages("python")).not_to eql(described_class.site_packages("pypy")) end end describe "#homebrew_site_packages" do it "returns the Homebrew site packages location" do expect(described_class).to receive(:site_packages).and_return(Pathname) described_class.site_packages("python") end end describe "#user_site_packages" do it "can determine user site packages location" do expect(described_class).to receive(:user_site_packages).and_return(Pathname) described_class.user_site_packages("python") end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/language/node_spec.rb
Library/Homebrew/test/language/node_spec.rb
# frozen_string_literal: true require "language/node" RSpec.describe Language::Node do let(:npm_pack_cmd) { ["npm", "pack", "--ignore-scripts"] } describe "#setup_npm_environment" do it "calls prepend_path when node formula exists only during the first call" do node = formula "node" do url "node-test-v1.0" end stub_formula_loader(node) without_partial_double_verification do expect(ENV).to receive(:prepend_path) end described_class.instance_variable_set(:@env_set, false) described_class.setup_npm_environment expect(described_class.instance_variable_get(:@env_set)).to be(true) without_partial_double_verification do expect(ENV).not_to receive(:prepend_path) end described_class.setup_npm_environment end it "does not call prepend_path when node formula does not exist" do without_partial_double_verification do expect(ENV).not_to receive(:prepend_path) end described_class.setup_npm_environment end end describe "#std_pack_for_installation" do it "removes prepare and prepack scripts" do mktmpdir.cd do path = Pathname("package.json") path.atomic_write("{\"scripts\":{\"prepare\": \"ls\", \"prepack\": \"ls\", \"test\": \"ls\"}}") allow(Utils).to receive(:popen_read).with(*npm_pack_cmd).and_return(`echo pack.tgz`) described_class.pack_for_installation expect(path.read).not_to include("prepare") expect(path.read).not_to include("prepack") expect(path.read).to include("test") end end end describe "#std_npm_install_args" do let(:npm_install_arg) { Pathname("libexec") } it "raises error with non zero exitstatus" do allow(Utils).to receive(:popen_read).with(*npm_pack_cmd).and_return(`false`) expect { described_class.std_npm_install_args(npm_install_arg) }.to raise_error("npm failed to pack #{Dir.pwd}") end it "raises error with empty npm pack output" do allow(Utils).to receive(:popen_read).with(*npm_pack_cmd).and_return(`true`) expect { described_class.std_npm_install_args(npm_install_arg) }.to raise_error("npm failed to pack #{Dir.pwd}") end it "does not raise error with a zero exitstatus" do allow(Utils).to receive(:popen_read).with(*npm_pack_cmd).and_return(`echo pack.tgz`) resp = described_class.std_npm_install_args(npm_install_arg) expect(resp).to include("--prefix=#{npm_install_arg}", "#{Dir.pwd}/pack.tgz") end end specify "#local_npm_install_args" do resp = described_class.local_npm_install_args expect(resp).to include("--loglevel=silly", "--build-from-source", "--cache=#{HOMEBREW_CACHE}/npm_cache") end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/language/python/virtualenv_spec.rb
Library/Homebrew/test/language/python/virtualenv_spec.rb
# frozen_string_literal: true require "language/python" require "resource" RSpec.describe Language::Python::Virtualenv, :needs_python do describe "#virtualenv_install_with_resources" do let(:venv) { instance_double(Language::Python::Virtualenv::Virtualenv) } let(:f) do formula "foo" do # Couldn't find a way to get described_class to work inside formula do # rubocop:disable RSpec/DescribedClass include Language::Python::Virtualenv # rubocop:enable RSpec/DescribedClass url "https://brew.sh/foo-1.0.tgz" resource "resource-a" do url "https://brew.sh/resource1.tar.gz" sha256 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" end resource "resource-b" do url "https://brew.sh/resource2.tar.gz" sha256 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" end resource "resource-c" do url "https://brew.sh/resource3.tar.gz" sha256 "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" end resource "resource-d" do url "https://brew.sh/resource4.tar.gz" sha256 "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" end end end let(:r_a) { f.resource("resource-a") } let(:r_b) { f.resource("resource-b") } let(:r_c) { f.resource("resource-c") } let(:r_d) { f.resource("resource-d") } let(:buildpath) { Pathname(TEST_TMPDIR) } before { f.instance_variable_set(:@buildpath, buildpath) } it "works with `using: \"python\"` and installs resources in order" do expect(f).to receive(:virtualenv_create).with( f.libexec, "python", { system_site_packages: true, without_pip: true } ).and_return(venv) expect(venv).to receive(:pip_install).with([r_a, r_b, r_c, r_d]) expect(venv).to receive(:pip_install_and_link).with(buildpath, { link_manpages: true }) f.virtualenv_install_with_resources(using: "python") end it "works with `using: \"python@3.12\"` and installs resources in order" do expect(f).to receive(:virtualenv_create).with( f.libexec, "python3.12", { system_site_packages: true, without_pip: true } ).and_return(venv) expect(venv).to receive(:pip_install).with([r_a, r_b, r_c, r_d]) expect(venv).to receive(:pip_install_and_link).with(buildpath, { link_manpages: true }) f.virtualenv_install_with_resources(using: "python@3.12") end it "skips a `without` resource string and installs remaining resources in order" do expect(f).to receive(:virtualenv_create).and_return(venv) expect(venv).to receive(:pip_install).with([r_a, r_b, r_d]) expect(venv).to receive(:pip_install_and_link).with(buildpath, { link_manpages: true }) f.virtualenv_install_with_resources(using: "python", without: r_c.name) end it "skips all resources in `without` array and installs remaining resources in order" do expect(f).to receive(:virtualenv_create).and_return(venv) expect(venv).to receive(:pip_install).with([r_b, r_c]) expect(venv).to receive(:pip_install_and_link).with(buildpath, { link_manpages: true }) f.virtualenv_install_with_resources(using: "python", without: [r_d.name, r_a.name]) end it "errors if `without` resource string does not exist in formula" do expect do f.virtualenv_install_with_resources(using: "python", without: "unknown") end.to raise_error(ArgumentError) end it "errors if `without` resource array refers to a resource that does not exist in formula" do expect do f.virtualenv_install_with_resources(using: "python", without: [r_a.name, "unknown"]) end.to raise_error(ArgumentError) end it "installs a `start_with` resource string and then remaining resources in order" do expect(f).to receive(:virtualenv_create).and_return(venv) expect(venv).to receive(:pip_install).with([r_c, r_a, r_b, r_d]) expect(venv).to receive(:pip_install_and_link).with(buildpath, { link_manpages: true }) f.virtualenv_install_with_resources(using: "python", start_with: r_c.name) end it "installs all resources in `start_with` array and then remaining resources in order" do expect(f).to receive(:virtualenv_create).and_return(venv) expect(venv).to receive(:pip_install).with([r_d, r_b, r_a, r_c]) expect(venv).to receive(:pip_install_and_link).with(buildpath, { link_manpages: true }) f.virtualenv_install_with_resources(using: "python", start_with: [r_d.name, r_b.name]) end it "errors if `start_with` resource string does not exist in formula" do expect do f.virtualenv_install_with_resources(using: "python", start_with: "unknown") end.to raise_error(ArgumentError) end it "errors if `start_with` resource array refers to a resource that does not exist in formula" do expect do f.virtualenv_install_with_resources(using: "python", start_with: [r_a.name, "unknown"]) end.to raise_error(ArgumentError) end it "installs an `end_with` resource string as last resource" do expect(f).to receive(:virtualenv_create).and_return(venv) expect(venv).to receive(:pip_install).with([r_a, r_c, r_d, r_b]) expect(venv).to receive(:pip_install_and_link).with(buildpath, { link_manpages: true }) f.virtualenv_install_with_resources(using: "python", end_with: r_b.name) end it "installs all resources in `end_with` array after other resources are installed" do expect(f).to receive(:virtualenv_create).and_return(venv) expect(venv).to receive(:pip_install).with([r_a, r_d, r_c, r_b]) expect(venv).to receive(:pip_install_and_link).with(buildpath, { link_manpages: true }) f.virtualenv_install_with_resources(using: "python", end_with: [r_c.name, r_b.name]) end it "errors if `end_with` resource string does not exist in formula" do expect do f.virtualenv_install_with_resources(using: "python", end_with: "unknown") end.to raise_error(ArgumentError) end it "errors if `end_with` resource array refers to a resource that does not exist in formula" do expect do f.virtualenv_install_with_resources(using: "python", end_with: [r_a.name, "unknown"]) end.to raise_error(ArgumentError) end it "installs resources in correct order when combining `without`, `start_with` and `end_with" do expect(f).to receive(:virtualenv_create).and_return(venv) expect(venv).to receive(:pip_install).with([r_d, r_c, r_b]) expect(venv).to receive(:pip_install_and_link).with(buildpath, { link_manpages: true }) f.virtualenv_install_with_resources(using: "python", without: r_a.name, start_with: r_d.name, end_with: r_b.name) end end describe Language::Python::Virtualenv::Virtualenv do subject(:virtualenv) { described_class.new(formula, dir, "python") } let(:dir) { mktmpdir } let(:resource) { instance_double(Resource, "resource", stage: true) } let(:formula_bin) { dir/"formula_bin" } let(:formula_man) { dir/"formula_man" } let(:formula) { instance_double(Formula, "formula", resource:, bin: formula_bin, man: formula_man) } describe "#create" do it "creates a venv" do expect(formula).to receive(:system) .with("python", "-m", "venv", "--system-site-packages", "--without-pip", dir) virtualenv.create end it "creates a venv with pip" do expect(formula).to receive(:system).with("python", "-m", "venv", "--system-site-packages", dir) virtualenv.create(without_pip: false) end end describe "#pip_install" do it "accepts a string" do expect(formula).to receive(:std_pip_args).with(prefix: false, build_isolation: true).and_return(["--std-pip-args"]) expect(formula).to receive(:system) .with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", "foo") .and_return(true) virtualenv.pip_install "foo" end it "accepts a multi-line strings" do expect(formula).to receive(:std_pip_args).with(prefix: false, build_isolation: true).and_return(["--std-pip-args"]) expect(formula).to receive(:system) .with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", "foo", "bar") .and_return(true) virtualenv.pip_install <<~EOS foo bar EOS end it "accepts an array" do expect(formula).to receive(:std_pip_args).with(prefix: false, build_isolation: true).and_return(["--std-pip-args"]) expect(formula).to receive(:system) .with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", "foo") .and_return(true) expect(formula).to receive(:std_pip_args).with(prefix: false, build_isolation: true).and_return(["--std-pip-args"]) expect(formula).to receive(:system) .with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", "bar") .and_return(true) virtualenv.pip_install ["foo", "bar"] end it "accepts a Resource" do res = Resource.new("test") expect(res).to receive(:stage).and_yield expect(formula).to receive(:std_pip_args).with(prefix: false, build_isolation: true).and_return(["--std-pip-args"]) expect(formula).to receive(:system) .with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", Pathname.pwd) .and_return(true) virtualenv.pip_install res end it "works without build isolation" do expect(formula).to receive(:std_pip_args).with(prefix: false, build_isolation: false).and_return(["--std-pip-args"]) expect(formula).to receive(:system) .with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", "foo") .and_return(true) virtualenv.pip_install("foo", build_isolation: false) end end describe "#pip_install_and_link" do let(:src_bin) { dir/"bin" } let(:src_man) { dir/"share/man" } let(:dest_bin) { formula.bin } let(:dest_man) { formula.man } it "can link scripts" do src_bin.mkpath expect(src_bin/"kilroy").not_to exist expect(dest_bin/"kilroy").not_to exist FileUtils.touch src_bin/"irrelevant" bin_before = Dir.glob(src_bin/"*") FileUtils.touch src_bin/"kilroy" bin_after = Dir.glob(src_bin/"*") expect(virtualenv).to receive(:pip_install).with("foo", { build_isolation: true }) expect(Dir).to receive(:[]).with(src_bin/"*").twice.and_return(bin_before, bin_after) virtualenv.pip_install_and_link("foo", link_manpages: false) expect(src_bin/"kilroy").to exist expect(dest_bin/"kilroy").to exist expect(dest_bin/"kilroy").to be_a_symlink expect((src_bin/"kilroy").realpath).to eq((dest_bin/"kilroy").realpath) expect(dest_bin/"irrelevant").not_to exist end it "can link manpages" do (src_man/"man1").mkpath (src_man/"man3").mkpath expect(src_man/"man1/kilroy.1").not_to exist expect(dest_man/"man1").not_to exist expect(dest_man/"man3").not_to exist expect(dest_man/"man5").not_to exist FileUtils.touch src_man/"man1/irrelevant.1" FileUtils.touch src_man/"man3/irrelevant.3" man_before = Dir.glob(src_man/"**/*") (src_man/"man5").mkpath FileUtils.touch src_man/"man1/kilroy.1" FileUtils.touch src_man/"man5/kilroy.5" man_after = Dir.glob(src_man/"**/*") expect(virtualenv).to receive(:pip_install).with("foo", { build_isolation: true }) expect(Dir).to receive(:[]).with(src_bin/"*").and_return([]) expect(Dir).to receive(:[]).with(src_man/"man*/*").and_return(man_before) expect(Dir).to receive(:[]).with(src_bin/"*").and_return([]) expect(Dir).to receive(:[]).with(src_man/"man*/*").and_return(man_after) virtualenv.pip_install_and_link("foo", link_manpages: true) expect(src_man/"man1/kilroy.1").to exist expect(dest_man/"man1/kilroy.1").to exist expect(dest_man/"man5/kilroy.5").to exist expect(dest_man/"man1/kilroy.1").to be_a_symlink expect((src_man/"man1/kilroy.1").realpath).to eq((dest_man/"man1/kilroy.1").realpath) expect(dest_man/"man1/irrelevant.1").not_to exist expect(dest_man/"man3").not_to exist end end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/language/python/shebang_spec.rb
Library/Homebrew/test/language/python/shebang_spec.rb
# frozen_string_literal: true require "language/python" require "utils/shebang" RSpec.describe Language::Python::Shebang do let(:file) { Tempfile.new("python-shebang") } let(:broken_file) { Tempfile.new("python-shebang") } let(:f) do f = {} f[:python311] = formula "python@3.11" do url "https://brew.sh/python-1.0.tgz" end f[:versioned_python_dep] = formula "foo" do url "https://brew.sh/foo-1.0.tgz" depends_on "python@3.11" end f[:no_deps] = formula "foo" do url "https://brew.sh/foo-1.0.tgz" end f[:multiple_deps] = formula "foo" do url "https://brew.sh/foo-1.0.tgz" depends_on "python" depends_on "python@3.11" end f end before do file.write <<~EOS #!/usr/bin/python2 a b c EOS file.flush broken_file.write <<~EOS #!python a b c EOS broken_file.flush end after { [file, broken_file].each(&:unlink) } describe "#detected_python_shebang" do it "can be used to replace Python shebangs" do allow(Formulary).to receive(:factory).with(f[:python311].name).and_return(f[:python311]) Utils::Shebang.rewrite_shebang( described_class.detected_python_shebang(f[:versioned_python_dep], use_python_from_path: false), file.path ) expect(File.read(file)).to eq <<~EOS #!#{HOMEBREW_PREFIX}/opt/python@3.11/bin/python3.11 a b c EOS end it "can be pointed to a `python3` in PATH" do Utils::Shebang.rewrite_shebang( described_class.detected_python_shebang(f[:versioned_python_dep], use_python_from_path: true), file.path ) expect(File.read(file)).to eq <<~EOS #!/usr/bin/env python3 a b c EOS end it "can fix broken shebang line `#!python`" do Utils::Shebang.rewrite_shebang( described_class.detected_python_shebang(f[:versioned_python_dep], use_python_from_path: true), broken_file.path ) expect(File.read(broken_file)).to eq <<~EOS #!/usr/bin/env python3 a b c EOS end it "errors if formula doesn't depend on python" do expect do Utils::Shebang.rewrite_shebang( described_class.detected_python_shebang(f[:no_deps], use_python_from_path: false), file.path, ) end.to raise_error(ShebangDetectionError, "Cannot detect Python shebang: formula does not depend on Python.") end it "errors if formula depends on more than one python" do expect do Utils::Shebang.rewrite_shebang( described_class.detected_python_shebang(f[:multiple_deps], use_python_from_path: false), file.path, ) end.to raise_error( ShebangDetectionError, "Cannot detect Python shebang: formula has multiple Python dependencies.", ) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false