ruby-changes:36260
From: akr <ko1@a...>
Date: Sun, 9 Nov 2014 20:51:22 +0900 (JST)
Subject: [ruby-changes:36260] akr:r48341 (trunk): * test/webrick: Store log in an array.
akr 2014-11-09 20:51:06 +0900 (Sun, 09 Nov 2014) New Revision: 48341 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48341 Log: * test/webrick: Store log in an array. * test/net/http: Ditto. * test/open-uri: Ditto. Modified files: trunk/ChangeLog trunk/test/net/http/test_http.rb trunk/test/net/http/test_https.rb trunk/test/net/http/utils.rb trunk/test/open-uri/test_open-uri.rb trunk/test/open-uri/test_ssl.rb trunk/test/webrick/test_httpauth.rb trunk/test/webrick/test_server.rb trunk/test/webrick/utils.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 48340) +++ ChangeLog (revision 48341) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Nov 9 20:29:01 2014 Tanaka Akira <akr@f...> + + * test/webrick: Store log in an array. + + * test/net/http: Ditto. + + * test/open-uri: Ditto. + Sun Nov 9 18:35:36 2014 Tanaka Akira <akr@f...> * test/xmlrpc: Refine log test. Index: test/webrick/test_httpauth.rb =================================================================== --- test/webrick/test_httpauth.rb (revision 48340) +++ test/webrick/test_httpauth.rb (revision 48341) @@ -61,7 +61,6 @@ class TestWEBrickHTTPAuth < Test::Unit:: https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httpauth.rb#L61 http.request(g){|res| assert_not_equal("hoge", res.body, log.call)} } } - log = log.lines.to_a log.reject! {|line| /\A\s*\z/ =~ line } pats = [ /ERROR Basic WEBrick's realm: webrick: password unmatch\./, @@ -154,7 +153,6 @@ class TestWEBrickHTTPAuth < Test::Unit:: https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httpauth.rb#L153 end } } - log = log.lines.to_a log.reject! {|line| /\A\s*\z/ =~ line } pats = [ /ERROR Digest WEBrick's realm: no credentials in the request\./, Index: test/webrick/utils.rb =================================================================== --- test/webrick/utils.rb (revision 48340) +++ test/webrick/utils.rb (revision 48341) @@ -32,17 +32,13 @@ module TestWEBrick https://github.com/ruby/ruby/blob/trunk/test/webrick/utils.rb#L32 module_function def start_server(klass, config={}, &block) - log_string = "" - logger = Object.new - logger.instance_eval do - define_singleton_method(:<<) {|msg| log_string << msg } - end - log = proc { "webrick log start:\n" + log_string.gsub(/^/, " ").chomp + "\nwebrick log end" } + log_ary = [] + log = proc { "webrick log start:\n" + log_ary.join.gsub(/^/, " ").chomp + "\nwebrick log end" } server = klass.new({ :BindAddress => "127.0.0.1", :Port => 0, :ServerType => Thread, - :Logger => WEBrick::Log.new(logger, WEBrick::BasicLog::WARN), - :AccessLog => [[logger, ""]] + :Logger => WEBrick::Log.new(log_ary, WEBrick::BasicLog::WARN), + :AccessLog => [[log_ary, ""]] }.update(config)) server_thread = server.start addr = server.listeners[0].addr @@ -54,7 +50,7 @@ module TestWEBrick https://github.com/ruby/ruby/blob/trunk/test/webrick/utils.rb#L50 end } assert_join_threads([client_thread, server_thread]) - log_string + log_ary end def start_httpserver(config={}, &block) Index: test/webrick/test_server.rb =================================================================== --- test/webrick/test_server.rb (revision 48340) +++ test/webrick/test_server.rb (revision 48341) @@ -26,7 +26,7 @@ class TestWEBrickServer < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/webrick/test_server.rb#L26 def test_start_exception stopped = 0 - log = StringIO.new('') + log = [] logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN) assert_raises(SignalException) do @@ -47,7 +47,8 @@ class TestWEBrickServer < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/webrick/test_server.rb#L47 end assert_equal(stopped, 1) - assert_match(/FATAL SignalException: SIGTERM/, log.string) + assert_equal(1, log.length) + assert_match(/FATAL SignalException: SIGTERM/, log[0]) end def test_callbacks Index: test/open-uri/test_open-uri.rb =================================================================== --- test/open-uri/test_open-uri.rb (revision 48340) +++ test/open-uri/test_open-uri.rb (revision 48341) @@ -14,7 +14,7 @@ class TestOpenURI < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_open-uri.rb#L14 end def with_http(log_is_empty=true) - log = StringIO.new('') + log = [] logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN) Dir.mktmpdir {|dr| srv = WEBrick::HTTPServer.new({ @@ -34,7 +34,7 @@ class TestOpenURI < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_open-uri.rb#L34 end } if log_is_empty - assert_equal("", log.string) + assert_equal([], log) end end @@ -92,7 +92,8 @@ class TestOpenURI < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_open-uri.rb#L92 } server_thread2 = Thread.new { server_thread.join - assert_match(%r{ERROR `/not-exist' not found}, server_log.string) + assert_equal(1, server_log.length) + assert_match(%r{ERROR `/not-exist' not found}, server_log[0]) } assert_join_threads([client_thread, server_thread2]) } @@ -486,7 +487,8 @@ class TestOpenURI < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_open-uri.rb#L487 } server_thread2 = Thread.new { server_thread.join - assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log.string) + assert_equal(1, server_log.length) + assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log[0]) } assert_join_threads([client_thread, server_thread2]) } @@ -505,7 +507,8 @@ class TestOpenURI < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_open-uri.rb#L507 } server_thread2 = Thread.new { server_thread.join - assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log.string) + assert_equal(1, server_log.length) + assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log[0]) } assert_join_threads([client_thread, server_thread2]) } Index: test/open-uri/test_ssl.rb =================================================================== --- test/open-uri/test_ssl.rb (revision 48340) +++ test/open-uri/test_ssl.rb (revision 48341) @@ -19,7 +19,7 @@ class TestOpenURISSL https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_ssl.rb#L19 end def with_https(log_is_empty=true) - log = StringIO.new('') + log = [] logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN) Dir.mktmpdir {|dr| srv = WEBrick::HTTPServer.new({ @@ -42,7 +42,7 @@ class TestOpenURISSL https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_ssl.rb#L42 th.join end if log_is_empty - assert_equal("", log.string) + assert_equal([], log) end } end @@ -96,14 +96,15 @@ class TestOpenURISSL https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_ssl.rb#L96 } server_thread2 = Thread.new { server_thread.join - assert_match(/ERROR OpenSSL::SSL::SSLError:/, server_log.string) + assert_equal(1, server_log.length) + assert_match(/ERROR OpenSSL::SSL::SSLError:/, server_log[0]) } assert_join_threads([client_thread, server_thread2]) } end def with_https_proxy - proxy_log = StringIO.new('') + proxy_log = [] proxy_logger = WEBrick::Log.new(proxy_log, WEBrick::BasicLog::WARN) with_https {|srv, dr, url, server_thread, server_log| srv.mount_proc("/proxy", lambda { |req, res| res.body = "proxy" } ) @@ -116,7 +117,7 @@ class TestOpenURISSL https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_ssl.rb#L117 proxy = WEBrick::HTTPProxyServer.new({ :ServerType => Thread, :Logger => proxy_logger, - :AccessLog => [[proxy_access_log=StringIO.new, WEBrick::AccessLog::COMMON_LOG_FORMAT]], + :AccessLog => [[proxy_access_log=[], WEBrick::AccessLog::COMMON_LOG_FORMAT]], :BindAddress => '127.0.0.1', :Port => 0}) _, proxy_port, _, proxy_host = proxy.listeners[0].addr @@ -128,7 +129,7 @@ class TestOpenURISSL https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_ssl.rb#L129 proxy_thread.join end } - assert_equal('', proxy_log.string) + assert_equal([], proxy_log) end def test_proxy_cacert_file @@ -146,8 +147,9 @@ class TestOpenURISSL https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_ssl.rb#L147 } proxy_thread2 = Thread.new { proxy_thread.join - assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log.string) - assert_equal('', proxy_log.string) + assert_equal(1, proxy_access_log.length) + assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log[0]) + assert_equal([], proxy_log) } assert_join_threads([client_thread, proxy_thread2, server_thread]) } @@ -168,8 +170,9 @@ class TestOpenURISSL https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_ssl.rb#L170 } proxy_thread2 = Thread.new { proxy_thread.join - assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log.string) - assert_equal('', proxy_log.string) + assert_equal(1, proxy_access_log.length) + assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log[0]) + assert_equal([], proxy_log) } assert_join_threads([client_thread, proxy_thread2, server_thread]) } Index: test/net/http/test_http.rb =================================================================== --- test/net/http/test_http.rb (revision 48340) +++ test/net/http/test_http.rb (revision 48341) @@ -277,7 +277,7 @@ module TestNetHTTP_version_1_1_methods https://github.com/ruby/ruby/blob/trunk/test/net/http/test_http.rb#L277 end } assert_equal 1, i - @log_pattern = nil # server may encount ECONNRESET + @log_tester = nil # server may encount ECONNRESET end def test_get__implicit_start Index: test/net/http/utils.rb =================================================================== --- test/net/http/utils.rb (revision 48340) +++ test/net/http/utils.rb (revision 48341) @@ -36,14 +36,14 @@ module TestNetHTTPUtils https://github.com/ruby/ruby/blob/trunk/test/net/http/utils.rb#L36 @server.shutdown @server_thread.join end - assert_match(@log_pattern, @log.string) if @log_pattern + @log_tester.call(@log) if @log_tester # resume global state Net::HTTP.version_1_2 end def spawn_server - @log = StringIO.new('') - @log_pattern = /\A\z/ + @log = [] + @log_tester = lambda {|log| assert_equal([], log ) } @config = self.class::CONFIG server_config = { :BindAddress => config('host'), Index: test/net/http/test_https.rb =================================================================== --- test/net/http/test_https.rb (revision 48340) +++ test/net/http/test_https.rb (revision 48341) @@ -117,7 +117,10 @@ class TestNetHTTPS < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/net/http/test_https.rb#L117 end } assert_match(/certificate verify failed/, ex.message) - @log_pattern = /ERROR OpenSSL::SSL::SSLError:/ + @log_tester = lambda {|log| + assert_equal(1, log.length) + assert_match(/ERROR OpenSSL::SSL::SSLError:/, log[0]) + } end def test_identity_verify_failure -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/