mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
'brew tests --changed' supports changed test files
This commit is contained in:
parent
a4545e5231
commit
489d38324b
@ -68,6 +68,23 @@ module Homebrew
|
|||||||
"--repository-id", ENV["HOMEBREW_BUILDPULSE_REPOSITORY_ID"]
|
"--repository-id", ENV["HOMEBREW_BUILDPULSE_REPOSITORY_ID"]
|
||||||
end
|
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
|
def tests
|
||||||
args = tests_args.parse
|
args = tests_args.parse
|
||||||
|
|
||||||
@ -129,14 +146,7 @@ module Homebrew
|
|||||||
["test/#{test_name}_spec.rb:#{line}"]
|
["test/#{test_name}_spec.rb:#{line}"]
|
||||||
end
|
end
|
||||||
elsif args.changed?
|
elsif args.changed?
|
||||||
changed_files = Utils.popen_read("git", "diff", "--name-only", "master")
|
changed_test_files
|
||||||
|
|
||||||
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?)
|
|
||||||
else
|
else
|
||||||
Dir.glob("test/**/*_spec.rb")
|
Dir.glob("test/**/*_spec.rb")
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user