From 9e24bae3428f726800da2963a8f2695f7d4064cd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 2 Jan 2016 22:29:12 +0000 Subject: enable frozen_string_literal for Ruby 2.3+ There are likely yet-to-be-discovered bugs in here. Also, keeping explicit #freeze calls for 2.2 users, since most users have not migrated to 2.3, yet. --- test/covshow.rb | 1 + test/helper.rb | 1 + test/server_helper.rb | 1 + test/test_bin.rb | 1 + test/test_buffer_tmpdir.rb | 1 + test/test_client_expire.rb | 5 +++-- test/test_client_max_body_size.rb | 3 ++- test/test_config.rb | 1 + test/test_expect_100.rb | 5 +++-- test/test_extras_autoindex.rb | 1 + test/test_extras_exec_cgi.rb | 3 ++- test/test_extras_proxy_pass.rb | 1 + test/test_extras_try_gzip_static.rb | 1 + test/test_fdmap.rb | 1 + test/test_input.rb | 3 ++- test/test_mt_accept.rb | 1 + test/test_output_buffering.rb | 3 ++- test/test_proxy_pass.rb | 25 +++++++++++++------------ test/test_rack.rb | 1 + test/test_rack_hijack.rb | 1 + test/test_reopen_logs.rb | 1 + test/test_response.rb | 1 + test/test_server.rb | 17 +++++++++-------- test/test_ssl.rb | 5 +++-- test/test_stream_file.rb | 1 + test/test_tmpio.rb | 1 + test/test_unix_socket.rb | 1 + test/test_wbuf.rb | 1 + 28 files changed, 58 insertions(+), 30 deletions(-) (limited to 'test') diff --git a/test/covshow.rb b/test/covshow.rb index 1d6367d..63f37ee 100644 --- a/test/covshow.rb +++ b/test/covshow.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true # # this works with the __covmerge method in test/helper.rb # run this file after all tests are run diff --git a/test/helper.rb b/test/helper.rb index 5dca23f..445a0e6 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true $stdout.sync = $stderr.sync = Thread.abort_on_exception = true $-w = true if RUBY_VERSION.to_f >= 2.0 require 'thread' diff --git a/test/server_helper.rb b/test/server_helper.rb index cc34f4a..16a3ae3 100644 --- a/test/server_helper.rb +++ b/test/server_helper.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'helper' require 'timeout' require 'socket' diff --git a/test/test_bin.rb b/test/test_bin.rb index 97e672e..20031b3 100644 --- a/test/test_bin.rb +++ b/test/test_bin.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' class TestBin < Testcase ENV["N"].to_i > 1 and parallelize_me! diff --git a/test/test_buffer_tmpdir.rb b/test/test_buffer_tmpdir.rb index f1af602..0c5fa5f 100644 --- a/test/test_buffer_tmpdir.rb +++ b/test/test_buffer_tmpdir.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' require 'sleepy_penguin' diff --git a/test/test_client_expire.rb b/test/test_client_expire.rb index 0260850..9cc85c2 100644 --- a/test/test_client_expire.rb +++ b/test/test_client_expire.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' class TestClientExpire < Testcase @@ -53,7 +54,7 @@ class TestClientExpire < Testcase s = get_tcp_client(host, port) req = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" s.write(req) - str = "" + str = ''.dup Timeout.timeout(20) { str << s.readpartial(666) until str =~ /\r\n\r\n/ } assert_match(%r{keep-alive}, str) sleep 2 @@ -113,7 +114,7 @@ class TestClientExpire < Testcase s = get_tcp_client(host, port) req = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" s.write(req) - str = "" + str = ''.dup Timeout.timeout(20) { str << s.readpartial(666) until str =~ /\r\n\r\n/ } assert_match(%r{keep-alive}, str) sleep 1 diff --git a/test/test_client_max_body_size.rb b/test/test_client_max_body_size.rb index 8be2856..9ea91ad 100644 --- a/test/test_client_max_body_size.rb +++ b/test/test_client_max_body_size.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' class TestClientMaxBodySize < Testcase @@ -11,7 +12,7 @@ class TestClientMaxBodySize < Testcase DRAINER = lambda do |e| input = e["rack.input"] - buf = "" + buf = ''.dup nr = 0 while rv = input.read(16384, buf) nr += rv.size diff --git a/test/test_config.rb b/test/test_config.rb index 08c33db..088a253 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'helper' require 'rack/lobster' diff --git a/test/test_expect_100.rb b/test/test_expect_100.rb index 1701bca..f34c29e 100644 --- a/test/test_expect_100.rb +++ b/test/test_expect_100.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' class TestExpect100 < Testcase @@ -161,8 +162,8 @@ class TestExpect100 < Testcase end c = get_tcp_client(host, port) if body.size > 0 - r = "PUT / HTTP/1.0\r\nExpect: 100-continue\r\n" - r << "Content-Length: #{body.size}\r\n\r\n#{body}" + r = "PUT / HTTP/1.0\r\nExpect: 100-continue\r\n" \ + "Content-Length: #{body.size}\r\n\r\n#{body}" else r = "PUT / HTTP/1.0\r\nExpect: 100-continue\r\n\r\n" end diff --git a/test/test_extras_autoindex.rb b/test/test_extras_autoindex.rb index 5471598..998b280 100644 --- a/test/test_extras_autoindex.rb +++ b/test/test_extras_autoindex.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' require 'zlib' require 'time' diff --git a/test/test_extras_exec_cgi.rb b/test/test_extras_exec_cgi.rb index a9bcd34..5b2f2ff 100644 --- a/test/test_extras_exec_cgi.rb +++ b/test/test_extras_exec_cgi.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' # note: we use worker_processes to avoid polling/excessive wakeup issues @@ -160,7 +161,7 @@ class TestExtrasExecCGI < Testcase poke_until_dead exec_pid when 11 # pid of executable, persistent c.write "GET /pid HTTP/1.0\r\nConnection: keep-alive\r\n\r\n" - buf = "" + buf = ''.dup begin buf << c.readpartial(666) end until buf =~ /\r\n\r\n\d+\n/ diff --git a/test/test_extras_proxy_pass.rb b/test/test_extras_proxy_pass.rb index 851b6aa..cda302a 100644 --- a/test/test_extras_proxy_pass.rb +++ b/test/test_extras_proxy_pass.rb @@ -1,5 +1,6 @@ # Copyright (C) 2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' begin require 'kcar' diff --git a/test/test_extras_try_gzip_static.rb b/test/test_extras_try_gzip_static.rb index 874f700..7051d68 100644 --- a/test/test_extras_try_gzip_static.rb +++ b/test/test_extras_try_gzip_static.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' require 'zlib' require 'time' diff --git a/test/test_fdmap.rb b/test/test_fdmap.rb index e611862..05eac07 100644 --- a/test/test_fdmap.rb +++ b/test/test_fdmap.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'helper' class TestFdmap < Testcase diff --git a/test/test_input.rb b/test/test_input.rb index add7598..802e099 100644 --- a/test/test_input.rb +++ b/test/test_input.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' require 'digest/md5' @@ -22,7 +23,7 @@ class TestInput < Testcase abort "unrecognized input type: #{input.class}" end - buf = "" + buf = ''.dup md5 = Digest::MD5.new while input.read(16384, buf) md5 << buf diff --git a/test/test_mt_accept.rb b/test/test_mt_accept.rb index fb02430..9f28078 100644 --- a/test/test_mt_accept.rb +++ b/test/test_mt_accept.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' require 'rack/lobster' diff --git a/test/test_output_buffering.rb b/test/test_output_buffering.rb index 7f75702..8134b53 100644 --- a/test/test_output_buffering.rb +++ b/test/test_output_buffering.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' require 'digest/md5' require 'rack/file' @@ -88,7 +89,7 @@ class TestOutputBuffering < Testcase def md5sum(c) dig = Digest::MD5.new - buf = "" + buf = ''.dup nr = 0 while c.read(8192, buf) dig << buf diff --git a/test/test_proxy_pass.rb b/test/test_proxy_pass.rb index 7f752e3..29c5a61 100644 --- a/test/test_proxy_pass.rb +++ b/test/test_proxy_pass.rb @@ -1,5 +1,6 @@ # Copyright (C) 2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' require 'json' require 'digest' @@ -390,9 +391,9 @@ class TestProxyPass < Testcase def check_pipelining(host, port) pl = TCPSocket.new(host, port) - r1 = '' - r2 = '' - r3 = '' + r1 = ''.dup + r2 = ''.dup + r3 = ''.dup Timeout.timeout(60) do pl.write "GET / HTTP/1.1\r\nHost: example.com\r\n\r\nGET /" until r1 =~ /hi\n/ @@ -415,7 +416,7 @@ class TestProxyPass < Testcase # ensure stuff still works after a chunked upload: pl.write "GET / HTTP/1.1\r\nHost: example.com\r\n\r\nP" - after_up = '' + after_up = ''.dup until after_up =~ /hi\n/ after_up << pl.readpartial(666) end @@ -426,7 +427,7 @@ class TestProxyPass < Testcase pl.write "UT / HTTP/1.1\r\nHost: example.com\r\n" pl.write "Content-Length: 8\r\n\r\n" pl.write "identity" - identity = '' + identity = ''.dup until identity =~ /identity/ identity << pl.readpartial(666) @@ -436,7 +437,7 @@ class TestProxyPass < Testcase # ensure stuff still works after an identity upload: pl.write "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" - after_up = '' + after_up = ''.dup until after_up =~ /hi\n/ after_up << pl.readpartial(666) end @@ -509,8 +510,8 @@ class TestProxyPass < Testcase s = TCPSocket.new(host, port) s.write "GET /giant-body HTTP/1.0\r\n\r\n" sleep 0.1 - str = '' - buf = '' + str = ''.dup + buf = ''.dup assert_raises(EOFError) { loop { str << s.readpartial(400, buf) } } h, b = str.split(/\r\n\r\n/, 2) assert_equal OMFG, b @@ -523,8 +524,8 @@ class TestProxyPass < Testcase s = TCPSocket.new(host, port) s.write "GET /big-headers HTTP/1.1\r\nHost: example.com\r\n\r\n" s.write "HEAD /big-headers HTTP/1.0\r\n\r\n" - buf = '' - res = '' + buf = ''.dup + res = ''.dup sleep 0.1 begin res << s.readpartial(32786, buf) @@ -552,8 +553,8 @@ class TestProxyPass < Testcase s = TCPSocket.new(host, port) s.write "GET /response-trailer HTTP/1.1\r\n#{x}" \ "Host: example.com\r\n\r\n" - res = '' - buf = '' + res = ''.dup + buf = ''.dup Timeout.timeout(60) do until res =~ /Foo: bar\r\n\r\n\z/ res << s.readpartial(16384, buf) diff --git a/test/test_rack.rb b/test/test_rack.rb index f601425..82a5fb7 100644 --- a/test/test_rack.rb +++ b/test/test_rack.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'helper' require 'rack/lobster' require 'yahns/rack' diff --git a/test/test_rack_hijack.rb b/test/test_rack_hijack.rb index d326bcd..23858b8 100644 --- a/test/test_rack_hijack.rb +++ b/test/test_rack_hijack.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' class TestRackHijack < Testcase diff --git a/test/test_reopen_logs.rb b/test/test_reopen_logs.rb index f8aa7b8..e4e076b 100644 --- a/test/test_reopen_logs.rb +++ b/test/test_reopen_logs.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' require 'rack/commonlogger' diff --git a/test/test_response.rb b/test/test_response.rb index 19adbd6..a46c286 100644 --- a/test/test_response.rb +++ b/test/test_response.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' class TestResponse < Testcase diff --git a/test/test_server.rb b/test/test_server.rb index c753919..a2c5ea2 100644 --- a/test/test_server.rb +++ b/test/test_server.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' class TestServer < Testcase @@ -25,7 +26,7 @@ class TestServer < Testcase # test pipelining r = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" c.write(r + r) - buf = "" + buf = ''.dup Timeout.timeout(10) do until buf =~ /HI.+HI/m buf << c.readpartial(4096) @@ -34,7 +35,7 @@ class TestServer < Testcase # trickle pipelining c.write(r + "GET ") - buf = "" + buf = ''.dup Timeout.timeout(10) do until buf =~ /HI\z/ buf << c.readpartial(4096) @@ -91,7 +92,7 @@ class TestServer < Testcase buf = "PUT / HTTP/1.1\r\nContent-Length: 2\r\n\r\nHI" c = get_tcp_client(host, port) c.write(buf + buf) - buf = "" + buf = ''.dup Timeout.timeout(10) do until buf =~ /HI.+HI/m buf << c.readpartial(4096) @@ -110,7 +111,7 @@ class TestServer < Testcase sleep(0.01) if b.chr == ":" Thread.pass end - buf = "" + buf = ''.dup Timeout.timeout(10) do until buf =~ /HIBYE.+HIBYE/m buf << c.readpartial(4096) @@ -709,7 +710,7 @@ class TestServer < Testcase c = get_tcp_client(host, port) c.write "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" assert_equal c, c.wait(30) - buf = "" + buf = ''.dup re = /\r\n\r\nOK\z/ Timeout.timeout(30) do begin @@ -781,7 +782,7 @@ class TestServer < Testcase # normal response c.write "GET /keep-alive HTTP/1.1\r\nHost: example.com\r\n\r\n" - buf = "" + buf = ''.dup Timeout.timeout(30) do buf << c.readpartial(4096) until buf =~ /HI\z/ end @@ -790,7 +791,7 @@ class TestServer < Testcase # we allow whatever in the response, but don't send it c.write "GET /whatever HTTP/1.1\r\nHost: example.com\r\n\r\n" - buf = "" + buf = ''.dup Timeout.timeout(30) do buf << c.readpartial(4096) until buf =~ /HI\z/ end @@ -798,7 +799,7 @@ class TestServer < Testcase assert_raises(Errno::EAGAIN,IO::WaitReadable) { c.read_nonblock(666) } c.write "GET /close HTTP/1.1\r\nHost: example.com\r\n\r\n" - buf = "" + buf = ''.dup Timeout.timeout(30) do buf << c.readpartial(4096) until buf =~ /HI\z/ end diff --git a/test/test_ssl.rb b/test/test_ssl.rb index c54cc3c..1379e93 100644 --- a/test/test_ssl.rb +++ b/test/test_ssl.rb @@ -1,5 +1,6 @@ # Copyright (C) 2014, all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' require 'openssl' class TestSSL < Testcase @@ -72,7 +73,7 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC end client = ssl_client(host, port) client.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n") - buf = '' + buf = ''.dup Timeout.timeout(60) do buf << client.readpartial(111) until buf =~ /HI\z/ end @@ -104,7 +105,7 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC when "remote_address\n" s.puts(s.remote_address.inspect) when "each\n" - line = '' + line = ''.dup s.each do |l| l.strip! line << l diff --git a/test/test_stream_file.rb b/test/test_stream_file.rb index 4bc3b2e..4219836 100644 --- a/test/test_stream_file.rb +++ b/test/test_stream_file.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'helper' require 'timeout' diff --git a/test/test_tmpio.rb b/test/test_tmpio.rb index 79c9f32..5e49cce 100644 --- a/test/test_tmpio.rb +++ b/test/test_tmpio.rb @@ -1,6 +1,7 @@ # -*- encoding: binary -*- # Copyright (C) 2009-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-2.0.txt) +# frozen_string_literal: true require_relative 'helper' class TestTmpIO < Testcase diff --git a/test/test_unix_socket.rb b/test/test_unix_socket.rb index 712e99f..3bda4df 100644 --- a/test/test_unix_socket.rb +++ b/test/test_unix_socket.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'server_helper' class TestUnixSocket < Testcase diff --git a/test/test_wbuf.rb b/test/test_wbuf.rb index 0d7959c..4905eff 100644 --- a/test/test_wbuf.rb +++ b/test/test_wbuf.rb @@ -1,5 +1,6 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# frozen_string_literal: true require_relative 'helper' require 'timeout' -- cgit v1.2.3-24-ge0c7