Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'brew tests --changed' supports changed test files #13237

Merged
merged 1 commit into from
May 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 deletions Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ def run_buildpulse
"--repository-id", ENV["HOMEBREW_BUILDPULSE_REPOSITORY_ID"]
end

def changed_test_files
changed_files = Utils.popen_read("git", "diff", "--name-only", "master")

raise UsageError, "No files have been changed from the master branch!" if changed_files.blank?

filestub_regex = %r{Library/Homebrew/([\w/-]+).rb}
changed_files.scan(filestub_regex).map(&:last).map do |filestub|
if filestub.start_with?("test/")
# Only run tests on *_spec.rb files in test/ folder
filestub.end_with?("_spec") ? Pathname("#{filestub}.rb") : nil
else
# For all other changed .rb files guess the associated test file name
Pathname("test/#{filestub}_spec.rb")
end
end.compact.select(&:exist?)
end

def tests
args = tests_args.parse

Expand Down Expand Up @@ -129,14 +146,7 @@ def tests
["test/#{test_name}_spec.rb:#{line}"]
end
elsif args.changed?
changed_files = Utils.popen_read("git", "diff", "--name-only", "master")

raise UsageError, "No files have been changed from the master branch!" if changed_files.blank?

filestub_regex = %r{Library/Homebrew/([\w/-]+).rb}
changed_files.scan(filestub_regex)
.map { |filestub| Pathname("test/#{filestub.last}_spec.rb") }
.select(&:exist?)
changed_test_files
else
Dir.glob("test/**/*_spec.rb")
end
Expand Down