diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-25 08:17:24 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-25 08:17:24 +0000 |
commit | 5ad56e7c0b5a99df526d3bffbb3c6d3461af73be (patch) | |
tree | 775945357a22bac1bdfce41f16b7e1ee23c7a8d0 /test/ruby | |
parent | 0adeb1c8ab237280896091e9d2034fabf0d050ab (diff) | |
download | ruby-5ad56e7c0b5a99df526d3bffbb3c6d3461af73be.tar.gz |
load.c: backtrace of circular require
* load.c (load_lock): print backtrace of circular require via
`Warning.warn` [ruby-core:80850] [Bug #13505]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58471 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_exception.rb | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 1179c26c51..8a8edd2ff2 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -943,23 +943,23 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| end end - def test_warning_warn + def capture_warning_warn verbose = $VERBOSE - warning = nil + warning = [] ::Warning.class_eval do alias_method :warn2, :warn remove_method :warn define_method(:warn) do |str| - warning = str + warning << str end end $VERBOSE = true - a = @a + yield - assert_match(/instance variable @a not initialized/, warning) + return warning ensure $VERBOSE = verbose @@ -970,6 +970,11 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| end end + def test_warning_warn + warning = capture_warning_warn {@a} + assert_match(/instance variable @a not initialized/, warning[0]) + end + def test_warning_warn_invalid_argument assert_raise(TypeError) do ::Warning.warn nil @@ -982,6 +987,25 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| end end + def test_warning_warn_circular_require_backtrace + warning = nil + path = nil + Tempfile.create(%w[circular .rb]) do |t| + path = t.path + basename = File.basename(path) + t.puts "require '#{basename}'" + t.close + $LOAD_PATH.push(File.dirname(t)) + warning = capture_warning_warn {require basename} + ensure + $LOAD_PATH.pop + $LOADED_FEATURES.delete(t) + end + assert_match(/circular require/, warning.first) + warning.pop while %r[lib/rubygems/core_ext/kernel_require.rb:] =~ warning.last + assert_operator(warning.last, :start_with?, "\tfrom #{path}:1:") + end + def test_undefined_backtrace assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}") begin; |