Skip to content
This repository has been archived by the owner on Nov 14, 2021. It is now read-only.

Commit

Permalink
Add test for interoperability with Archive::Tar::Minitar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Quintus committed Nov 8, 2015
1 parent 62d78a2 commit dc23dc2
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions ruby-xz.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ DESCRIPTION
spec.required_ruby_version = ">=1.9.3"
spec.add_runtime_dependency("ffi", "~> 1.9")
spec.add_runtime_dependency("io-like", "~> 0.3")
spec.add_development_dependency("archive-tar-minitar", "~> 0.5")
spec.files.concat(Dir["lib/**/*.rb"])
spec.files.concat(Dir["**/*.rdoc"])
spec.files << "COPYING" << "AUTHORS"
Expand Down
71 changes: 71 additions & 0 deletions test/test_tarball.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
# (The MIT license)
#
# Basic liblzma-bindings for Ruby.
#
# Copyright © 2012,2013 Marvin Gülker
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the ‘Software’),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software
# is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require "archive/tar/minitar"
require_relative "./common"

# Create XZ-compressed tarballs and unpack them with the system's
# tar(1) utility, and vice-versa. This ensures our library interacts
# with the environment as one expects it to.
class TarballTest < Minitest::Test

def test_pack_tarball
filename = File.join(Dir.pwd, "testtarball.tar.xz")
content = File.read("test-data/lorem_ipsum.txt")

XZ::StreamWriter.open(filename) do |txz|
Archive::Tar::Minitar.pack("test-data/lorem_ipsum.txt", txz)
end

Dir.mktmpdir("testtarball") do |dir|
Dir.chdir(dir) do
system("tar -xJf '#{filename}'")
assert File.exist?("test-data/lorem_ipsum.txt"), "compressed file missing!"
assert_equal File.read("test-data/lorem_ipsum.txt"), content
end
end
ensure
File.unlink(filename) if File.exist?(filename)
end

def test_unpack_tarball
filename = File.join(Dir.pwd, "testtarball.tar.xz")
content = File.read("test-data/lorem_ipsum.txt")

system("tar -cJf '#{filename}' test-data/lorem_ipsum.txt")

Dir.mktmpdir("testtarball") do |dir|
Dir.chdir(dir) do
XZ::StreamReader.open(filename) do |txz|
Archive::Tar::Minitar.unpack(txz, ".")
end

assert File.exist?("test-data/lorem_ipsum.txt"), "compresed file missing!"
assert_equal File.read("test-data/lorem_ipsum.txt"), content
end
end
end

end
Binary file added test/testtarball.tar.xz
Binary file not shown.

0 comments on commit dc23dc2

Please sign in to comment.