############################################################################### # tc_archive.rb # # Test suite for the archive-tarsimple package. ############################################################################### base = File.basename(Dir.pwd) if base == 'test' || base =~ /archive-tar-external/i Dir.chdir('..') if base == 'test' $LOAD_PATH.unshift(Dir.pwd + '/lib') Dir.chdir('test') rescue nil end require 'archive/tar_external' require 'test/unit' include Archive class TC_Archive < Test::Unit::TestCase def setup @t = Tar::External.new('test.tar') @tar_name = 'test.tar' @pattern = '*.txt' @archive = 'temp.tar.gz' end def test_version assert_equal('1.2.0', Tar::External::VERSION) end def test_constructor assert_nothing_raised{ Tar::External.new(@tar_name) } assert_nothing_raised{ Tar::External.new(@tar_name, '*.txt') } assert_raises(ArgumentError){ Tar::External.new } end def test_tar_program assert_respond_to(@t, :tar_program) assert_equal('tar', @t.tar_program) end def test_archive_name assert_respond_to(@t, :archive_name) assert_respond_to(@t, :archive_name=) assert_equal('test.tar', @t.archive_name) assert_nothing_raised{ @t.archive_name } assert_nothing_raised{ @t.archive_name = 'foo' } end def test_compressed_archive_name_get assert_respond_to(@t, :compressed_archive_name) assert_nil(@t.compressed_archive_name) end def test_compressed_archive_name_set assert_respond_to(@t, :compressed_archive_name=) assert_nothing_raised{ @t.compressed_archive_name = 'test.tar.gz' } assert_equal('test.tar.gz', @t.compressed_archive_name) assert_equal('test.tar', @t.archive_name) assert_nothing_raised{ @t.compressed_archive_name = 'test.tgz' } assert_equal('test.tgz', @t.compressed_archive_name) assert_equal('test.tar', @t.archive_name) end def test_create_archive_basic assert_respond_to(@t, :create_archive) assert_respond_to(@t, :create) # Alias assert_raises(ArgumentError){ @t.create_archive } assert_raises(TarError){ @t.create_archive('*.blah') } assert_nothing_raised{ @t.create_archive(@pattern) } assert(@t.create_archive(@pattern)) assert(File.exists?(@tar_name)) end def test_compress_archive_basic assert_respond_to(@t, :compress_archive) assert_respond_to(@t, :compress) # Alias end def test_compress_archive_gzip assert_nothing_raised{ @t.create_archive('*.txt') } assert_nothing_raised{ @t.compress_archive } assert_equal('test.tar.gz', @t.compressed_archive_name) assert(File.exists?('test.tar.gz')) end def test_compress_archive_bzip2 assert_nothing_raised{ @t.create_archive('*.txt') } assert_nothing_raised{ @t.compress_archive('bzip2') } assert(File.exists?('test.tar.bz2')) end def test_uncompress_archive assert_respond_to(@t, :uncompress_archive) assert_nothing_raised{ @t.create_archive('*.txt') } assert_nothing_raised{ @t.compress_archive } assert_nothing_raised{ @t.uncompress_archive } assert(!File.exists?('test.tar.gz')) end def test_uncompress_archive_class_method assert_respond_to(Tar::External, :uncompress_archive) assert_respond_to(Tar::External, :uncompress) end def test_archive_info assert_respond_to(@t, :archive_info) assert_nothing_raised{ @t.create_archive('*.txt') } assert_equal(['temp1.txt','temp2.txt','temp3.txt'], @t.archive_info) end def test_add_to_archive assert_respond_to(@t,:add_to_archive) assert_nothing_raised{ @t.create_archive('temp1.txt') } assert_nothing_raised{ @t.add_to_archive('temp2.txt') } assert_nothing_raised{ @t.add_to_archive('temp2.txt','temp3.txt') } end def test_update_archive assert_respond_to(@t, :update_archive) assert_nothing_raised{ @t.create_archive('*.txt') } assert_nothing_raised{ @t.update_archive('temp2.txt') } end def test_extract_archive_basic assert_respond_to(@t, :extract_archive) assert_respond_to(@t, :expand_archive) # Alias assert_respond_to(@t, :extract) # Alias assert_respond_to(@t, :expand) # Alias end def test_extract_archive_advanced @t.tar_program = 'gtar' if PLATFORM.match('solaris') assert_nothing_raised{ @t.create('*.txt') } assert_raises(TarError){ @t.expand('blah.txt') } assert_nothing_raised{ @t.extract_archive } assert_nothing_raised{ @t.extract_archive('temp2.txt') } end def test_extract_archive_class_method assert_respond_to(Tar::External, :extract_archive) assert_respond_to(Tar::External, :expand_archive) assert_respond_to(Tar::External, :extract) assert_respond_to(Tar::External, :expand) end def teardown @t = nil File.unlink('test.tar') if File.exists?('test.tar') File.unlink('test.tar.gz') if File.exists?('test.tar.gz') File.unlink('test.tar.bz2') if File.exists?('test.tar.bz2') File.unlink('test.tar.zip') if File.exists?('test.tar.zip') end end