mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/logger.rb: check if the given logdevice object respond_to :write and
:close, not is_a? IO. duck duck. * test/logger/test_logger.rb: self IO.pipe reading/writing may be locked by the flood. use tempfile. * lib/wsdl/xmlSchema/data.rb: wrong constant reference. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
14f9af6015
commit
523cd7be9c
4 changed files with 68 additions and 15 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Mon Sep 29 16:18:30 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||
|
||||
* lib/logger.rb: check if the given logdevice object respond_to :write
|
||||
and :close, not is_a? IO. duck duck.
|
||||
|
||||
* test/logger/test_logger.rb: self IO.pipe reading/writing may be
|
||||
locked by the flood. use tempfile.
|
||||
|
||||
* lib/wsdl/xmlSchema/data.rb: wrong constant reference.
|
||||
|
||||
Mon Sep 29 16:11:23 2003 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* test/fileutils/test_fileutils.rb: clean up temporary symlink.
|
||||
|
|
|
@ -322,7 +322,7 @@ private
|
|||
#
|
||||
def initialize(log = nil, opt = {})
|
||||
@dev = @filename = @shift_age = @shift_size = nil
|
||||
if log.is_a?(IO)
|
||||
if log.respond_to?(:write) and log.respond_to?(:close)
|
||||
@dev = log
|
||||
elsif log.is_a?(String)
|
||||
@dev = open_logfile(log)
|
||||
|
|
|
@ -36,7 +36,7 @@ module XMLSchema
|
|||
|
||||
AllName = XSD::QName.new(XSD::Namespace, 'all')
|
||||
AnyName = XSD::QName.new(XSD::Namespace, 'any')
|
||||
ArrayTypeAttrName = XSD::QName.new(Namespace, 'arrayType')
|
||||
ArrayTypeAttrName = XSD::QName.new(XSD::Namespace, 'arrayType')
|
||||
AttributeName = XSD::QName.new(XSD::Namespace, 'attribute')
|
||||
ChoiceName = XSD::QName.new(XSD::Namespace, 'choice')
|
||||
ComplexContentName = XSD::QName.new(XSD::Namespace, 'complexContent')
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require 'test/unit'
|
||||
require 'logger'
|
||||
require 'tempfile'
|
||||
|
||||
|
||||
class TestLoggerSeverity < Test::Unit::TestCase
|
||||
def test_enum
|
||||
|
@ -34,19 +36,13 @@ class TestLogger < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def log(logger, msg_id, *arg, &block)
|
||||
r, w = IO.pipe
|
||||
logger.instance_eval { @logdev = Logger::LogDevice.new(w) }
|
||||
logdev = Tempfile.new(File.basename(__FILE__) + '.log')
|
||||
logger.instance_eval { @logdev = Logger::LogDevice.new(logdev) }
|
||||
logger.__send__(msg_id, *arg, &block)
|
||||
read_ready, = IO.select([r], nil, nil, 0.1)
|
||||
w.close
|
||||
if read_ready
|
||||
line = r.read
|
||||
r.close
|
||||
Log.new(line)
|
||||
else
|
||||
r.close
|
||||
nil
|
||||
end
|
||||
logdev.open
|
||||
msg = logdev.read
|
||||
logdev.close
|
||||
Log.new(msg)
|
||||
end
|
||||
|
||||
def test_level
|
||||
|
@ -118,7 +114,7 @@ class TestLogger < Test::Unit::TestCase
|
|||
assert_equal("my_progname", log.progname)
|
||||
logger.level = WARN
|
||||
assert(logger.log(INFO))
|
||||
assert_nil(log_add(logger, INFO, "msg"))
|
||||
assert_nil(log_add(logger, INFO, "msg").msg)
|
||||
log = log_add(logger, WARN, nil) { "msg" }
|
||||
assert_equal("msg\n", log.msg)
|
||||
log = log_add(logger, WARN, "") { "msg" }
|
||||
|
@ -230,3 +226,50 @@ class TestLogger < Test::Unit::TestCase
|
|||
assert_equal("msg2\n\n", msg)
|
||||
end
|
||||
end
|
||||
|
||||
class TestLogDevice < Test::Unit::TestCase
|
||||
def d(log)
|
||||
Logger::LogDevice.new(log)
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
logdev = d(STDERR)
|
||||
assert_equal(STDERR, logdev.dev)
|
||||
assert_nil(logdev.filename)
|
||||
assert_raises(ArgumentError) do
|
||||
d(nil)
|
||||
end
|
||||
#
|
||||
filename = __FILE__ + ".#{$$}"
|
||||
begin
|
||||
logdev = d(filename)
|
||||
assert(File.exist?(filename))
|
||||
assert(logdev.dev.sync)
|
||||
assert_equal(filename, logdev.filename)
|
||||
ensure
|
||||
File.unlink(filename)
|
||||
end
|
||||
end
|
||||
|
||||
def test_write
|
||||
r, w = IO.pipe
|
||||
logdev = d(w)
|
||||
logdev.write("msg2\n\n")
|
||||
read_ready, = IO.select([r], nil, nil, 0.1)
|
||||
w.close
|
||||
msg = r.read
|
||||
r.close
|
||||
assert_equal("msg2\n\n", msg)
|
||||
end
|
||||
|
||||
def test_close
|
||||
r, w = IO.pipe
|
||||
logdev = d(w)
|
||||
logdev.write("msg2\n\n")
|
||||
read_ready, = IO.select([r], nil, nil, 0.1)
|
||||
assert(!w.closed?)
|
||||
logdev.close
|
||||
assert(w.closed?)
|
||||
r.close
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue