archive-tar-external 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,14 @@
1
+ == 1.2.2 - 28-Jul-2009
2
+ * Compatibility fixes for Ruby 1.9.x and JRuby.
3
+ * Singleton methods that were previously synonyms are now true aliases.
4
+ * License changed to Artistic 2.0.
5
+ * Several gemspec updates, including an updated description, the addition
6
+ of a license and development dependencies and refactored platform handling.
7
+ * Added test-unit and ptools as development dependencies for the test suite.
8
+ * Some refactoring of the test suite to take advantage of some of the features
9
+ in test-unit 2.x.
10
+ * Renamed the test file to test_archive_tar_external.rb.
11
+
1
12
  == 1.2.1 - 30-Jul-2007
2
13
  * The TarError class is now Tar::Error.
3
14
  * Added a Rakefile with tasks for installation and testing.
data/doc/tar_external.txt CHANGED
@@ -21,7 +21,7 @@
21
21
 
22
22
  == Constants
23
23
  VERSION
24
- Current version number of this package. This is a string.
24
+ Current version number of this library. This is a string.
25
25
 
26
26
  == Class Methods
27
27
  Archive::Tar::External.new(archive_name, pattern=nil, program=nil)
@@ -119,7 +119,7 @@ Tar::CompressError
119
119
  Anything folks are looking for?
120
120
 
121
121
  == License
122
- Ruby's
122
+ Artistic 2.0
123
123
 
124
124
  == Warranty
125
125
  This package is provided "as is" and without any express or
@@ -127,7 +127,7 @@ Tar::CompressError
127
127
  warranties of merchantability and fitness for a particular purpose.
128
128
 
129
129
  == Copyright
130
- (C) 2003 - 2007 Daniel J. Berger
130
+ (C) 2003 - 2009 Daniel J. Berger
131
131
  All Rights Reserved
132
132
 
133
133
  == Author
