Merge pull request #13237 from apainintheneck/tests-changed-option

'brew tests --changed' supports changed test files
This commit is contained in:
Mike McQuaid 2022-05-04 14:34:59 +01:00 committed by GitHub
commit 6d0bf18d7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -68,6 +68,23 @@ module Homebrew
"--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
@ -129,14 +146,7 @@ module Homebrew
["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