Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rake test loader swallowing useful error information #367

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions lib/rake/rake_test_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,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