Skip to content

Commit 17e69a5

Browse files
Fix rake test loader swallowing useful error information
1 parent fc688bd commit 17e69a5

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

lib/rake/rake_test_loader.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22

33
# Load the test files from the command line.
44
argv = ARGV.select do |argument|
5-
begin
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
5+
case argument
6+
when /^-/ then
7+
argument
8+
when /\*/ then
9+
FileList[argument].to_a.each do |file|
10+
require File.expand_path file
11+
end
1312

14-
false
15-
else
16-
require File.expand_path argument
13+
false
14+
else
15+
path = File.expand_path argument
1716

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

test/test_rake_rake_test_loader.rb

Lines changed: 19 additions & 1 deletion
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)