A basis for full test coverage

This commit is contained in:
Max Howell 2009-07-31 02:57:08 +01:00
parent a39e0d20c3
commit 5fd7fd0578
3 changed files with 68 additions and 7 deletions

View File

@ -15,6 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with Homebrew. If not, see <http://www.gnu.org/licenses/>.
require 'utils'
class BuildError <RuntimeError
def initialize cmd
super "Build failed during: #{cmd}"

Binary file not shown.

View File

@ -1,17 +1,24 @@
#!/usr/bin/ruby
$:.unshift File.dirname(__FILE__)
require 'formula'
require 'keg'
require 'pathname+yeast'
require 'stringio'
require 'test/unit'
require 'utils'
# these are defined in env usually, but we want a fake place for everything init
HOMEBREW_VERSION='1t'
# these are defined in env.rb usually, but we don't want to break our actual
# homebrew tree, and we do want to test everything :)
HOMEBREW_VERSION='0.3t'
HOMEBREW_CACHE="/tmp/testbrew"
HOMEBREW_PREFIX=Pathname.new(HOMEBREW_CACHE)+'prefix'
HOMEBREW_CELLAR=Pathname.new(HOMEBREW_CACHE)+'cellar'
HOMEBREW_CELLAR.mkpath
raise "HOMEBREW_CELLAR couldn't be created!" unless HOMEBREW_CELLAR.directory?
at_exit { Pathname.new(HOMEBREW_CACHE).rmtree }
require 'test/unit' # must be after at_exit
class TestFormula <Formula
def initialize url, md5='nomd5'
@url=url
@ -20,6 +27,27 @@ class TestFormula <Formula
end
end
class TestBall <Formula
def initialize
@url="file:///#{Pathname.new(__FILE__).parent.realpath}/testball-0.1.tbz"
super "testball"
end
def install
prefix.install "bin"
prefix.install "libexec"
end
end
class TestBallValidMd5 <TestBall
@md5='71aa838a9e4050d1876a295a9e62cbe6'
end
class TestBallInvalidMd5 <TestBall
@md5='61aa838a9e4050d1876a295a9e62cbe6'
end
def nostdout
tmp=$stdout
$stdout=StringIO.new
@ -109,19 +137,50 @@ class BeerTasting <Test::Unit::TestCase
TestFormula.new 'test-0.1.tar.gz'
TestFormula.new 'test-0.1.tar.bz2'
TestFormula.new 'test-0.1.tgz'
TestFormula.new 'test-0.1.bgz'
TestFormula.new 'test-0.1.zip'
end
end
def test_prefix
url='http://www.methylblue.com/test-0.1.tar.gz'
md5='d496ea538a21dc4bb8524a8888baf88c'
nostdout do
TestFormula.new(url, md5).brew do |f|
TestBall.new.brew do |f|
assert_equal File.expand_path(f.prefix), (HOMEBREW_CELLAR+f.name+'0.1').to_s
assert_kind_of Pathname, f.prefix
end
end
end
def test_install
f=TestBall.new
nostdout do
f.brew do
f.install
end
end
assert f.bin.directory?
assert_equal f.bin.children.length, 3
libexec=f.prefix+'libexec'
assert libexec.directory?
assert_equal libexec.children.length, 1
assert !(f.prefix+'main.c').exist?
keg=Keg.new f
keg.ln
assert_equal HOMEBREW_PREFIX.children.length, 1
assert (HOMEBREW_PREFIX+'bin').directory?
assert_equal (HOMEBREW_PREFIX+'bin').children.length, 3
end
def test_md5
assert_nothing_raised { nostdout { TestBallValidMd5.new.brew {} } }
end
def test_badmd5
assert_raises RuntimeError do
nostdout { TestBallInvalidMd5.new.brew {} }
end
end
end