From 17e69a5e0082d3ae84efbb4c9567756092910d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 11 Nov 2020 17:24:24 +0100 Subject: [PATCH] Fix rake test loader swallowing useful error information --- lib/rake/rake_test_loader.rb | 31 +++++++++++++++--------------- test/test_rake_rake_test_loader.rb | 20 ++++++++++++++++++- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/lib/rake/rake_test_loader.rb b/lib/rake/rake_test_loader.rb index 1707493b8..15ffbd2e6 100644 --- a/lib/rake/rake_test_loader.rb +++ b/lib/rake/rake_test_loader.rb @@ -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 diff --git a/test/test_rake_rake_test_loader.rb b/test/test_rake_rake_test_loader.rb index 4423a9b1c..4f481cd28 100644 --- a/test/test_rake_rake_test_loader.rb +++ b/test/test_rake_rake_test_loader.rb @@ -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] @@ -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