2009-05-21 00:04:43 +01:00
|
|
|
#!/usr/bin/ruby
|
2009-06-05 23:39:56 +01:00
|
|
|
$:.unshift File.dirname(__FILE__)
|
2009-07-24 15:10:01 +01:00
|
|
|
require 'formula'
|
2009-07-31 02:57:08 +01:00
|
|
|
require 'keg'
|
2009-07-31 02:51:17 +01:00
|
|
|
require 'pathname+yeast'
|
2009-06-15 01:16:00 +01:00
|
|
|
require 'stringio'
|
2009-07-31 02:51:17 +01:00
|
|
|
require 'utils'
|
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
# 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 :)
|
2009-08-04 00:43:16 +01:00
|
|
|
HOMEBREW_PREFIX=Pathname.new '/tmp/testbrew/prefix'
|
|
|
|
HOMEBREW_CACHE=HOMEBREW_PREFIX.parent+"cache"
|
|
|
|
HOMEBREW_CELLAR=HOMEBREW_PREFIX.parent+"cellar"
|
2009-08-03 09:59:14 -07:00
|
|
|
HOMEBREW_USER_AGENT="Homebrew"
|
2009-06-02 13:39:39 +01:00
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
HOMEBREW_CELLAR.mkpath
|
|
|
|
raise "HOMEBREW_CELLAR couldn't be created!" unless HOMEBREW_CELLAR.directory?
|
2009-08-04 01:31:32 +01:00
|
|
|
at_exit { HOMEBREW_PREFIX.parent.rmtree }
|
2009-07-31 02:57:08 +01:00
|
|
|
require 'test/unit' # must be after at_exit
|
|
|
|
|
|
|
|
|
2009-08-01 17:54:44 +01:00
|
|
|
class MockFormula <Formula
|
|
|
|
def initialize url
|
2009-06-02 13:39:39 +01:00
|
|
|
@url=url
|
2009-06-05 23:39:56 +01:00
|
|
|
super 'test'
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
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
|
|
|
|
|
2009-07-31 14:17:56 +01:00
|
|
|
class TestBallOverrideBrew <Formula
|
|
|
|
def initialize
|
|
|
|
super "foo"
|
|
|
|
end
|
|
|
|
def brew
|
|
|
|
puts "We can't override brew"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
|
2009-06-15 01:16:00 +01:00
|
|
|
def nostdout
|
|
|
|
tmp=$stdout
|
|
|
|
$stdout=StringIO.new
|
|
|
|
yield
|
|
|
|
$stdout=tmp
|
|
|
|
end
|
|
|
|
|
2009-06-02 13:39:39 +01:00
|
|
|
|
|
|
|
class BeerTasting <Test::Unit::TestCase
|
2009-05-21 00:04:43 +01:00
|
|
|
def test_version_all_dots
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://example.com/foo.bar.la.1.14.zip"
|
2009-05-21 00:04:43 +01:00
|
|
|
assert_equal '1.14', r.version
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_version_underscore_separator
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://example.com/grc_1.1.tar.gz"
|
2009-05-21 00:04:43 +01:00
|
|
|
assert_equal '1.1', r.version
|
|
|
|
end
|
|
|
|
|
2009-06-05 23:39:56 +01:00
|
|
|
def test_boost_version_style
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://example.com/boost_1_39_0.tar.bz2"
|
2009-05-25 11:57:12 +01:00
|
|
|
assert_equal '1.39.0', r.version
|
|
|
|
end
|
|
|
|
|
2009-06-05 23:39:56 +01:00
|
|
|
def test_erlang_version_style
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://erlang.org/download/otp_src_R13B.tar.gz"
|
2009-06-05 23:39:56 +01:00
|
|
|
assert_equal 'R13B', r.version
|
|
|
|
end
|
2009-06-08 15:57:24 +01:00
|
|
|
|
2009-06-26 13:05:48 +01:00
|
|
|
def test_p7zip_version_style
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://kent.dl.sourceforge.net/sourceforge/p7zip/p7zip_9.04_src_all.tar.bz2"
|
2009-06-26 13:05:48 +01:00
|
|
|
assert_equal '9.04', r.version
|
|
|
|
end
|
|
|
|
|
2009-07-10 03:11:05 +01:00
|
|
|
def test_gloox_beta_style
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://camaya.net/download/gloox-1.0-beta7.tar.bz2"
|
2009-07-10 03:11:05 +01:00
|
|
|
assert_equal '1.0-beta7', r.version
|
|
|
|
end
|
|
|
|
|
2009-06-15 00:54:58 +01:00
|
|
|
def test_astyle_verson_style
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://kent.dl.sourceforge.net/sourceforge/astyle/astyle_1.23_macosx.tar.gz"
|
2009-06-15 00:54:58 +01:00
|
|
|
assert_equal '1.23', r.version
|
|
|
|
end
|
|
|
|
|
2009-06-18 09:52:38 +01:00
|
|
|
def test_version_libvorbis
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.2rc1.tar.bz2"
|
2009-06-18 09:52:38 +01:00
|
|
|
assert_equal '1.2.2rc1', r.version
|
|
|
|
end
|
|
|
|
|
2009-06-08 15:57:24 +01:00
|
|
|
def test_dos2unix
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://www.sfr-fresh.com/linux/misc/dos2unix-3.1.tar.gz"
|
2009-06-08 15:57:24 +01:00
|
|
|
assert_equal '3.1', r.version
|
|
|
|
end
|
2009-06-05 23:39:56 +01:00
|
|
|
|
2009-05-21 00:04:43 +01:00
|
|
|
def test_version_internal_dash
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://example.com/foo-arse-1.1-2.tar.gz"
|
2009-05-21 00:04:43 +01:00
|
|
|
assert_equal '1.1-2', r.version
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_version_single_digit
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://example.com/foo_bar.45.tar.gz"
|
2009-05-21 00:04:43 +01:00
|
|
|
assert_equal '45', r.version
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_noseparator_single_digit
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://example.com/foo_bar45.tar.gz"
|
2009-05-21 00:04:43 +01:00
|
|
|
assert_equal '45', r.version
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_version_developer_that_hates_us_format
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://example.com/foo-bar-la.1.2.3.tar.gz"
|
2009-05-21 00:04:43 +01:00
|
|
|
assert_equal '1.2.3', r.version
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_version_regular
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://example.com/foo_bar-1.21.tar.gz"
|
2009-05-21 00:04:43 +01:00
|
|
|
assert_equal '1.21', r.version
|
|
|
|
end
|
|
|
|
|
2009-06-02 13:39:39 +01:00
|
|
|
def test_yet_another_version
|
2009-08-01 17:54:44 +01:00
|
|
|
r=MockFormula.new "http://example.com/mad-0.15.1b.tar.gz"
|
2009-06-02 13:39:39 +01:00
|
|
|
assert_equal '0.15.1b', r.version
|
|
|
|
end
|
|
|
|
|
2009-06-05 23:39:56 +01:00
|
|
|
def test_supported_compressed_types
|
|
|
|
assert_nothing_raised do
|
2009-08-01 17:54:44 +01:00
|
|
|
MockFormula.new 'test-0.1.tar.gz'
|
|
|
|
MockFormula.new 'test-0.1.tar.bz2'
|
|
|
|
MockFormula.new 'test-0.1.tgz'
|
|
|
|
MockFormula.new 'test-0.1.bgz'
|
|
|
|
MockFormula.new 'test-0.1.zip'
|
2009-06-05 23:39:56 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-05-21 00:04:43 +01:00
|
|
|
def test_prefix
|
2009-06-15 01:16:00 +01:00
|
|
|
nostdout do
|
2009-07-31 02:57:08 +01:00
|
|
|
TestBall.new.brew do |f|
|
2009-07-31 02:51:17 +01:00
|
|
|
assert_equal File.expand_path(f.prefix), (HOMEBREW_CELLAR+f.name+'0.1').to_s
|
2009-06-15 01:16:00 +01:00
|
|
|
assert_kind_of Pathname, f.prefix
|
|
|
|
end
|
2009-05-21 00:04:43 +01:00
|
|
|
end
|
|
|
|
end
|
2009-07-31 02:57:08 +01:00
|
|
|
|
|
|
|
def test_install
|
|
|
|
f=TestBall.new
|
2009-07-31 14:04:24 +01:00
|
|
|
|
|
|
|
assert !f.installed?
|
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
nostdout do
|
|
|
|
f.brew do
|
|
|
|
f.install
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-07-31 14:04:24 +01:00
|
|
|
assert_match Regexp.new("^#{HOMEBREW_CELLAR}/"), f.prefix.to_s
|
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
assert f.bin.directory?
|
2009-07-31 14:04:24 +01:00
|
|
|
assert_equal 3, f.bin.children.length
|
2009-07-31 02:57:08 +01:00
|
|
|
libexec=f.prefix+'libexec'
|
|
|
|
assert libexec.directory?
|
2009-07-31 14:04:24 +01:00
|
|
|
assert_equal 1, libexec.children.length
|
2009-07-31 02:57:08 +01:00
|
|
|
assert !(f.prefix+'main.c').exist?
|
2009-07-31 14:04:24 +01:00
|
|
|
assert f.installed?
|
2009-07-31 02:57:08 +01:00
|
|
|
|
|
|
|
keg=Keg.new f
|
|
|
|
keg.ln
|
2009-07-31 14:04:24 +01:00
|
|
|
assert_equal 2, HOMEBREW_PREFIX.children.length
|
2009-07-31 02:57:08 +01:00
|
|
|
assert (HOMEBREW_PREFIX+'bin').directory?
|
2009-07-31 14:04:24 +01:00
|
|
|
assert_equal 3, (HOMEBREW_PREFIX+'bin').children.length
|
2009-07-31 14:17:56 +01:00
|
|
|
|
|
|
|
keg.rm
|
|
|
|
assert !keg.path.exist?
|
|
|
|
assert !f.installed?
|
2009-07-31 02:57:08 +01:00
|
|
|
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
|
2009-07-31 14:04:24 +01:00
|
|
|
|
|
|
|
FOOBAR='foo-bar'
|
|
|
|
def test_formula_funcs
|
|
|
|
classname=Formula.class(FOOBAR)
|
|
|
|
path=Formula.path(FOOBAR)
|
|
|
|
|
|
|
|
assert_equal "FooBar", classname
|
|
|
|
assert_match Regexp.new("^#{HOMEBREW_PREFIX}/Library/Formula"), path.to_s
|
|
|
|
|
|
|
|
path=HOMEBREW_PREFIX+'Library'+'Formula'+"#{FOOBAR}.rb"
|
|
|
|
path.dirname.mkpath
|
|
|
|
`echo "require 'brewkit'; class #{classname} <Formula; @url=''; end" > #{path}`
|
|
|
|
|
|
|
|
assert_not_nil Formula.create(FOOBAR)
|
|
|
|
end
|
2009-07-31 14:17:56 +01:00
|
|
|
|
|
|
|
def test_cant_override_brew
|
|
|
|
assert_raises(RuntimeError) { TestBallOverrideBrew.new }
|
|
|
|
end
|
2009-07-31 14:04:24 +01:00
|
|
|
end
|