Skip to content

Commit 52f55fc

Browse files
authored
Merge pull request #195 from ruby/drbrain/better-load-error
Make LoadError from running tests more obvious
2 parents cba565f + 8d3a682 commit 52f55fc

2 files changed

Lines changed: 42 additions & 12 deletions

File tree

lib/rake/rake_test_loader.rb

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

33
# Load the test files from the command line.
44
argv = ARGV.select do |argument|
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
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
1213

13-
false
14-
else
15-
require File.expand_path argument
14+
false
15+
else
16+
require File.expand_path argument
1617

17-
false
18+
false
19+
end
20+
rescue LoadError => e
21+
abort "\nFile does not exist: #{e.path}\n\n"
1822
end
1923
end
2024

test/test_rake_rake_test_loader.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
class TestRakeRakeTestLoader < Rake::TestCase
44

5+
def setup
6+
super
7+
8+
@loader = File.join @rake_lib, 'rake/rake_test_loader.rb'
9+
end
10+
511
def test_pattern
612
orig_loaded_features = $:.dup
713
FileUtils.touch "foo.rb"
@@ -10,11 +16,31 @@ def test_pattern
1016

1117
ARGV.replace %w[foo.rb test_*.rb -v]
1218

13-
load File.join(@rake_lib, "rake/rake_test_loader.rb")
19+
load @loader
1420

1521
assert_equal %w[-v], ARGV
1622
ensure
1723
$:.replace orig_loaded_features
1824
end
1925

26+
def test_load_error
27+
out, err = capture_io do
28+
ARGV.replace %w[no_such_test_file.rb]
29+
30+
assert_raises SystemExit do
31+
load @loader
32+
end
33+
end
34+
35+
assert_empty out
36+
37+
no_such_path = File.join @tempdir, 'no_such_test_file'
38+
39+
expected =
40+
/\A\n
41+
File\ does\ not\ exist:\ #{no_such_path}(\.rb)? # JRuby is different
42+
\n\n\Z/x
43+
44+
assert_match expected, err
45+
end
2046
end

0 commit comments

Comments
 (0)