From ef24d77d411c992ad0471311c73341a732426418 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 16 Jun 2026 16:02:49 +0900 Subject: [PATCH 1/2] Do not pass -v to the test runner for the global verbose flag The global verbose flag is also set by --trace and -n, so deriving the test runner's -v from it leaked -v into the test process ARGV and broke apps that inspect ARGV at load time. Keep echoing the command for the global flag, but base the -v injection only on the task's own @verbose. Fixes #732 Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/rake/testtask.rb | 5 ++++- test/test_rake_test_task.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/rake/testtask.rb b/lib/rake/testtask.rb index 6979b6b4c..bd0515862 100644 --- a/lib/rake/testtask.rb +++ b/lib/rake/testtask.rb @@ -110,9 +110,12 @@ def define task @name => Array(deps) do effective_verbose = @verbose || FileUtilsExt.verbose_flag == true FileUtilsExt.verbose(effective_verbose) do + # The global verbose flag (e.g. set by --trace or -n) controls + # whether rake echoes the command, but it must not inject "-v" + # into the test runner's ARGV. Only the task's own @verbose does. args = "#{ruby_opts_string} #{run_code} " + - "#{file_list_string} #{option_list(verbose: effective_verbose)}" + "#{file_list_string} #{option_list(verbose: @verbose)}" ruby args do |ok, status| if !ok && status.respond_to?(:signaled?) && status.signaled? raise SignalException.new(status.termsig) diff --git a/test/test_rake_test_task.rb b/test/test_rake_test_task.rb index 3514cfedd..a3ec2aed9 100644 --- a/test/test_rake_test_task.rb +++ b/test/test_rake_test_task.rb @@ -20,6 +20,18 @@ def teardown super end + # Run the test task's action with the +ruby+ invocation stubbed out and + # return the command string that would have been executed. + def captured_test_command(test_task) + command = nil + test_task.define_singleton_method(:ruby) do |*args, **_opts, &_block| + command = args.first + nil + end + Rake::Task[test_task.name].execute + command + end + def test_initialize tt = Rake::TestTask.new do |t| end refute_nil tt @@ -242,6 +254,21 @@ def test_option_list_verbose_keyword_overrides assert_equal "-v", tt.option_list(verbose: true) end + def test_run_omits_v_for_global_verbose_only + # --trace and -n set the global verbose flag via Rake.verbose(true), but + # that must not leak "-v" into the test runner's ARGV. (issue #732) + Rake::FileUtilsExt.verbose_flag = true + tt = Rake::TestTask.new { |t| t.verbose = false } + refute_includes captured_test_command(tt).split, "-v" + ensure + Rake::FileUtilsExt.verbose_flag = false + end + + def test_run_injects_v_for_task_verbose + tt = Rake::TestTask.new { |t| t.verbose = true } + assert_includes captured_test_command(tt).split, "-v" + end + def test_task_order_only_prerequisites_key t = task "a" => "b", order_only: ["c"] b, c = task("b"), task("c") From 3f2115f66973e24fd3b56d6184eba0cb28c55c91 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 16 Jun 2026 17:14:06 +0900 Subject: [PATCH 2/2] Make captured_test_command a private test helper It is a helper, not a test case, so keep it under private like the other helpers in the test suite. Co-Authored-By: Claude Opus 4.8 (1M context) --- test/test_rake_test_task.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/test/test_rake_test_task.rb b/test/test_rake_test_task.rb index a3ec2aed9..2a171447b 100644 --- a/test/test_rake_test_task.rb +++ b/test/test_rake_test_task.rb @@ -20,18 +20,6 @@ def teardown super end - # Run the test task's action with the +ruby+ invocation stubbed out and - # return the command string that would have been executed. - def captured_test_command(test_task) - command = nil - test_task.define_singleton_method(:ruby) do |*args, **_opts, &_block| - command = args.first - nil - end - Rake::Task[test_task.name].execute - command - end - def test_initialize tt = Rake::TestTask.new do |t| end refute_nil tt @@ -276,4 +264,18 @@ def test_task_order_only_prerequisites_key assert_equal ["c"], t.order_only_prerequisites assert_equal [b, c], t.prerequisite_tasks end + + private + + # Run the test task's action with the +ruby+ invocation stubbed out and + # return the command string that would have been executed. + def captured_test_command(test_task) + command = nil + test_task.define_singleton_method(:ruby) do |*args, **_opts, &_block| + command = args.first + nil + end + Rake::Task[test_task.name].execute + command + end end