* 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:
nahi 2003-09-29 07:27:57 +00:00
Родитель 14f9af6015
Коммит 523cd7be9c
4 изменённых файлов: 68 добавлений и 15 удалений

Просмотреть файл

@ -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> Mon Sep 29 16:11:23 2003 Minero Aoki <aamine@loveruby.net>
* test/fileutils/test_fileutils.rb: clean up temporary symlink. * test/fileutils/test_fileutils.rb: clean up temporary symlink.

Просмотреть файл

@ -322,7 +322,7 @@ private
# #
def initialize(log = nil, opt = {}) def initialize(log = nil, opt = {})
@dev = @filename = @shift_age = @shift_size = nil @dev = @filename = @shift_age = @shift_size = nil
if log.is_a?(IO) if log.respond_to?(:write) and log.respond_to?(:close)
@dev = log @dev = log
elsif log.is_a?(String) elsif log.is_a?(String)
@dev = open_logfile(log) @dev = open_logfile(log)

Просмотреть файл

@ -36,7 +36,7 @@ module XMLSchema
AllName = XSD::QName.new(XSD::Namespace, 'all') AllName = XSD::QName.new(XSD::Namespace, 'all')
AnyName = XSD::QName.new(XSD::Namespace, 'any') 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') AttributeName = XSD::QName.new(XSD::Namespace, 'attribute')
ChoiceName = XSD::QName.new(XSD::Namespace, 'choice') ChoiceName = XSD::QName.new(XSD::Namespace, 'choice')
ComplexContentName = XSD::QName.new(XSD::Namespace, 'complexContent') ComplexContentName = XSD::QName.new(XSD::Namespace, 'complexContent')

Просмотреть файл

@ -1,5 +1,7 @@
require 'test/unit' require 'test/unit'
require 'logger' require 'logger'
require 'tempfile'
class TestLoggerSeverity < Test::Unit::TestCase class TestLoggerSeverity < Test::Unit::TestCase
def test_enum def test_enum
@ -34,19 +36,13 @@ class TestLogger < Test::Unit::TestCase
end end
def log(logger, msg_id, *arg, &block) def log(logger, msg_id, *arg, &block)
r, w = IO.pipe logdev = Tempfile.new(File.basename(__FILE__) + '.log')
logger.instance_eval { @logdev = Logger::LogDevice.new(w) } logger.instance_eval { @logdev = Logger::LogDevice.new(logdev) }
logger.__send__(msg_id, *arg, &block) logger.__send__(msg_id, *arg, &block)
read_ready, = IO.select([r], nil, nil, 0.1) logdev.open
w.close msg = logdev.read
if read_ready logdev.close
line = r.read Log.new(msg)
r.close
Log.new(line)
else
r.close
nil
end
end end
def test_level def test_level
@ -118,7 +114,7 @@ class TestLogger < Test::Unit::TestCase
assert_equal("my_progname", log.progname) assert_equal("my_progname", log.progname)
logger.level = WARN logger.level = WARN
assert(logger.log(INFO)) 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" } log = log_add(logger, WARN, nil) { "msg" }
assert_equal("msg\n", log.msg) assert_equal("msg\n", log.msg)
log = log_add(logger, WARN, "") { "msg" } log = log_add(logger, WARN, "") { "msg" }
@ -230,3 +226,50 @@ class TestLogger < Test::Unit::TestCase
assert_equal("msg2\n\n", msg) assert_equal("msg2\n\n", msg)
end end
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