Skip to content

Commit

Permalink
Added --changed option to "brew tests" dev cmd
Browse files Browse the repository at this point in the history
This option allows the user to run tests on all
files that have been changed from the master
branch.
  • Loading branch information
apainintheneck committed Apr 18, 2022
1 parent 09e766f commit 77ded1d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def tests_args
"official external commands."
switch "--byebug",
description: "Enable debugging using byebug."
switch "--changed",
description: "Only runs tests on files that were changed from the master branch."
flag "--only=",
description: "Run only <test_script>`_spec.rb`. Appending `:`<line_number> will start at a "\
"specific line."
Expand Down Expand Up @@ -124,10 +126,28 @@ def tests
parallel = false
["test/#{test_name}_spec.rb:#{line}"]
end
elsif args.changed?
changed_files = Utils.popen_read("git", "diff", "--name-only", "master")

filestub_regex = %r{Library/Homebrew/([A-Za-z/_-]+).rb}

changed_files.scan(filestub_regex)
.map { |filestub| "test/#{filestub.last}_spec.rb" }
.select { |filename| File.exist?(filename) }
else
Dir.glob("test/**/*_spec.rb")
end

if files.empty?
raise UsageError, "The --only= argument requires a valid file or folder name!" if args.only

if args.changed?
opoo "Either no files have been changed from the master branch " \
"or no tests are associated with the changed files!"
return
end
end

parallel_rspec_log_name = "parallel_runtime_rspec"
parallel_rspec_log_name = "#{parallel_rspec_log_name}.no_compat" if args.no_compat?
parallel_rspec_log_name = "#{parallel_rspec_log_name}.generic" if args.generic?
Expand Down

0 comments on commit 77ded1d

Please sign in to comment.