fix rubocop Style/Blocks cop
This commit is contained in:
parent
0c6a10e631
commit
d2d8590ef8
|
@ -67,11 +67,6 @@ Style/AccessorMethodName:
|
|||
Style/BarePercentLiterals:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 137
|
||||
# Cop supports --auto-correct.
|
||||
Style/Blocks:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 3
|
||||
Style/CaseEquality:
|
||||
Enabled: false
|
||||
|
|
|
@ -256,25 +256,25 @@ module Zip
|
|||
end
|
||||
|
||||
def chown(ownerInt, groupInt, *filenames)
|
||||
filenames.each { |fileName|
|
||||
filenames.each do |fileName|
|
||||
e = get_entry(fileName)
|
||||
unless e.extra.member?("IUnix")
|
||||
e.extra.create("IUnix")
|
||||
end
|
||||
e.extra["IUnix"].uid = ownerInt
|
||||
e.extra["IUnix"].gid = groupInt
|
||||
}
|
||||
end
|
||||
filenames.size
|
||||
end
|
||||
|
||||
def chmod (modeInt, *filenames)
|
||||
filenames.each { |fileName|
|
||||
filenames.each do |fileName|
|
||||
e = get_entry(fileName)
|
||||
e.fstype = 3 # force convertion filesystem type to unix
|
||||
e.unix_perms = modeInt
|
||||
e.external_file_attributes = modeInt << 16
|
||||
e.dirty = true
|
||||
}
|
||||
end
|
||||
filenames.size
|
||||
end
|
||||
|
||||
|
@ -307,9 +307,9 @@ module Zip
|
|||
end
|
||||
|
||||
def utime(modifiedTime, *fileNames)
|
||||
fileNames.each { |fileName|
|
||||
fileNames.each do |fileName|
|
||||
get_entry(fileName).time = modifiedTime
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def mtime(fileName)
|
||||
|
@ -404,13 +404,12 @@ module Zip
|
|||
end
|
||||
|
||||
def delete(*args)
|
||||
args.each {
|
||||
|fileName|
|
||||
args.each do |fileName|
|
||||
if directory?(fileName)
|
||||
raise Errno::EISDIR, "Is a directory - \"#{fileName}\""
|
||||
end
|
||||
@mappedZip.remove(fileName)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def rename(fileToRename, newName)
|
||||
|
@ -483,11 +482,10 @@ module Zip
|
|||
path << '/' unless path.end_with?('/')
|
||||
path = Regexp.escape(path)
|
||||
subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
|
||||
@mappedZip.each {
|
||||
|fileName|
|
||||
@mappedZip.each do |fileName|
|
||||
match = subDirEntriesRegex.match(fileName)
|
||||
yield(match[1]) unless match == nil
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def delete(entryName)
|
||||
|
@ -595,10 +593,9 @@ module Zip
|
|||
# Turns entries into strings and adds leading /
|
||||
# and removes trailing slash on directories
|
||||
def each
|
||||
@zipFile.each {
|
||||
|e|
|
||||
@zipFile.each do |e|
|
||||
yield("/"+e.to_s.chomp("/"))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def expand_path(aPath)
|
||||
|
|
|
@ -7,34 +7,30 @@ require 'zip'
|
|||
|
||||
####### Using ZipInputStream alone: #######
|
||||
|
||||
Zip::InputStream.open("example.zip") {
|
||||
|zis|
|
||||
Zip::InputStream.open("example.zip") do |zis|
|
||||
entry = zis.get_next_entry
|
||||
print "First line of '#{entry.name} (#{entry.size} bytes): "
|
||||
puts "'#{zis.gets.chomp}'"
|
||||
entry = zis.get_next_entry
|
||||
print "First line of '#{entry.name} (#{entry.size} bytes): "
|
||||
puts "'#{zis.gets.chomp}'"
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
####### Using ZipFile to read the directory of a zip file: #######
|
||||
|
||||
zf = Zip::File.new("example.zip")
|
||||
zf.each_with_index {
|
||||
|entry, index|
|
||||
|
||||
zf.each_with_index do |entry, index|
|
||||
puts "entry #{index} is #{entry.name}, size = #{entry.size}, compressed size = #{entry.compressed_size}"
|
||||
# use zf.get_input_stream(entry) to get a ZipInputStream for the entry
|
||||
# entry can be the ZipEntry object or any object which has a to_s method that
|
||||
# returns the name of the entry.
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
####### Using ZipOutputStream to write a zip file: #######
|
||||
|
||||
Zip::OutputStream.open("exampleout.zip") {
|
||||
|zos|
|
||||
Zip::OutputStream.open("exampleout.zip") do |zos|
|
||||
zos.put_next_entry("the first little entry")
|
||||
zos.puts "Hello hello hello hello hello hello hello hello hello"
|
||||
|
||||
|
@ -43,24 +39,22 @@ Zip::OutputStream.open("exampleout.zip") {
|
|||
|
||||
# Use rubyzip or your zip client of choice to verify
|
||||
# the contents of exampleout.zip
|
||||
}
|
||||
end
|
||||
|
||||
####### Using ZipFile to change a zip file: #######
|
||||
|
||||
Zip::File.open("exampleout.zip") {
|
||||
|zip_file|
|
||||
Zip::File.open("exampleout.zip") do |zip_file|
|
||||
zip_file.add("thisFile.rb", "example.rb")
|
||||
zip_file.rename("thisFile.rb", "ILikeThisName.rb")
|
||||
zip_file.add("Again", "example.rb")
|
||||
}
|
||||
end
|
||||
|
||||
# Lets check
|
||||
Zip::File.open("exampleout.zip") {
|
||||
|zip_file|
|
||||
Zip::File.open("exampleout.zip") do |zip_file|
|
||||
puts "Changed zip file contains: #{zip_file.entries.join(', ')}"
|
||||
zip_file.remove("Again")
|
||||
puts "Without 'Again': #{zip_file.entries.join(', ')}"
|
||||
}
|
||||
end
|
||||
|
||||
####### Using ZipFile to split a zip file: #######
|
||||
|
||||
|
|
|
@ -8,8 +8,7 @@ EXAMPLE_ZIP = "filesystem.zip"
|
|||
|
||||
File.delete(EXAMPLE_ZIP) if File.exist?(EXAMPLE_ZIP)
|
||||
|
||||
Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) {
|
||||
|zf|
|
||||
Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) do |zf|
|
||||
zf.file.open("file1.txt", "w") { |os| os.write "first file1.txt" }
|
||||
zf.dir.mkdir("dir1")
|
||||
zf.dir.chdir("dir1")
|
||||
|
@ -19,12 +18,11 @@ Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) {
|
|||
zf.dir.chdir("..")
|
||||
zf.file.open("file2.txt", "w") { |os| os.write "first file2.txt" }
|
||||
puts "Entries: #{zf.entries.join(', ')}"
|
||||
}
|
||||
end
|
||||
|
||||
Zip::File.open(EXAMPLE_ZIP) {
|
||||
|zf|
|
||||
Zip::File.open(EXAMPLE_ZIP) do |zf|
|
||||
puts "Entries from reloaded zip: #{zf.entries.join(', ')}"
|
||||
}
|
||||
end
|
||||
|
||||
# For other examples, look at zip.rb and ziptest.rb
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class ZipFileGenerator
|
|||
private
|
||||
def writeEntries(entries, path, io)
|
||||
|
||||
entries.each { |e|
|
||||
entries.each do |e|
|
||||
zipFilePath = path == "" ? e : File.join(path, e)
|
||||
diskFilePath = File.join(@inputDir, zipFilePath)
|
||||
puts "Deflating " + diskFilePath
|
||||
|
@ -42,7 +42,7 @@ class ZipFileGenerator
|
|||
else
|
||||
io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -19,12 +19,12 @@ class MainApp < Gtk::Window
|
|||
|
||||
@zipfile = nil
|
||||
@buttonPanel = ButtonPanel.new
|
||||
@buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
@buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
||||
show_file_selector
|
||||
}
|
||||
@buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
end
|
||||
@buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
||||
puts "Not implemented!"
|
||||
}
|
||||
end
|
||||
box.pack_start(@buttonPanel, false, false, 0)
|
||||
|
||||
sw = Gtk::ScrolledWindow.new
|
||||
|
@ -35,10 +35,9 @@ class MainApp < Gtk::Window
|
|||
@clist.set_selection_mode(Gtk::SELECTION_BROWSE)
|
||||
@clist.set_column_width(0, 120)
|
||||
@clist.set_column_width(1, 120)
|
||||
@clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW) {
|
||||
|_w, row, _column, _event|
|
||||
@clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW) do |_w, row, _column, _event|
|
||||
@selected_row = row
|
||||
}
|
||||
end
|
||||
sw.add(@clist)
|
||||
end
|
||||
|
||||
|
@ -58,24 +57,23 @@ class MainApp < Gtk::Window
|
|||
def show_file_selector
|
||||
@fileSelector = Gtk::FileSelection.new("Open zip file")
|
||||
@fileSelector.show
|
||||
@fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
@fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
||||
open_zip(@fileSelector.filename)
|
||||
@fileSelector.destroy
|
||||
}
|
||||
@fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
end
|
||||
@fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
||||
@fileSelector.destroy
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def open_zip(filename)
|
||||
@zipfile = Zip::File.open(filename)
|
||||
@clist.clear
|
||||
@zipfile.each {
|
||||
|entry|
|
||||
@zipfile.each do |entry|
|
||||
@clist.append([ entry.name,
|
||||
entry.size.to_s,
|
||||
(100.0*entry.compressedSize/entry.size).to_s+"%" ])
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -35,10 +35,9 @@ class ZipDialog < ZipDialogUI
|
|||
def refresh()
|
||||
lv = child("entry_list_view")
|
||||
lv.clear
|
||||
each {
|
||||
|e|
|
||||
each do |e|
|
||||
lv.insert_item(Qt::ListViewItem.new(lv, e.name, e.size.to_s))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -49,13 +48,11 @@ class ZipDialog < ZipDialogUI
|
|||
|
||||
def add_files
|
||||
l = Qt::FileDialog.getOpenFileNames(nil, nil, self)
|
||||
zipfile {
|
||||
|zf|
|
||||
l.each {
|
||||
|path|
|
||||
zipfile do |zf|
|
||||
l.each do |path|
|
||||
zf.add(File.basename(path), path)
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
refresh
|
||||
end
|
||||
|
||||
|
|
|
@ -6,8 +6,7 @@ require 'zip'
|
|||
|
||||
include Zip
|
||||
|
||||
OutputStream.open('simple.zip') {
|
||||
|zos|
|
||||
OutputStream.open('simple.zip') do |zos|
|
||||
zos.put_next_entry 'entry.txt'
|
||||
zos.puts "Hello world"
|
||||
}
|
||||
end
|
||||
|
|
|
@ -10,27 +10,24 @@ require 'find'
|
|||
module Zip
|
||||
module ZipFind
|
||||
def self.find(path, zipFilePattern = /\.zip$/i)
|
||||
Find.find(path) {
|
||||
|fileName|
|
||||
yield(fileName)
|
||||
if zipFilePattern.match(fileName) && File.file?(fileName)
|
||||
begin
|
||||
Zip::File.foreach(fileName) {
|
||||
|zipEntry|
|
||||
yield(fileName + File::SEPARATOR + zipEntry.to_s)
|
||||
}
|
||||
rescue Errno::EACCES => ex
|
||||
puts ex
|
||||
end
|
||||
end
|
||||
}
|
||||
Find.find(path) do |fileName|
|
||||
yield(fileName)
|
||||
if zipFilePattern.match(fileName) && File.file?(fileName)
|
||||
begin
|
||||
Zip::File.foreach(fileName) do |zipEntry|
|
||||
yield(fileName + File::SEPARATOR + zipEntry.to_s)
|
||||
end
|
||||
rescue Errno::EACCES => ex
|
||||
puts ex
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
|
||||
self.find(path, zipFilePattern) {
|
||||
|fileName|
|
||||
yield(fileName) if fileNamePattern.match(fileName)
|
||||
}
|
||||
self.find(path, zipFilePattern) do |fileName|
|
||||
yield(fileName) if fileNamePattern.match(fileName)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -47,16 +44,15 @@ if __FILE__ == $0
|
|||
check_args(args)
|
||||
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
|
||||
args[FILENAME_PATTERN_ARG_INDEX],
|
||||
args[ZIPFILE_PATTERN_ARG_INDEX]) {
|
||||
|fileName|
|
||||
report_entry_found fileName
|
||||
}
|
||||
args[ZIPFILE_PATTERN_ARG_INDEX]) do |fileName|
|
||||
report_entry_found fileName
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_args(args)
|
||||
if (args.size != 3)
|
||||
usage
|
||||
exit
|
||||
usage
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,26 +16,24 @@ class BasicZipFileTest < MiniTest::Test
|
|||
def test_each
|
||||
count = 0
|
||||
visited = {}
|
||||
@zip_file.each {
|
||||
|entry|
|
||||
@zip_file.each do |entry|
|
||||
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
||||
assert(!visited.include?(entry.name))
|
||||
visited[entry.name] = nil
|
||||
count = count.succ
|
||||
}
|
||||
end
|
||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
||||
end
|
||||
|
||||
def test_foreach
|
||||
count = 0
|
||||
visited = {}
|
||||
::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name) {
|
||||
|entry|
|
||||
::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name) do |entry|
|
||||
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
||||
assert(!visited.include?(entry.name))
|
||||
visited[entry.name] = nil
|
||||
count = count.succ
|
||||
}
|
||||
end
|
||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
||||
end
|
||||
|
||||
|
@ -53,12 +51,11 @@ class BasicZipFileTest < MiniTest::Test
|
|||
|
||||
def test_get_input_streamBlock
|
||||
fileAndEntryName = @zip_file.entries.first.name
|
||||
@zip_file.get_input_stream(fileAndEntryName) {
|
||||
|zis|
|
||||
@zip_file.get_input_stream(fileAndEntryName) do |zis|
|
||||
assert_entryContentsForStream(fileAndEntryName,
|
||||
zis,
|
||||
fileAndEntryName)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,8 +3,7 @@ require 'test_helper'
|
|||
class ZipCentralDirectoryEntryTest < MiniTest::Test
|
||||
|
||||
def test_read_from_stream
|
||||
File.open("test/data/testDirectory.bin", "rb") {
|
||||
|file|
|
||||
File.open("test/data/testDirectory.bin", "rb") do |file|
|
||||
entry = ::Zip::Entry.read_c_dir_entry(file)
|
||||
|
||||
assert_equal("longAscii.txt", entry.name)
|
||||
|
@ -57,7 +56,7 @@ class ZipCentralDirectoryEntryTest < MiniTest::Test
|
|||
# extra field (variable size)
|
||||
# file comment (variable size)
|
||||
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_ReadEntryFromTruncatedZipFile
|
||||
|
|
|
@ -7,25 +7,22 @@ class ZipCentralDirectoryTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_read_from_stream
|
||||
::File.open(TestZipFile::TEST_ZIP2.zip_name, "rb") {
|
||||
|zipFile|
|
||||
::File.open(TestZipFile::TEST_ZIP2.zip_name, "rb") do |zipFile|
|
||||
cdir = ::Zip::CentralDirectory.read_from_stream(zipFile)
|
||||
|
||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names.size, cdir.size)
|
||||
assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) {
|
||||
|cdirEntry, testEntryName|
|
||||
assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) do |cdirEntry, testEntryName|
|
||||
cdirEntry.name == testEntryName
|
||||
})
|
||||
end)
|
||||
assert_equal(TestZipFile::TEST_ZIP2.comment, cdir.comment)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_readFromInvalidStream
|
||||
File.open("test/data/file2.txt", "rb") {
|
||||
|zipFile|
|
||||
File.open("test/data/file2.txt", "rb") do |zipFile|
|
||||
cdir = ::Zip::CentralDirectory.new
|
||||
cdir.read_from_stream(zipFile)
|
||||
}
|
||||
end
|
||||
fail "ZipError expected!"
|
||||
rescue ::Zip::Error
|
||||
end
|
||||
|
|
|
@ -42,23 +42,21 @@ class DeflaterTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def deflate(data, fileName)
|
||||
File.open(fileName, "wb") {
|
||||
|file|
|
||||
File.open(fileName, "wb") do |file|
|
||||
deflater = ::Zip::Deflater.new(file)
|
||||
deflater << data
|
||||
deflater.finish
|
||||
assert_equal(deflater.size, data.size)
|
||||
file << "trailing data for zlib with -MAX_WBITS"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def inflate(fileName)
|
||||
txt = nil
|
||||
File.open(fileName, "rb") {
|
||||
|file|
|
||||
File.open(fileName, "rb") do |file|
|
||||
inflater = ::Zip::Inflater.new(file)
|
||||
txt = inflater.sysread
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_crc
|
||||
|
|
|
@ -11,10 +11,9 @@ class ZipFileExtractDirectoryTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def extract_test_dir(&aProc)
|
||||
open_zip {
|
||||
|zf|
|
||||
open_zip do |zf|
|
||||
zf.extract(TestFiles::EMPTY_TEST_DIR, TEST_OUT_NAME, &aProc)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
|
@ -43,13 +42,12 @@ class ZipFileExtractDirectoryTest < MiniTest::Test
|
|||
def test_extractDirectoryExistsAsFileOverwrite
|
||||
File.open(TEST_OUT_NAME, "w") { |f| f.puts "something" }
|
||||
gotCalled = false
|
||||
extract_test_dir {
|
||||
|entry, destPath|
|
||||
extract_test_dir do |entry, destPath|
|
||||
gotCalled = true
|
||||
assert_equal(TEST_OUT_NAME, destPath)
|
||||
assert(entry.directory?)
|
||||
true
|
||||
}
|
||||
end
|
||||
assert(gotCalled)
|
||||
assert(File.directory?(TEST_OUT_NAME))
|
||||
end
|
||||
|
|
|
@ -11,8 +11,7 @@ class ZipFileExtractTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_extract
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
zf.extract(ENTRY_TO_EXTRACT, EXTRACTED_FILENAME)
|
||||
|
||||
assert(File.exist?(EXTRACTED_FILENAME))
|
||||
|
@ -29,21 +28,21 @@ class ZipFileExtractTest < MiniTest::Test
|
|||
AssertEntry::assert_contents(EXTRACTED_FILENAME,
|
||||
entry.get_input_stream() { |is| is.read })
|
||||
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_extractExists
|
||||
writtenText = "written text"
|
||||
::File.open(EXTRACTED_FILENAME, "w") { |f| f.write(writtenText) }
|
||||
|
||||
assert_raises(::Zip::DestinationFileExistsError) {
|
||||
::Zip::File.open(TEST_ZIP.zip_name) { |zf|
|
||||
assert_raises(::Zip::DestinationFileExistsError) do
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
zf.extract(zf.entries.first, EXTRACTED_FILENAME)
|
||||
}
|
||||
}
|
||||
File.open(EXTRACTED_FILENAME, "r") { |f|
|
||||
end
|
||||
end
|
||||
File.open(EXTRACTED_FILENAME, "r") do |f|
|
||||
assert_equal(writtenText, f.read)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_extractExistsOverwrite
|
||||
|
@ -51,21 +50,18 @@ class ZipFileExtractTest < MiniTest::Test
|
|||
::File.open(EXTRACTED_FILENAME, "w") { |f| f.write(writtenText) }
|
||||
|
||||
gotCalledCorrectly = false
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
zf.extract(zf.entries.first, EXTRACTED_FILENAME) {
|
||||
|entry, extractLoc|
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
zf.extract(zf.entries.first, EXTRACTED_FILENAME) do |entry, extractLoc|
|
||||
gotCalledCorrectly = zf.entries.first == entry &&
|
||||
extractLoc == EXTRACTED_FILENAME
|
||||
true
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert(gotCalledCorrectly)
|
||||
::File.open(EXTRACTED_FILENAME, "r") {
|
||||
|f|
|
||||
::File.open(EXTRACTED_FILENAME, "r") do |f|
|
||||
assert(writtenText != f.read)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_extractNonEntry
|
||||
|
@ -77,13 +73,13 @@ class ZipFileExtractTest < MiniTest::Test
|
|||
|
||||
def test_extractNonEntry2
|
||||
outFile = "outfile"
|
||||
assert_raises(Errno::ENOENT) {
|
||||
assert_raises(Errno::ENOENT) do
|
||||
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||
nonEntry = "hotdog-diddelidoo"
|
||||
assert(!zf.entries.include?(nonEntry))
|
||||
zf.extract(nonEntry, outFile)
|
||||
zf.close
|
||||
}
|
||||
end
|
||||
assert(!File.exist?(outFile))
|
||||
end
|
||||
|
||||
|
|
|
@ -43,28 +43,24 @@ class ZipFileTest < MiniTest::Test
|
|||
|
||||
def test_get_output_stream
|
||||
entryCount = nil
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
entryCount = zf.size
|
||||
zf.get_output_stream('newEntry.txt') {
|
||||
|os|
|
||||
zf.get_output_stream('newEntry.txt') do |os|
|
||||
os.write "Putting stuff in newEntry.txt"
|
||||
}
|
||||
end
|
||||
assert_equal(entryCount+1, zf.size)
|
||||
assert_equal("Putting stuff in newEntry.txt", zf.read("newEntry.txt"))
|
||||
|
||||
zf.get_output_stream(zf.get_entry('test/data/generated/empty.txt')) {
|
||||
|os|
|
||||
zf.get_output_stream(zf.get_entry('test/data/generated/empty.txt')) do |os|
|
||||
os.write "Putting stuff in data/generated/empty.txt"
|
||||
}
|
||||
end
|
||||
assert_equal(entryCount+1, zf.size)
|
||||
assert_equal("Putting stuff in data/generated/empty.txt", zf.read("test/data/generated/empty.txt"))
|
||||
|
||||
custom_entry_args = [ZipEntryTest::TEST_COMMENT, ZipEntryTest::TEST_EXTRA, ZipEntryTest::TEST_COMPRESSED_SIZE, ZipEntryTest::TEST_CRC, ::Zip::Entry::STORED, ZipEntryTest::TEST_SIZE, ZipEntryTest::TEST_TIME]
|
||||
zf.get_output_stream('entry_with_custom_args.txt', nil, *custom_entry_args) {
|
||||
|os|
|
||||
zf.get_output_stream('entry_with_custom_args.txt', nil, *custom_entry_args) do |os|
|
||||
os.write "Some data"
|
||||
}
|
||||
end
|
||||
assert_equal(entryCount+2, zf.size)
|
||||
entry = zf.get_entry('entry_with_custom_args.txt')
|
||||
assert_equal(custom_entry_args[0], entry.comment)
|
||||
|
@ -74,19 +70,17 @@ class ZipFileTest < MiniTest::Test
|
|||
assert_equal(custom_entry_args[5], entry.size)
|
||||
assert_equal(custom_entry_args[6], entry.time)
|
||||
|
||||
zf.get_output_stream('entry.bin') {
|
||||
|os|
|
||||
zf.get_output_stream('entry.bin') do |os|
|
||||
os.write(::File.open('test/data/generated/5entry.zip', 'rb').read)
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
assert_equal(entryCount+3, zf.size)
|
||||
assert_equal("Putting stuff in newEntry.txt", zf.read("newEntry.txt"))
|
||||
assert_equal("Putting stuff in data/generated/empty.txt", zf.read("test/data/generated/empty.txt"))
|
||||
assert_equal(File.open('test/data/generated/5entry.zip', 'rb').read, zf.read("entry.bin"))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_cleans_up_tempfiles_after_close
|
||||
|
@ -133,39 +127,34 @@ class ZipFileTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_addExistingEntryName
|
||||
assert_raises(::Zip::EntryExistsError) {
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
assert_raises(::Zip::EntryExistsError) do
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
zf.add(zf.entries.first.name, "test/data/file2.txt")
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_addExistingEntryNameReplace
|
||||
gotCalled = false
|
||||
replacedEntry = nil
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
replacedEntry = zf.entries.first.name
|
||||
zf.add(replacedEntry, "test/data/file2.txt") { gotCalled = true; true }
|
||||
}
|
||||
end
|
||||
assert(gotCalled)
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
assert_contains(zf, replacedEntry, "test/data/file2.txt")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_addDirectory
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
zf.add(TestFiles::EMPTY_TEST_DIR, TestFiles::EMPTY_TEST_DIR)
|
||||
}
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
end
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
dirEntry = zf.entries.detect { |e| e.name == TestFiles::EMPTY_TEST_DIR+"/" }
|
||||
assert(dirEntry.directory?)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_remove
|
||||
|
@ -281,9 +270,7 @@ class ZipFileTest < MiniTest::Test
|
|||
target_entry = "target_entryName"
|
||||
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||
assert(!zf.entries.include?(nonEntry))
|
||||
assert_raises(Errno::ENOENT) {
|
||||
zf.rename(nonEntry, target_entry)
|
||||
}
|
||||
assert_raises(Errno::ENOENT) { zf.rename(nonEntry, target_entry) }
|
||||
zf.commit
|
||||
assert(!zf.entries.include?(target_entry))
|
||||
ensure
|
||||
|
@ -293,9 +280,7 @@ class ZipFileTest < MiniTest::Test
|
|||
def test_renameEntryToExistingEntry
|
||||
entry1, entry2, * = TEST_ZIP.entry_names
|
||||
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||
assert_raises(::Zip::EntryExistsError) {
|
||||
zf.rename(entry1, entry2)
|
||||
}
|
||||
assert_raises(::Zip::EntryExistsError) { zf.rename(entry1, entry2) }
|
||||
ensure
|
||||
zf.close
|
||||
end
|
||||
|
@ -321,12 +306,9 @@ class ZipFileTest < MiniTest::Test
|
|||
|
||||
def test_replaceNonEntry
|
||||
entryToReplace = "nonExistingEntryname"
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
assert_raises(Errno::ENOENT) {
|
||||
zf.replace(entryToReplace, "test/data/file2.txt")
|
||||
}
|
||||
}
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
assert_raises(Errno::ENOENT) { zf.replace(entryToReplace, "test/data/file2.txt") }
|
||||
end
|
||||
end
|
||||
|
||||
def test_commit
|
||||
|
@ -420,11 +402,10 @@ class ZipFileTest < MiniTest::Test
|
|||
zf.rename(entry_to_rename, renamedName)
|
||||
assert_contains(zf, renamedName)
|
||||
|
||||
TestFiles::BINARY_TEST_FILES.each {
|
||||
|filename|
|
||||
TestFiles::BINARY_TEST_FILES.each do |filename|
|
||||
zf.add(filename, filename)
|
||||
assert_contains(zf, filename)
|
||||
}
|
||||
end
|
||||
|
||||
assert_contains(zf, originalEntries.last.to_s)
|
||||
filename_to_remove = originalEntries.map(&:to_s).find { |name| name.match('longBinary') }
|
||||
|
@ -438,10 +419,9 @@ class ZipFileTest < MiniTest::Test
|
|||
zfRead = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||
assert_contains(zfRead, TestFiles::RANDOM_ASCII_FILE1)
|
||||
assert_contains(zfRead, renamedName)
|
||||
TestFiles::BINARY_TEST_FILES.each {
|
||||
|filename|
|
||||
TestFiles::BINARY_TEST_FILES.each do |filename|
|
||||
assert_contains(zfRead, filename)
|
||||
}
|
||||
end
|
||||
assert_not_contains(zfRead, filename_to_remove)
|
||||
ensure
|
||||
zfRead.close
|
||||
|
@ -453,18 +433,16 @@ class ZipFileTest < MiniTest::Test
|
|||
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||
originalEntries = zf.entries.dup
|
||||
|
||||
originalEntries.each {
|
||||
|entry|
|
||||
originalEntries.each do |entry|
|
||||
zf.remove(entry)
|
||||
assert_not_contains(zf, entry)
|
||||
}
|
||||
end
|
||||
assert(zf.entries.empty?)
|
||||
|
||||
TestFiles::ASCII_TEST_FILES.each {
|
||||
|filename|
|
||||
TestFiles::ASCII_TEST_FILES.each do |filename|
|
||||
zf.add(filename, filename)
|
||||
assert_contains(zf, filename)
|
||||
}
|
||||
end
|
||||
assert_equal(zf.entries.sort.map { |e| e.name }, TestFiles::ASCII_TEST_FILES)
|
||||
|
||||
zf.rename(TestFiles::ASCII_TEST_FILES[0], "newName")
|
||||
|
@ -477,10 +455,9 @@ class ZipFileTest < MiniTest::Test
|
|||
zfRead = ::Zip::File.new(TEST_ZIP.zip_name)
|
||||
asciiTestFiles = TestFiles::ASCII_TEST_FILES.dup
|
||||
asciiTestFiles.shift
|
||||
asciiTestFiles.each {
|
||||
|filename|
|
||||
asciiTestFiles.each do |filename|
|
||||
assert_contains(zf, filename)
|
||||
}
|
||||
end
|
||||
|
||||
assert_contains(zf, "newName")
|
||||
ensure
|
||||
|
@ -498,30 +475,26 @@ class ZipFileTest < MiniTest::Test
|
|||
|
||||
def test_preserve_file_order
|
||||
entryNames = nil
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
entryNames = zf.entries.map { |e| e.to_s }
|
||||
zf.get_output_stream("a.txt") { |os| os.write "this is a.txt" }
|
||||
zf.get_output_stream("z.txt") { |os| os.write "this is z.txt" }
|
||||
zf.get_output_stream("k.txt") { |os| os.write "this is k.txt" }
|
||||
entryNames << "a.txt" << "z.txt" << "k.txt"
|
||||
}
|
||||
end
|
||||
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
assert_equal(entryNames, zf.entries.map { |e| e.to_s })
|
||||
entries = zf.entries.sort_by { |e| e.name }.reverse
|
||||
entries.each {
|
||||
|e|
|
||||
entries.each do |e|
|
||||
zf.remove e
|
||||
zf.get_output_stream(e) { |os| os.write "foo" }
|
||||
}
|
||||
end
|
||||
entryNames = entries.map { |e| e.to_s }
|
||||
}
|
||||
::Zip::File.open(TEST_ZIP.zip_name) {
|
||||
|zf|
|
||||
end
|
||||
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
||||
assert_equal(entryNames, zf.entries.map { |e| e.to_s })
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_streaming
|
||||
|
|
|
@ -11,21 +11,21 @@ class ZipFsDirIteratorTest < MiniTest::Test
|
|||
|
||||
def test_close
|
||||
@dirIt.close
|
||||
assert_raises(IOError, "closed directory") {
|
||||
assert_raises(IOError, "closed directory") do
|
||||
@dirIt.each { |e| p e }
|
||||
}
|
||||
assert_raises(IOError, "closed directory") {
|
||||
end
|
||||
assert_raises(IOError, "closed directory") do
|
||||
@dirIt.read
|
||||
}
|
||||
assert_raises(IOError, "closed directory") {
|
||||
end
|
||||
assert_raises(IOError, "closed directory") do
|
||||
@dirIt.rewind
|
||||
}
|
||||
assert_raises(IOError, "closed directory") {
|
||||
end
|
||||
assert_raises(IOError, "closed directory") do
|
||||
@dirIt.seek(0)
|
||||
}
|
||||
assert_raises(IOError, "closed directory") {
|
||||
end
|
||||
assert_raises(IOError, "closed directory") do
|
||||
@dirIt.tell
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -35,10 +35,9 @@ class ZipFsDirIteratorTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_read
|
||||
FILENAME_ARRAY.size.times {
|
||||
|i|
|
||||
FILENAME_ARRAY.size.times do |i|
|
||||
assert_equal(FILENAME_ARRAY[i], @dirIt.read)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_rewind
|
||||
|
|
|
@ -9,50 +9,47 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_delete
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
assert_raises(Errno::ENOENT, "No such file or directory - NoSuchFile.txt") {
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
assert_raises(Errno::ENOENT, "No such file or directory - NoSuchFile.txt") do
|
||||
zf.dir.delete("NoSuchFile.txt")
|
||||
}
|
||||
assert_raises(Errno::EINVAL, "Invalid argument - file1") {
|
||||
end
|
||||
assert_raises(Errno::EINVAL, "Invalid argument - file1") do
|
||||
zf.dir.delete("file1")
|
||||
}
|
||||
end
|
||||
assert(zf.file.exists?("dir1"))
|
||||
zf.dir.delete("dir1")
|
||||
assert(! zf.file.exists?("dir1"))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_mkdir
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
assert_raises(Errno::EEXIST, "File exists - dir1") {
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
assert_raises(Errno::EEXIST, "File exists - dir1") do
|
||||
zf.dir.mkdir("file1")
|
||||
}
|
||||
assert_raises(Errno::EEXIST, "File exists - dir1") {
|
||||
end
|
||||
assert_raises(Errno::EEXIST, "File exists - dir1") do
|
||||
zf.dir.mkdir("dir1")
|
||||
}
|
||||
end
|
||||
assert(!zf.file.exists?("newDir"))
|
||||
zf.dir.mkdir("newDir")
|
||||
assert(zf.file.directory?("newDir"))
|
||||
assert(!zf.file.exists?("newDir2"))
|
||||
zf.dir.mkdir("newDir2", 3485)
|
||||
assert(zf.file.directory?("newDir2"))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_pwd_chdir_entries
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
assert_equal("/", zf.dir.pwd)
|
||||
|
||||
assert_raises(Errno::ENOENT, "No such file or directory - no such dir") {
|
||||
assert_raises(Errno::ENOENT, "No such file or directory - no such dir") do
|
||||
zf.dir.chdir "no such dir"
|
||||
}
|
||||
end
|
||||
|
||||
assert_raises(Errno::EINVAL, "Invalid argument - file1") {
|
||||
assert_raises(Errno::EINVAL, "Invalid argument - file1") do
|
||||
zf.dir.chdir "file1"
|
||||
}
|
||||
end
|
||||
|
||||
assert_equal(%w(dir1 dir2 file1).sort, zf.dir.entries(".").sort)
|
||||
zf.dir.chdir "dir1"
|
||||
|
@ -62,22 +59,20 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|||
zf.dir.chdir "../dir2/dir21"
|
||||
assert_equal("/dir2/dir21", zf.dir.pwd)
|
||||
assert_equal(["dir221"].sort, zf.dir.entries(".").sort)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_foreach
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
blockCalled = false
|
||||
assert_raises(Errno::ENOENT, "No such file or directory - noSuchDir") {
|
||||
assert_raises(Errno::ENOENT, "No such file or directory - noSuchDir") do
|
||||
zf.dir.foreach("noSuchDir") { |_e| blockCalled = true }
|
||||
}
|
||||
end
|
||||
assert(! blockCalled)
|
||||
|
||||
assert_raises(Errno::ENOTDIR, "Not a directory - file1") {
|
||||
assert_raises(Errno::ENOTDIR, "Not a directory - file1") do
|
||||
zf.dir.foreach("file1") { |_e| blockCalled = true }
|
||||
}
|
||||
end
|
||||
assert(! blockCalled)
|
||||
|
||||
entries = []
|
||||
|
@ -87,16 +82,15 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|||
entries = []
|
||||
zf.dir.foreach("dir1") { |e| entries << e }
|
||||
assert_equal(%w(dir11 file11 file12), entries.sort)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_chroot
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
assert_raises(NotImplementedError) {
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
assert_raises(NotImplementedError) do
|
||||
zf.dir.chroot
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Globbing not supported yet
|
||||
|
@ -106,26 +100,23 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|||
#end
|
||||
|
||||
def test_open_new
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
|
||||
assert_raises(Errno::ENOTDIR, "Not a directory - file1") {
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
assert_raises(Errno::ENOTDIR, "Not a directory - file1") do
|
||||
zf.dir.new("file1")
|
||||
}
|
||||
end
|
||||
|
||||
assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") {
|
||||
assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") do
|
||||
zf.dir.new("noSuchFile")
|
||||
}
|
||||
end
|
||||
|
||||
d = zf.dir.new(".")
|
||||
assert_equal(%w(file1 dir1 dir2).sort, d.entries.sort)
|
||||
d.close
|
||||
|
||||
zf.dir.open("dir1") {
|
||||
|dir|
|
||||
zf.dir.open("dir1") do |dir|
|
||||
assert_equal(%w(dir11 file11 file12).sort, dir.entries.sort)
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -19,58 +19,49 @@ class ZipFsFileMutatingTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_open_write
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
|
||||
zf.file.open("test_open_write_entry", "w") {
|
||||
|f|
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
zf.file.open("test_open_write_entry", "w") do |f|
|
||||
f.write "This is what I'm writing"
|
||||
}
|
||||
end
|
||||
assert_equal("This is what I'm writing",
|
||||
zf.file.read("test_open_write_entry"))
|
||||
|
||||
# Test with existing entry
|
||||
zf.file.open("file1", "wb") { #also check that 'b' option is ignored
|
||||
|f|
|
||||
zf.file.open("file1", "wb") do |f| #also check that 'b' option is ignored
|
||||
f.write "This is what I'm writing too"
|
||||
}
|
||||
end
|
||||
assert_equal("This is what I'm writing too",
|
||||
zf.file.read("file1"))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_rename
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
assert_raises(Errno::ENOENT, "") {
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
assert_raises(Errno::ENOENT, "") do
|
||||
zf.file.rename("NoSuchFile", "bimse")
|
||||
}
|
||||
end
|
||||
zf.file.rename("file1", "newNameForFile1")
|
||||
}
|
||||
end
|
||||
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
assert(! zf.file.exists?("file1"))
|
||||
assert(zf.file.exists?("newNameForFile1"))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_chmod
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
|
||||
zf.file.chmod(0765, "file1")
|
||||
}
|
||||
end
|
||||
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
assert_equal(0100765, zf.file.stat("file1").mode)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def do_test_delete_or_unlink(symbol)
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
assert(zf.file.exists?("dir2/dir21/dir221/file2221"))
|
||||
zf.file.send(symbol, "dir2/dir21/dir221/file2221")
|
||||
assert(! zf.file.exists?("dir2/dir21/dir221/file2221"))
|
||||
|
@ -84,17 +75,16 @@ class ZipFsFileMutatingTest < MiniTest::Test
|
|||
assert_raises(Errno::ENOENT) { zf.file.send(symbol, "noSuchFile") }
|
||||
assert_raises(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11") }
|
||||
assert_raises(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11/") }
|
||||
}
|
||||
end
|
||||
|
||||
::Zip::File.open(TEST_ZIP) {
|
||||
|zf|
|
||||
::Zip::File.open(TEST_ZIP) do |zf|
|
||||
assert(! zf.file.exists?("dir2/dir21/dir221/file2221"))
|
||||
assert(! zf.file.exists?("dir1/file11"))
|
||||
assert(! zf.file.exists?("dir1/file12"))
|
||||
|
||||
assert(zf.file.exists?("dir1/dir11"))
|
||||
assert(zf.file.exists?("dir1/dir11/"))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -32,37 +32,34 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|||
|
||||
def test_open_read
|
||||
blockCalled = false
|
||||
@zip_file.file.open("file1", "r") {
|
||||
|f|
|
||||
@zip_file.file.open("file1", "r") do |f|
|
||||
blockCalled = true
|
||||
assert_equal("this is the entry 'file1' in my test archive!",
|
||||
f.readline.chomp)
|
||||
}
|
||||
end
|
||||
assert(blockCalled)
|
||||
|
||||
blockCalled = false
|
||||
@zip_file.file.open("file1", "rb") { # test binary flag is ignored
|
||||
|f|
|
||||
@zip_file.file.open("file1", "rb") do |f| # test binary flag is ignored
|
||||
blockCalled = true
|
||||
assert_equal("this is the entry 'file1' in my test archive!",
|
||||
f.readline.chomp)
|
||||
}
|
||||
end
|
||||
assert(blockCalled)
|
||||
|
||||
blockCalled = false
|
||||
@zip_file.dir.chdir "dir2"
|
||||
@zip_file.file.open("file21", "r") {
|
||||
|f|
|
||||
@zip_file.file.open("file21", "r") do |f|
|
||||
blockCalled = true
|
||||
assert_equal("this is the entry 'dir2/file21' in my test archive!",
|
||||
f.readline.chomp)
|
||||
}
|
||||
end
|
||||
assert(blockCalled)
|
||||
@zip_file.dir.chdir "/"
|
||||
|
||||
assert_raises(Errno::ENOENT) {
|
||||
assert_raises(Errno::ENOENT) do
|
||||
@zip_file.file.open("noSuchEntry")
|
||||
}
|
||||
end
|
||||
|
||||
begin
|
||||
is = @zip_file.file.open("file1")
|
||||
|
@ -82,18 +79,18 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|||
is.close if is
|
||||
end
|
||||
begin
|
||||
is = @zip_file.file.new("file1") {
|
||||
fail "should not call block"
|
||||
}
|
||||
is = @zip_file.file.new("file1") do
|
||||
fail "should not call block"
|
||||
end
|
||||
ensure
|
||||
is.close if is
|
||||
end
|
||||
end
|
||||
|
||||
def test_symlink
|
||||
assert_raises(NotImplementedError) {
|
||||
assert_raises(NotImplementedError) do
|
||||
@zip_file.file.symlink("file1", "aSymlink")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_size
|
||||
|
@ -130,21 +127,21 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|||
include ExtraAssertions
|
||||
|
||||
def test_dirname
|
||||
assert_forwarded(File, :dirname, "retVal", "a/b/c/d") {
|
||||
assert_forwarded(File, :dirname, "retVal", "a/b/c/d") do
|
||||
@zip_file.file.dirname("a/b/c/d")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_basename
|
||||
assert_forwarded(File, :basename, "retVal", "a/b/c/d") {
|
||||
assert_forwarded(File, :basename, "retVal", "a/b/c/d") do
|
||||
@zip_file.file.basename("a/b/c/d")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_split
|
||||
assert_forwarded(File, :split, "retVal", "a/b/c/d") {
|
||||
assert_forwarded(File, :split, "retVal", "a/b/c/d") do
|
||||
@zip_file.file.split("a/b/c/d")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_join
|
||||
|
@ -201,15 +198,15 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_truncate
|
||||
assert_raises(StandardError, "truncate not supported") {
|
||||
assert_raises(StandardError, "truncate not supported") do
|
||||
@zip_file.file.truncate("file1", 100)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def assert_e_n_o_e_n_t(operation, args = ["NoSuchFile"])
|
||||
assert_raises(Errno::ENOENT) {
|
||||
assert_raises(Errno::ENOENT) do
|
||||
@zip_file.file.send(operation, *args)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_ftype
|
||||
|
@ -220,9 +217,9 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_link
|
||||
assert_raises(NotImplementedError) {
|
||||
assert_raises(NotImplementedError) do
|
||||
@zip_file.file.link("file1", "someOtherString")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_directory?
|
||||
|
@ -252,34 +249,31 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|||
assert(! @zip_file.file.zero?("file1"))
|
||||
assert(@zip_file.file.zero?("dir1"))
|
||||
blockCalled = false
|
||||
::Zip::File.open("test/data/generated/5entry.zip") {
|
||||
|zf|
|
||||
::Zip::File.open("test/data/generated/5entry.zip") do |zf|
|
||||
blockCalled = true
|
||||
assert(zf.file.zero?("test/data/generated/empty.txt"))
|
||||
}
|
||||
end
|
||||
assert(blockCalled)
|
||||
|
||||
assert(! @zip_file.file.stat("file1").zero?)
|
||||
assert(@zip_file.file.stat("dir1").zero?)
|
||||
blockCalled = false
|
||||
::Zip::File.open("test/data/generated/5entry.zip") {
|
||||
|zf|
|
||||
::Zip::File.open("test/data/generated/5entry.zip") do |zf|
|
||||
blockCalled = true
|
||||
assert(zf.file.stat("test/data/generated/empty.txt").zero?)
|
||||
}
|
||||
end
|
||||
assert(blockCalled)
|
||||
end
|
||||
|
||||
def test_expand_path
|
||||
::Zip::File.open("test/data/zipWithDirs.zip") {
|
||||
|zf|
|
||||
::Zip::File.open("test/data/zipWithDirs.zip") do |zf|
|
||||
assert_equal("/", zf.file.expand_path("."))
|
||||
zf.dir.chdir "dir1"
|
||||
assert_equal("/dir1", zf.file.expand_path("."))
|
||||
assert_equal("/dir1/file12", zf.file.expand_path("file12"))
|
||||
assert_equal("/", zf.file.expand_path(".."))
|
||||
assert_equal("/dir2/dir21", zf.file.expand_path("../dir2/dir21"))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_mtime
|
||||
|
@ -287,9 +281,9 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|||
@zip_file.file.mtime("dir2/file21"))
|
||||
assert_equal(::Zip::DOSTime.at(1027690863),
|
||||
@zip_file.file.mtime("dir2/dir21"))
|
||||
assert_raises(Errno::ENOENT) {
|
||||
assert_raises(Errno::ENOENT) do
|
||||
@zip_file.file.mtime("noSuchEntry")
|
||||
}
|
||||
end
|
||||
|
||||
assert_equal(::Zip::DOSTime.at(1027694306),
|
||||
@zip_file.file.stat("dir2/file21").mtime)
|
||||
|
@ -385,17 +379,17 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_readlink
|
||||
assert_raises(NotImplementedError) {
|
||||
assert_raises(NotImplementedError) do
|
||||
@zip_file.file.readlink("someString")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_stat
|
||||
s = @zip_file.file.stat("file1")
|
||||
assert(s.kind_of?(File::Stat)) # It pretends
|
||||
assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") {
|
||||
assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") do
|
||||
@zip_file.file.stat("noSuchFile")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_lstat
|
||||
|
@ -403,9 +397,9 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_pipe
|
||||
assert_raises(NotImplementedError) {
|
||||
assert_raises(NotImplementedError) do
|
||||
@zip_file.file.pipe
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_foreach
|
||||
|
|
|
@ -11,11 +11,11 @@ class ZipInputStreamTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_openWithBlock
|
||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do
|
||||
|zis|
|
||||
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
||||
assert_equal(true, zis.eof?)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_openWithoutBlock
|
||||
|
@ -50,7 +50,7 @@ class ZipInputStreamTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_incompleteReads
|
||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do
|
||||
|zis|
|
||||
entry = zis.get_next_entry # longAscii.txt
|
||||
assert_equal(false, zis.eof?)
|
||||
|
@ -73,7 +73,7 @@ class ZipInputStreamTest < MiniTest::Test
|
|||
entry = zis.get_next_entry # longBinary.bin
|
||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
||||
assert zis.gets.length > 0
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_incomplete_reads_from_string_io
|
||||
|
@ -114,7 +114,7 @@ class ZipInputStreamTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_rewind
|
||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do
|
||||
|zis|
|
||||
e = zis.get_next_entry
|
||||
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)
|
||||
|
@ -141,11 +141,11 @@ class ZipInputStreamTest < MiniTest::Test
|
|||
assert_equal(0, zis.pos)
|
||||
|
||||
assert_entry(e.name, zis, e.name)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_mix_read_and_gets
|
||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
||||
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do
|
||||
|zis|
|
||||
zis.get_next_entry
|
||||
assert_equal("#!/usr/bin/env ruby", zis.gets.chomp)
|
||||
|
@ -154,7 +154,7 @@ class ZipInputStreamTest < MiniTest::Test
|
|||
assert_equal(false, zis.eof?)
|
||||
assert_equal("$VERBOSE =", zis.read(10))
|
||||
assert_equal(false, zis.eof?)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_ungetc
|
||||
|
|
|
@ -81,11 +81,10 @@ class AbstractInputStreamTest < MiniTest::Test
|
|||
|
||||
def test_each_line
|
||||
lineNumber=0
|
||||
@io.each_line {
|
||||
|line|
|
||||
@io.each_line do |line|
|
||||
assert_equal(TEST_LINES[lineNumber], line)
|
||||
lineNumber+=1
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_readlines
|
||||
|
|
|
@ -28,19 +28,19 @@ class ZipLocalEntryTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_readDateTime
|
||||
::File.open("test/data/rubycode.zip", "rb") {
|
||||
::File.open("test/data/rubycode.zip", "rb") do
|
||||
|file|
|
||||
entry = ::Zip::Entry.read_local_entry(file)
|
||||
assert_equal("zippedruby1.rb", entry.name)
|
||||
assert_equal(::Zip::DOSTime.at(1019261638), entry.time)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_read_local_entryFromNonZipFile
|
||||
::File.open("test/data/file2.txt") {
|
||||
::File.open("test/data/file2.txt") do
|
||||
|file|
|
||||
assert_equal(nil, ::Zip::Entry.read_local_entry(file))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_read_local_entryFromTruncatedZipFile
|
||||
|
|
|
@ -113,11 +113,11 @@ class ZipOutputStreamTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def assert_i_o_error_in_closed_stream
|
||||
assert_raises(IOError) {
|
||||
assert_raises(IOError) do
|
||||
zos = ::Zip::OutputStream.new("test/data/generated/test_putOnClosedStream.zip")
|
||||
zos.close
|
||||
yield zos
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def write_test_zip(zos)
|
||||
|
|
|
@ -4,8 +4,7 @@ class PassThruCompressorTest < MiniTest::Test
|
|||
include CrcTest
|
||||
|
||||
def test_size
|
||||
File.open("test/data/generated/dummy.txt", "wb") {
|
||||
|file|
|
||||
File.open("test/data/generated/dummy.txt", "wb") do |file|
|
||||
compressor = ::Zip::PassThruCompressor.new(file)
|
||||
|
||||
assert_equal(0, compressor.size)
|
||||
|
@ -22,7 +21,7 @@ class PassThruCompressorTest < MiniTest::Test
|
|||
|
||||
compressor << t3
|
||||
assert_equal(compressor.size, t1.size + t2.size + t3.size)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_crc
|
||||
|
|
|
@ -23,10 +23,9 @@ class ZipSettingsTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def extract_test_dir(&aProc)
|
||||
open_zip {
|
||||
|zf|
|
||||
open_zip do |zf|
|
||||
zf.extract(TestFiles::EMPTY_TEST_DIR, TEST_OUT_NAME, &aProc)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_true_on_exists_proc
|
||||
|
|
|
@ -98,8 +98,7 @@ module AssertEntry
|
|||
end
|
||||
|
||||
def assert_entryContentsForStream(filename, zis, entryName)
|
||||
File.open(filename, "rb") {
|
||||
|file|
|
||||
File.open(filename, "rb") do |file|
|
||||
expected = file.read
|
||||
actual = zis.read
|
||||
if (expected != actual)
|
||||
|
@ -111,7 +110,7 @@ module AssertEntry
|
|||
assert_equal(expected, actual)
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def AssertEntry.assert_contents(filename, aString)
|
||||
|
@ -182,10 +181,9 @@ end
|
|||
module Enumerable
|
||||
def compare_enumerables(otherEnumerable)
|
||||
otherAsArray = otherEnumerable.to_a
|
||||
each_with_index {
|
||||
|element, index|
|
||||
each_with_index do |element, index|
|
||||
return false unless yield(element, otherAsArray[index])
|
||||
}
|
||||
end
|
||||
return self.size == otherAsArray.size
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue