[ruby/logger] Let Logger#reopen not raise on nil log devices

https://github.com/ruby/logger/commit/da7bf844e5
This commit is contained in:
Lourens Naudé 2020-03-28 16:16:00 +00:00 committed by Hiroshi SHIBATA
parent f3e12caa08
commit ae93ebae67
2 changed files with 8 additions and 1 deletions

View File

@ -410,7 +410,7 @@ class Logger
# Reopen a log device.
#
def reopen(logdev = nil)
@logdev.reopen(logdev)
@logdev&.reopen(logdev)
self
end

View File

@ -216,6 +216,13 @@ class TestLogger < Test::Unit::TestCase
assert_equal(STDOUT, logger.instance_variable_get(:@logdev).dev)
end
def test_reopen_nil_logdevice
logger = Logger.new(File::NULL)
assert_nothing_raised do
logger.reopen(STDOUT)
end
end
def test_add
logger = Logger.new(nil)
logger.progname = "my_progname"