Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rake/file_utils_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def #{name}(*args, **options, &block)
def verbose(value=nil)
oldvalue = FileUtilsExt.verbose_flag
FileUtilsExt.verbose_flag = value unless value.nil?
ENV["TESTOPTS"] = "-v" if value

if block_given?
begin
yield
Expand Down
15 changes: 10 additions & 5 deletions lib/rake/testtask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ def initialize(name=:test)
def define
desc @description
task @name => Array(deps) do
FileUtilsExt.verbose(@verbose) do
effective_verbose = @verbose || FileUtilsExt.verbose_flag == true
FileUtilsExt.verbose(effective_verbose) do
args =
"#{ruby_opts_string} #{run_code} " +
"#{file_list_string} #{option_list}"
"#{file_list_string} #{option_list(verbose: effective_verbose)}"
ruby args do |ok, status|
if !ok && status.respond_to?(:signaled?) && status.signaled?
raise SignalException.new(status.termsig)
Expand All @@ -133,13 +134,17 @@ def define
self
end

def option_list # :nodoc:
(ENV["TESTOPTS"] ||
def option_list(verbose: @verbose) # :nodoc:
opts = ENV["TESTOPTS"] ||
ENV["TESTOPT"] ||
ENV["TEST_OPTS"] ||
ENV["TEST_OPT"] ||
@options ||
"")
""
if verbose && !opts.split.include?("-v")
opts = opts.empty? ? "-v" : "#{opts} -v"
end
opts
end

def ruby_opts_string # :nodoc:
Expand Down
4 changes: 0 additions & 4 deletions test/test_rake_file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def teardown
FileUtils::LN_SUPPORTED[0] = true
RakeFileUtils.verbose_flag = Rake::FileUtilsExt::DEFAULT
ENV["RAKE_TEST_SH"] = @rake_test_sh
ENV["TESTOPTS"] = nil

super
end
Expand Down Expand Up @@ -107,12 +106,9 @@ def test_safe_ln_fails_on_script_error
def test_verbose
verbose true
assert_equal true, verbose
assert_equal "-v", ENV["TESTOPTS"]

ENV["TESTOPTS"] = nil
verbose false
assert_equal false, verbose
assert_equal nil, ENV["TESTOPTS"]

verbose(true) {
assert_equal true, verbose
Expand Down
43 changes: 43 additions & 0 deletions test/test_rake_test_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
class TestRakeTestTask < Rake::TestCase # :nodoc:
include Rake

def setup
super
@_previous_testopts = ENV["TESTOPTS"]
ENV.delete "TESTOPTS"
end

def teardown
if @_previous_testopts.nil?
ENV.delete "TESTOPTS"
else
ENV["TESTOPTS"] = @_previous_testopts
end
super
end

def test_initialize
tt = Rake::TestTask.new do |t| end
refute_nil tt
Expand Down Expand Up @@ -191,6 +206,34 @@ def test_task_order_only_prerequisites
assert_equal [b, c], t.prerequisite_tasks
end

def test_option_list_verbose_without_testopts
tt = Rake::TestTask.new { |t| t.verbose = true }
assert_equal "-v", tt.option_list
Comment on lines +209 to +211
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_option_list_verbose_without_testopts assumes ENV["TESTOPTS"] is unset; if a developer/CI environment has TESTOPTS pre-populated, this assertion will fail. Consider saving the original value and clearing/restoring TESTOPTS within this test (similar to the other tests here).

Suggested change
def test_option_list_verbose_without_testopts
tt = Rake::TestTask.new { |t| t.verbose = true }
assert_equal "-v", tt.option_list
def test_option_list_verbose_without_testopts
testopts = ENV["TESTOPTS"]
ENV.delete "TESTOPTS"
tt = Rake::TestTask.new { |t| t.verbose = true }
assert_equal "-v", tt.option_list
ensure
if testopts
ENV["TESTOPTS"] = testopts
else
ENV.delete "TESTOPTS"
end

Copilot uses AI. Check for mistakes.
end

def test_option_list_verbose_with_testopts
ENV["TESTOPTS"] = "--ci-reporter"
tt = Rake::TestTask.new { |t| t.verbose = true }
assert_equal "--ci-reporter -v", tt.option_list
end

def test_option_list_not_verbose_with_testopts
ENV["TESTOPTS"] = "--ci-reporter"
tt = Rake::TestTask.new { |t| t.verbose = false }
assert_equal "--ci-reporter", tt.option_list
end

def test_option_list_skips_duplicate_v
ENV["TESTOPTS"] = "-v --ci-reporter"
tt = Rake::TestTask.new { |t| t.verbose = true }
assert_equal "-v --ci-reporter", tt.option_list
end

def test_option_list_verbose_keyword_overrides
tt = Rake::TestTask.new { |t| t.verbose = false }
assert_equal "-v", tt.option_list(verbose: true)
end

def test_task_order_only_prerequisites_key
t = task "a" => "b", order_only: ["c"]
b, c = task("b"), task("c")
Expand Down