@@ -0,0 +1,201 @@
1
+ ###############################################################################
2
+ # test_archive_tar_external.rb
3
+ #
4
+ # Test suite for the archive-tar-external library. This test case should be
5
+ # run via the 'rake test' Rake task.
6
+ ###############################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'archive/tar_external'
11
+ require 'test/unit'
12
+ require 'ptools'
13
+ include Archive
14
+
15
+ class TC_ArchiveTarExternal < Test::Unit::TestCase
16
+ def self.startup
17
+ Dir.chdir(File.dirname(File.expand_path(__FILE__)))
18
+
19
+ @@tmp_file1 = 'temp1.txt'
20
+ @@tmp_file2 = 'temp2.txt'
21
+ @@tmp_file3 = 'temp3.txt'
22
+
23
+ @@gtar_found = File.which('gtar')
24
+ @@tar_found = File.which('tar')
25
+ @@gzip_found = File.which('gzip')
26
+ @@bzip2_found = File.which('bzip2')
27
+
28
+ File.open(@@tmp_file1, 'w'){ |f| f.puts 'This is a temporary text file' }
29
+ File.open(@@tmp_file2, 'w'){ |f| f.puts 'This is a temporary text file' }
30
+ File.open(@@tmp_file3, 'w'){ |f| f.puts 'This is a temporary text file' }
31
+ end
32
+
33
+ def setup
34
+ @tar = Tar::External.new('test.tar')
35
+ @tar_name = 'test.tar'
36
+ @pattern = '*.txt'
37
+ @archive = 'temp.tar.gz'
38
+ end
39
+
40
+ def test_version
41
+ assert_equal('1.2.2', Tar::External::VERSION)
42
+ end
43
+
44
+ def test_constructor
45
+ assert_nothing_raised{ Tar::External.new(@tar_name) }
46
+ end
47
+
48
+ def test_constructor_with_extension
49
+ assert_nothing_raised{ Tar::External.new(@tar_name, '*.txt') }
50
+ end
51
+
52
+ def test_constructor_with_program
53
+ omit_unless(@@gzip_found){ 'gzip program not found - skipping' }
54
+ assert_nothing_raised{ Tar::External.new(@tar_name, '*.txt', 'gzip') }
55
+ end
56
+
57
+ def test_constructor_expected_errors
58
+ assert_raise(ArgumentError){ Tar::External.new }
59
+ end
60
+
61
+ def test_tar_program
62
+ assert_respond_to(@tar, :tar_program)
63
+ assert_equal('tar', @tar.tar_program)
64
+ end
65
+
66
+ def test_archive_name
67
+ assert_respond_to(@tar, :archive_name)
68
+ assert_respond_to(@tar, :archive_name=)
69
+
70
+ assert_equal('test.tar', @tar.archive_name)
71
+ assert_nothing_raised{ @tar.archive_name }
72
+ assert_nothing_raised{ @tar.archive_name = 'foo' }
73
+ end
74
+
75
+ def test_compressed_archive_name_get
76
+ assert_respond_to(@tar, :compressed_archive_name)
77
+ assert_nil(@tar.compressed_archive_name)
78
+ end
79
+
80
+ def test_compressed_archive_name_set
81
+ assert_respond_to(@tar, :compressed_archive_name=)
82
+ assert_nothing_raised{ @tar.compressed_archive_name = 'test.tar.gz' }
83
+ assert_equal('test.tar.gz', @tar.compressed_archive_name)
84
+ assert_equal('test.tar', @tar.archive_name)
85
+
86
+ assert_nothing_raised{ @tar.compressed_archive_name = 'test.tgz' }
87
+ assert_equal('test.tgz', @tar.compressed_archive_name)
88
+ assert_equal('test.tar', @tar.archive_name)
89
+ end
90
+
91
+ def test_create_archive_basic
92
+ assert_respond_to(@tar, :create_archive)
93
+
94
+ assert_raises(ArgumentError){ @tar.create_archive }
95
+ assert_raises(Tar::Error){ @tar.create_archive('*.blah') }
96
+
97
+ assert_nothing_raised{ @tar.create_archive(@pattern) }
98
+ assert_true(File.exists?(@tar_name))
99
+ end
100
+
101
+ def test_create_alias
102
+ assert_respond_to(@tar, :create)
103
+ assert_true(Tar::External.instance_method(:create) == Tar::External.instance_method(:create_archive))
104
+ end
105
+
106
+ def test_compress_archive_basic
107
+ assert_respond_to(@tar, :compress_archive)
108
+ end
109
+
110
+ def test_compress_alias
111
+ assert_respond_to(@tar, :compress)
112
+ assert_true(Tar::External.instance_method(:compress) == Tar::External.instance_method(:compress_archive))
113
+ end
114
+
115
+ def test_compress_archive_gzip
116
+ assert_nothing_raised{ @tar.create_archive('*.txt') }
117
+ assert_nothing_raised{ @tar.compress_archive }
118
+
119
+ assert_equal('test.tar.gz', @tar.compressed_archive_name)
120
+ assert_true(File.exists?('test.tar.gz'))
121
+ end
122
+
123
+ def test_compress_archive_bzip2
124
+ assert_nothing_raised{ @tar.create_archive('*.txt') }
125
+ assert_nothing_raised{ @tar.compress_archive('bzip2') }
126
+ assert_true(File.exists?('test.tar.bz2'))
127
+ end
128
+
129
+ def test_uncompress_archive
130
+ assert_respond_to(@tar, :uncompress_archive)
131
+ assert_nothing_raised{ @tar.create_archive('*.txt') }
132
+ assert_nothing_raised{ @tar.compress_archive }
133
+ assert_nothing_raised{ @tar.uncompress_archive }
134
+ assert_false(File.exists?('test.tar.gz'))
135
+ end
136
+
137
+ def test_uncompress_archive_class_method
138
+ assert_respond_to(Tar::External, :uncompress_archive)
139
+ end
140
+
141
+ def test_uncompress_alias
142
+ assert_respond_to(Tar::External, :uncompress)
143
+ assert_true(Tar::External.method(:uncompress) == Tar::External.method(:uncompress_archive))
144
+ end
145
+
146
+ def test_archive_info
147
+ assert_respond_to(@tar, :archive_info)
148
+ assert_nothing_raised{ @tar.create_archive('*.txt') }
149
+ assert_equal(['temp1.txt','temp2.txt','temp3.txt'], @tar.archive_info)
150
+ end
151
+
152
+ def test_add_to_archive
153
+ assert_respond_to(@tar,:add_to_archive)
154
+ assert_nothing_raised{ @tar.create_archive('temp1.txt') }
155
+ assert_nothing_raised{ @tar.add_to_archive('temp2.txt') }
156
+ assert_nothing_raised{ @tar.add_to_archive('temp2.txt','temp3.txt') }
157
+ end
158
+
159
+ def test_update_archive
160
+ assert_respond_to(@tar, :update_archive)
161
+ assert_nothing_raised{ @tar.create_archive('*.txt') }
162
+ assert_nothing_raised{ @tar.update_archive('temp2.txt') }
163
+ end
164
+
165
+ def test_extract_archive_basic
166
+ assert_respond_to(@tar, :extract_archive)
167
+ end
168
+
169
+ def test_extract_archive_aliases
170
+ assert_true(Tar::External.instance_method(:extract_archive) == Tar::External.instance_method(:expand_archive))
171
+ assert_true(Tar::External.instance_method(:extract) == Tar::External.instance_method(:expand_archive))
172
+ assert_true(Tar::External.instance_method(:expand) == Tar::External.instance_method(:expand_archive))
173
+ end
174
+
175
+ def test_extract_archive_advanced
176
+ assert_nothing_raised{ @tar.tar_program = @@gtar } if Config::CONFIG['host_os'] =~ /sunos|solaris/i
177
+ assert_nothing_raised{ @tar.create('*.txt') }
178
+ assert_raises(Tar::Error){ @tar.expand('blah.txt') }
179
+
180
+ assert_nothing_raised{ @tar.extract_archive }
181
+ assert_nothing_raised{ @tar.extract_archive('temp2.txt') }
182
+ end
183
+
184
+ def teardown
185
+ @tar = nil
186
+ File.delete('test.tar') if File.exists?('test.tar')
187
+ File.delete('test.tar.gz') if File.exists?('test.tar.gz')
188
+ File.delete('test.tar.bz2') if File.exists?('test.tar.bz2')
189
+ File.delete('test.tar.zip') if File.exists?('test.tar.zip')
190
+ end
191
+
192
+ def self.shutdown
193
+ @@tar_foudn = nil
194
+ @@gzip_found = nil
195
+ @@bzip2_found = nil
196
+
197
+ File.delete(@@tmp_file1) if File.exists?(@@tmp_file1)
198
+ File.delete(@@tmp_file2) if File.exists?(@@tmp_file2)
199
+ File.delete(@@tmp_file3) if File.exists?(@@tmp_file3)
200
+ end
201
+ end
metadata CHANGED
@@ -1,58 +1,81 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: archive-tar-external
5
3
  version: !ruby/object:Gem::Version
