diff --git a/lib/zip/ioextras.rb b/lib/zip/ioextras.rb index c3a6053..7129e93 100755 --- a/lib/zip/ioextras.rb +++ b/lib/zip/ioextras.rb @@ -1,4 +1,4 @@ -module IOExtras +module IOExtras #:nodoc: # Implements kind_of? in order to pretend to be an IO object module FakeIO diff --git a/lib/zip/stdrubyext.rb b/lib/zip/stdrubyext.rb index a03aaf6..833365d 100755 --- a/lib/zip/stdrubyext.rb +++ b/lib/zip/stdrubyext.rb @@ -16,7 +16,7 @@ module Enumerable #:nodoc:all end unless Object.method_defined?(:object_id) - class Object + class Object #:nodoc:all # Using object_id which is the new thing, so we need # to make that work in versions prior to 1.8.0 alias object_id id @@ -32,7 +32,7 @@ unless File.respond_to?(:read) end end -class String +class String #:nodoc:all def starts_with(aString) rindex(aString, 0) == 0 end @@ -50,7 +50,7 @@ class String end end -class Time +class Time #:nodoc:all #MS-DOS File Date and Time format as used in Interrupt 21H Function 57H: # @@ -95,7 +95,7 @@ class Time end end -class Module +class Module #:nodoc:all def forward_message(forwarder, *messagesToForward) methodDefs = messagesToForward.map { |msg| diff --git a/lib/zip/tempfile_bugfixed.rb b/lib/zip/tempfile_bugfixed.rb index 8dd551a..6cf8e0a 100755 --- a/lib/zip/tempfile_bugfixed.rb +++ b/lib/zip/tempfile_bugfixed.rb @@ -1,13 +1,13 @@ # # tempfile - manipulates temporary files # -# $Id: tempfile_bugfixed.rb,v 1.1 2005/02/15 21:10:32 thomas Exp $ +# $Id: tempfile_bugfixed.rb,v 1.2 2005/02/19 20:30:33 thomas Exp $ # require 'delegate' require 'tmpdir' -module BugFix +module BugFix #:nodoc:all # A class for managing temporary files. This library is written to be # thread safe. diff --git a/lib/zip/zip.rb b/lib/zip/zip.rb index b3db287..fefee5a 100755 --- a/lib/zip/zip.rb +++ b/lib/zip/zip.rb @@ -11,7 +11,7 @@ if Tempfile.superclass == SimpleDelegator Tempfile = BugFix::Tempfile end -module Zlib +module Zlib #:nodoc:all if ! const_defined? :MAX_WBITS MAX_WBITS = Zlib::Deflate.MAX_WBITS end @@ -36,12 +36,12 @@ module Zip # ZipFileSystem interface) object for a particular entry in the zip # archive. # - # A ZipInputStream inherits AbstractInputStream in order to provide an - # IO-like interface for reading from a single zip entry. Beyond methods - # for mimicking an IO-object it contains the method get_next_entry for - # iterating through the entries of an archive. get_next_entry returns a - # ZipEntry object that describes the zip entry the ZipInputStream is - # currently reading from. + # A ZipInputStream inherits IOExtras::AbstractInputStream in order + # to provide an IO-like interface for reading from a single zip + # entry. Beyond methods for mimicking an IO-object it contains + # the method get_next_entry for iterating through the entries of + # an archive. get_next_entry returns a ZipEntry object that describes + # the zip entry the ZipInputStream is currently reading from. # # Example that creates a zip archive with ZipOutputStream and reads it # back again with a ZipInputStream. @@ -73,6 +73,9 @@ module Zip class ZipInputStream include IOExtras::AbstractInputStream + # Opens the indicated zip file. An exception is thrown + # if the specified offset in the specified filename is + # not a local zip entry header. def initialize(filename, offset = 0) super() @archiveIO = File.open(filename, "rb") @@ -84,7 +87,10 @@ module Zip def close @archiveIO.close end - + + # Same as #initialize but if a block is passed the opened + # stream is passed to the block and closed when the block + # returns. def ZipInputStream.open(filename) return new(filename) unless block_given? @@ -94,12 +100,17 @@ module Zip zio.close if zio end + # Returns a ZipEntry object. It is necessary to call this + # method on a newly created ZipInputStream before reading from + # the first entry in the archive. Returns nil when there are + # no more entries. def get_next_entry @archiveIO.seek(@currentEntry.next_header_offset, IO::SEEK_SET) if @currentEntry open_entry end + # Rewinds the stream to the beginning of the current entry def rewind return if @currentEntry.nil? @lineno = 0 @@ -108,6 +119,13 @@ module Zip open_entry end + # Modeled after IO.read + def read(numberOfBytes = nil) + @decompressor.read(numberOfBytes) + end + + protected + def open_entry @currentEntry = ZipEntry.read_local_entry(@archiveIO) if (@currentEntry == nil) @@ -125,10 +143,6 @@ module Zip return @currentEntry end - def read(numberOfBytes = nil) - @decompressor.read(numberOfBytes) - end - protected def produce_input @decompressor.produce_input end @@ -549,16 +563,17 @@ module Zip # ZipOutputStream is the basic class for writing zip files. It is - # possible to create a ZipInputStream object directly, passing + # possible to create a ZipOutputStream object directly, passing # the zip file name to the constructor, but more often than not # the ZipOutputStream will be obtained from a ZipFile (perhaps using the # ZipFileSystem interface) object for a particular entry in the zip # archive. # - # A ZipOutputStream inherits AbstractOutputStream in order to provide an - # IO-like interface for writing to a single zip entry. Beyond methods - # for mimicking an IO-object it contains the method put_next_entry that - # closes the current entry and creates a new. + # A ZipOutputStream inherits IOExtras::AbstractOutputStream in order + # to provide an IO-like interface for writing to a single zip + # entry. Beyond methods for mimicking an IO-object it contains + # the method put_next_entry that closes the current entry + # and creates a new. # # Please refer to ZipInputStream for example code. # @@ -570,6 +585,8 @@ module Zip attr_accessor :comment + # Opens the indicated zip file. If a file with that name already + # exists it will be overwritten. def initialize(fileName) super() @fileName = fileName @@ -581,6 +598,9 @@ module Zip @comment = nil end + # Same as #initialize but if a block is passed the opened + # stream is passed to the block and closed when the block + # returns. def ZipOutputStream.open(fileName) return new(fileName) unless block_given? zos = new(fileName) @@ -589,6 +609,7 @@ module Zip zos.close if zos end + # Closes the stream and writes the central directory to the zip file def close return if @closed finalize_current_entry @@ -598,6 +619,8 @@ module Zip @closed = true end + # Closes the current entry and opens a new for writing. + # +entry+ can be a ZipEntry object or a string. def put_next_entry(entry, level = Zlib::DEFAULT_COMPRESSION) raise ZipError, "zip stream is closed" if @closed newEntry = entry.kind_of?(ZipEntry) ? entry : ZipEntry.new(@fileName, entry.to_s) @@ -673,6 +696,7 @@ module Zip end public + # Modeled after IO.<< def << (data) @compressor << data end @@ -738,7 +762,7 @@ module Zip end - class ZipEntrySet + class ZipEntrySet #:nodoc:all include Enumerable def initialize(anEnumerable = []) diff --git a/lib/zip/ziprequire.rb b/lib/zip/ziprequire.rb index 9cd4411..8a34215 100755 --- a/lib/zip/ziprequire.rb +++ b/lib/zip/ziprequire.rb @@ -1,6 +1,6 @@ require 'zip/zip' -class ZipList +class ZipList #:nodoc:all def initialize(zipFileList) @zipFileList = zipFileList end @@ -23,7 +23,7 @@ class ZipList end -module Kernel +module Kernel #:nodoc:all alias :oldRequire :require def require(moduleName) diff --git a/test/ioextrastest.rb b/test/ioextrastest.rb index 30c2a77..b18e9db 100755 --- a/test/ioextrastest.rb +++ b/test/ioextrastest.rb @@ -4,12 +4,12 @@ $VERBOSE = true $: << "../lib" -require 'rubyunit' +require 'test/unit' require 'zip/ioextras' include IOExtras -class FakeIOTest < RUNIT::TestCase +class FakeIOTest < Test::Unit::TestCase class FakeIOUsingClass include FakeIO end @@ -25,7 +25,7 @@ class FakeIOTest < RUNIT::TestCase end end -class AbstractInputStreamTest < RUNIT::TestCase +class AbstractInputStreamTest < Test::Unit::TestCase # AbstractInputStream subclass that provides a read method TEST_LINES = [ "Hello world#{$/}", @@ -60,32 +60,32 @@ class AbstractInputStreamTest < RUNIT::TestCase end def test_gets - assert_equals(TEST_LINES[0], @io.gets) - assert_equals(1, @io.lineno) - assert_equals(TEST_LINES[1], @io.gets) - assert_equals(2, @io.lineno) - assert_equals(TEST_LINES[2], @io.gets) - assert_equals(3, @io.lineno) - assert_equals(nil, @io.gets) - assert_equals(4, @io.lineno) + assert_equal(TEST_LINES[0], @io.gets) + assert_equal(1, @io.lineno) + assert_equal(TEST_LINES[1], @io.gets) + assert_equal(2, @io.lineno) + assert_equal(TEST_LINES[2], @io.gets) + assert_equal(3, @io.lineno) + assert_equal(nil, @io.gets) + assert_equal(4, @io.lineno) end def test_getsMultiCharSeperator - assert_equals("Hell", @io.gets("ll")) - assert_equals("o world#{$/}this is the second l", @io.gets("d l")) + assert_equal("Hell", @io.gets("ll")) + assert_equal("o world#{$/}this is the second l", @io.gets("d l")) end def test_each_line lineNumber=0 @io.each_line { |line| - assert_equals(TEST_LINES[lineNumber], line) + assert_equal(TEST_LINES[lineNumber], line) lineNumber+=1 } end def test_readlines - assert_equals(TEST_LINES, @io.readlines) + assert_equal(TEST_LINES, @io.readlines) end def test_readline @@ -98,7 +98,7 @@ class AbstractInputStreamTest < RUNIT::TestCase end end -class AbstractOutputStreamTest < RUNIT::TestCase +class AbstractOutputStreamTest < Test::Unit::TestCase class TestOutputStream include AbstractOutputStream @@ -128,77 +128,77 @@ class AbstractOutputStreamTest < RUNIT::TestCase def test_write count = @outputStream.write("a little string") - assert_equals("a little string", @outputStream.buffer) - assert_equals("a little string".length, count) + assert_equal("a little string", @outputStream.buffer) + assert_equal("a little string".length, count) count = @outputStream.write(". a little more") - assert_equals("a little string. a little more", @outputStream.buffer) - assert_equals(". a little more".length, count) + assert_equal("a little string. a little more", @outputStream.buffer) + assert_equal(". a little more".length, count) end def test_print $\ = nil # record separator set to nil @outputStream.print("hello") - assert_equals("hello", @outputStream.buffer) + assert_equal("hello", @outputStream.buffer) @outputStream.print(" world.") - assert_equals("hello world.", @outputStream.buffer) + assert_equal("hello world.", @outputStream.buffer) @outputStream.print(" You ok ", "out ", "there?") - assert_equals("hello world. You ok out there?", @outputStream.buffer) + assert_equal("hello world. You ok out there?", @outputStream.buffer) $\ = "\n" @outputStream.print - assert_equals("hello world. You ok out there?\n", @outputStream.buffer) + assert_equal("hello world. You ok out there?\n", @outputStream.buffer) @outputStream.print("I sure hope so!") - assert_equals("hello world. You ok out there?\nI sure hope so!\n", @outputStream.buffer) + assert_equal("hello world. You ok out there?\nI sure hope so!\n", @outputStream.buffer) $, = "X" @outputStream.buffer = "" @outputStream.print("monkey", "duck", "zebra") - assert_equals("monkeyXduckXzebra\n", @outputStream.buffer) + assert_equal("monkeyXduckXzebra\n", @outputStream.buffer) $\ = nil @outputStream.buffer = "" @outputStream.print(20) - assert_equals("20", @outputStream.buffer) + assert_equal("20", @outputStream.buffer) end def test_printf @outputStream.printf("%d %04x", 123, 123) - assert_equals("123 007b", @outputStream.buffer) + assert_equal("123 007b", @outputStream.buffer) end def test_putc @outputStream.putc("A") - assert_equals("A", @outputStream.buffer) + assert_equal("A", @outputStream.buffer) @outputStream.putc(65) - assert_equals("AA", @outputStream.buffer) + assert_equal("AA", @outputStream.buffer) end def test_puts @outputStream.puts - assert_equals("\n", @outputStream.buffer) + assert_equal("\n", @outputStream.buffer) @outputStream.puts("hello", "world") - assert_equals("\nhello\nworld\n", @outputStream.buffer) + assert_equal("\nhello\nworld\n", @outputStream.buffer) @outputStream.buffer = "" @outputStream.puts("hello\n", "world\n") - assert_equals("hello\nworld\n", @outputStream.buffer) + assert_equal("hello\nworld\n", @outputStream.buffer) @outputStream.buffer = "" @outputStream.puts(["hello\n", "world\n"]) - assert_equals("hello\nworld\n", @outputStream.buffer) + assert_equal("hello\nworld\n", @outputStream.buffer) @outputStream.buffer = "" @outputStream.puts(["hello\n", "world\n"], "bingo") - assert_equals("hello\nworld\nbingo\n", @outputStream.buffer) + assert_equal("hello\nworld\nbingo\n", @outputStream.buffer) @outputStream.buffer = "" @outputStream.puts(16, 20, 50, "hello") - assert_equals("16\n20\n50\nhello\n", @outputStream.buffer) + assert_equal("16\n20\n50\nhello\n", @outputStream.buffer) end end diff --git a/test/stdrubyexttest.rb b/test/stdrubyexttest.rb index 4a0e1b4..f11608f 100755 --- a/test/stdrubyexttest.rb +++ b/test/stdrubyexttest.rb @@ -4,18 +4,18 @@ $VERBOSE = true $: << "../lib" -require 'rubyunit' +require 'test/unit' require 'zip/stdrubyext' -class ModuleTest < RUNIT::TestCase +class ModuleTest < Test::Unit::TestCase def test_select_map - assert_equals([2, 4, 8, 10], [1, 2, 3, 4, 5].select_map { |e| e == 3 ? nil : 2*e }) + assert_equal([2, 4, 8, 10], [1, 2, 3, 4, 5].select_map { |e| e == 3 ? nil : 2*e }) end end -class StringExtensionsTest < RUNIT::TestCase +class StringExtensionsTest < Test::Unit::TestCase def test_starts_with assert("hello".starts_with("")) @@ -24,7 +24,7 @@ class StringExtensionsTest < RUNIT::TestCase assert(! "hello".starts_with("hello there")) assert(! "hello".starts_with(" he")) - assert_exception(TypeError, "type mismatch: NilClass given") { + assert_raise(TypeError, "type mismatch: NilClass given") { "hello".starts_with(nil) } end @@ -40,10 +40,10 @@ class StringExtensionsTest < RUNIT::TestCase end def test_ensure_end - assert_equals("hello!", "hello!".ensure_end("!")) - assert_equals("hello!", "hello!".ensure_end("o!")) - assert_equals("hello!", "hello".ensure_end("!")) - assert_equals("hello!", "hel".ensure_end("lo!")) + assert_equal("hello!", "hello!".ensure_end("!")) + assert_equal("hello!", "hello!".ensure_end("o!")) + assert_equal("hello!", "hello".ensure_end("!")) + assert_equal("hello!", "hel".ensure_end("lo!")) end end diff --git a/test/zipfilesystemtest.rb b/test/zipfilesystemtest.rb index f593a4f..10140e1 100755 --- a/test/zipfilesystemtest.rb +++ b/test/zipfilesystemtest.rb @@ -5,7 +5,7 @@ $VERBOSE = true $: << "../lib" require 'zip/zipfilesystem' -require 'rubyunit' +require 'test/unit' module ExtraAssertions @@ -20,8 +20,8 @@ module ExtraAssertions end end_eval - assert_equals(retVal, yield) # Invoke test - assert_equals(expectedArgs, callArgs) + assert_equal(retVal, yield) # Invoke test + assert_equal(expectedArgs, callArgs) ensure anObject.instance_eval "alias #{method} #{method}_org" end @@ -30,7 +30,7 @@ end include Zip -class ZipFsFileNonmutatingTest < RUNIT::TestCase +class ZipFsFileNonmutatingTest < Test::Unit::TestCase def setup @zipFile = ZipFile.new("data/zipWithDirs.zip") end @@ -40,7 +40,7 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase end def test_umask - assert_equals(File.umask, @zipFile.file.umask) + assert_equal(File.umask, @zipFile.file.umask) @zipFile.file.umask(0006) end @@ -62,7 +62,7 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase @zipFile.file.open("file1", "r") { |f| blockCalled = true - assert_equals("this is the entry 'file1' in my test archive!", + assert_equal("this is the entry 'file1' in my test archive!", f.readline.chomp) } assert(blockCalled) @@ -72,19 +72,19 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase @zipFile.file.open("file21", "r") { |f| blockCalled = true - assert_equals("this is the entry 'dir2/file21' in my test archive!", + assert_equal("this is the entry 'dir2/file21' in my test archive!", f.readline.chomp) } assert(blockCalled) @zipFile.dir.chdir "/" - assert_exception(Errno::ENOENT) { + assert_raise(Errno::ENOENT) { @zipFile.file.open("noSuchEntry") } begin is = @zipFile.file.open("file1") - assert_equals("this is the entry 'file1' in my test archive!", + assert_equal("this is the entry 'file1' in my test archive!", is.readline.chomp) ensure is.close if is @@ -94,7 +94,7 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase def test_new begin is = @zipFile.file.new("file1") - assert_equals("this is the entry 'file1' in my test archive!", + assert_equal("this is the entry 'file1' in my test archive!", is.readline.chomp) ensure is.close if is @@ -109,27 +109,27 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase end def test_symlink - assert_exception(NotImplementedError) { + assert_raise(NotImplementedError) { @zipFile.file.symlink("file1", "aSymlink") } end def test_size - assert_exception(Errno::ENOENT) { @zipFile.file.size("notAFile") } - assert_equals(72, @zipFile.file.size("file1")) - assert_equals(0, @zipFile.file.size("dir2/dir21")) + assert_raise(Errno::ENOENT) { @zipFile.file.size("notAFile") } + assert_equal(72, @zipFile.file.size("file1")) + assert_equal(0, @zipFile.file.size("dir2/dir21")) - assert_equals(72, @zipFile.file.stat("file1").size) - assert_equals(0, @zipFile.file.stat("dir2/dir21").size) + assert_equal(72, @zipFile.file.stat("file1").size) + assert_equal(0, @zipFile.file.stat("dir2/dir21").size) end def test_size? - assert_equals(nil, @zipFile.file.size?("notAFile")) - assert_equals(72, @zipFile.file.size?("file1")) - assert_equals(nil, @zipFile.file.size?("dir2/dir21")) + assert_equal(nil, @zipFile.file.size?("notAFile")) + assert_equal(72, @zipFile.file.size?("file1")) + assert_equal(nil, @zipFile.file.size?("dir2/dir21")) - assert_equals(72, @zipFile.file.stat("file1").size?) - assert_equals(nil, @zipFile.file.stat("dir2/dir21").size?) + assert_equal(72, @zipFile.file.stat("file1").size?) + assert_equal(nil, @zipFile.file.stat("dir2/dir21").size?) end @@ -166,19 +166,19 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase end def test_join - assert_equals("a/b/c", @zipFile.file.join("a/b", "c")) - assert_equals("a/b/c/d", @zipFile.file.join("a/b", "c/d")) - assert_equals("/c/d", @zipFile.file.join("", "c/d")) - assert_equals("a/b/c/d", @zipFile.file.join("a", "b", "c", "d")) + assert_equal("a/b/c", @zipFile.file.join("a/b", "c")) + assert_equal("a/b/c/d", @zipFile.file.join("a/b", "c/d")) + assert_equal("/c/d", @zipFile.file.join("", "c/d")) + assert_equal("a/b/c/d", @zipFile.file.join("a", "b", "c", "d")) end def test_utime t_now = Time.now t_bak = @zipFile.file.mtime("file1") @zipFile.file.utime(t_now, "file1") - assert_equals(t_now, @zipFile.file.mtime("file1")) + assert_equal(t_now, @zipFile.file.mtime("file1")) @zipFile.file.utime(t_bak, "file1") - assert_equals(t_bak, @zipFile.file.mtime("file1")) + assert_equal(t_bak, @zipFile.file.mtime("file1")) end @@ -219,26 +219,26 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase end def test_truncate - assert_exception(StandardError, "truncate not supported") { + assert_raise(StandardError, "truncate not supported") { @zipFile.file.truncate("file1", 100) } end def assert_e_n_o_e_n_t(operation, args = ["NoSuchFile"]) - assert_exception(Errno::ENOENT) { + assert_raise(Errno::ENOENT) { @zipFile.file.send(operation, *args) } end def test_ftype assert_e_n_o_e_n_t(:ftype) - assert_equals("file", @zipFile.file.ftype("file1")) - assert_equals("directory", @zipFile.file.ftype("dir1/dir11")) - assert_equals("directory", @zipFile.file.ftype("dir1/dir11/")) + assert_equal("file", @zipFile.file.ftype("file1")) + assert_equal("directory", @zipFile.file.ftype("dir1/dir11")) + assert_equal("directory", @zipFile.file.ftype("dir1/dir11/")) end def test_link - assert_exception(NotImplementedError) { + assert_raise(NotImplementedError) { @zipFile.file.link("file1", "someOtherString") } end @@ -259,10 +259,10 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase end def test_chown - assert_equals(2, @zipFile.file.chown(1,2, "dir1", "file1")) - assert_equals(1, @zipFile.file.stat("dir1").uid) - assert_equals(2, @zipFile.file.stat("dir1").gid) - assert_equals(2, @zipFile.file.chown(nil, nil, "dir1", "file1")) + assert_equal(2, @zipFile.file.chown(1,2, "dir1", "file1")) + assert_equal(1, @zipFile.file.stat("dir1").uid) + assert_equal(2, @zipFile.file.stat("dir1").gid) + assert_equal(2, @zipFile.file.chown(nil, nil, "dir1", "file1")) end def test_zero? @@ -291,27 +291,27 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase def test_expand_path ZipFile.open("data/zipWithDirs.zip") { |zf| - assert_equals("/", zf.file.expand_path(".")) + assert_equal("/", zf.file.expand_path(".")) zf.dir.chdir "dir1" - assert_equals("/dir1", zf.file.expand_path(".")) - assert_equals("/dir1/file12", zf.file.expand_path("file12")) - assert_equals("/", zf.file.expand_path("..")) - assert_equals("/dir2/dir21", zf.file.expand_path("../dir2/dir21")) + 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 def test_mtime - assert_equals(Time.at(1027694306), + assert_equal(Time.at(1027694306), @zipFile.file.mtime("dir2/file21")) - assert_equals(Time.at(1027690863), + assert_equal(Time.at(1027690863), @zipFile.file.mtime("dir2/dir21")) - assert_exception(Errno::ENOENT) { + assert_raise(Errno::ENOENT) { @zipFile.file.mtime("noSuchEntry") } - assert_equals(Time.at(1027694306), + assert_equal(Time.at(1027694306), @zipFile.file.stat("dir2/file21").mtime) - assert_equals(Time.at(1027690863), + assert_equal(Time.at(1027690863), @zipFile.file.stat("dir2/dir21").mtime) end @@ -394,7 +394,7 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase end def test_readlink - assert_exception(NotImplementedError) { + assert_raise(NotImplementedError) { @zipFile.file.readlink("someString") } end @@ -402,7 +402,7 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase def test_stat s = @zipFile.file.stat("file1") assert(s.kind_of?(File::Stat)) # It pretends - assert_exception(Errno::ENOENT, "No such file or directory - noSuchFile") { + assert_raise(Errno::ENOENT, "No such file or directory - noSuchFile") { @zipFile.file.stat("noSuchFile") } end @@ -413,14 +413,14 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase def test_chmod - assert_exception(Errno::ENOENT, "No such file or directory - noSuchFile") { + assert_raise(Errno::ENOENT, "No such file or directory - noSuchFile") { @zipFile.file.chmod(0644, "file1", "NoSuchFile") } - assert_equals(2, @zipFile.file.chmod(0644, "file1", "dir1")) + assert_equal(2, @zipFile.file.chmod(0644, "file1", "dir1")) end def test_pipe - assert_exception(NotImplementedError) { + assert_raise(NotImplementedError) { @zipFile.file.pipe } end @@ -434,10 +434,10 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase index = 0 zf.file.foreach("data/file1.txt") { |l| - assert_equals(ref[index], l) + assert_equal(ref[index], l) index = index.next } - assert_equals(ref.size, index) + assert_equal(ref.size, index) } ZipFile.open("data/generated/zipWithDir.zip") { @@ -448,15 +448,15 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase index = 0 zf.file.foreach("data/file1.txt", " ") { |l| - assert_equals(ref[index], l) + assert_equal(ref[index], l) index = index.next } - assert_equals(ref.size, index) + assert_equal(ref.size, index) } end def test_popen - assert_equals(File.popen("ls") { |f| f.read }, + assert_equal(File.popen("ls") { |f| f.read }, @zipFile.file.popen("ls") { |f| f.read }) end @@ -468,7 +468,7 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase def test_readlines ZipFile.open("data/generated/zipWithDir.zip") { |zf| - assert_equals(File.readlines("data/file1.txt"), + assert_equal(File.readlines("data/file1.txt"), zf.file.readlines("data/file1.txt")) } end @@ -476,14 +476,14 @@ class ZipFsFileNonmutatingTest < RUNIT::TestCase def test_read ZipFile.open("data/generated/zipWithDir.zip") { |zf| - assert_equals(File.read("data/file1.txt"), + assert_equal(File.read("data/file1.txt"), zf.file.read("data/file1.txt")) } end end -class ZipFsFileStatTest < RUNIT::TestCase +class ZipFsFileStatTest < Test::Unit::TestCase def setup @zipFile = ZipFile.new("data/zipWithDirs.zip") @@ -494,51 +494,51 @@ class ZipFsFileStatTest < RUNIT::TestCase end def test_blocks - assert_equals(nil, @zipFile.file.stat("file1").blocks) + assert_equal(nil, @zipFile.file.stat("file1").blocks) end def test_ino - assert_equals(0, @zipFile.file.stat("file1").ino) + assert_equal(0, @zipFile.file.stat("file1").ino) end def test_uid - assert_equals(0, @zipFile.file.stat("file1").uid) + assert_equal(0, @zipFile.file.stat("file1").uid) end def test_gid - assert_equals(0, @zipFile.file.stat("file1").gid) + assert_equal(0, @zipFile.file.stat("file1").gid) end def test_ftype - assert_equals("file", @zipFile.file.stat("file1").ftype) - assert_equals("directory", @zipFile.file.stat("dir1").ftype) + assert_equal("file", @zipFile.file.stat("file1").ftype) + assert_equal("directory", @zipFile.file.stat("dir1").ftype) end def test_mode - assert_equals(0600, @zipFile.file.stat("file1").mode & 0777) - assert_equals(0600, @zipFile.file.stat("file1").mode & 0777) - assert_equals(0755, @zipFile.file.stat("dir1").mode & 0777) - assert_equals(0755, @zipFile.file.stat("dir1").mode & 0777) + assert_equal(0600, @zipFile.file.stat("file1").mode & 0777) + assert_equal(0600, @zipFile.file.stat("file1").mode & 0777) + assert_equal(0755, @zipFile.file.stat("dir1").mode & 0777) + assert_equal(0755, @zipFile.file.stat("dir1").mode & 0777) end def test_dev - assert_equals(0, @zipFile.file.stat("file1").dev) + assert_equal(0, @zipFile.file.stat("file1").dev) end def test_rdev - assert_equals(0, @zipFile.file.stat("file1").rdev) + assert_equal(0, @zipFile.file.stat("file1").rdev) end def test_rdev_major - assert_equals(0, @zipFile.file.stat("file1").rdev_major) + assert_equal(0, @zipFile.file.stat("file1").rdev_major) end def test_rdev_minor - assert_equals(0, @zipFile.file.stat("file1").rdev_minor) + assert_equal(0, @zipFile.file.stat("file1").rdev_minor) end def test_nlink - assert_equals(1, @zipFile.file.stat("file1").nlink) + assert_equal(1, @zipFile.file.stat("file1").nlink) end def test_blksize @@ -547,7 +547,7 @@ class ZipFsFileStatTest < RUNIT::TestCase end -class ZipFsFileMutatingTest < RUNIT::TestCase +class ZipFsFileMutatingTest < Test::Unit::TestCase TEST_ZIP = "zipWithDirs_copy.zip" def setup File.copy("data/zipWithDirs.zip", TEST_ZIP) @@ -573,7 +573,7 @@ class ZipFsFileMutatingTest < RUNIT::TestCase blockCalled = true f.write "This is what I'm writing" } - assert_equals("This is what I'm writing", + assert_equal("This is what I'm writing", zf.file.read("test_open_write_entry")) # Test with existing entry @@ -582,7 +582,7 @@ class ZipFsFileMutatingTest < RUNIT::TestCase blockCalled = true f.write "This is what I'm writing too" } - assert_equals("This is what I'm writing too", + assert_equal("This is what I'm writing too", zf.file.read("file1")) } end @@ -590,7 +590,7 @@ class ZipFsFileMutatingTest < RUNIT::TestCase def test_rename ZipFile.open(TEST_ZIP) { |zf| - assert_exception(Errno::ENOENT, "") { + assert_raise(Errno::ENOENT, "") { zf.file.rename("NoSuchFile", "bimse") } zf.file.rename("file1", "newNameForFile1") @@ -616,9 +616,9 @@ class ZipFsFileMutatingTest < RUNIT::TestCase assert(! zf.file.exists?("dir1/file11")) assert(! zf.file.exists?("dir1/file12")) - assert_exception(Errno::ENOENT) { zf.file.send(symbol, "noSuchFile") } - assert_exception(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11") } - assert_exception(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11/") } + assert_raise(Errno::ENOENT) { zf.file.send(symbol, "noSuchFile") } + assert_raise(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11") } + assert_raise(Errno::EISDIR) { zf.file.send(symbol, "dir1/dir11/") } } ZipFile.open(TEST_ZIP) { @@ -634,7 +634,7 @@ class ZipFsFileMutatingTest < RUNIT::TestCase end -class ZipFsDirectoryTest < RUNIT::TestCase +class ZipFsDirectoryTest < Test::Unit::TestCase TEST_ZIP = "zipWithDirs_copy.zip" def setup @@ -644,10 +644,10 @@ class ZipFsDirectoryTest < RUNIT::TestCase def test_delete ZipFile.open(TEST_ZIP) { |zf| - assert_exception(Errno::ENOENT, "No such file or directory - NoSuchFile.txt") { + assert_raise(Errno::ENOENT, "No such file or directory - NoSuchFile.txt") { zf.dir.delete("NoSuchFile.txt") } - assert_exception(Errno::EINVAL, "Invalid argument - file1") { + assert_raise(Errno::EINVAL, "Invalid argument - file1") { zf.dir.delete("file1") } assert(zf.file.exists?("dir1")) @@ -659,10 +659,10 @@ class ZipFsDirectoryTest < RUNIT::TestCase def test_mkdir ZipFile.open(TEST_ZIP) { |zf| - assert_exception(Errno::EEXIST, "File exists - dir1") { + assert_raise(Errno::EEXIST, "File exists - dir1") { zf.dir.mkdir("file1") } - assert_exception(Errno::EEXIST, "File exists - dir1") { + assert_raise(Errno::EEXIST, "File exists - dir1") { zf.dir.mkdir("dir1") } assert(!zf.file.exists?("newDir")) @@ -677,24 +677,24 @@ class ZipFsDirectoryTest < RUNIT::TestCase def test_pwd_chdir_entries ZipFile.open(TEST_ZIP) { |zf| - assert_equals("/", zf.dir.pwd) + assert_equal("/", zf.dir.pwd) - assert_exception(Errno::ENOENT, "No such file or directory - no such dir") { + assert_raise(Errno::ENOENT, "No such file or directory - no such dir") { zf.dir.chdir "no such dir" } - assert_exception(Errno::EINVAL, "Invalid argument - file1") { + assert_raise(Errno::EINVAL, "Invalid argument - file1") { zf.dir.chdir "file1" } - assert_equals(["dir1", "dir2", "file1"].sort, zf.dir.entries(".").sort) + assert_equal(["dir1", "dir2", "file1"].sort, zf.dir.entries(".").sort) zf.dir.chdir "dir1" - assert_equals("/dir1", zf.dir.pwd) - assert_equals(["dir11", "file11", "file12"], zf.dir.entries(".").sort) + assert_equal("/dir1", zf.dir.pwd) + assert_equal(["dir11", "file11", "file12"], zf.dir.entries(".").sort) zf.dir.chdir "../dir2/dir21" - assert_equals("/dir2/dir21", zf.dir.pwd) - assert_equals(["dir221"].sort, zf.dir.entries(".").sort) + assert_equal("/dir2/dir21", zf.dir.pwd) + assert_equal(["dir221"].sort, zf.dir.entries(".").sort) } end @@ -703,30 +703,30 @@ class ZipFsDirectoryTest < RUNIT::TestCase |zf| blockCalled = false - assert_exception(Errno::ENOENT, "No such file or directory - noSuchDir") { + assert_raise(Errno::ENOENT, "No such file or directory - noSuchDir") { zf.dir.foreach("noSuchDir") { |e| blockCalled = true } } assert(! blockCalled) - assert_exception(Errno::ENOTDIR, "Not a directory - file1") { + assert_raise(Errno::ENOTDIR, "Not a directory - file1") { zf.dir.foreach("file1") { |e| blockCalled = true } } assert(! blockCalled) entries = [] zf.dir.foreach(".") { |e| entries << e } - assert_equals(["dir1", "dir2", "file1"].sort, entries.sort) + assert_equal(["dir1", "dir2", "file1"].sort, entries.sort) entries = [] zf.dir.foreach("dir1") { |e| entries << e } - assert_equals(["dir11", "file11", "file12"], entries.sort) + assert_equal(["dir11", "file11", "file12"], entries.sort) } end def test_chroot ZipFile.open(TEST_ZIP) { |zf| - assert_exception(NotImplementedError) { + assert_raise(NotImplementedError) { zf.dir.chroot } } @@ -742,28 +742,28 @@ class ZipFsDirectoryTest < RUNIT::TestCase ZipFile.open(TEST_ZIP) { |zf| - assert_exception(Errno::ENOTDIR, "Not a directory - file1") { + assert_raise(Errno::ENOTDIR, "Not a directory - file1") { zf.dir.new("file1") } - assert_exception(Errno::ENOENT, "No such file or directory - noSuchFile") { + assert_raise(Errno::ENOENT, "No such file or directory - noSuchFile") { zf.dir.new("noSuchFile") } d = zf.dir.new(".") - assert_equals(["file1", "dir1", "dir2"].sort, d.entries.sort) + assert_equal(["file1", "dir1", "dir2"].sort, d.entries.sort) d.close zf.dir.open("dir1") { |d| - assert_equals(["dir11", "file11", "file12"].sort, d.entries.sort) + assert_equal(["dir11", "file11", "file12"].sort, d.entries.sort) } } end end -class ZipFsDirIteratorTest < RUNIT::TestCase +class ZipFsDirIteratorTest < Test::Unit::TestCase FILENAME_ARRAY = [ "f1", "f2", "f3", "f4", "f5", "f6" ] @@ -773,19 +773,19 @@ class ZipFsDirIteratorTest < RUNIT::TestCase def test_close @dirIt.close - assert_exception(IOError, "closed directory") { + assert_raise(IOError, "closed directory") { @dirIt.each { |e| p e } } - assert_exception(IOError, "closed directory") { + assert_raise(IOError, "closed directory") { @dirIt.read } - assert_exception(IOError, "closed directory") { + assert_raise(IOError, "closed directory") { @dirIt.rewind } - assert_exception(IOError, "closed directory") { + assert_raise(IOError, "closed directory") { @dirIt.seek(0) } - assert_exception(IOError, "closed directory") { + assert_raise(IOError, "closed directory") { @dirIt.tell } @@ -793,22 +793,22 @@ class ZipFsDirIteratorTest < RUNIT::TestCase def test_each # Tested through Enumerable.entries - assert_equals(FILENAME_ARRAY, @dirIt.entries) + assert_equal(FILENAME_ARRAY, @dirIt.entries) end def test_read FILENAME_ARRAY.size.times { |i| - assert_equals(FILENAME_ARRAY[i], @dirIt.read) + assert_equal(FILENAME_ARRAY[i], @dirIt.read) } end def test_rewind @dirIt.read @dirIt.read - assert_equals(FILENAME_ARRAY[2], @dirIt.read) + assert_equal(FILENAME_ARRAY[2], @dirIt.read) @dirIt.rewind - assert_equals(FILENAME_ARRAY[0], @dirIt.read) + assert_equal(FILENAME_ARRAY[0], @dirIt.read) end def test_tell_seek @@ -818,7 +818,7 @@ class ZipFsDirIteratorTest < RUNIT::TestCase valAtPos = @dirIt.read @dirIt.read @dirIt.seek(pos) - assert_equals(valAtPos, @dirIt.read) + assert_equal(valAtPos, @dirIt.read) end end diff --git a/test/ziprequiretest.rb b/test/ziprequiretest.rb index 353a6c4..68d2c71 100755 --- a/test/ziprequiretest.rb +++ b/test/ziprequiretest.rb @@ -4,12 +4,12 @@ $VERBOSE = true $: << "../lib" -require 'rubyunit' +require 'test/unit' require 'zip/ziprequire' $: << 'data/rubycode.zip' << 'data/rubycode2.zip' -class ZipRequireTest < RUNIT::TestCase +class ZipRequireTest < Test::Unit::TestCase def test_require assert(require('data/notzippedruby')) assert(!require('data/notzippedruby')) @@ -27,13 +27,13 @@ class ZipRequireTest < RUNIT::TestCase assert(c1.returnTrue) assert(ZippedRuby1.returnTrue) assert(!ZippedRuby2.returnFalse) - assert_equals(4, ZippedRuby3.multiplyValues(2, 2)) + assert_equal(4, ZippedRuby3.multiplyValues(2, 2)) end def test_get_resource get_resource("aResource.txt") { |f| - assert_equals("Nothing exciting in this file!", f.read) + assert_equal("Nothing exciting in this file!", f.read) } end end diff --git a/test/ziptest.rb b/test/ziptest.rb index c675063..ffb87fc 100755 --- a/test/ziptest.rb +++ b/test/ziptest.rb @@ -4,7 +4,7 @@ $VERBOSE = true $: << "../lib" -require 'rubyunit' +require 'test/unit' require 'zip/zip' require 'gentestfiles'