summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-27 09:19:14 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-27 09:19:14 +0000
commit4e60f99803e0b9ab49fb368f3660438934bf1a4e (patch)
tree5cf0fd8168252e170864060a779a2e6badc9a4bf /test
parenta38b2f84f468638bb910455fe618cae4c431d893 (diff)
* 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.rb27
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