archive-tar-external 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,281 @@
1
+ require 'rbconfig'
2
+
3
+ if Config::CONFIG['host_os'] =~ /mswin|dos|win32|cygwin|mingw/i
4
+ if RUBY_VERSION.to_f < 1.9 && RUBY_PLATFORM !~ /java/i
5
+ require 'win32/open3'
6
+ else
7
+ require 'open3'
8
+ end
9
+ else
10
+ require 'open3'
11
+ end
12
+
13
+ # The Archive module serves as a namespace only.
14
+ module Archive
15
+
16
+ # The Tar class serves as a toplevel class namespace only.
17
+ class Tar
18
+
19
+ # Raised if something goes wrong during the execution of any methods
20
+ # which use the tar command internally.
21
+ class Error < StandardError; end
22
+
23
+ # Raised if something goes wrong during the Tar#compress_archive or
24
+ # Tar#uncompress_archive methods.
25
+ class CompressError < StandardError; end
26
+
27
+ # This class encapsulates tar & zip operations.
28
+ class Tar::External
29
+ # The version of the archive-tar-external library.
30
+ VERSION = '1.3.0'
31
+
32
+ # The name of the archive file to be used, e.g. "test.tar"
33
+ attr_accessor :archive_name
34
+
35
+ # The name of the tar program you wish to use. The default is "tar".
36
+ attr_accessor :tar_program
37
+
38
+ # The name of the archive file after compression, e.g. "test.tar.gz"
39
+ attr_reader :compressed_archive_name
40
+
41
+ # Returns an Archive::Tar::External object. The +archive_name+ is the
42
+ # name of the tarball. While a .tar extension is recommended based on
43
+ # years of convention, it is not enforced.
44
+ #
45
+ # Note that this does not actually create the archive unless you
46
+ # pass a value to +file_pattern+. This then becomes a shortcut for
47
+ # Archive::Tar::External.new + Archive::Tar::External#create_archive.
48
+ #
49
+ # If +program+ is provided, then it compresses the archive as well by
50
+ # calling Archive::Tar::External#compress_archive internally.
51
+ #
52
+ def initialize(archive_name, file_pattern=nil, program=nil)
53
+ @archive_name = archive_name.to_s
54
+ @compressed_archive_name = nil
55
+ @tar_program = 'tar'
56
+
57
+ if file_pattern
58
+ create_archive(file_pattern)
59
+ end
60
+
61
+ if program
62
+ compress_archive(program)
63
+ end
64
+ end
65
+
66
+ # Assign a compressed archive name. This autogenerates the archive_name
67
+ # based on the extension of the name provided, unless you provide the
68
+ # extension yourself. If the extension is '.tgz', then the base of the
69
+ # name + '.tar' will be the new archive name.
70
+ #
71
+ # This should only be used if you have a pre-existing, compressed archive
72
+ # that you want to uncompress, and want to have a Tar::External object
73
+ # around. Otherwise, use the class method Tar::External.uncompress.
74
+ #
75
+ def compressed_archive_name=(name, ext=File.extname(name))
76
+ if ext.downcase == '.tgz'
77
+ @archive_name = File.basename(name, ext.downcase) + '.tar'
78
+ else
79
+ @archive_name = File.basename(name, ext)
80
+ end
81
+ @compressed_archive_name = name
82
+ end
83
+
84
+ # Creates the archive using +file_pattern+. Any errors that occur
85
+ # here will raise a Error.
86
+ #
87
+ def create_archive(file_pattern)
88
+ cmd = "#{@tar_program} cf #{@archive_name} #{file_pattern}"
89
+
90
+ Open3.popen3(cmd){ |tar_in, tar_out, tar_err|
91
+ err = tar_err.gets
92
+ if err
93
+ raise Error, err.chomp
94
+ end
95
+ }
96
+
97
+ self
98
+ end
99
+
100
+ alias :create :create_archive
101
+
102
+ # Compresses the archive with +program+, or gzip if no program is
103
+ # provided. If you want to pass arguments to +program+, merely include
104
+ # them as part of the program name, e.g. "gzip -f".
105
+ #
106
+ # Any errors that occur here will raise a Tar::CompressError.
107
+ #
108
+ def compress_archive(program='gzip')
109
+ cmd = "#{program} #{@archive_name}"
110
+
111
+ Open3.popen3(cmd){ |prog_in, prog_out, prog_err|
112
+ err = prog_err.gets
113
+ raise CompressError, err.chomp if err
114
+
115
+ # Find the new file name with the extension. There's probably a more
116
+ # reliable way to do this, but this should work 99% of the time.
117
+ name = Dir["#{@archive_name}.{gz,bz2,cpio,zip}"].first
118
+ @compressed_archive_name = name
119
+ }
120
+
121
+ self
122
+ end
123
+
124
+ alias :compress :compress_archive
125
+
126
+ # Uncompresses the tarball using the program you pass to this method. The
127
+ # default is "gunzip". Just as for +compress_archive+, you can pass
128
+ # arguments along as part of the argument.
129
+ #
130
+ # Note that this is only for use with archives that have been zipped up
131
+ # with gunzip, or whatever. If you want to *extract* the files from the
132
+ # tarball, use Tar::External#extract instead.
133
+ #
134
+ # Any errors that occur here will raise a Tar::CompressError.
135
+ #
136
+ def uncompress_archive(program="gunzip")
137
+ unless @compressed_archive_name
138
+ raise CompressError, "no compressed file found"
139
+ end
140
+
141
+ cmd = "#{program} #{@compressed_archive_name}"
142
+
143
+ Open3.popen3(cmd){ |prog_in, prog_out, prog_err|
144
+ err = prog_err.gets
145
+ raise CompressError, err.chomp if err
146
+ @compressed_archive_name = nil
147
+ }
148
+ self
149
+ end
150
+
151
+ alias :uncompress :uncompress_archive
152
+
153
+ # Uncompress an existing archive, using +program+ to uncompress it.
154
+ # The default decompression program is gunzip.
155
+ #
156
+ def self.uncompress_archive(archive, program='gunzip')
157
+ cmd = "#{program} #{archive}"
158
+
159
+ Open3.popen3(cmd){ |prog_in, prog_out, prog_err|
160
+ err = prog_err.gets
161
+ raise CompressError, err.chomp if err
162
+ }
163
+ end
164
+
165
+ class << self
166
+ alias uncompress uncompress_archive
167
+ end
168
+
169
+ # Returns an array of file names that are included within the tarball.
170
+ # This method does not extract the archive.
171
+ #
172
+ def archive_info
173
+ result = []
174
+ cmd = "#{@tar_program} tf #{@archive_name}"
175
+ Open3.popen3(cmd){ |ain, aout, aerr|
176
+ err = aerr.gets
177
+ if err
178
+ raise Error, err.chomp
179
+ end
180
+
181
+ while output = aout.gets
182
+ result << output.chomp
183
+ end
184
+ }
185
+ result
186
+ end
187
+
188
+ alias :info :archive_info
189
+
190
+ # Adds +files+ to an already existing archive.
191
+ #
192
+ def add_to_archive(*files)
193
+ if files.empty?
194
+ raise Error, "there must be at least one file specified"
195
+ end
196
+
197
+ cmd = "#{@tar_program} rf #{@archive_name} #{files.join(" ")}"
198
+
199
+ Open3.popen3(cmd){ |ain, aout, aerr|
200
+ err = aerr.gets
201
+ raise Error, err.chomp if err
202
+ }
203
+ self
204
+ end
205
+
206
+ alias :add :add_to_archive
207
+
208
+ # Updates the given +files+ in the archive, i.e. they are added if they
209
+ # are not already in the archive or have been modified.
210
+ #
211
+ def update_archive(*files)
212
+ if files.empty?
213
+ raise Error, "there must be at least one file specified"
214
+ end
215
+
216
+ cmd = "#{@tar_program} uf #{@archive_name} #{files.join(" ")}"
217
+
218
+ Open3.popen3(cmd){ |ain, aout, aerr|
219
+ err = aerr.gets
220
+ raise Error, err.chomp if err
221
+ }
222
+
223
+ self
224
+ end
225
+
226
+ alias :update :update_archive
227
+
228
+ # Expands the contents of the tarball. It does NOT delete the tarball.
229
+ # If +files+ are provided, then only those files are extracted.
230
+ # Otherwise, all files are extracted.
231
+ #
232
+ # Note that some tar programs, notably the tar program shipped by Sun,
233
+ # does not issue any sort of warning or error if you try to extract a
234
+ # file that does not exist in the archive.
235
+ #
236
+ def extract_archive(*files)
237
+ cmd = "#{@tar_program} xf #{@archive_name}"
238
+
239
+ unless files.empty?
240
+ cmd << " " << files.join(" ")
241
+ end
242
+
243
+ Open3.popen3(cmd){ |ain, aout, aerr|
244
+ err = aerr.gets
245
+ raise Error, err.chomp if err
246
+ }
247
+
248
+ self
249
+ end
250
+
251
+ alias :expand_archive :extract_archive
252
+ alias :extract :extract_archive
253
+ alias :expand :extract_archive
254
+
255
+ # A class method that behaves identically to the equivalent instance
256
+ # method, except that you must specifiy that tarball as the first
257
+ # argument. Also, the tar program is hard coded to 'tar xf'.
258
+ #
259
+ def self.extract_archive(archive, *files)
260
+ cmd = "tar xf #{archive}"
261
+
262
+ unless files.empty?
263
+ cmd << " " << files.join(" ")
264
+ end
265
+
266
+ Open3.popen3(cmd){ |ain, aout, aerr|
267
+ err = aerr.gets
268
+ raise Error, err.chomp if err
269
+ }
270
+
271
+ self
272
+ end
273
+
274
+ class << self
275
+ alias expand_archive extract_archive
276
+ alias extract extract_archive
277
+ alias expand extract_archive
278
+ end
279
+ end
280
+ end
281
+ end
@@ -1,201 +1,203 @@
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.3', 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
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.3.0', 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
+ omit_unless(Config::CONFIG['host_os'] =~ /sunos|solaris/){
177
+ assert_nothing_raised{ @tar.tar_program = @@gtar }
178
+ }
179
+ assert_nothing_raised{ @tar.create('*.txt') }
180
+ assert_raises(Tar::Error){ @tar.expand('blah.txt') }
181
+
182
+ assert_nothing_raised{ @tar.extract_archive }
183
+ assert_nothing_raised{ @tar.extract_archive('temp2.txt') }
184
+ end
185
+
186
+ def teardown
187
+ @tar = nil
188
+ File.delete('test.tar') if File.exists?('test.tar')
189
+ File.delete('test.tar.gz') if File.exists?('test.tar.gz')
190
+ File.delete('test.tar.bz2') if File.exists?('test.tar.bz2')
191
+ File.delete('test.tar.zip') if File.exists?('test.tar.zip')
192
+ end
193
+
194
+ def self.shutdown
195
+ @@tar_foudn = nil
196
+ @@gzip_found = nil
197
+ @@bzip2_found = nil
198
+
199
+ File.delete(@@tmp_file1) if File.exists?(@@tmp_file1)
200
+ File.delete(@@tmp_file2) if File.exists?(@@tmp_file2)
201
+ File.delete(@@tmp_file3) if File.exists?(@@tmp_file3)
202
+ end
203
+ end