mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb, test/openssl/test_config.rb, test/psych/test_encoding.rb, test/psych/test_exception.rb, test/psych/test_psych.rb, test/psych/test_tainted.rb, test/readline/test_readline.rb, test/rexml/test_contrib.rb, test/ruby/test_autoload.rb, test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb, test/ruby/test_file.rb, test/ruby/test_io.rb, test/ruby/test_marshal.rb, test/ruby/test_process.rb, test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb, test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb, test/zlib/test_zlib.rb: Use Tempfile.create. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
65261bda4d
commit
8f671120f1
24 changed files with 1148 additions and 1183 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
Sun Apr 21 08:00:55 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* test/csv/test_features.rb, test/logger/test_logger.rb
|
||||
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
|
||||
test/openssl/test_config.rb, test/psych/test_encoding.rb,
|
||||
test/psych/test_exception.rb, test/psych/test_psych.rb,
|
||||
test/psych/test_tainted.rb, test/readline/test_readline.rb,
|
||||
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
|
||||
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
|
||||
test/ruby/test_file.rb, test/ruby/test_io.rb,
|
||||
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
|
||||
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
|
||||
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
|
||||
test/zlib/test_zlib.rb: Use Tempfile.create.
|
||||
|
||||
Sun Apr 21 00:15:36 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* lib/tempfile.rb (Tempfile.create): Close when the block exits.
|
||||
|
|
|
@ -212,7 +212,7 @@ class TestCSV::Features < TestCSV
|
|||
end if defined?(Zlib::GzipReader)
|
||||
|
||||
def test_gzip_writer_bug_fix
|
||||
tempfile = Tempfile.new(%w"temp .gz")
|
||||
Tempfile.create(%w"temp .gz") {|tempfile|
|
||||
tempfile.close
|
||||
file = tempfile.path
|
||||
zipped = nil
|
||||
|
@ -226,7 +226,7 @@ class TestCSV::Features < TestCSV
|
|||
assert( Zlib::GzipReader.open(file) { |f| f.read }.
|
||||
include?($INPUT_RECORD_SEPARATOR),
|
||||
"@row_sep did not default" )
|
||||
tempfile.close(true)
|
||||
}
|
||||
end if defined?(Zlib::GzipWriter)
|
||||
|
||||
def test_inspect_is_smart_about_io_types
|
||||
|
@ -236,13 +236,13 @@ class TestCSV::Features < TestCSV
|
|||
str = CSV.new($stderr).inspect
|
||||
assert(str.include?("io_type:$stderr"), "IO type not detected.")
|
||||
|
||||
tempfile = Tempfile.new(%w"temp .csv")
|
||||
Tempfile.create(%w"temp .csv") {|tempfile|
|
||||
tempfile.close
|
||||
path = tempfile.path
|
||||
File.open(path, "w") { |csv| csv << "one,two,three\n1,2,3\n" }
|
||||
str = CSV.open(path) { |csv| csv.inspect }
|
||||
assert(str.include?("io_type:File"), "IO type not detected.")
|
||||
tempfile.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_inspect_shows_key_attributes
|
||||
|
|
|
@ -41,13 +41,12 @@ class TestLogger < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def log_raw(logger, msg_id, *arg, &block)
|
||||
logdev = Tempfile.new(File.basename(__FILE__) + '.log')
|
||||
Tempfile.create(File.basename(__FILE__) + '.log') {|logdev|
|
||||
logger.instance_eval { @logdev = Logger::LogDevice.new(logdev) }
|
||||
logger.__send__(msg_id, *arg, &block)
|
||||
logdev.open
|
||||
msg = logdev.read
|
||||
logdev.close(true)
|
||||
msg
|
||||
logdev.rewind
|
||||
logdev.read
|
||||
}
|
||||
end
|
||||
|
||||
def test_level
|
||||
|
|
|
@ -10,13 +10,12 @@ class TestMkmf
|
|||
end
|
||||
|
||||
def test_have_macro_header
|
||||
Tempfile.open(%w"test_mkmf .h", ".") do |tmp|
|
||||
Tempfile.create(%w"test_mkmf .h", ".") do |tmp|
|
||||
tmp.puts("#undef #{MACRO_NAME}")
|
||||
tmp.puts("#define #{MACRO_NAME} 1")
|
||||
tmp.close
|
||||
base = File.basename(tmp.path)
|
||||
assert_equal(true, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
|
||||
tmp.close(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -25,12 +24,11 @@ class TestMkmf
|
|||
end
|
||||
|
||||
def test_not_have_macro_header
|
||||
Tempfile.open(%w"test_mkmf .h", ".") do |tmp|
|
||||
Tempfile.create(%w"test_mkmf .h", ".") do |tmp|
|
||||
tmp.puts("#undef #{MACRO_NAME}")
|
||||
tmp.close
|
||||
base = File.basename(tmp.path)
|
||||
assert_equal(false, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
|
||||
tmp.close(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -599,7 +599,7 @@ module TestNetHTTP_version_1_2_methods
|
|||
|
||||
def test_set_form
|
||||
require 'tempfile'
|
||||
file = Tempfile.new('ruby-test')
|
||||
Tempfile.create('ruby-test') {|file|
|
||||
file << "\u{30c7}\u{30fc}\u{30bf}"
|
||||
data = [
|
||||
['name', 'Gonbei Nanashi'],
|
||||
|
@ -632,8 +632,7 @@ __EOM__
|
|||
_test_set_form_multipart(http, false, data, expected)
|
||||
_test_set_form_multipart(http, true, data, expected)
|
||||
}
|
||||
ensure
|
||||
file.close! if file
|
||||
}
|
||||
end
|
||||
|
||||
def _test_set_form_urlencoded(http, data)
|
||||
|
@ -658,7 +657,7 @@ __EOM__
|
|||
|
||||
def test_set_form_with_file
|
||||
require 'tempfile'
|
||||
file = Tempfile.new('ruby-test')
|
||||
Tempfile.create('ruby-test') {|file|
|
||||
file.binmode
|
||||
file << $test_net_http_data
|
||||
filename = File.basename(file.to_path)
|
||||
|
@ -694,8 +693,7 @@ __EOM__
|
|||
res = http.request req
|
||||
#assert_equal(expected, res.body)
|
||||
}
|
||||
ensure
|
||||
file.close! if file
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -121,13 +121,12 @@ __EOC__
|
|||
assert_equal("", c.to_s)
|
||||
assert_equal([], c.sections)
|
||||
#
|
||||
file = Tempfile.open("openssl.cnf")
|
||||
Tempfile.create("openssl.cnf") {|file|
|
||||
file.close
|
||||
c = OpenSSL::Config.load(file.path)
|
||||
assert_equal("[ default ]\n\n", c.to_s)
|
||||
assert_equal(['default'], c.sections)
|
||||
ensure
|
||||
file.unlink if file
|
||||
}
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
|
@ -137,13 +136,12 @@ __EOC__
|
|||
end
|
||||
|
||||
def test_initialize_with_empty_file
|
||||
file = Tempfile.open("openssl.cnf")
|
||||
Tempfile.create("openssl.cnf") {|file|
|
||||
file.close
|
||||
c = OpenSSL::Config.new(file.path)
|
||||
assert_equal("[ default ]\n\n", c.to_s)
|
||||
assert_equal(['default'], c.sections)
|
||||
ensure
|
||||
file.unlink if file
|
||||
}
|
||||
end
|
||||
|
||||
def test_initialize_with_example_file
|
||||
|
|
|
@ -50,7 +50,7 @@ module Psych
|
|||
end
|
||||
|
||||
def test_io_shiftjis
|
||||
t = Tempfile.new(['shiftjis', 'yml'], :encoding => 'SHIFT_JIS')
|
||||
Tempfile.create(['shiftjis', 'yml'], :encoding => 'SHIFT_JIS') {|t|
|
||||
t.write '--- こんにちは!'
|
||||
t.close
|
||||
|
||||
|
@ -61,12 +61,11 @@ module Psych
|
|||
Psych.load(f)
|
||||
end
|
||||
end
|
||||
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_io_utf16le
|
||||
t = Tempfile.new(['utf16le', 'yml'])
|
||||
Tempfile.create(['utf16le', 'yml']) {|t|
|
||||
t.binmode
|
||||
t.write '--- こんにちは!'.encode('UTF-16LE')
|
||||
t.close
|
||||
|
@ -74,12 +73,11 @@ module Psych
|
|||
File.open(t.path, 'rb', :encoding => 'UTF-16LE') do |f|
|
||||
assert_equal "こんにちは!", Psych.load(f)
|
||||
end
|
||||
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_io_utf16be
|
||||
t = Tempfile.new(['utf16be', 'yml'])
|
||||
Tempfile.create(['utf16be', 'yml']) {|t|
|
||||
t.binmode
|
||||
t.write '--- こんにちは!'.encode('UTF-16BE')
|
||||
t.close
|
||||
|
@ -87,12 +85,11 @@ module Psych
|
|||
File.open(t.path, 'rb', :encoding => 'UTF-16BE') do |f|
|
||||
assert_equal "こんにちは!", Psych.load(f)
|
||||
end
|
||||
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_io_utf8
|
||||
t = Tempfile.new(['utf8', 'yml'])
|
||||
Tempfile.create(['utf8', 'yml']) {|t|
|
||||
t.binmode
|
||||
t.write '--- こんにちは!'.encode('UTF-8')
|
||||
t.close
|
||||
|
@ -100,8 +97,7 @@ module Psych
|
|||
File.open(t.path, 'rb', :encoding => 'UTF-8') do |f|
|
||||
assert_equal "こんにちは!", Psych.load(f)
|
||||
end
|
||||
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_emit_alias
|
||||
|
|
|
@ -56,7 +56,7 @@ module Psych
|
|||
end
|
||||
|
||||
def test_parse_file_exception
|
||||
t = Tempfile.new(['parsefile', 'yml'])
|
||||
Tempfile.create(['parsefile', 'yml']) {|t|
|
||||
t.binmode
|
||||
t.write '--- `'
|
||||
t.close
|
||||
|
@ -64,11 +64,11 @@ module Psych
|
|||
Psych.parse_file t.path
|
||||
end
|
||||
assert_equal t.path, ex.file
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_load_file_exception
|
||||
t = Tempfile.new(['loadfile', 'yml'])
|
||||
Tempfile.create(['loadfile', 'yml']) {|t|
|
||||
t.binmode
|
||||
t.write '--- `'
|
||||
t.close
|
||||
|
@ -76,7 +76,7 @@ module Psych
|
|||
Psych.load_file t.path
|
||||
end
|
||||
assert_equal t.path, ex.file
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_psych_parse_takes_file
|
||||
|
@ -128,7 +128,7 @@ module Psych
|
|||
end
|
||||
|
||||
def test_psych_syntax_error
|
||||
Tempfile.open(['parsefile', 'yml']) do |t|
|
||||
Tempfile.create(['parsefile', 'yml']) do |t|
|
||||
t.binmode
|
||||
t.write '--- `'
|
||||
t.close
|
||||
|
@ -138,7 +138,6 @@ module Psych
|
|||
rescue StandardError
|
||||
assert true # count assertion
|
||||
ensure
|
||||
t.close(true)
|
||||
return unless $!
|
||||
|
||||
ancestors = $!.class.ancestors.inspect
|
||||
|
|
|
@ -64,11 +64,10 @@ class TestPsych < Psych::TestCase
|
|||
|
||||
def test_dump_file
|
||||
hash = {'hello' => 'TGIF!'}
|
||||
Tempfile.open('fun.yml') do |io|
|
||||
Tempfile.create('fun.yml') do |io|
|
||||
assert_equal io, Psych.dump(hash, io)
|
||||
io.rewind
|
||||
assert_equal Psych.dump(hash), io.read
|
||||
io.close(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -126,21 +125,21 @@ class TestPsych < Psych::TestCase
|
|||
end
|
||||
|
||||
def test_load_file
|
||||
t = Tempfile.new(['yikes', 'yml'])
|
||||
Tempfile.create(['yikes', 'yml']) {|t|
|
||||
t.binmode
|
||||
t.write('--- hello world')
|
||||
t.close
|
||||
assert_equal 'hello world', Psych.load_file(t.path)
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_parse_file
|
||||
t = Tempfile.new(['yikes', 'yml'])
|
||||
Tempfile.create(['yikes', 'yml']) {|t|
|
||||
t.binmode
|
||||
t.write('--- hello world')
|
||||
t.close
|
||||
assert_equal 'hello world', Psych.parse_file(t.path).transform
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_degenerate_strings
|
||||
|
|
|
@ -117,14 +117,14 @@ module Psych
|
|||
|
||||
class TestIOTainted < TestStringTainted
|
||||
def assert_taintedness string
|
||||
t = Tempfile.new(['something', 'yml'])
|
||||
Tempfile.create(['something', 'yml']) {|t|
|
||||
t.binmode
|
||||
t.write string
|
||||
t.close
|
||||
File.open(t.path, 'r:bom|utf-8') { |f|
|
||||
@parser.parse f
|
||||
}
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -72,13 +72,13 @@ class TestReadline < Test::Unit::TestCase
|
|||
with_temp_stdio do |stdin, stdout|
|
||||
stdin.write("hello\n")
|
||||
stdin.close
|
||||
stdout.close
|
||||
stdout.flush
|
||||
line = replace_stdio(stdin.path, stdout.path) {
|
||||
Readline.readline("> ", true)
|
||||
}
|
||||
assert_equal("hello", line)
|
||||
assert_equal(true, line.tainted?)
|
||||
stdout.open
|
||||
stdout.rewind
|
||||
assert_equal("> ", stdout.read(2))
|
||||
assert_equal(1, Readline::HISTORY.length)
|
||||
assert_equal("hello", Readline::HISTORY[0])
|
||||
|
@ -118,8 +118,8 @@ class TestReadline < Test::Unit::TestCase
|
|||
actual_point = Readline.point
|
||||
actual_line_buffer = Readline.line_buffer
|
||||
stdin.write(" finish\n")
|
||||
stdin.close
|
||||
stdout.close
|
||||
stdin.flush
|
||||
stdout.flush
|
||||
return ["complete"]
|
||||
}
|
||||
|
||||
|
@ -137,8 +137,8 @@ class TestReadline < Test::Unit::TestCase
|
|||
assert_equal(true, Readline.line_buffer.tainted?)
|
||||
assert_equal(22, Readline.point)
|
||||
|
||||
stdin.open
|
||||
stdout.open
|
||||
stdin.rewind
|
||||
stdout.rewind
|
||||
|
||||
stdin.write("first second\t")
|
||||
stdin.flush
|
||||
|
@ -377,9 +377,8 @@ class TestReadline < Test::Unit::TestCase
|
|||
end if !/EditLine/n.match(Readline::VERSION)
|
||||
|
||||
def test_modify_text_in_pre_input_hook
|
||||
with_temp_stdio {|stdin, stdout|
|
||||
begin
|
||||
stdin = Tempfile.new("readline_redisplay_stdin")
|
||||
stdout = Tempfile.new("readline_redisplay_stdout")
|
||||
stdin.write("world\n")
|
||||
stdin.close
|
||||
Readline.pre_input_hook = proc do
|
||||
|
@ -399,9 +398,8 @@ class TestReadline < Test::Unit::TestCase
|
|||
Readline.pre_input_hook = nil
|
||||
rescue NotImplementedError
|
||||
end
|
||||
stdin.close(true)
|
||||
stdout.close(true)
|
||||
end
|
||||
}
|
||||
end if !/EditLine|\A4\.3\z/n.match(Readline::VERSION)
|
||||
|
||||
def test_input_metachar
|
||||
|
@ -472,12 +470,11 @@ class TestReadline < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def with_temp_stdio
|
||||
stdin = Tempfile.new("test_readline_stdin")
|
||||
stdout = Tempfile.new("test_readline_stdout")
|
||||
Tempfile.create("test_readline_stdin") {|stdin|
|
||||
Tempfile.create("test_readline_stdout") {|stdout|
|
||||
yield stdin, stdout
|
||||
ensure
|
||||
stdin.close(true) if stdin
|
||||
stdout.close(true) if stdout
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def with_pipe
|
||||
|
|
|
@ -511,7 +511,7 @@ EOL
|
|||
|
||||
def test_pos
|
||||
require 'tempfile'
|
||||
testfile = Tempfile.new("tidal")
|
||||
Tempfile.create("tidal") {|testfile|
|
||||
testdata = %Q{<calibration>
|
||||
<section name="parameters">
|
||||
<param name="barpress">760</param>
|
||||
|
@ -525,7 +525,7 @@ EOL
|
|||
assert_nothing_raised do
|
||||
REXML::Document.new(testfile)
|
||||
end
|
||||
testfile.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_deep_clone
|
||||
|
|
|
@ -57,7 +57,7 @@ p Foo::Bar
|
|||
end
|
||||
|
||||
def test_require_explicit
|
||||
file = Tempfile.open(['autoload', '.rb'])
|
||||
Tempfile.create(['autoload', '.rb']) {|file|
|
||||
file.puts 'class Object; AutoloadTest = 1; end'
|
||||
file.close
|
||||
add_autoload(file.path)
|
||||
|
@ -69,12 +69,11 @@ p Foo::Bar
|
|||
ensure
|
||||
remove_autoload_constant
|
||||
end
|
||||
ensure
|
||||
file.unlink
|
||||
}
|
||||
end
|
||||
|
||||
def test_threaded_accessing_constant
|
||||
file = Tempfile.open(['autoload', '.rb'])
|
||||
Tempfile.create(['autoload', '.rb']) {|file|
|
||||
file.puts 'sleep 0.5; class AutoloadTest; X = 1; end'
|
||||
file.close
|
||||
add_autoload(file.path)
|
||||
|
@ -87,12 +86,11 @@ p Foo::Bar
|
|||
ensure
|
||||
remove_autoload_constant
|
||||
end
|
||||
ensure
|
||||
file.unlink
|
||||
}
|
||||
end
|
||||
|
||||
def test_threaded_accessing_inner_constant
|
||||
file = Tempfile.open(['autoload', '.rb'])
|
||||
Tempfile.create(['autoload', '.rb']) {|file|
|
||||
file.puts 'class AutoloadTest; sleep 0.5; X = 1; end'
|
||||
file.close
|
||||
add_autoload(file.path)
|
||||
|
@ -105,12 +103,11 @@ p Foo::Bar
|
|||
ensure
|
||||
remove_autoload_constant
|
||||
end
|
||||
ensure
|
||||
file.unlink
|
||||
}
|
||||
end
|
||||
|
||||
def test_nameerror_when_autoload_did_not_define_the_constant
|
||||
file = Tempfile.open(['autoload', '.rb'])
|
||||
Tempfile.create(['autoload', '.rb']) {|file|
|
||||
file.puts ''
|
||||
file.close
|
||||
add_autoload(file.path)
|
||||
|
@ -121,12 +118,11 @@ p Foo::Bar
|
|||
ensure
|
||||
remove_autoload_constant
|
||||
end
|
||||
ensure
|
||||
file.unlink
|
||||
}
|
||||
end
|
||||
|
||||
def test_override_autoload
|
||||
file = Tempfile.open(['autoload', '.rb'])
|
||||
Tempfile.create(['autoload', '.rb']) {|file|
|
||||
file.puts ''
|
||||
file.close
|
||||
add_autoload(file.path)
|
||||
|
@ -136,12 +132,11 @@ p Foo::Bar
|
|||
ensure
|
||||
remove_autoload_constant
|
||||
end
|
||||
ensure
|
||||
file.unlink
|
||||
}
|
||||
end
|
||||
|
||||
def test_override_while_autoloading
|
||||
file = Tempfile.open(['autoload', '.rb'])
|
||||
Tempfile.create(['autoload', '.rb']) {|file|
|
||||
file.puts 'class AutoloadTest; sleep 0.5; end'
|
||||
file.close
|
||||
add_autoload(file.path)
|
||||
|
@ -158,8 +153,7 @@ p Foo::Bar
|
|||
ensure
|
||||
remove_autoload_constant
|
||||
end
|
||||
ensure
|
||||
file.unlink
|
||||
}
|
||||
end
|
||||
|
||||
def add_autoload(path)
|
||||
|
|
|
@ -16,22 +16,19 @@ class TestBeginEndBlock < Test::Unit::TestCase
|
|||
result = IO.popen([ruby, target]){|io|io.read}
|
||||
assert_equal(%w(b1 b2-1 b2 main b3-1 b3 b4 e1 e1-1 e4 e4-2 e4-1 e4-1-1 e3 e2), result.split)
|
||||
|
||||
input = Tempfile.new(self.class.name)
|
||||
Tempfile.create(self.class.name) {|input|
|
||||
inputpath = input.path
|
||||
input.close
|
||||
result = IO.popen([ruby, "-n", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read}
|
||||
assert_equal(%w(:begin), result.split)
|
||||
result = IO.popen([ruby, "-p", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read}
|
||||
assert_equal(%w(:begin), result.split)
|
||||
input.open
|
||||
input.puts "foo\nbar"
|
||||
input.close
|
||||
result = IO.popen([ruby, "-n", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read}
|
||||
assert_equal(%w(:begin :end), result.split)
|
||||
result = IO.popen([ruby, "-p", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read}
|
||||
assert_equal(%w(:begin foo bar :end), result.split)
|
||||
ensure
|
||||
input.unlink
|
||||
}
|
||||
end
|
||||
|
||||
def test_begininmethod
|
||||
|
@ -56,8 +53,8 @@ class TestBeginEndBlock < Test::Unit::TestCase
|
|||
def test_endblockwarn
|
||||
ruby = EnvUtil.rubybin
|
||||
# Use Tempfile to create temporary file path.
|
||||
launcher = Tempfile.new(self.class.name)
|
||||
errout = Tempfile.new(self.class.name)
|
||||
Tempfile.create(self.class.name) {|launcher|
|
||||
Tempfile.create(self.class.name) {|errout|
|
||||
|
||||
launcher << <<EOF
|
||||
# -*- coding: #{ruby.encoding.name} -*-
|
||||
|
@ -77,10 +74,8 @@ endblockwarn_rb:2: warning: END in method; use at_exit
|
|||
(eval):2: warning: END in method; use at_exit
|
||||
EOW
|
||||
assert_equal(expected, File.read(erroutpath))
|
||||
# expecting Tempfile to unlink launcher and errout file.
|
||||
ensure
|
||||
launcher.unlink
|
||||
errout.unlink
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_raise_in_at_exit
|
||||
|
@ -134,7 +129,7 @@ EOW
|
|||
end
|
||||
|
||||
def test_nested_at_exit
|
||||
t = Tempfile.new(["test_nested_at_exit_", ".rb"])
|
||||
Tempfile.create(["test_nested_at_exit_", ".rb"]) {|t|
|
||||
t.puts "at_exit { puts :outer0 }"
|
||||
t.puts "at_exit { puts :outer1_begin; at_exit { puts :inner1 }; puts :outer1_end }"
|
||||
t.puts "at_exit { puts :outer2_begin; at_exit { puts :inner2 }; puts :outer2_end }"
|
||||
|
@ -151,8 +146,7 @@ EOW
|
|||
"outer0" ]
|
||||
|
||||
assert_in_out_err(t.path, "", expected, [], "[ruby-core:35237]")
|
||||
ensure
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_rescue_at_exit
|
||||
|
|
|
@ -108,12 +108,11 @@ class TestException < Test::Unit::TestCase
|
|||
|
||||
def test_catch_throw_in_require
|
||||
bug7185 = '[ruby-dev:46234]'
|
||||
t = Tempfile.open(["dep", ".rb"])
|
||||
Tempfile.create(["dep", ".rb"]) {|t|
|
||||
t.puts("throw :extdep, 42")
|
||||
t.close
|
||||
assert_equal(42, catch(:extdep) {require t.path}, bug7185)
|
||||
ensure
|
||||
t.close! if t
|
||||
}
|
||||
end
|
||||
|
||||
def test_else_no_exception
|
||||
|
@ -398,9 +397,7 @@ end.join
|
|||
|
||||
def test_exception_in_name_error_to_str
|
||||
bug5575 = '[ruby-core:41612]'
|
||||
t = nil
|
||||
Tempfile.open(["test_exception_in_name_error_to_str", ".rb"]) do |f|
|
||||
t = f
|
||||
Tempfile.create(["test_exception_in_name_error_to_str", ".rb"]) do |t|
|
||||
t.puts <<-EOC
|
||||
begin
|
||||
BasicObject.new.inspect
|
||||
|
@ -408,12 +405,11 @@ end.join
|
|||
$!.inspect
|
||||
end
|
||||
EOC
|
||||
end
|
||||
t.close
|
||||
assert_nothing_raised(NameError, bug5575) do
|
||||
load(t.path)
|
||||
end
|
||||
ensure
|
||||
t.close(true) if t
|
||||
end
|
||||
end
|
||||
|
||||
def test_equal
|
||||
|
@ -424,21 +420,18 @@ end.join
|
|||
|
||||
def test_exception_in_exception_equal
|
||||
bug5865 = '[ruby-core:41979]'
|
||||
t = nil
|
||||
Tempfile.open(["test_exception_in_exception_equal", ".rb"]) do |f|
|
||||
t = f
|
||||
Tempfile.create(["test_exception_in_exception_equal", ".rb"]) do |t|
|
||||
t.puts <<-EOC
|
||||
o = Object.new
|
||||
def o.exception(arg)
|
||||
end
|
||||
_ = RuntimeError.new("a") == o
|
||||
EOC
|
||||
end
|
||||
t.close
|
||||
assert_nothing_raised(ArgumentError, bug5865) do
|
||||
load(t.path)
|
||||
end
|
||||
ensure
|
||||
t.close(true) if t
|
||||
end
|
||||
end
|
||||
|
||||
Bug4438 = '[ruby-core:35364]'
|
||||
|
|
|
@ -29,12 +29,11 @@ class TestFile < Test::Unit::TestCase
|
|||
|
||||
include TestEOF
|
||||
def open_file(content)
|
||||
f = Tempfile.new("test-eof")
|
||||
Tempfile.create("test-eof") {|f|
|
||||
f << content
|
||||
f.rewind
|
||||
yield f
|
||||
ensure
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
alias open_file_rw open_file
|
||||
|
||||
|
@ -42,18 +41,17 @@ class TestFile < Test::Unit::TestCase
|
|||
|
||||
def test_empty_file_bom
|
||||
bug6487 = '[ruby-core:45203]'
|
||||
f = Tempfile.new(__method__.to_s)
|
||||
f.close
|
||||
Tempfile.create(__method__.to_s) {|f|
|
||||
assert_file.exist?(f.path)
|
||||
assert_nothing_raised(bug6487) {File.read(f.path, mode: 'r:utf-8')}
|
||||
assert_nothing_raised(bug6487) {File.read(f.path, mode: 'r:bom|utf-8')}
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def assert_bom(bytes, name)
|
||||
bug6487 = '[ruby-core:45203]'
|
||||
|
||||
f = Tempfile.new(name.to_s)
|
||||
Tempfile.create(name.to_s) {|f|
|
||||
f.sync = true
|
||||
expected = ""
|
||||
result = nil
|
||||
|
@ -68,7 +66,7 @@ class TestFile < Test::Unit::TestCase
|
|||
f.write bytes[-1]
|
||||
assert_nothing_raised(bug6487) {result = File.read(f.path, mode: 'rb:bom|utf-8')}
|
||||
assert_equal '', result, "valid bom"
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_bom_8
|
||||
|
@ -92,113 +90,112 @@ class TestFile < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_truncate_wbuf
|
||||
f = Tempfile.new("test-truncate")
|
||||
Tempfile.create("test-truncate") {|f|
|
||||
f.print "abc"
|
||||
f.truncate(0)
|
||||
f.print "def"
|
||||
f.flush
|
||||
assert_equal("\0\0\0def", File.read(f.path), "[ruby-dev:24191]")
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_truncate_rbuf
|
||||
f = Tempfile.new("test-truncate")
|
||||
Tempfile.create("test-truncate") {|f|
|
||||
f.puts "abc"
|
||||
f.puts "def"
|
||||
f.close
|
||||
f.open
|
||||
f.rewind
|
||||
assert_equal("abc\n", f.gets)
|
||||
f.truncate(3)
|
||||
assert_equal(nil, f.gets, "[ruby-dev:24197]")
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_truncate_beyond_eof
|
||||
f = Tempfile.new("test-truncate")
|
||||
Tempfile.create("test-truncate") {|f|
|
||||
f.print "abc"
|
||||
f.truncate 10
|
||||
assert_equal("\0" * 7, f.read(100), "[ruby-dev:24532]")
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_read_all_extended_file
|
||||
[nil, {:textmode=>true}, {:binmode=>true}].each do |mode|
|
||||
f = Tempfile.new("test-extended-file", mode)
|
||||
Tempfile.create("test-extended-file", mode) {|f|
|
||||
assert_nil(f.getc)
|
||||
f.print "a"
|
||||
f.rewind
|
||||
assert_equal("a", f.read, "mode = <#{mode}>")
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_gets_extended_file
|
||||
[nil, {:textmode=>true}, {:binmode=>true}].each do |mode|
|
||||
f = Tempfile.new("test-extended-file", mode)
|
||||
Tempfile.create("test-extended-file", mode) {|f|
|
||||
assert_nil(f.getc)
|
||||
f.print "a"
|
||||
f.rewind
|
||||
assert_equal("a", f.gets("a"), "mode = <#{mode}>")
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_gets_para_extended_file
|
||||
[nil, {:textmode=>true}, {:binmode=>true}].each do |mode|
|
||||
f = Tempfile.new("test-extended-file", mode)
|
||||
Tempfile.create("test-extended-file", mode) {|f|
|
||||
assert_nil(f.getc)
|
||||
f.print "\na"
|
||||
f.rewind
|
||||
assert_equal("a", f.gets(""), "mode = <#{mode}>")
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_each_char_extended_file
|
||||
[nil, {:textmode=>true}, {:binmode=>true}].each do |mode|
|
||||
f = Tempfile.new("test-extended-file", mode)
|
||||
Tempfile.create("test-extended-file", mode) {|f|
|
||||
assert_nil(f.getc)
|
||||
f.print "a"
|
||||
f.rewind
|
||||
result = []
|
||||
f.each_char {|b| result << b }
|
||||
assert_equal([?a], result, "mode = <#{mode}>")
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_each_byte_extended_file
|
||||
[nil, {:textmode=>true}, {:binmode=>true}].each do |mode|
|
||||
f = Tempfile.new("test-extended-file", mode)
|
||||
Tempfile.create("test-extended-file", mode) {|f|
|
||||
assert_nil(f.getc)
|
||||
f.print "a"
|
||||
f.rewind
|
||||
result = []
|
||||
f.each_byte {|b| result << b.chr }
|
||||
assert_equal([?a], result, "mode = <#{mode}>")
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_getc_extended_file
|
||||
[nil, {:textmode=>true}, {:binmode=>true}].each do |mode|
|
||||
f = Tempfile.new("test-extended-file", mode)
|
||||
Tempfile.create("test-extended-file", mode) {|f|
|
||||
assert_nil(f.getc)
|
||||
f.print "a"
|
||||
f.rewind
|
||||
assert_equal(?a, f.getc, "mode = <#{mode}>")
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_getbyte_extended_file
|
||||
[nil, {:textmode=>true}, {:binmode=>true}].each do |mode|
|
||||
f = Tempfile.new("test-extended-file", mode)
|
||||
Tempfile.create("test-extended-file", mode) {|f|
|
||||
assert_nil(f.getc)
|
||||
f.print "a"
|
||||
f.rewind
|
||||
assert_equal(?a, f.getbyte.chr, "mode = <#{mode}>")
|
||||
f.close(true)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -258,11 +255,10 @@ class TestFile < Test::Unit::TestCase
|
|||
require "tempfile"
|
||||
t = Time.at(-1)
|
||||
begin
|
||||
f = Tempfile.new('test_utime_with_minus_time_segv')
|
||||
Tempfile.create('test_utime_with_minus_time_segv') {|f|
|
||||
File.utime(t, t, f)
|
||||
}
|
||||
rescue
|
||||
ensure
|
||||
f.close(true)
|
||||
end
|
||||
puts '#{bug5596}'
|
||||
EOS
|
||||
|
|
|
@ -2204,7 +2204,7 @@ End
|
|||
return if /x86_64-linux/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform
|
||||
|
||||
pad=0
|
||||
Tempfile.open(self.class.name) do |f|
|
||||
Tempfile.create(self.class.name) do |f|
|
||||
r, w = IO.pipe
|
||||
pid = fork do
|
||||
r.close
|
||||
|
@ -2230,7 +2230,6 @@ End
|
|||
|
||||
Process.kill :TERM, pid
|
||||
Process.waitpid2(pid)
|
||||
f.close(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2240,7 +2239,7 @@ End
|
|||
start = 12
|
||||
len = 34
|
||||
sysid = 0
|
||||
Tempfile.open(self.class.name) do |f|
|
||||
Tempfile.create(self.class.name) do |f|
|
||||
r, w = IO.pipe
|
||||
pid = fork do
|
||||
r.close
|
||||
|
@ -2270,14 +2269,13 @@ End
|
|||
end
|
||||
|
||||
def test_fcntl_dupfd
|
||||
Tempfile.open(self.class.name) do |f|
|
||||
Tempfile.create(self.class.name) do |f|
|
||||
fd = f.fcntl(Fcntl::F_DUPFD, 63)
|
||||
begin
|
||||
assert_operator(fd, :>=, 63)
|
||||
ensure
|
||||
IO.for_fd(fd).close
|
||||
end
|
||||
f.unlink
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2396,7 +2394,8 @@ End
|
|||
end
|
||||
|
||||
def test_race_between_read
|
||||
file = Tempfile.new("test")
|
||||
Tempfile.create("test") {|file|
|
||||
begin
|
||||
path = file.path
|
||||
file.close
|
||||
write_file = File.open(path, "wt")
|
||||
|
@ -2412,7 +2411,8 @@ End
|
|||
ensure
|
||||
read_file.close
|
||||
write_file.close
|
||||
file.close!
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_warn
|
||||
|
|
|
@ -333,11 +333,10 @@ class TestMarshal < Test::Unit::TestCase
|
|||
assert_equal(c, Marshal.load(Marshal.dump(c)), bug2109)
|
||||
|
||||
assert_nothing_raised(ArgumentError, '[ruby-dev:40386]') do
|
||||
re = Tempfile.open("marshal_regexp") do |f|
|
||||
re = Tempfile.create("marshal_regexp") do |f|
|
||||
f.binmode.write("\x04\bI/\x00\x00\x06:\rencoding\"\rUS-ASCII")
|
||||
f.close
|
||||
re2 = Marshal.load(f.open.binmode)
|
||||
f.close(true)
|
||||
f.rewind
|
||||
re2 = Marshal.load(f)
|
||||
re2
|
||||
end
|
||||
assert_equal(//, re)
|
||||
|
|
|
@ -808,14 +808,13 @@ class TestProcess < Test::Unit::TestCase
|
|||
|
||||
def test_execopts_redirect_tempfile
|
||||
bug6269 = '[ruby-core:44181]'
|
||||
Tempfile.open("execopts") do |tmp|
|
||||
Tempfile.create("execopts") do |tmp|
|
||||
pid = assert_nothing_raised(ArgumentError, bug6269) do
|
||||
break spawn(RUBY, "-e", "print $$", out: tmp)
|
||||
end
|
||||
Process.wait(pid)
|
||||
tmp.rewind
|
||||
assert_equal(pid.to_s, tmp.read)
|
||||
tmp.close(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class TestRequire < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_require_invalid_shared_object
|
||||
t = Tempfile.new(["test_ruby_test_require", ".so"])
|
||||
Tempfile.create(["test_ruby_test_require", ".so"]) {|t|
|
||||
t.puts "dummy"
|
||||
t.close
|
||||
|
||||
|
@ -26,7 +26,7 @@ class TestRequire < Test::Unit::TestCase
|
|||
p :ok
|
||||
end
|
||||
INPUT
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_require_too_long_filename
|
||||
|
@ -111,7 +111,7 @@ class TestRequire < Test::Unit::TestCase
|
|||
def test_require_path_home_3
|
||||
env_rubypath, env_home = ENV["RUBYPATH"], ENV["HOME"]
|
||||
|
||||
t = Tempfile.new(["test_ruby_test_require", ".rb"])
|
||||
Tempfile.create(["test_ruby_test_require", ".rb"]) {|t|
|
||||
t.puts "p :ok"
|
||||
t.close
|
||||
|
||||
|
@ -121,11 +121,10 @@ class TestRequire < Test::Unit::TestCase
|
|||
|
||||
ENV["HOME"], name = File.split(t.path)
|
||||
assert_in_out_err(["-S", name], "", %w(:ok), [])
|
||||
|
||||
}
|
||||
ensure
|
||||
env_rubypath ? ENV["RUBYPATH"] = env_rubypath : ENV.delete("RUBYPATH")
|
||||
env_home ? ENV["HOME"] = env_home : ENV.delete("HOME")
|
||||
t.close(true)
|
||||
end
|
||||
|
||||
def test_require_with_unc
|
||||
|
@ -269,7 +268,7 @@ class TestRequire < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_load
|
||||
t = Tempfile.new(["test_ruby_test_require", ".rb"])
|
||||
Tempfile.create(["test_ruby_test_require", ".rb"]) {|t|
|
||||
t.puts "module Foo; end"
|
||||
t.puts "at_exit { p :wrap_end }"
|
||||
t.puts "at_exit { raise 'error in at_exit test' }"
|
||||
|
@ -283,11 +282,11 @@ class TestRequire < Test::Unit::TestCase
|
|||
INPUT
|
||||
|
||||
assert_raise(ArgumentError) { at_exit }
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_load2 # [ruby-core:25039]
|
||||
t = Tempfile.new(["test_ruby_test_require", ".rb"])
|
||||
Tempfile.create(["test_ruby_test_require", ".rb"]) {|t|
|
||||
t.puts "Hello = 'hello'"
|
||||
t.puts "class Foo"
|
||||
t.puts " p Hello"
|
||||
|
@ -297,11 +296,11 @@ class TestRequire < Test::Unit::TestCase
|
|||
assert_in_out_err([], <<-INPUT, %w("hello"), [])
|
||||
load(#{ t.path.dump }, true)
|
||||
INPUT
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_tainted_loadpath
|
||||
t = Tempfile.new(["test_ruby_test_require", ".rb"])
|
||||
Tempfile.create(["test_ruby_test_require", ".rb"]) {|t|
|
||||
abs_dir, file = File.split(t.path)
|
||||
abs_dir = File.expand_path(abs_dir).untaint
|
||||
|
||||
|
@ -347,8 +346,7 @@ class TestRequire < Test::Unit::TestCase
|
|||
require "#{ file }"
|
||||
p :ok
|
||||
INPUT
|
||||
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_relative
|
||||
|
@ -402,7 +400,8 @@ class TestRequire < Test::Unit::TestCase
|
|||
|
||||
def test_race_exception
|
||||
bug5754 = '[ruby-core:41618]'
|
||||
tmp = Tempfile.new(%w"bug5754 .rb")
|
||||
path = nil
|
||||
Tempfile.create(%w"bug5754 .rb") {|tmp|
|
||||
path = tmp.path
|
||||
tmp.print %{\
|
||||
th = Thread.current
|
||||
|
@ -458,9 +457,9 @@ class TestRequire < Test::Unit::TestCase
|
|||
assert_equal(true, (t1_res ^ t2_res), bug5754 + " t1:#{t1_res} t2:#{t2_res}")
|
||||
assert_equal([:pre, :post], scratch, bug5754)
|
||||
end;
|
||||
}
|
||||
ensure
|
||||
$".delete(path)
|
||||
tmp.close(true) if tmp
|
||||
end
|
||||
|
||||
def test_loaded_features_encoding
|
||||
|
@ -642,7 +641,7 @@ class TestRequire < Test::Unit::TestCase
|
|||
|
||||
def test_require_with_loaded_features_pop
|
||||
bug7530 = '[ruby-core:50645]'
|
||||
script = Tempfile.new(%w'bug-7530- .rb')
|
||||
Tempfile.create(%w'bug-7530- .rb') {|script|
|
||||
script.close
|
||||
assert_in_out_err([{"RUBYOPT" => nil}, "-", script.path], <<-INPUT, %w(:ok), [], bug7530)
|
||||
PATH = ARGV.shift
|
||||
|
@ -659,7 +658,6 @@ class TestRequire < Test::Unit::TestCase
|
|||
}.each(&:join)
|
||||
p :ok
|
||||
INPUT
|
||||
ensure
|
||||
script.close(true) if script
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -271,7 +271,7 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
rubypath_orig = ENV['RUBYPATH']
|
||||
path_orig = ENV['PATH']
|
||||
|
||||
t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"])
|
||||
Tempfile.create(["test_ruby_test_rubyoption", ".rb"]) {|t|
|
||||
t.puts "p 1"
|
||||
t.close
|
||||
|
||||
|
@ -285,6 +285,7 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
ENV['RUBYPATH'] = File.dirname(t.path)
|
||||
|
||||
assert_in_out_err(%w(-S) + [File.basename(t.path)], "", %w(1), [])
|
||||
}
|
||||
|
||||
ensure
|
||||
if rubypath_orig
|
||||
|
@ -297,7 +298,6 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
else
|
||||
ENV.delete('PATH')
|
||||
end
|
||||
t.close(true) if t
|
||||
$VERBOSE = @verbose
|
||||
end
|
||||
|
||||
|
@ -333,7 +333,7 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_assignment_in_conditional
|
||||
t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"])
|
||||
Tempfile.create(["test_ruby_test_rubyoption", ".rb"]) {|t|
|
||||
t.puts "if a = 1"
|
||||
t.puts "end"
|
||||
t.puts "0.times do"
|
||||
|
@ -341,7 +341,7 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
t.puts " a += b"
|
||||
t.puts " end"
|
||||
t.puts "end"
|
||||
t.close
|
||||
t.flush
|
||||
warning = ' warning: found = in conditional, should be =='
|
||||
err = ["#{t.path}:1:#{warning}",
|
||||
"#{t.path}:4:#{warning}",
|
||||
|
@ -350,7 +350,7 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
assert_in_out_err(["-w", t.path], "", [], err, bug2136)
|
||||
assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err, bug2136)
|
||||
|
||||
t.open
|
||||
t.rewind
|
||||
t.truncate(0)
|
||||
t.puts "if a = ''; end"
|
||||
t.puts "if a = []; end"
|
||||
|
@ -359,7 +359,7 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
t.puts "if a = {}; end"
|
||||
t.puts "if a = {1=>2}; end"
|
||||
t.puts "if a = {3=>a}; end"
|
||||
t.close
|
||||
t.flush
|
||||
err = ["#{t.path}:1:#{warning}",
|
||||
"#{t.path}:2:#{warning}",
|
||||
"#{t.path}:3:#{warning}",
|
||||
|
@ -369,45 +369,43 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
feature4299 = '[ruby-dev:43083]'
|
||||
assert_in_out_err(["-w", t.path], "", [], err, feature4299)
|
||||
assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err, feature4299)
|
||||
ensure
|
||||
t.close(true) if t
|
||||
}
|
||||
end
|
||||
|
||||
def test_indentation_check
|
||||
t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"])
|
||||
Tempfile.create(["test_ruby_test_rubyoption", ".rb"]) {|t|
|
||||
t.puts "begin"
|
||||
t.puts " end"
|
||||
t.close
|
||||
t.flush
|
||||
err = ["#{t.path}:2: warning: mismatched indentations at 'end' with 'begin' at 1"]
|
||||
assert_in_out_err(["-w", t.path], "", [], err)
|
||||
assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err)
|
||||
|
||||
t.open
|
||||
t.rewind
|
||||
t.puts "# -*- warn-indent: false -*-"
|
||||
t.puts "begin"
|
||||
t.puts " end"
|
||||
t.close
|
||||
t.flush
|
||||
assert_in_out_err(["-w", t.path], "", [], [], '[ruby-core:25442]')
|
||||
|
||||
err = ["#{t.path}:4: warning: mismatched indentations at 'end' with 'begin' at 3"]
|
||||
t.open
|
||||
t.rewind
|
||||
t.puts "# -*- warn-indent: false -*-"
|
||||
t.puts "# -*- warn-indent: true -*-"
|
||||
t.puts "begin"
|
||||
t.puts " end"
|
||||
t.close
|
||||
t.flush
|
||||
assert_in_out_err(["-w", t.path], "", [], err, '[ruby-core:25442]')
|
||||
|
||||
err = ["#{t.path}:4: warning: mismatched indentations at 'end' with 'begin' at 2"]
|
||||
t.open
|
||||
t.rewind
|
||||
t.puts "# -*- warn-indent: true -*-"
|
||||
t.puts "begin"
|
||||
t.puts "# -*- warn-indent: false -*-"
|
||||
t.puts " end"
|
||||
t.close
|
||||
t.flush
|
||||
assert_in_out_err(["-w", t.path], "", [], [], '[ruby-core:25442]')
|
||||
ensure
|
||||
t.close(true) if t
|
||||
}
|
||||
end
|
||||
|
||||
def test_notfound
|
||||
|
@ -523,25 +521,24 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
assert_not_predicate(status, :success?, "segv but success #{bug7402}")
|
||||
|
||||
bug7597 = '[ruby-dev:46786]'
|
||||
t = Tempfile.new(["test_ruby_test_bug7597", ".rb"])
|
||||
Tempfile.create(["test_ruby_test_bug7597", ".rb"]) {|t|
|
||||
t.write "f" * 100
|
||||
t.flush
|
||||
assert_in_out_err(["-e", "$0=ARGV[0]; Process.kill :SEGV, $$", t.path],
|
||||
"", [], expected_stderr, bug7597, opts)
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_DATA
|
||||
t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"])
|
||||
Tempfile.create(["test_ruby_test_rubyoption", ".rb"]) {|t|
|
||||
t.puts "puts DATA.read.inspect"
|
||||
t.puts "__END__"
|
||||
t.puts "foo"
|
||||
t.puts "bar"
|
||||
t.puts "baz"
|
||||
t.close
|
||||
t.flush
|
||||
assert_in_out_err([t.path], "", %w("foo\\nbar\\nbaz\\n"), [])
|
||||
ensure
|
||||
t.close(true) if t
|
||||
}
|
||||
end
|
||||
|
||||
def test_unused_variable
|
||||
|
|
|
@ -80,13 +80,12 @@ class TestSyslogRootLogger < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def log_raw(msg_id, *arg, &block)
|
||||
logdev = Tempfile.new(File.basename(__FILE__) + '.log')
|
||||
Tempfile.create(File.basename(__FILE__) + '.log') {|logdev|
|
||||
@logger.instance_eval { @logdev = Logger::LogDevice.new(logdev) }
|
||||
assert_equal true, @logger.__send__(msg_id, *arg, &block)
|
||||
logdev.open
|
||||
msg = logdev.read
|
||||
logdev.close(true)
|
||||
msg
|
||||
logdev.rewind
|
||||
logdev.read
|
||||
}
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
|
|
|
@ -31,7 +31,7 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
|
|||
realm = "WEBrick's realm"
|
||||
path = "/basic_auth2"
|
||||
|
||||
tmpfile = Tempfile.new("test_webrick_auth")
|
||||
Tempfile.create("test_webrick_auth") {|tmpfile|
|
||||
tmpfile.close
|
||||
tmp_pass = WEBrick::HTTPAuth::Htpasswd.new(tmpfile.path)
|
||||
tmp_pass.set_passwd(realm, "webrick", "supersecretpassword")
|
||||
|
@ -59,26 +59,26 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
|
|||
http.request(g){|res| assert_equal("hoge", res.body, log.call)}
|
||||
g.basic_auth("webrick", "not super")
|
||||
http.request(g){|res| assert_not_equal("hoge", res.body, log.call)}
|
||||
tmpfile.close(true)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_basic_auth3
|
||||
tmpfile = Tempfile.new("test_webrick_auth")
|
||||
Tempfile.create("test_webrick_auth") {|tmpfile|
|
||||
tmpfile.puts("webrick:{SHA}GJYFRpBbdchp595jlh3Bhfmgp8k=")
|
||||
tmpfile.flush
|
||||
assert_raise(NotImplementedError){
|
||||
WEBrick::HTTPAuth::Htpasswd.new(tmpfile.path)
|
||||
}
|
||||
tmpfile.close(true)
|
||||
}
|
||||
|
||||
tmpfile = Tempfile.new("test_webrick_auth")
|
||||
Tempfile.create("test_webrick_auth") {|tmpfile|
|
||||
tmpfile.puts("webrick:$apr1$IOVMD/..$rmnOSPXr0.wwrLPZHBQZy0")
|
||||
tmpfile.flush
|
||||
assert_raise(NotImplementedError){
|
||||
WEBrick::HTTPAuth::Htpasswd.new(tmpfile.path)
|
||||
}
|
||||
tmpfile.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
DIGESTRES_ = /
|
||||
|
@ -96,7 +96,7 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
|
|||
realm = "WEBrick's realm"
|
||||
path = "/digest_auth"
|
||||
|
||||
tmpfile = Tempfile.new("test_webrick_auth")
|
||||
Tempfile.create("test_webrick_auth") {|tmpfile|
|
||||
tmpfile.close
|
||||
tmp_pass = WEBrick::HTTPAuth::Htdigest.new(tmpfile.path)
|
||||
tmp_pass.set_passwd(realm, "webrick", "supersecretpassword")
|
||||
|
@ -141,7 +141,7 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
|
|||
g['Authorization'] = credentials_for_request('webrick', "not super", params)
|
||||
http.request(g){|res| assert_not_equal("hoge", res.body, log.call)}
|
||||
end
|
||||
tmpfile.close(true)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -432,18 +432,18 @@ if defined? Zlib
|
|||
|
||||
class TestZlibGzipFile < Test::Unit::TestCase
|
||||
def test_to_io
|
||||
t = Tempfile.new("test_zlib_gzip_file_to_io")
|
||||
Tempfile.create("test_zlib_gzip_file_to_io") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
||||
|
||||
Zlib::GzipReader.open(t.path) do |f|
|
||||
assert_kind_of(IO, f.to_io)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_crc
|
||||
t = Tempfile.new("test_zlib_gzip_file_crc")
|
||||
Tempfile.create("test_zlib_gzip_file_crc") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
||||
|
||||
|
@ -451,13 +451,13 @@ if defined? Zlib
|
|||
f.read
|
||||
assert_equal(0x8c736521, f.crc)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_mtime
|
||||
tim = Time.now
|
||||
|
||||
t = Tempfile.new("test_zlib_gzip_file_mtime")
|
||||
Tempfile.create("test_zlib_gzip_file_mtime") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) do |gz|
|
||||
gz.mtime = -1
|
||||
|
@ -470,33 +470,32 @@ if defined? Zlib
|
|||
Zlib::GzipReader.open(t.path) do |f|
|
||||
assert_equal(tim.to_i, f.mtime.to_i)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_level
|
||||
t = Tempfile.new("test_zlib_gzip_file_level")
|
||||
Tempfile.create("test_zlib_gzip_file_level") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
||||
|
||||
Zlib::GzipReader.open(t.path) do |f|
|
||||
assert_equal(Zlib::DEFAULT_COMPRESSION, f.level)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_os_code
|
||||
t = Tempfile.new("test_zlib_gzip_file_os_code")
|
||||
t.close
|
||||
Tempfile.create("test_zlib_gzip_file_os_code") {|t|
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
||||
|
||||
Zlib::GzipReader.open(t.path) do |f|
|
||||
assert_equal(Zlib::OS_CODE, f.os_code)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_orig_name
|
||||
t = Tempfile.new("test_zlib_gzip_file_orig_name")
|
||||
Tempfile.create("test_zlib_gzip_file_orig_name") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) do |gz|
|
||||
gz.orig_name = "foobarbazqux\0quux"
|
||||
|
@ -508,11 +507,11 @@ if defined? Zlib
|
|||
Zlib::GzipReader.open(t.path) do |f|
|
||||
assert_equal("foobarbazqux", f.orig_name)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_comment
|
||||
t = Tempfile.new("test_zlib_gzip_file_comment")
|
||||
Tempfile.create("test_zlib_gzip_file_comment") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) do |gz|
|
||||
gz.comment = "foobarbazqux\0quux"
|
||||
|
@ -524,11 +523,11 @@ if defined? Zlib
|
|||
Zlib::GzipReader.open(t.path) do |f|
|
||||
assert_equal("foobarbazqux", f.comment)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_lineno
|
||||
t = Tempfile.new("test_zlib_gzip_file_lineno")
|
||||
Tempfile.create("test_zlib_gzip_file_lineno") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\nqux\n") }
|
||||
|
||||
|
@ -539,11 +538,11 @@ if defined? Zlib
|
|||
assert_equal([1000, "baz\n"], [f.lineno, f.gets])
|
||||
assert_equal([1001, "qux\n"], [f.lineno, f.gets])
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_closed_p
|
||||
t = Tempfile.new("test_zlib_gzip_file_closed_p")
|
||||
Tempfile.create("test_zlib_gzip_file_closed_p") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
||||
|
||||
|
@ -554,11 +553,11 @@ if defined? Zlib
|
|||
f.close
|
||||
assert_equal(true, f.closed?)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_sync
|
||||
t = Tempfile.new("test_zlib_gzip_file_sync")
|
||||
Tempfile.create("test_zlib_gzip_file_sync") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
||||
|
||||
|
@ -569,22 +568,22 @@ if defined? Zlib
|
|||
f.sync = false
|
||||
assert_equal(false, f.sync)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_pos
|
||||
t = Tempfile.new("test_zlib_gzip_file_pos")
|
||||
Tempfile.create("test_zlib_gzip_file_pos") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) do |gz|
|
||||
gz.print("foo")
|
||||
gz.flush
|
||||
assert_equal(3, gz.tell)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_path
|
||||
t = Tempfile.new("test_zlib_gzip_file_path")
|
||||
Tempfile.create("test_zlib_gzip_file_path") {|t|
|
||||
t.close
|
||||
|
||||
gz = Zlib::GzipWriter.open(t.path)
|
||||
|
@ -610,7 +609,7 @@ if defined? Zlib
|
|||
Zlib::GzipReader.new(sio) do |f|
|
||||
assert_raise(NoMethodError) { f.path }
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -650,7 +649,7 @@ if defined? Zlib
|
|||
end
|
||||
|
||||
def test_open
|
||||
t = Tempfile.new("test_zlib_gzip_reader_open")
|
||||
Tempfile.create("test_zlib_gzip_reader_open") {|t|
|
||||
t.close
|
||||
e = assert_raise(Zlib::GzipFile::Error) {
|
||||
Zlib::GzipReader.open(t.path)
|
||||
|
@ -682,11 +681,11 @@ if defined? Zlib
|
|||
ensure
|
||||
f.close
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_rewind
|
||||
t = Tempfile.new("test_zlib_gzip_reader_rewind")
|
||||
Tempfile.create("test_zlib_gzip_reader_rewind") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
||||
|
||||
|
@ -695,11 +694,11 @@ if defined? Zlib
|
|||
f.rewind
|
||||
assert_equal("foo", f.read)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_unused
|
||||
t = Tempfile.new("test_zlib_gzip_reader_unused")
|
||||
Tempfile.create("test_zlib_gzip_reader_unused") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
||||
|
||||
|
@ -710,7 +709,7 @@ if defined? Zlib
|
|||
assert_equal("bar", f.read)
|
||||
assert_equal(nil, f.unused)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_unused2
|
||||
|
@ -741,7 +740,7 @@ if defined? Zlib
|
|||
end
|
||||
|
||||
def test_read
|
||||
t = Tempfile.new("test_zlib_gzip_reader_read")
|
||||
Tempfile.create("test_zlib_gzip_reader_read") {|t|
|
||||
t.close
|
||||
str = "\u3042\u3044\u3046"
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print(str) }
|
||||
|
@ -750,11 +749,11 @@ if defined? Zlib
|
|||
assert_raise(ArgumentError) { f.read(-1) }
|
||||
assert_equal(str, f.read)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_readpartial
|
||||
t = Tempfile.new("test_zlib_gzip_reader_readpartial")
|
||||
Tempfile.create("test_zlib_gzip_reader_readpartial") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
||||
|
||||
|
@ -769,11 +768,11 @@ if defined? Zlib
|
|||
|
||||
assert_raise(ArgumentError) { f.readpartial(-1) }
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_getc
|
||||
t = Tempfile.new("test_zlib_gzip_reader_getc")
|
||||
Tempfile.create("test_zlib_gzip_reader_getc") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
||||
|
||||
|
@ -781,11 +780,11 @@ if defined? Zlib
|
|||
"foobar".each_char {|c| assert_equal(c, f.getc) }
|
||||
assert_nil(f.getc)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_getbyte
|
||||
t = Tempfile.new("test_zlib_gzip_reader_getbyte")
|
||||
Tempfile.create("test_zlib_gzip_reader_getbyte") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
||||
|
||||
|
@ -793,11 +792,11 @@ if defined? Zlib
|
|||
"foobar".each_byte {|c| assert_equal(c, f.getbyte) }
|
||||
assert_nil(f.getbyte)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_readchar
|
||||
t = Tempfile.new("test_zlib_gzip_reader_readchar")
|
||||
Tempfile.create("test_zlib_gzip_reader_readchar") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
||||
|
||||
|
@ -805,11 +804,11 @@ if defined? Zlib
|
|||
"foobar".each_byte {|c| assert_equal(c, f.readchar.ord) }
|
||||
assert_raise(EOFError) { f.readchar }
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_each_byte
|
||||
t = Tempfile.new("test_zlib_gzip_reader_each_byte")
|
||||
Tempfile.create("test_zlib_gzip_reader_each_byte") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
||||
|
||||
|
@ -818,11 +817,11 @@ if defined? Zlib
|
|||
f.each_byte {|c| a << c }
|
||||
assert_equal("foobar".each_byte.to_a, a)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_gets
|
||||
t = Tempfile.new("test_zlib_gzip_reader_gets")
|
||||
Tempfile.create("test_zlib_gzip_reader_gets") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
|
||||
|
||||
|
@ -844,11 +843,11 @@ if defined? Zlib
|
|||
assert_equal("az\n", f.gets(nil, 10))
|
||||
assert_nil(f.gets)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_gets2
|
||||
t = Tempfile.new("test_zlib_gzip_reader_gets2")
|
||||
Tempfile.create("test_zlib_gzip_reader_gets2") {|t|
|
||||
t.close
|
||||
ustrs = %W"\u{3042 3044 3046}\n \u{304b 304d 304f}\n \u{3055 3057 3059}\n"
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print(*ustrs) }
|
||||
|
@ -871,11 +870,11 @@ if defined? Zlib
|
|||
assert_equal(ustrs[2][1..-1], f.gets(nil, 20))
|
||||
assert_nil(f.gets)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_readline
|
||||
t = Tempfile.new("test_zlib_gzip_reader_readline")
|
||||
Tempfile.create("test_zlib_gzip_reader_readline") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
|
||||
|
||||
|
@ -885,11 +884,11 @@ if defined? Zlib
|
|||
assert_equal("baz\n", f.readline)
|
||||
assert_raise(EOFError) { f.readline }
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_each
|
||||
t = Tempfile.new("test_zlib_gzip_reader_each")
|
||||
Tempfile.create("test_zlib_gzip_reader_each") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
|
||||
|
||||
|
@ -897,29 +896,29 @@ if defined? Zlib
|
|||
a = ["foo\n", "bar\n", "baz\n"]
|
||||
f.each {|l| assert_equal(a.shift, l) }
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_readlines
|
||||
t = Tempfile.new("test_zlib_gzip_reader_readlines")
|
||||
Tempfile.create("test_zlib_gzip_reader_readlines") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
|
||||
|
||||
Zlib::GzipReader.open(t.path) do |f|
|
||||
assert_equal(["foo\n", "bar\n", "baz\n"], f.readlines)
|
||||
end
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_reader_wrap
|
||||
t = Tempfile.new("test_zlib_gzip_reader_wrap")
|
||||
Tempfile.create("test_zlib_gzip_reader_wrap") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
||||
f = open(t.path)
|
||||
f.binmode
|
||||
assert_equal("foo", Zlib::GzipReader.wrap(f) {|gz| gz.read })
|
||||
assert_raise(IOError) { f.close }
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_corrupted_header
|
||||
|
@ -937,11 +936,10 @@ if defined? Zlib
|
|||
end
|
||||
|
||||
def test_encoding
|
||||
t = Tempfile.new("test_zlib_gzip_reader_encoding")
|
||||
Tempfile.create("test_zlib_gzip_reader_encoding") {|t|
|
||||
t.binmode
|
||||
content = (0..255).to_a.pack('c*')
|
||||
Zlib::GzipWriter.wrap(t) {|gz| gz.print(content) }
|
||||
t.close
|
||||
|
||||
read_all = Zlib::GzipReader.open(t.path) {|gz| gz.read }
|
||||
assert_equal(Encoding.default_external, read_all.encoding)
|
||||
|
@ -950,7 +948,7 @@ if defined? Zlib
|
|||
read_size = Zlib::GzipReader.open(t.path) {|gz| gz.read(1024) }
|
||||
assert_equal(Encoding::ASCII_8BIT, read_size.encoding)
|
||||
assert_equal(content, read_size)
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -965,7 +963,7 @@ if defined? Zlib
|
|||
def test_open
|
||||
assert_raise(ArgumentError) { Zlib::GzipWriter.open }
|
||||
|
||||
t = Tempfile.new("test_zlib_gzip_writer_open")
|
||||
Tempfile.create("test_zlib_gzip_writer_open") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
||||
assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
||||
|
@ -979,11 +977,11 @@ if defined? Zlib
|
|||
assert_equal("bar", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
||||
|
||||
assert_raise(Zlib::StreamError) { Zlib::GzipWriter.open(t.path, 10000) }
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_write
|
||||
t = Tempfile.new("test_zlib_gzip_writer_write")
|
||||
Tempfile.create("test_zlib_gzip_writer_write") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
||||
assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
||||
|
@ -992,26 +990,25 @@ if defined? Zlib
|
|||
def o.to_s; "bar"; end
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.print(o) }
|
||||
assert_equal("bar", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_putc
|
||||
t = Tempfile.new("test_zlib_gzip_writer_putc")
|
||||
Tempfile.create("test_zlib_gzip_writer_putc") {|t|
|
||||
t.close
|
||||
Zlib::GzipWriter.open(t.path) {|gz| gz.putc(?x) }
|
||||
assert_equal("x", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
||||
|
||||
# todo: multibyte char
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
|
||||
def test_writer_wrap
|
||||
t = Tempfile.new("test_zlib_gzip_writer_wrap")
|
||||
Tempfile.create("test_zlib_gzip_writer_wrap") {|t|
|
||||
t.binmode
|
||||
Zlib::GzipWriter.wrap(t) {|gz| gz.print("foo") }
|
||||
t.close
|
||||
assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
||||
t.close(true)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue