mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
* 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
This commit is contained in:
parent
a38b2f84f4
commit
4e60f99803
3 changed files with 63 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue