diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index 7acdf6153a..9a657d1c7e 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -26,12 +26,16 @@ module Homebrew "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 `_spec.rb`. Appending `:` will start at a "\ "specific line." flag "--seed=", description: "Randomise tests with the specified instead of a random seed." + conflicts "--changed", "--only" + named_args :none end end @@ -124,10 +128,28 @@ module Homebrew parallel = false ["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?) else Dir.glob("test/**/*_spec.rb") end + if files.blank? + raise UsageError, "The --only= argument requires a valid file or folder name!" if args.only + + if args.changed? + opoo "No tests are directly 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?