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
|
|
|
|
2014-02-21 20:07:41 -05:00
|
|
|
def test_formula_path_initialization
|
|
|
|
name = "formula_name"
|
|
|
|
klass = Class.new(Formula) { url "http://example.com/foo-1.0.tar.gz" }
|
|
|
|
|
|
|
|
f = klass.new(name)
|
|
|
|
assert_equal Formula.path(name), f.path
|
|
|
|
|
|
|
|
f = klass.new(name, path = Object.new)
|
|
|
|
assert_equal path, f.path
|
|
|
|
|
|
|
|
f = klass.new(name, nil)
|
|
|
|
assert_nil f.path
|
|
|
|
end
|
|
|
|
|
2010-03-16 22:33:13 -07:00
|
|
|
def test_prefix
|
2013-04-08 17:43:01 -05:00
|
|
|
f = TestBall.new
|
2013-12-11 19:18:23 -06:00
|
|
|
assert_equal HOMEBREW_CELLAR/f.name/'0.1', f.prefix
|
2013-04-08 17:43:01 -05:00
|
|
|
assert_kind_of Pathname, f.prefix
|
2010-03-16 22:33:13 -07:00
|
|
|
end
|
2012-06-20 00:51:01 -05:00
|
|
|
|
2014-03-05 20:12:51 -06:00
|
|
|
def test_revised_prefix
|
|
|
|
f = Class.new(TestBall) { revision 1 }.new
|
|
|
|
assert_equal HOMEBREW_CELLAR/f.name/'0.1_1', f.prefix
|
|
|
|
end
|
|
|
|
|
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
|
2014-02-21 00:43:58 -05:00
|
|
|
assert_equal 'ShellFm', Formulary.class_s('shell.fm')
|
|
|
|
assert_equal 'Fooxx', Formulary.class_s('foo++')
|
|
|
|
assert_equal 'SLang', Formulary.class_s('s-lang')
|
|
|
|
assert_equal 'PkgConfig', Formulary.class_s('pkg-config')
|
|
|
|
assert_equal 'FooBar', Formulary.class_s('foo_bar')
|
2010-03-16 22:33:13 -07:00
|
|
|
end
|
|
|
|
|
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'
|
2013-12-09 15:57:50 -06:00
|
|
|
sha1 TEST_SHA1
|
2013-04-13 17:46:11 -05:00
|
|
|
|
2013-12-14 18:14:50 +00:00
|
|
|
head 'https://github.com/Homebrew/homebrew.git', :tag => 'foo'
|
2013-04-13 17:46:11 -05:00
|
|
|
|
|
|
|
devel do
|
|
|
|
url 'file:///foo.com/testball-0.2.tbz'
|
|
|
|
mirror 'file:///foo.org/testball-0.2.tbz'
|
2013-12-09 15:57:50 -06:00
|
|
|
sha256 TEST_SHA256
|
2013-04-13 17:46:11 -05:00
|
|
|
end
|
|
|
|
|
2013-12-09 15:57:50 -06:00
|
|
|
bottle { sha1 TEST_SHA1 => bottle_tag }
|
2013-04-13 17:46:11 -05:00
|
|
|
|
|
|
|
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 SoftwareSpec, f.stable
|
|
|
|
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'
|
2013-10-30 13:20:48 -07:00
|
|
|
assert_equal Pathname.new("#{HOMEBREW_LIBRARY}/Formula/#{name}.rb"), Formula.path(name)
|
2013-04-16 01:43:26 -05:00
|
|
|
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'
|
2014-02-21 00:43:58 -05:00
|
|
|
class #{Formulary.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)
|
|
|
|
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
|
Eagerly initialize formula specs
Declarations of dependencies, options, and resources in the DSL only
apply to specs that have already been initialized. For example, given
this snippet:
url ...
sha1 ...
depends_on 'foo'
devel do
url ...
sha1 ...
end
The dependency 'foo' will be recorded for the stable spec, but not the
devel spec, since it was not initialized prior to the call to
depends_on.
While it is considered best practice to declare all specs (stable,
devel, head, and bottle) prior to other declarations, there is nothing
that enforces this ordering, so when it happens it can be confusing and
hard to debug.
To prevent this, we can initialize all specs up front. This comes with
a performance penalty for commands that load all formulae into memory,
but that is probably outweighed by what we gain in correctness.
Fixes Homebrew/homebrew#23425.
2013-10-22 13:07:08 -05:00
|
|
|
|
|
|
|
def test_class_specs_are_always_initialized
|
|
|
|
f = formula { url 'foo-1.0' }
|
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
%w{stable devel head}.each do |spec|
|
Eagerly initialize formula specs
Declarations of dependencies, options, and resources in the DSL only
apply to specs that have already been initialized. For example, given
this snippet:
url ...
sha1 ...
depends_on 'foo'
devel do
url ...
sha1 ...
end
The dependency 'foo' will be recorded for the stable spec, but not the
devel spec, since it was not initialized prior to the call to
depends_on.
While it is considered best practice to declare all specs (stable,
devel, head, and bottle) prior to other declarations, there is nothing
that enforces this ordering, so when it happens it can be confusing and
hard to debug.
To prevent this, we can initialize all specs up front. This comes with
a performance penalty for commands that load all formulae into memory,
but that is probably outweighed by what we gain in correctness.
Fixes Homebrew/homebrew#23425.
2013-10-22 13:07:08 -05:00
|
|
|
assert_kind_of SoftwareSpec, f.class.send(spec)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_incomplete_instance_specs_are_not_accessible
|
|
|
|
f = formula { url 'foo-1.0' }
|
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
%w{devel head}.each { |spec| assert_nil f.send(spec) }
|
Eagerly initialize formula specs
Declarations of dependencies, options, and resources in the DSL only
apply to specs that have already been initialized. For example, given
this snippet:
url ...
sha1 ...
depends_on 'foo'
devel do
url ...
sha1 ...
end
The dependency 'foo' will be recorded for the stable spec, but not the
devel spec, since it was not initialized prior to the call to
depends_on.
While it is considered best practice to declare all specs (stable,
devel, head, and bottle) prior to other declarations, there is nothing
that enforces this ordering, so when it happens it can be confusing and
hard to debug.
To prevent this, we can initialize all specs up front. This comes with
a performance penalty for commands that load all formulae into memory,
but that is probably outweighed by what we gain in correctness.
Fixes Homebrew/homebrew#23425.
2013-10-22 13:07:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_honors_attributes_declared_before_specs
|
|
|
|
f = formula do
|
|
|
|
url 'foo-1.0'
|
|
|
|
depends_on 'foo'
|
|
|
|
devel { url 'foo-1.1' }
|
|
|
|
end
|
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
%w{stable devel head}.each do |spec|
|
Eagerly initialize formula specs
Declarations of dependencies, options, and resources in the DSL only
apply to specs that have already been initialized. For example, given
this snippet:
url ...
sha1 ...
depends_on 'foo'
devel do
url ...
sha1 ...
end
The dependency 'foo' will be recorded for the stable spec, but not the
devel spec, since it was not initialized prior to the call to
depends_on.
While it is considered best practice to declare all specs (stable,
devel, head, and bottle) prior to other declarations, there is nothing
that enforces this ordering, so when it happens it can be confusing and
hard to debug.
To prevent this, we can initialize all specs up front. This comes with
a performance penalty for commands that load all formulae into memory,
but that is probably outweighed by what we gain in correctness.
Fixes Homebrew/homebrew#23425.
2013-10-22 13:07:08 -05:00
|
|
|
assert_equal 'foo', f.class.send(spec).deps.first.name
|
|
|
|
end
|
|
|
|
end
|
2014-03-05 20:12:51 -06:00
|
|
|
|
|
|
|
def test_simple_version
|
|
|
|
assert_equal PkgVersion.parse('1.0'), formula { url 'foo-1.0.bar' }.pkg_version
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_version_with_revision
|
|
|
|
f = formula do
|
|
|
|
url 'foo-1.0.bar'
|
|
|
|
revision 1
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal PkgVersion.parse('1.0_1'), f.pkg_version
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_head_ignores_revisions
|
|
|
|
ARGV.stubs(:build_head?).returns(true)
|
|
|
|
|
|
|
|
f = formula do
|
|
|
|
url 'foo-1.0.bar'
|
|
|
|
revision 1
|
|
|
|
head 'foo'
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal PkgVersion.parse('HEAD'), f.pkg_version
|
|
|
|
end
|
2010-03-16 22:33:13 -07:00
|
|
|
end
|