diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-27 09:19:14 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-27 09:19:14 +0000 |
commit | 957bdcd85cebc40a826c2c99c1c6fd11486884b5 (patch) | |
tree | 5cf0fd8168252e170864060a779a2e6badc9a4bf /test | |
parent | a73c7e87fa13490b147b7fe9da9124e168cf5d3f (diff) | |
download | ruby-957bdcd85cebc40a826c2c99c1c6fd11486884b5.tar.gz |
* error.c: This makes all warnings raised call Warning.warn, which
by default does the same thing it does currently
(rb_write_error_str). You can override Warning.warn to change
the behavior. [ruby-core:75016] [Feature #12299]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_exception.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 208c5ecfc0..3735e492d8 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -913,4 +913,31 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| end end end + + def test_warning_warn + verbose = $VERBOSE + warning = nil + + ::Warning.class_eval do + alias_method :warn2, :warn + remove_method :warn + + define_method(:warn) do |str| + warning = str + end + end + + $VERBOSE = true + a = @a + + assert_match(/instance variable @a not initialized/, warning) + ensure + $VERBOSE = verbose + + ::Warning.class_eval do + remove_method :warn + alias_method :warn, :warn2 + remove_method :warn2 + end + end end |