6
- version: 1.2.1
7
- date: 2007-07-30 00:00:00 -06:00
8
- summary: A simple way to create tar archives using external calls
9
- require_paths:
10
- - lib
11
- email: djberg96@gmail.com
12
- homepage: http://www.rubyforge.org/shards
13
- rubyforge_project:
14
- description: A simple way to create tar archives using external calls
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 1.2.2
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Daniel Berger
31
- files:
32
- - doc/tar_external.txt
33
- - lib/archive
34
- - lib/archive/tar_external.rb
35
- - test/tc_archive.rb
36
- - test/temp1.txt
37
- - test/temp2.txt
38
- - test/temp3.txt
39
- - README
40
- - CHANGES
41
- - MANIFEST
42
- test_files:
43
- - test/tc_archive.rb
44
- rdoc_options: []
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-28 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: test-unit
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: ptools
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.7
34
+ version:
35
+ description: " The archive-tar-external is a simple wrapper interface for creating\n tar files using your system's tar command. You can also easily compress\n your tar files with your system's compression programs such as zip, gzip,\n or bzip2.\n"
36
+ email: djberg96@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
45
40
 
46
41
  extra_rdoc_files:
47
42
  - README
48
43
  - CHANGES
49
44
  - MANIFEST
50
45
  - doc/tar_external.txt
51
- executables: []
52
-
53
- extensions: []
46
+ files:
47
+ - doc/tar_external.txt
48
+ - test/test_archive_tar_external.rb
49
+ - README
50
+ - CHANGES
51
+ - MANIFEST
52
+ has_rdoc: true
53
+ homepage: http://www.rubyforge.org/shards
54
+ licenses:
55
+ - Artistic 2.0
56
+ post_install_message:
57
+ rdoc_options: []
54
58
 
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
55
73
  requirements: []
