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
5 changes: 4 additions & 1 deletion lib/rake/testtask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions test/test_rake_test_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,40 @@ 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")
assert_equal ["b"], t.prerequisites
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