Skip to content

Commit 3ec8c35

Browse files
hsbtclaude
andcommitted
Skip option-like arguments in the :direct test loader
The :direct loader required every ARGV entry, so a verbose run that appended -v tried to require "-v" and aborted with a LoadError. Skip arguments starting with "-", matching rake_test_loader.rb. #724 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f7e9df5 commit 3ec8c35

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

lib/rake/testtask.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def ruby_version # :nodoc:
180180
def run_code # :nodoc:
181181
case @loader
182182
when :direct
183-
"-e \"ARGV.each{|f| require f}\""
183+
"-e \"ARGV.each{|f| require f unless f.start_with?('-')}\""
184184
when :"test-unit"
185185
"-S test-unit"
186186
when :rake

test/test_rake_test_task.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,34 @@ def test_run_code_direct
141141
# t.pettern is "test/test*.rb"
142142
end
143143

144-
assert_equal '-e "ARGV.each{|f| require f}"', test_task.run_code
144+
assert_equal %q{-e "ARGV.each{|f| require f unless f.start_with?('-')}"}, test_task.run_code
145145
assert_equal globbed, test_task.file_list.to_a
146146
end
147147

148+
def test_run_code_direct_skips_option_arguments
149+
test_task = Rake::TestTask.new do |t|
150+
t.loader = :direct
151+
t.verbose = true
152+
end
153+
154+
code = test_task.run_code[/\A-e "(.*)"\z/, 1]
155+
refute_nil code
156+
157+
required = []
158+
receiver = Object.new
159+
receiver.define_singleton_method(:require) { |file| required << file }
160+
161+
saved_argv = ARGV.dup
162+
begin
163+
ARGV.replace(["test/foo_test.rb", "-v"])
164+
receiver.instance_eval(code)
165+
ensure
166+
ARGV.replace(saved_argv)
167+
end
168+
169+
assert_equal ["test/foo_test.rb"], required
170+
end
171+
148172
test "run code test-unit" do
149173
test_task = Rake::TestTask.new do |t|
150174
t.loader = :"test-unit"

0 commit comments

Comments
 (0)