Skip to content

Commit

Permalink
packages_detect: tweak syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcQuaid authored and SMillerDev committed Mar 25, 2024
1 parent 985e984 commit c181e87
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
2 changes: 2 additions & 0 deletions cmd/test-bot.rb
Expand Up @@ -43,6 +43,8 @@ def test_bot_args
"passing output as raw bytes instead of re-encoding in UTF-8."
switch "--test-default-formula",
description: "Use a default testing formula when not building a tap and no other formulae are specified."
switch "--test-default-cask",
description: "Use a default testing cask when not building a tap and no other formulae are specified."
flag "--root-url=",
description: "Use the specified <URL> as the root of the bottle's URL instead of Homebrew's default."
flag "--git-name=",
Expand Down
10 changes: 5 additions & 5 deletions lib/test_runner.rb
Expand Up @@ -142,14 +142,14 @@ def build_tests(argument, tap:, git:, output_paths:, skip_setup:,
args.deleted_formulae.nil?
if no_formulae_flags &&
(no_only_args || args.only_formulae? || args.only_formulae_detect?)
tests[:formulae_detect] = Tests::PackagesDetect.new(argument, tap: tap,
git: git,
tests[:formulae_detect] = Tests::PackagesDetect.new(argument, tap:,
git:,
dry_run: args.dry_run?,
fail_fast: args.fail_fast?,
verbose: args.verbose?)
elsif (no_only_args || args.only_casks_detect?)
tests[:casks_detect] = Tests::PackagesDetect.new(argument, tap: tap,
git: git,
elsif no_only_args || args.only_casks_detect?
tests[:casks_detect] = Tests::PackagesDetect.new(argument, tap:,
git:,
dry_run: args.dry_run?,
fail_fast: args.fail_fast?,
verbose: args.verbose?)
Expand Down
31 changes: 12 additions & 19 deletions lib/tests/packages_detect.rb
Expand Up @@ -3,7 +3,7 @@
module Homebrew
module Tests
class PackagesDetect < Test
attr_reader :testing_formulae, :added_formulae, :deleted_formulae,
attr_reader :testing_formulae, :added_formulae, :deleted_formulae,
:testing_casks, :added_casks, :deleted_casks

def initialize(argument, tap:, git:, dry_run:, fail_fast:, verbose:)
Expand Down Expand Up @@ -60,6 +60,7 @@ def detect_packages!(args:)
end

@testing_formulae = [canonical_formula_name]
@testing_casks = []
else
raise UsageError,
"#{@argument} is not detected from GitHub Actions or a formula name!"
Expand Down Expand Up @@ -139,20 +140,14 @@ def detect_packages!(args:)

if tap && diff_start_sha1 != diff_end_sha1
formula_path = tap.formula_dir.to_s
@added_formulae +=
diff_packages(diff_start_sha1, diff_end_sha1, formula_path, "A")
modified_formulae +=
diff_packages(diff_start_sha1, diff_end_sha1, formula_path, "M")
@deleted_formulae +=
diff_packages(diff_start_sha1, diff_end_sha1, formula_path, "D")
@added_formulae += diff_packages(diff_start_sha1, diff_end_sha1, formula_path, "A")
modified_formulae += diff_packages(diff_start_sha1, diff_end_sha1, formula_path, "M")
@deleted_formulae += diff_packages(diff_start_sha1, diff_end_sha1, formula_path, "D")

cask_path = tap.cask_dir.to_s
@added_casks += @added_formulae +
diff_packages(diff_start_sha1, diff_end_sha1, cask_path, "A")
modified_casks += modified_formulae +
diff_packages(diff_start_sha1, diff_end_sha1, cask_path, "M")
@deleted_casks += @deleted_formulae +
diff_packages(diff_start_sha1, diff_end_sha1, cask_path, "D")
@added_casks += diff_packages(diff_start_sha1, diff_end_sha1, cask_path, "A")
modified_casks += diff_packages(diff_start_sha1, diff_end_sha1, cask_path, "M")
@deleted_casks += diff_packages(diff_start_sha1, diff_end_sha1, cask_path, "D")
end

# If a package is both added and deleted: it's actually modified.
Expand All @@ -169,8 +164,8 @@ def detect_packages!(args:)
if args.test_default_formula?
# Build the default test formula.
modified_formulae << "homebrew/test-bot/testbottest"
modified_casks << "homebrew/test-bot/testbottest"
end
modified_casks << "homebrew/test-bot/testbottest" if args.test_default_cask?

@testing_formulae += @added_formulae + modified_formulae
@testing_casks += @added_casks + modified_casks
Expand All @@ -189,6 +184,7 @@ def detect_packages!(args:)
@added_formulae.uniq!
modified_formulae.uniq!
@deleted_formulae.uniq!

@testing_casks.uniq!
@added_casks.uniq!
modified_casks.uniq!
Expand Down Expand Up @@ -264,14 +260,11 @@ def diff_packages(start_revision, end_revision, path, filter)
).lines.filter_map do |line|
file = Pathname.new line.chomp

name = nil
if tap.formula_file?(file)
name = tap.formula_file_to_name(file)
tap.formula_file_to_name(file)
elsif tap.cask_file?(file)
name = file.basename(".rb").to_s
file.basename(".rb").to_s
end

name
end.compact
end
end
Expand Down

0 comments on commit c181e87

Please sign in to comment.