Read/write test files in binay mode (for Windows compatibility)
This commit is contained in:
parent
cf22ff1b92
commit
0051d5bb1f
|
@ -113,21 +113,21 @@ class ZipFileTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_buffer_with_string
|
def test_open_buffer_with_string
|
||||||
string = File.read('test/data/rubycode.zip')
|
string = File.read('test/data/rubycode.zip', mode: 'rb')
|
||||||
::Zip::File.open_buffer string do |zf|
|
::Zip::File.open_buffer string do |zf|
|
||||||
assert zf.entries.map(&:name).include?('zippedruby1.rb')
|
assert zf.entries.map(&:name).include?('zippedruby1.rb')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_buffer_with_stringio
|
def test_open_buffer_with_stringio
|
||||||
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
string_io = StringIO.new File.read('test/data/rubycode.zip', mode: 'rb')
|
||||||
::Zip::File.open_buffer string_io do |zf|
|
::Zip::File.open_buffer string_io do |zf|
|
||||||
assert zf.entries.map(&:name).include?('zippedruby1.rb')
|
assert zf.entries.map(&:name).include?('zippedruby1.rb')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_close_buffer_with_stringio
|
def test_close_buffer_with_stringio
|
||||||
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
string_io = StringIO.new File.read('test/data/rubycode.zip', mode: 'rb')
|
||||||
zf = ::Zip::File.open_buffer string_io
|
zf = ::Zip::File.open_buffer string_io
|
||||||
assert_nil zf.close
|
assert_nil zf.close
|
||||||
end
|
end
|
||||||
|
@ -178,7 +178,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_buffer_without_block
|
def test_open_buffer_without_block
|
||||||
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
string_io = StringIO.new File.read('test/data/rubycode.zip', mode: 'rb')
|
||||||
zf = ::Zip::File.open_buffer string_io
|
zf = ::Zip::File.open_buffer string_io
|
||||||
assert zf.entries.map(&:name).include?('zippedruby1.rb')
|
assert zf.entries.map(&:name).include?('zippedruby1.rb')
|
||||||
end
|
end
|
||||||
|
|
|
@ -79,19 +79,19 @@ class TestZipFile
|
||||||
"zip -q #{TEST_ZIP1.zip_name} -d test/data/file2.txt"
|
"zip -q #{TEST_ZIP1.zip_name} -d test/data/file2.txt"
|
||||||
)
|
)
|
||||||
|
|
||||||
File.open('test/data/generated/empty.txt', 'w') {} # Empty file.
|
File.open('test/data/generated/empty.txt', 'wb') {} # Empty file.
|
||||||
File.open('test/data/generated/empty_chmod640.txt', 'w') {} # Empty file.
|
File.open('test/data/generated/empty_chmod640.txt', 'wb') {} # Empty file.
|
||||||
::File.chmod(0o640, 'test/data/generated/empty_chmod640.txt')
|
::File.chmod(0o640, 'test/data/generated/empty_chmod640.txt')
|
||||||
|
|
||||||
File.open('test/data/generated/short.txt', 'w') { |file| file << 'ABCDEF' }
|
File.open('test/data/generated/short.txt', 'wb') { |file| file << 'ABCDEF' }
|
||||||
test_text = ''
|
test_text = ''
|
||||||
File.open('test/data/file2.txt') { |file| test_text = file.read }
|
File.open('test/data/file2.txt', 'rb') { |file| test_text = file.read }
|
||||||
File.open('test/data/generated/longAscii.txt', 'w') do |file|
|
File.open('test/data/generated/longAscii.txt', 'wb') do |file|
|
||||||
file << test_text while file.tell < 1E5
|
file << test_text while file.tell < 1E5
|
||||||
end
|
end
|
||||||
|
|
||||||
binary_pattern = ''
|
binary_pattern = ''
|
||||||
File.open('test/data/generated/empty.zip') do |file|
|
File.open('test/data/generated/empty.zip', 'rb') do |file|
|
||||||
binary_pattern = file.read
|
binary_pattern = file.read
|
||||||
end
|
end
|
||||||
binary_pattern *= 4
|
binary_pattern *= 4
|
||||||
|
|
|
@ -42,13 +42,13 @@ class ZipInputStreamTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_string_io_without_block
|
def test_open_string_io_without_block
|
||||||
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
|
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name, mode: 'rb'))
|
||||||
zis = ::Zip::InputStream.open(string_io)
|
zis = ::Zip::InputStream.open(string_io)
|
||||||
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_string_io_with_block
|
def test_open_string_io_with_block
|
||||||
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
|
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name, mode: 'rb'))
|
||||||
::Zip::InputStream.open(string_io) do |zis|
|
::Zip::InputStream.open(string_io) do |zis|
|
||||||
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
||||||
assert_equal(true, zis.eof?)
|
assert_equal(true, zis.eof?)
|
||||||
|
@ -106,7 +106,7 @@ class ZipInputStreamTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_incomplete_reads_from_string_io
|
def test_incomplete_reads_from_string_io
|
||||||
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
|
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name, mode: 'rb'))
|
||||||
::Zip::InputStream.open(string_io) do |zis|
|
::Zip::InputStream.open(string_io) do |zis|
|
||||||
entry = zis.get_next_entry # longAscii.txt
|
entry = zis.get_next_entry # longAscii.txt
|
||||||
assert_equal(false, zis.eof?)
|
assert_equal(false, zis.eof?)
|
||||||
|
|
|
@ -85,7 +85,7 @@ class ZipOutputStreamTest < MiniTest::Test
|
||||||
zos << stored_text
|
zos << stored_text
|
||||||
end
|
end
|
||||||
|
|
||||||
assert(File.read(TEST_ZIP.zip_name)[stored_text])
|
assert(File.read(TEST_ZIP.zip_name, mode: 'rb')[stored_text])
|
||||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||||
assert_equal(stored_text, zf.read(entry_name))
|
assert_equal(stored_text, zf.read(entry_name))
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ class PassThruDecompressorTest < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@file = File.new(TEST_FILE)
|
@file = File.new(TEST_FILE, 'rb')
|
||||||
@decompressor = ::Zip::PassThruDecompressor.new(@file, File.size(TEST_FILE))
|
@decompressor = ::Zip::PassThruDecompressor.new(@file, File.size(TEST_FILE))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ module DecompressorTests
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ref_text = ''
|
@ref_text = ''
|
||||||
File.open(TEST_FILE) { |f| @ref_text = f.read }
|
File.open(TEST_FILE, 'rb') { |f| @ref_text = f.read }
|
||||||
@ref_lines = @ref_text.split($INPUT_RECORD_SEPARATOR)
|
@ref_lines = @ref_text.split($INPUT_RECORD_SEPARATOR)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue