Skip to content

Commit bef15b8

Browse files
Fix rake test loader swallowing useful error information
1 parent a7ecd32 commit bef15b8

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

lib/rake/rake_test_loader.rb

+15-16
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@
33

44
# Load the test files from the command line.
55
argv = ARGV.select do |argument|
6-
begin
7-
case argument
8-
when /^-/ then
9-
argument
10-
when /\*/ then
11-
FileList[argument].to_a.each do |file|
12-
require File.expand_path file
13-
end
6+
case argument
7+
when /^-/ then
8+
argument
9+
when /\*/ then
10+
FileList[argument].to_a.each do |file|
11+
require File.expand_path file
12+
end
1413

15-
false
16-
else
17-
require File.expand_path argument
14+
false
15+
else
16+
path = File.expand_path argument
1817

19-
false
20-
end
21-
rescue LoadError => e
22-
raise unless e.path
23-
abort "\nFile does not exist: #{e.path}\n\n"
18+
abort "\nFile does not exist: #{path}\n\n" unless File.exist?(path)
19+
20+
require path
21+
22+
false
2423
end
2524
end
2625

test/test_rake_rake_test_loader.rb

+19-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_pattern
2424
$:.replace orig_loaded_features
2525
end
2626

27-
def test_load_error_from_require
27+
def test_load_error_from_missing_test_file
2828
out, err = capture_io do
2929
ARGV.replace %w[no_such_test_file.rb]
3030

@@ -45,6 +45,24 @@ def test_load_error_from_require
4545
assert_match expected, err
4646
end
4747

48+
def test_load_error_raised_implicitly
49+
File.write("error_test.rb", "require 'superkalifragilisticoespialidoso'")
50+
out, err = capture_io do
51+
ARGV.replace %w[error_test.rb]
52+
53+
exc = assert_raises(LoadError) do
54+
load @loader
55+
end
56+
if RUBY_ENGINE == "jruby"
57+
assert_equal "no such file to load -- superkalifragilisticoespialidoso", exc.message
58+
else
59+
assert_equal "cannot load such file -- superkalifragilisticoespialidoso", exc.message
60+
end
61+
end
62+
assert_empty out
63+
assert_empty err
64+
end
65+
4866
def test_load_error_raised_explicitly
4967
File.write("error_test.rb", "raise LoadError, 'explicitly raised'")
5068
out, err = capture_io do

0 commit comments

Comments
 (0)