From 8492f6bbc56d42e3068f25ca233faa78884d5a77 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 25 Dec 2010 01:27:33 -0800 Subject: fix $msec and $usec in pure Ruby variant It was totally broken but nobody uses uses it, so it went unnoticed since the beginning of time. --- test/test_clogger.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/test_clogger.rb b/test/test_clogger.rb index 47387bb..58d38e8 100644 --- a/test/test_clogger.rb +++ b/test/test_clogger.rb @@ -241,32 +241,52 @@ class TestClogger < Test::Unit::TestCase str = StringIO.new app = lambda { |env| [ 200, {}, [] ] } cl = Clogger.new(app, :logger => str, :format => '$msec') + a = Time.now.to_f - 0.001 status, header, bodies = cl.call(@req) assert_match %r(\A\d+\.\d{3}\n\z), str.string + b = Time.now.to_f + 0.001 + logged = str.string.to_f + assert logged >= a, "#{logged} >= #{a}" + assert logged <= b, "#{logged} <= #{b}" end def test_usec str = StringIO.new app = lambda { |env| [ 200, {}, [] ] } cl = Clogger.new(app, :logger => str, :format => '$usec') + a = Time.now.to_f - 0.000001 status, header, bodies = cl.call(@req) assert_match %r(\A\d+\.\d{6}\n\z), str.string + b = Time.now.to_f + 0.000001 + logged = str.string.to_f + assert logged >= a, "#{logged} >= #{a}" + assert logged <= b, "#{logged} <= #{b}" end def test_time_0 str = StringIO.new app = lambda { |env| [ 200, {}, [] ] } cl = Clogger.new(app, :logger => str, :format => '$time{0}') + a = Time.now.to_f - 1 status, header, bodies = cl.call(@req) assert_match %r(\A\d+\n\z), str.string + b = Time.now.to_f + 1 + logged = str.string.to_f + assert logged >= a, "#{logged} >= #{a}" + assert logged <= b, "#{logged} <= #{b}" end def test_time_1 str = StringIO.new app = lambda { |env| [ 200, {}, [] ] } cl = Clogger.new(app, :logger => str, :format => '$time{1}') + a = Time.now.to_f - 0.5 status, header, bodies = cl.call(@req) assert_match %r(\A\d+\.\d\n\z), str.string + b = Time.now.to_f + 0.5 + logged = str.string.to_f + assert logged >= a, "#{logged} >= #{a}" + assert logged <= b, "#{logged} <= #{b}" end def test_request_length -- cgit v1.2.3-24-ge0c7