Skip to content

Commit

Permalink
Fix rake test loader swallowing useful error information
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Feb 4, 2021
1 parent c2eeae2 commit c955a5a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
31 changes: 15 additions & 16 deletions lib/rake/rake_test_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@

# Load the test files from the command line.
argv = ARGV.select do |argument|
begin
case argument
when /^-/ then
argument
when /\*/ then
FileList[argument].to_a.each do |file|
require File.expand_path file
end
case argument
when /^-/ then
argument
when /\*/ then
FileList[argument].to_a.each do |file|
require File.expand_path file
end

false
else
require File.expand_path argument
false
else
path = File.expand_path argument

false
end
rescue LoadError => e
raise unless e.path
abort "\nFile does not exist: #{e.path}\n\n"
abort "\nFile does not exist: #{path}\n\n" unless File.exist?(path)

require path

false
end
end

Expand Down
20 changes: 19 additions & 1 deletion test/test_rake_rake_test_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_pattern
$:.replace orig_loaded_features
end

def test_load_error_from_require
def test_load_error_from_missing_test_file
out, err = capture_io do
ARGV.replace %w[no_such_test_file.rb]

Expand All @@ -45,6 +45,24 @@ def test_load_error_from_require
assert_match expected, err
end

def test_load_error_raised_implicitly
File.write("error_test.rb", "require 'superkalifragilisticoespialidoso'")
out, err = capture_io do
ARGV.replace %w[error_test.rb]

exc = assert_raises(LoadError) do
load @loader
end
if RUBY_ENGINE == "jruby"
assert_equal "no such file to load -- superkalifragilisticoespialidoso", exc.message
else
assert_equal "cannot load such file -- superkalifragilisticoespialidoso", exc.message
end
end
assert_empty out
assert_empty err
end

def test_load_error_raised_explicitly
File.write("error_test.rb", "raise LoadError, 'explicitly raised'")
out, err = capture_io do
Expand Down

0 comments on commit c955a5a

Please sign in to comment.