2010-03-16 22:33:13 -07:00
|
|
|
require 'testing_env'
|
|
|
|
require 'test/testball'
|
2012-03-18 13:58:13 -05:00
|
|
|
|
2010-03-16 22:33:13 -07:00
|
|
|
class FormulaTests < Test::Unit::TestCase
|
2012-07-10 16:01:02 -05:00
|
|
|
include VersionAssertions
|
2010-03-16 22:33:13 -07:00
|
|
|
|
|
|
|
def test_prefix
|
2013-04-08 17:43:01 -05:00
|
|
|
f = TestBall.new
|
|
|
|
assert_equal File.expand_path(f.prefix), (HOMEBREW_CELLAR+f.name+'0.1').to_s
|
|
|
|
assert_kind_of Pathname, f.prefix
|
2010-03-16 22:33:13 -07:00
|
|
|
end
|
2012-06-20 00:51:01 -05:00
|
|
|
|
2013-04-09 19:40:08 -05:00
|
|
|
def test_installed?
|
|
|
|
f = TestBall.new
|
|
|
|
f.stubs(:installed_prefix).returns(stub(:directory? => false))
|
|
|
|
assert !f.installed?
|
|
|
|
|
|
|
|
f.stubs(:installed_prefix).returns(
|
|
|
|
stub(:directory? => true, :children => [])
|
|
|
|
)
|
|
|
|
assert !f.installed?
|
|
|
|
|
|
|
|
f.stubs(:installed_prefix).returns(
|
|
|
|
stub(:directory? => true, :children => [stub])
|
|
|
|
)
|
|
|
|
assert f.installed?
|
|
|
|
end
|
|
|
|
|
2013-05-25 17:19:19 -05:00
|
|
|
def test_installed_prefix
|
|
|
|
f = Class.new(TestBall).new
|
|
|
|
assert_equal f.prefix, f.installed_prefix
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_installed_prefix_head_installed
|
|
|
|
f = formula do
|
|
|
|
head 'foo'
|
|
|
|
devel do
|
|
|
|
url 'foo'
|
|
|
|
version '1.0'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
prefix = HOMEBREW_CELLAR+f.name+f.head.version
|
|
|
|
prefix.mkpath
|
|
|
|
assert_equal prefix, f.installed_prefix
|
|
|
|
ensure
|
|
|
|
prefix.rmtree
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_installed_prefix_devel_installed
|
|
|
|
f = formula do
|
|
|
|
head 'foo'
|
|
|
|
devel do
|
|
|
|
url 'foo'
|
|
|
|
version '1.0'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
prefix = HOMEBREW_CELLAR+f.name+f.devel.version
|
|
|
|
prefix.mkpath
|
|
|
|
assert_equal prefix, f.installed_prefix
|
|
|
|
ensure
|
|
|
|
prefix.rmtree
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_installed_prefix_stable_installed
|
|
|
|
f = formula do
|
|
|
|
head 'foo'
|
|
|
|
devel do
|
|
|
|
url 'foo'
|
|
|
|
version '1.0-devel'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
prefix = HOMEBREW_CELLAR+f.name+f.version
|
|
|
|
prefix.mkpath
|
|
|
|
assert_equal prefix, f.installed_prefix
|
|
|
|
ensure
|
|
|
|
prefix.rmtree
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_installed_prefix_head_active_spec
|
|
|
|
ARGV.stubs(:build_head? => true)
|
|
|
|
|
|
|
|
f = formula do
|
|
|
|
head 'foo'
|
|
|
|
devel do
|
|
|
|
url 'foo'
|
|
|
|
version '1.0-devel'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
prefix = HOMEBREW_CELLAR+f.name+f.head.version
|
|
|
|
assert_equal prefix, f.installed_prefix
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_installed_prefix_devel_active_spec
|
|
|
|
ARGV.stubs(:build_devel? => true)
|
|
|
|
|
|
|
|
f = formula do
|
|
|
|
head 'foo'
|
|
|
|
devel do
|
|
|
|
url 'foo'
|
|
|
|
version '1.0-devel'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
prefix = HOMEBREW_CELLAR+f.name+f.devel.version
|
|
|
|
assert_equal prefix, f.installed_prefix
|
|
|
|
end
|
|
|
|
|
2013-04-10 12:02:35 -05:00
|
|
|
def test_equality
|
|
|
|
x = TestBall.new
|
|
|
|
y = TestBall.new
|
|
|
|
assert x == y
|
|
|
|
assert y == x
|
|
|
|
assert x.eql?(y)
|
|
|
|
assert y.eql?(x)
|
|
|
|
assert x.hash == y.hash
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_inequality
|
|
|
|
x = TestBall.new("foo")
|
|
|
|
y = TestBall.new("bar")
|
|
|
|
assert x != y
|
|
|
|
assert y != x
|
|
|
|
assert x.hash != y.hash
|
|
|
|
assert !x.eql?(y)
|
|
|
|
assert !y.eql?(x)
|
|
|
|
end
|
|
|
|
|
2013-10-04 21:19:15 -05:00
|
|
|
def test_comparison_with_non_formula_objects_does_not_raise
|
|
|
|
assert_not_equal TestBall.new, Object.new
|
|
|
|
end
|
|
|
|
|
2010-03-16 22:33:13 -07:00
|
|
|
def test_class_naming
|
|
|
|
assert_equal 'ShellFm', Formula.class_s('shell.fm')
|
|
|
|
assert_equal 'Fooxx', Formula.class_s('foo++')
|
|
|
|
assert_equal 'SLang', Formula.class_s('s-lang')
|
|
|
|
assert_equal 'PkgConfig', Formula.class_s('pkg-config')
|
|
|
|
assert_equal 'FooBar', Formula.class_s('foo_bar')
|
|
|
|
end
|
|
|
|
|
2011-09-16 11:04:12 -07:00
|
|
|
def test_mirror_support
|
2013-04-08 19:15:22 -05:00
|
|
|
f = Class.new(Formula) do
|
|
|
|
url "file:///#{TEST_FOLDER}/bad_url/testball-0.1.tbz"
|
|
|
|
mirror "file:///#{TEST_FOLDER}/tarballs/testball-0.1.tbz"
|
|
|
|
end.new("test_mirror_support")
|
|
|
|
|
|
|
|
shutup { f.fetch }
|
|
|
|
|
|
|
|
assert_equal "file:///#{TEST_FOLDER}/bad_url/testball-0.1.tbz", f.url
|
|
|
|
assert_equal "file:///#{TEST_FOLDER}/tarballs/testball-0.1.tbz",
|
|
|
|
f.downloader.instance_variable_get(:@url)
|
2011-09-16 11:04:12 -07:00
|
|
|
end
|
2012-04-05 21:09:24 -05:00
|
|
|
|
2013-04-13 17:46:11 -05:00
|
|
|
def test_formula_spec_integration
|
|
|
|
f = Class.new(Formula) do
|
|
|
|
homepage 'http://example.com'
|
|
|
|
url 'file:///foo.com/testball-0.1.tbz'
|
|
|
|
mirror 'file:///foo.org/testball-0.1.tbz'
|
|
|
|
sha1 '482e737739d946b7c8cbaf127d9ee9c148b999f5'
|
|
|
|
|
|
|
|
head 'https://github.com/mxcl/homebrew.git', :tag => 'foo'
|
|
|
|
|
|
|
|
devel do
|
|
|
|
url 'file:///foo.com/testball-0.2.tbz'
|
|
|
|
mirror 'file:///foo.org/testball-0.2.tbz'
|
|
|
|
sha256 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
|
|
|
|
end
|
|
|
|
|
|
|
|
bottle do
|
|
|
|
sha1 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef' => :snow_leopard_32
|
|
|
|
sha1 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef' => :snow_leopard
|
|
|
|
sha1 'baadf00dbaadf00dbaadf00dbaadf00dbaadf00d' => :lion
|
|
|
|
sha1 '8badf00d8badf00d8badf00d8badf00d8badf00d' => :mountain_lion
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(name="spec_test_ball", path=nil)
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end.new
|
2012-04-05 21:09:24 -05:00
|
|
|
|
|
|
|
assert_equal 'http://example.com', f.homepage
|
2012-07-10 16:01:02 -05:00
|
|
|
assert_version_equal '0.1', f.version
|
2012-04-05 21:09:24 -05:00
|
|
|
assert_equal f.stable, f.active_spec
|
|
|
|
assert_instance_of CurlDownloadStrategy, f.downloader
|
|
|
|
|
|
|
|
assert_instance_of SoftwareSpec, f.stable
|
|
|
|
assert_instance_of Bottle, f.bottle
|
|
|
|
assert_instance_of SoftwareSpec, f.devel
|
|
|
|
assert_instance_of HeadSoftwareSpec, f.head
|
2012-07-10 21:45:17 -05:00
|
|
|
end
|
2013-04-10 22:14:53 -05:00
|
|
|
|
2013-04-16 01:43:26 -05:00
|
|
|
def test_path
|
|
|
|
name = 'foo-bar'
|
|
|
|
assert_equal Pathname.new("#{HOMEBREW_REPOSITORY}/Library/Formula/#{name}.rb"), Formula.path(name)
|
|
|
|
end
|
2013-04-10 22:14:53 -05:00
|
|
|
|
2013-04-16 01:43:26 -05:00
|
|
|
def test_factory
|
|
|
|
name = 'foo-bar'
|
|
|
|
path = HOMEBREW_PREFIX+"Library/Formula/#{name}.rb"
|
2013-04-10 22:14:53 -05:00
|
|
|
path.dirname.mkpath
|
|
|
|
File.open(path, 'w') do |f|
|
|
|
|
f << %{
|
|
|
|
require 'formula'
|
2013-04-16 01:43:26 -05:00
|
|
|
class #{Formula.class_s(name)} < Formula
|
2013-04-13 17:40:12 -05:00
|
|
|
url 'foo-1.0'
|
2013-04-10 22:14:53 -05:00
|
|
|
def initialize(*args)
|
|
|
|
@homepage = 'http://example.com/'
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
2013-04-16 01:43:26 -05:00
|
|
|
assert_kind_of Formula, Formula.factory(name)
|
|
|
|
ensure
|
|
|
|
path.unlink
|
2013-04-10 22:14:53 -05:00
|
|
|
end
|
2010-03-16 22:33:13 -07:00
|
|
|
end
|