56
74
 
57
- dependencies: []
58
-
75
+ rubyforge_project: shards
76
+ rubygems_version: 1.3.5
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: A simple way to create tar archives using external calls
80
+ test_files:
81
+ - test/test_archive_tar_external.rb
@@ -1,287 +0,0 @@
1
- if RUBY_PLATFORM.match('mswin')
2
- require 'win32/open3'
3
- else
4
- require 'open3'
5
- end
6
-
7
- # The Archive module serves as a namespace only.
8
- module Archive
9
-
10
- # The Tar class serves as a toplevel class namespace only.
11
- class Tar
12
-
13
- # Raised if something goes wrong during the execution of any methods
14
- # which use the tar command internally.
15
- class Error < StandardError; end
16
-
17
- # Raised if something goes wrong during the Tar#compress_archive or
18
- # Tar#uncompress_archive methods.
19
- class CompressError < StandardError; end
20
-
21
- # This class encapsulates tar & zip operations.
22
- class Tar::External
23
- VERSION = '1.2.1'
24
-
25
- # The name of the archive file to be used, e.g. "test.tar"
26
- attr_accessor :archive_name
27
-
28
- # The name of the tar program you wish to use. The default is "tar".
29
- attr_accessor :tar_program
30
-
31
- # The name of the archive file after compression, e.g. "test.tar.gz"
32
- attr_reader :compressed_archive_name
33
-
34
- # Returns an Archive::Tar::External object. The +archive_name+ is the
35
- # name of the tarball. While a .tar extension is recommended based on
36
- # years of convention, it is not enforced.
37
- #
38
- # Note that this does not actually create the archive unless you
39
- # pass a value to +file_pattern+. This then becomes a shortcut for
40
- # Archive::Tar::External.new + Archive::Tar::External#create_archive.
41
- #
42
- # If +program+ is provided, then it compresses the archive as well by
43
- # calling Archive::Tar::External#compress_archive internally.
44
- #
45
- def initialize(archive_name, file_pattern=nil, program=nil)
46
- @archive_name = archive_name.to_s
47
- @compressed_archive_name = nil
48
- @tar_program = "tar"
49
-
50
- if file_pattern
51
- create_archive(file_pattern)
52
- end
53
-
54
- if program
55
- compress_archive(program)
56
- end
57
- end
58
-
59
- # Assign a compressed archive name. This autogenerates the archive_name
60
- # based on the extension of the name provided, unless you provide the
61
- # extension yourself. If the extension is '.tgz', then the base of the
62
- # name + '.tar' will be the new archive name.
63
- #
64
- # This should only be used if you have a pre-existing, compressed archive
65
- # that you want to uncompress, and want to have a Tar::External object
66
- # around. Otherwise, use the class method Tar::External.uncompress.
67
- #
68
- def compressed_archive_name=(name, ext=File.extname(name))
69
- if ext == '.tgz' || ext == '.TGZ'
70
- @archive_name = File.basename(name, ext.downcase) + '.tar'
71
- else
72
- @archive_name = File.basename(name, ext)
73
- end
74
- @compressed_archive_name = name
75
- end
76
-
77
- # Creates the archive using +file_pattern+. Any errors that occur
78
- # here will raise a Error.
79
- #
80
- def create_archive(file_pattern)
81
- cmd = "#{@tar_program} cf #{@archive_name} #{file_pattern}"
82
- Open3.popen3(cmd){ |tar_in, tar_out, tar_err|
83
- err = tar_err.gets
84
- if err
85
- raise Error, err.chomp
86
- end
87
- }
88
- self
89
- end
90
- alias :create :create_archive
91
-
92
- # Compresses the archive with +program+, or gzip if no program is
93
- # provided. If you want to pass arguments to +program+, merely include
94
- # them as part of the program name, e.g. "gzip -f".
95
- #
96
- # Any errors that occur here will raise a Tar::CompressError.
97
- #
98
- def compress_archive(program="gzip")
99
- cmd = "#{program} #{@archive_name}"
100
- Open3.popen3(cmd){ |prog_in, prog_out, prog_err|
101
- err = prog_err.gets
102
- if err
103
- raise CompressError, err.chomp
104
- end
105
-
106
- # Find the new file name with the extension. There's probably a more
107
- # reliable way to do this, but this should work 99% of the time.
108
- name = Dir["#{@archive_name}.{gz,bz2,cpio,zip}"].first
109
- @compressed_archive_name = name
110
- }
111
- self
112
- end
113
- alias :compress :compress_archive
114
-
115
- # Uncompresses the tarball using the program you pass to this method. The
116
- # default is "gunzip". Just as for +compress_archive+, you can pass
117
- # arguments along as part of the argument.
118
- #
119
- # Note that this is only for use with archives that have been zipped up
120
- # with gunzip, or whatever. If you want to *extract* the files from the
121
- # tarball, use Tar::External#extract instead.
122
- #
123
- # Any errors that occur here will raise a Tar::CompressError.
124
- #
125
- def uncompress_archive(program="gunzip")
126
- unless @compressed_archive_name
127
- raise CompressError, "no compressed file found"
128
- end
129
-
130
- cmd = "#{program} #{@compressed_archive_name}"
131
-
132
- Open3.popen3(cmd){ |prog_in, prog_out, prog_err|
133
- err = prog_err.gets
134
- if err
135
- raise CompressError, err.chomp
136
- end
137
- @compressed_archive_name = nil
138
- }
139
- self
140
- end
141
- alias :uncompress :uncompress_archive
142
-
143
- # Uncompress an existing archive, using +program+ to uncompress it.
144
- # The default decompression program is gunzip.
145
- #
146
- def self.uncompress_archive(archive, program='gunzip')
147
- cmd = "#{program} #{archive}"
148
-
149
- Open3.popen3(cmd){ |prog_in, prog_out, prog_err|
150
- err = prog_err.gets
151
- if err
152
- raise CompressError, err.chomp
153
- end
154
- }
155
- end
156
-
157
- # An alias for Tar::External.uncompress_archive.
158
- #
159
- def self.uncompress(file, program='gunzip')
160
- self.uncompress_archive(file, program)
161
- end
162
-
163
- # Returns an array of file names that are included within the tarball.
164
- # This method does not extract the archive.
165
- #
166
- def archive_info
167
- result = []
168
- cmd = "#{@tar_program} tf #{@archive_name}"
169
- Open3.popen3(cmd){ |ain, aout, aerr|
170
- err = aerr.gets
171
- if err
172
- raise Error, err.chomp
173
- end
174
-
175
- while output = aout.gets
176
- result << output.chomp
177
- end
178
- }
179
- result
180
- end
181
- alias :info :archive_info
182
-
183
- # Adds +files+ to an already existing archive.
184
- #
185
- def add_to_archive(*files)
186
- if files.empty?
187
- raise Error, "there must be at least one file specified"
188
- end
189
-
190
- cmd = "#{@tar_program} rf #{@archive_name} #{files.join(" ")}"
191
- Open3.popen3(cmd){ |ain, aout, aerr|
192
- err = aerr.gets
193
-
194
- if err
195
- raise Error, err.chomp
196
- end
197
- }
198
- self
199
- end
200
- alias :add :add_to_archive
201
-
202
- # Updates the given +files+ in the archive, i.e. they are added if they
203
- # are not already in the archive or have been modified.
204
- #
205
- def update_archive(*files)
206
- if files.empty?
207
- raise Error, "there must be at least one file specified"
208
- end
209
-
210
- cmd = "#{@tar_program} uf #{@archive_name} #{files.join(" ")}"
211
-
212
- Open3.popen3(cmd){ |ain, aout, aerr|
213
- err = aerr.gets
214
- if err
215
- raise Error, err.chomp
216
- end
217
- }
218
- self
219
- end
220
- alias :update :update_archive
221
-
222
- # Expands the contents of the tarball. It does NOT delete the tarball.
223
- # If +files+ are provided, then only those files are extracted.
224
- # Otherwise, all files are extracted.
225
- #
226
- # Note that some tar programs, notably the tar program shipped by Sun,
227
- # does not issue any sort of warning or error if you try to extract a
228
- # file that does not exist in the archive.
229
- #
230
- def extract_archive(*files)
231
- cmd = "#{@tar_program} xf #{@archive_name}"
232
-
233
- unless files.empty?
234
- cmd << " " << files.join(" ")
235
- end
236
-
237
- Open3.popen3(cmd){ |ain, aout, aerr|
238
- err = aerr.gets
239
-
240
- if err
241
- raise Error, err.chomp
242
- end
243
- }
244
- self
245
- end
246
- alias :expand_archive :extract_archive
247
- alias :extract :extract_archive
248
- alias :expand :extract_archive
249
-
250
- # A class method that behaves identically to the equivalent instance
251
- # method, except that you must specifiy that tarball as the first
252
- # argument. Also, the tar program is hard coded to 'tar xf'.
253
- #
254
- def self.extract_archive(archive, *files)
255
- cmd = "tar xf #{archive}"
256
-
257
- unless files.empty?
258
- cmd << " " << files.join(" ")
259
- end
260
-
261
- Open3.popen3(cmd){ |ain, aout, aerr|
262
- err = aerr.gets
263
-
264
- if err
265
- raise Error, err.chomp
266
- end
267
- }
268
- self
269
- end
270
-
271
- # Alias for self.extract_archive
272
- def self.expand_archive(*args)
273
- self.extract_archive(*args)
274
- end
275
-
276
- # Alias for self.extract_archive
277
- def self.extract(*args)
278
- self.extract_archive(*args)
279
- end
280
-
281
- # Alias for self.extract_archive
282
- def self.expand(*args)
283
- self.extract_archive(*args)
284
- end
285
- end
286
- end
287
- end
data/test/tc_archive.rb DELETED
@@ -1,153 +0,0 @@
1
- ###############################################################################
2
- # tc_archive.rb
3
- #
4
- # Test suite for the archive-tarsimple package. This test case should be
5
- # run via the 'rake test' Rake task.
6
- ###############################################################################
7
- require 'archive/tar_external'
8
- require 'test/unit'
9
- include Archive
10
-
11
- class TC_Archive < Test::Unit::TestCase
12
- def setup
13
- Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
14
- @t = Tar::External.new('test.tar')
15
- @tar_name = 'test.tar'
16
- @pattern = '*.txt'
17
- @archive = 'temp.tar.gz'
18
- end
19
-
20
- def test_version
21
- assert_equal('1.2.1', Tar::External::VERSION)
22
- end
23
-
24
- def test_constructor
25
- assert_nothing_raised{ Tar::External.new(@tar_name) }
26
- assert_nothing_raised{ Tar::External.new(@tar_name, '*.txt') }
27
- assert_raises(ArgumentError){ Tar::External.new }
28
- end
29
-
30
- def test_tar_program
31
- assert_respond_to(@t, :tar_program)
32
- assert_equal('tar', @t.tar_program)
33
- end
34
-
35
- def test_archive_name
36
- assert_respond_to(@t, :archive_name)
37
- assert_respond_to(@t, :archive_name=)
38
-
39
- assert_equal('test.tar', @t.archive_name)
40
- assert_nothing_raised{ @t.archive_name }
41
- assert_nothing_raised{ @t.archive_name = 'foo' }
42
- end
43
-
44
- def test_compressed_archive_name_get
45
- assert_respond_to(@t, :compressed_archive_name)
46
- assert_nil(@t.compressed_archive_name)
47
- end
48
-
49
- def test_compressed_archive_name_set
50
- assert_respond_to(@t, :compressed_archive_name=)
51
- assert_nothing_raised{ @t.compressed_archive_name = 'test.tar.gz' }
52
- assert_equal('test.tar.gz', @t.compressed_archive_name)
53
- assert_equal('test.tar', @t.archive_name)
54
-
55
- assert_nothing_raised{ @t.compressed_archive_name = 'test.tgz' }
56
- assert_equal('test.tgz', @t.compressed_archive_name)
57
- assert_equal('test.tar', @t.archive_name)
58
- end
59
-
60
- def test_create_archive_basic
61
- assert_respond_to(@t, :create_archive)
62
- assert_respond_to(@t, :create) # Alias
63
-
64
- assert_raises(ArgumentError){ @t.create_archive }
65
- assert_raises(Tar::Error){ @t.create_archive('*.blah') }
66
-
67
- assert_nothing_raised{ @t.create_archive(@pattern) }
68
- assert(@t.create_archive(@pattern))
69
- assert(File.exists?(@tar_name))
70
- end
71
-
72
- def test_compress_archive_basic
73
- assert_respond_to(@t, :compress_archive)
74
- assert_respond_to(@t, :compress) # Alias
75
- end
76
-
77
- def test_compress_archive_gzip
78
- assert_nothing_raised{ @t.create_archive('*.txt') }
79
- assert_nothing_raised{ @t.compress_archive }
80
-
81
- assert_equal('test.tar.gz', @t.compressed_archive_name)
82
- assert(File.exists?('test.tar.gz'))
83
- end
84
-
85
- def test_compress_archive_bzip2
86
- assert_nothing_raised{ @t.create_archive('*.txt') }
87
- assert_nothing_raised{ @t.compress_archive('bzip2') }
88
- assert(File.exists?('test.tar.bz2'))
89
- end
90
-
91
- def test_uncompress_archive
92
- assert_respond_to(@t, :uncompress_archive)
93
- assert_nothing_raised{ @t.create_archive('*.txt') }
94
- assert_nothing_raised{ @t.compress_archive }
95
- assert_nothing_raised{ @t.uncompress_archive }
96
- assert(!File.exists?('test.tar.gz'))
97
- end
98
-
99
- def test_uncompress_archive_class_method
100
- assert_respond_to(Tar::External, :uncompress_archive)
101
- assert_respond_to(Tar::External, :uncompress)
102
- end
103
-
104
- def test_archive_info
105
- assert_respond_to(@t, :archive_info)
106
- assert_nothing_raised{ @t.create_archive('*.txt') }
107
- assert_equal(['temp1.txt','temp2.txt','temp3.txt'], @t.archive_info)
108
- end
109
-
110
- def test_add_to_archive
111
- assert_respond_to(@t,:add_to_archive)
112
- assert_nothing_raised{ @t.create_archive('temp1.txt') }
113
- assert_nothing_raised{ @t.add_to_archive('temp2.txt') }
114
- assert_nothing_raised{ @t.add_to_archive('temp2.txt','temp3.txt') }
115
- end
116
-
117
- def test_update_archive
118
- assert_respond_to(@t, :update_archive)
119
- assert_nothing_raised{ @t.create_archive('*.txt') }
120
- assert_nothing_raised{ @t.update_archive('temp2.txt') }
121
- end
122
-
123
- def test_extract_archive_basic
124
- assert_respond_to(@t, :extract_archive)
125
- assert_respond_to(@t, :expand_archive) # Alias
126
- assert_respond_to(@t, :extract) # Alias
127
- assert_respond_to(@t, :expand) # Alias
128
- end
129
-
130
- def test_extract_archive_advanced
131
- @t.tar_program = 'gtar' if PLATFORM.match('solaris')
132
- assert_nothing_raised{ @t.create('*.txt') }
133
- assert_raises(Tar::Error){ @t.expand('blah.txt') }
134
-
135
- assert_nothing_raised{ @t.extract_archive }
136
- assert_nothing_raised{ @t.extract_archive('temp2.txt') }
137
- end
138
-
139
- def test_extract_archive_class_method
140
- assert_respond_to(Tar::External, :extract_archive)
141
- assert_respond_to(Tar::External, :expand_archive)
142
- assert_respond_to(Tar::External, :extract)
143
- assert_respond_to(Tar::External, :expand)
144
- end
145
-
146
- def teardown
147
- @t = nil
148
- File.unlink('test.tar') if File.exists?('test.tar')
149
- File.unlink('test.tar.gz') if File.exists?('test.tar.gz')
150
- File.unlink('test.tar.bz2') if File.exists?('test.tar.bz2')
151
- File.unlink('test.tar.zip') if File.exists?('test.tar.zip')
152
- end
153
- end
data/test/temp1.txt DELETED
@@ -1 +0,0 @@
1
- This is a temporary text file
data/test/temp2.txt DELETED
@@ -1,4 +0,0 @@
1
- This is a temporary text file
2
- It is only used for testing
3
- It is only used for testing
4
- Feel free to delete these later
data/test/temp3.txt DELETED
@@ -1,3 +0,0 @@
1
- This is a temporary text file
2
- It is only used for testing
3
- Feel free to delete these later