2015-08-03 13:09:07 +01:00
|
|
|
require "testing_env"
|
|
|
|
require "testball"
|
2015-12-29 12:57:48 +01:00
|
|
|
require "formula"
|
2012-03-18 13:58:13 -05:00
|
|
|
|
2014-06-18 20:32:51 -05:00
|
|
|
class FormulaTests < Homebrew::TestCase
|
2014-06-10 15:41:45 -05:00
|
|
|
def test_formula_instantiation
|
2014-02-21 20:07:41 -05:00
|
|
|
klass = Class.new(Formula) { url "http://example.com/foo-1.0.tar.gz" }
|
2014-06-10 15:41:45 -05:00
|
|
|
name = "formula_name"
|
2015-05-08 18:59:08 +08:00
|
|
|
path = Formulary.core_path(name)
|
2014-06-19 21:35:46 -05:00
|
|
|
spec = :stable
|
2014-02-21 20:07:41 -05:00
|
|
|
|
2014-06-19 21:35:46 -05:00
|
|
|
f = klass.new(name, path, spec)
|
2014-06-10 15:41:45 -05:00
|
|
|
assert_equal name, f.name
|
2014-02-21 20:07:41 -05:00
|
|
|
assert_equal path, f.path
|
2014-06-10 15:41:45 -05:00
|
|
|
assert_raises(ArgumentError) { klass.new }
|
2014-02-21 20:07:41 -05:00
|
|
|
end
|
|
|
|
|
2010-03-16 22:33:13 -07:00
|
|
|
def test_prefix
|
2015-04-15 21:28:23 -04:00
|
|
|
f = Testball.new
|
2015-08-03 13:09:07 +01: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
|
2015-04-15 21:28:23 -04:00
|
|
|
f = Class.new(Testball) { revision 1 }.new
|
2015-08-03 13:09:07 +01:00
|
|
|
assert_equal HOMEBREW_CELLAR/f.name/"0.1_1", f.prefix
|
2014-03-05 20:12:51 -06:00
|
|
|
end
|
|
|
|
|
2015-07-31 16:04:52 +08:00
|
|
|
def test_any_version_installed?
|
|
|
|
f = formula do
|
2015-08-03 13:09:07 +01:00
|
|
|
url "foo"
|
|
|
|
version "1.0"
|
2015-07-31 16:04:52 +08:00
|
|
|
end
|
|
|
|
refute_predicate f, :any_version_installed?
|
|
|
|
prefix = HOMEBREW_CELLAR+f.name+"0.1"
|
|
|
|
prefix.mkpath
|
2015-11-09 23:08:50 +01:00
|
|
|
FileUtils.touch prefix+Tab::FILENAME
|
2015-07-31 16:04:52 +08:00
|
|
|
assert_predicate f, :any_version_installed?
|
|
|
|
ensure
|
|
|
|
f.rack.rmtree
|
|
|
|
end
|
|
|
|
|
2016-06-27 17:37:43 +03:00
|
|
|
def test_migration_needed
|
|
|
|
f = Testball.new("newname")
|
|
|
|
f.instance_variable_set(:@oldname, "oldname")
|
|
|
|
f.instance_variable_set(:@tap, CoreTap.instance)
|
|
|
|
|
|
|
|
oldname_prefix = HOMEBREW_CELLAR/"oldname/2.20"
|
2016-07-01 18:17:24 +03:00
|
|
|
newname_prefix = HOMEBREW_CELLAR/"newname/2.10"
|
2016-06-27 17:37:43 +03:00
|
|
|
oldname_prefix.mkpath
|
|
|
|
oldname_tab = Tab.empty
|
|
|
|
oldname_tab.tabfile = oldname_prefix.join("INSTALL_RECEIPT.json")
|
|
|
|
oldname_tab.write
|
|
|
|
|
|
|
|
refute_predicate f, :migration_needed?
|
|
|
|
|
|
|
|
oldname_tab.tabfile.unlink
|
|
|
|
oldname_tab.source["tap"] = "homebrew/core"
|
|
|
|
oldname_tab.write
|
|
|
|
|
|
|
|
assert_predicate f, :migration_needed?
|
2016-07-01 18:17:24 +03:00
|
|
|
|
|
|
|
newname_prefix.mkpath
|
|
|
|
|
|
|
|
refute_predicate f, :migration_needed?
|
2016-06-27 17:37:43 +03:00
|
|
|
ensure
|
|
|
|
oldname_prefix.parent.rmtree
|
2016-07-01 18:17:24 +03:00
|
|
|
newname_prefix.parent.rmtree
|
2016-06-27 17:37:43 +03:00
|
|
|
end
|
|
|
|
|
2013-04-09 19:40:08 -05:00
|
|
|
def test_installed?
|
2015-04-15 21:28:23 -04:00
|
|
|
f = Testball.new
|
2013-04-09 19:40:08 -05:00
|
|
|
f.stubs(:installed_prefix).returns(stub(:directory? => false))
|
2014-06-11 12:21:03 -05:00
|
|
|
refute_predicate f, :installed?
|
2013-04-09 19:40:08 -05:00
|
|
|
|
|
|
|
f.stubs(:installed_prefix).returns(
|
|
|
|
stub(:directory? => true, :children => [])
|
|
|
|
)
|
2014-06-11 12:21:03 -05:00
|
|
|
refute_predicate f, :installed?
|
2013-04-09 19:40:08 -05:00
|
|
|
|
|
|
|
f.stubs(:installed_prefix).returns(
|
|
|
|
stub(:directory? => true, :children => [stub])
|
|
|
|
)
|
2014-06-11 12:21:03 -05:00
|
|
|
assert_predicate f, :installed?
|
2013-04-09 19:40:08 -05:00
|
|
|
end
|
|
|
|
|
2013-05-25 17:19:19 -05:00
|
|
|
def test_installed_prefix
|
2015-04-15 21:28:23 -04:00
|
|
|
f = Testball.new
|
2013-05-25 17:19:19 -05:00
|
|
|
assert_equal f.prefix, f.installed_prefix
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_installed_prefix_head_installed
|
|
|
|
f = formula do
|
2015-08-03 13:09:07 +01:00
|
|
|
head "foo"
|
2013-05-25 17:19:19 -05:00
|
|
|
devel do
|
2015-08-03 13:09:07 +01:00
|
|
|
url "foo"
|
|
|
|
version "1.0"
|
2013-05-25 17:19:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
prefix = HOMEBREW_CELLAR+f.name+f.head.version
|
|
|
|
prefix.mkpath
|
|
|
|
assert_equal prefix, f.installed_prefix
|
|
|
|
ensure
|
2014-06-23 21:40:26 -05:00
|
|
|
f.rack.rmtree
|
2013-05-25 17:19:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_installed_prefix_devel_installed
|
|
|
|
f = formula do
|
2015-08-03 13:09:07 +01:00
|
|
|
head "foo"
|
2013-05-25 17:19:19 -05:00
|
|
|
devel do
|
2015-08-03 13:09:07 +01:00
|
|
|
url "foo"
|
|
|
|
version "1.0"
|
2013-05-25 17:19:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
prefix = HOMEBREW_CELLAR+f.name+f.devel.version
|
|
|
|
prefix.mkpath
|
|
|
|
assert_equal prefix, f.installed_prefix
|
|
|
|
ensure
|
2014-06-23 21:40:26 -05:00
|
|
|
f.rack.rmtree
|
2013-05-25 17:19:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_installed_prefix_stable_installed
|
|
|
|
f = formula do
|
2015-08-03 13:09:07 +01:00
|
|
|
head "foo"
|
2013-05-25 17:19:19 -05:00
|
|
|
devel do
|
2015-08-03 13:09:07 +01:00
|
|
|
url "foo"
|
|
|
|
version "1.0-devel"
|
2013-05-25 17:19:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
prefix = HOMEBREW_CELLAR+f.name+f.version
|
|
|
|
prefix.mkpath
|
|
|
|
assert_equal prefix, f.installed_prefix
|
|
|
|
ensure
|
2014-06-23 21:40:26 -05:00
|
|
|
f.rack.rmtree
|
2013-05-25 17:19:19 -05:00
|
|
|
end
|
|
|
|
|
2016-07-22 12:59:08 +03:00
|
|
|
def test_installed_prefix_outdated_stable_head_installed
|
|
|
|
f = formula do
|
|
|
|
url "foo"
|
|
|
|
version "1.9"
|
|
|
|
head "foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
head_prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD"
|
|
|
|
head_prefix.mkpath
|
|
|
|
tab = Tab.empty
|
|
|
|
tab.tabfile = head_prefix.join("INSTALL_RECEIPT.json")
|
|
|
|
tab.source["versions"] = { "stable" => "1.0" }
|
|
|
|
tab.write
|
|
|
|
|
|
|
|
assert_equal HOMEBREW_CELLAR/"#{f.name}/#{f.version}", f.installed_prefix
|
|
|
|
ensure
|
|
|
|
f.rack.rmtree
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_installed_prefix_outdated_devel_head_installed
|
|
|
|
f = formula do
|
|
|
|
url "foo"
|
|
|
|
version "1.9"
|
|
|
|
devel do
|
|
|
|
url "foo"
|
|
|
|
version "2.1"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
head_prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD"
|
|
|
|
head_prefix.mkpath
|
|
|
|
tab = Tab.empty
|
|
|
|
tab.tabfile = head_prefix.join("INSTALL_RECEIPT.json")
|
|
|
|
tab.source["versions"] = { "stable" => "1.9", "devel" => "2.0" }
|
|
|
|
tab.write
|
|
|
|
|
|
|
|
assert_equal HOMEBREW_CELLAR/"#{f.name}/#{f.version}", f.installed_prefix
|
|
|
|
ensure
|
|
|
|
f.rack.rmtree
|
|
|
|
end
|
|
|
|
|
2014-10-29 23:32:38 -05:00
|
|
|
def test_installed_prefix_head
|
2014-06-19 21:35:47 -05:00
|
|
|
f = formula("test", Pathname.new(__FILE__).expand_path, :head) do
|
2015-08-03 13:09:07 +01:00
|
|
|
head "foo"
|
2013-05-25 17:19:19 -05:00
|
|
|
devel do
|
2015-08-03 13:09:07 +01:00
|
|
|
url "foo"
|
|
|
|
version "1.0-devel"
|
2013-05-25 17:19:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
prefix = HOMEBREW_CELLAR+f.name+f.head.version
|
|
|
|
assert_equal prefix, f.installed_prefix
|
|
|
|
end
|
|
|
|
|
2014-10-29 23:32:38 -05:00
|
|
|
def test_installed_prefix_devel
|
2014-06-19 21:35:47 -05:00
|
|
|
f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do
|
2015-08-03 13:09:07 +01:00
|
|
|
head "foo"
|
2013-05-25 17:19:19 -05:00
|
|
|
devel do
|
2015-08-03 13:09:07 +01:00
|
|
|
url "foo"
|
|
|
|
version "1.0-devel"
|
2013-05-25 17:19:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
prefix = HOMEBREW_CELLAR+f.name+f.devel.version
|
|
|
|
assert_equal prefix, f.installed_prefix
|
|
|
|
end
|
|
|
|
|
2016-07-11 14:52:05 +03:00
|
|
|
def test_latest_head_prefix
|
|
|
|
f = Testball.new
|
|
|
|
|
|
|
|
stamps_with_revisions = [[111111, 1], [222222, 1], [222222, 2], [222222, 0]]
|
|
|
|
|
|
|
|
stamps_with_revisions.each do |stamp, revision|
|
|
|
|
version = "HEAD-#{stamp}"
|
|
|
|
version += "_#{revision}" if revision > 0
|
|
|
|
prefix = f.rack.join(version)
|
|
|
|
prefix.mkpath
|
|
|
|
|
|
|
|
tab = Tab.empty
|
|
|
|
tab.tabfile = prefix.join("INSTALL_RECEIPT.json")
|
|
|
|
tab.source_modified_time = stamp
|
|
|
|
tab.write
|
|
|
|
end
|
|
|
|
|
|
|
|
prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD-222222_2"
|
|
|
|
assert_equal prefix, f.latest_head_prefix
|
|
|
|
ensure
|
|
|
|
f.rack.rmtree
|
|
|
|
end
|
|
|
|
|
2013-04-10 12:02:35 -05:00
|
|
|
def test_equality
|
2015-04-15 21:28:23 -04:00
|
|
|
x = Testball.new
|
|
|
|
y = Testball.new
|
2014-06-04 16:31:57 -05:00
|
|
|
assert_equal x, y
|
2014-07-03 16:54:46 -05:00
|
|
|
assert_eql x, y
|
2014-06-04 16:31:57 -05:00
|
|
|
assert_equal x.hash, y.hash
|
2013-04-10 12:02:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_inequality
|
2015-04-15 21:28:23 -04:00
|
|
|
x = Testball.new("foo")
|
|
|
|
y = Testball.new("bar")
|
2014-06-10 22:43:47 -05:00
|
|
|
refute_equal x, y
|
2014-07-03 16:54:46 -05:00
|
|
|
refute_eql x, y
|
2014-06-10 22:43:47 -05:00
|
|
|
refute_equal x.hash, y.hash
|
2013-04-10 12:02:35 -05:00
|
|
|
end
|
|
|
|
|
2013-10-04 21:19:15 -05:00
|
|
|
def test_comparison_with_non_formula_objects_does_not_raise
|
2015-04-15 21:28:23 -04:00
|
|
|
refute_equal Testball.new, Object.new
|
2013-10-04 21:19:15 -05:00
|
|
|
end
|
|
|
|
|
2014-07-03 14:54:14 -05:00
|
|
|
def test_sort_operator
|
2015-04-15 21:28:23 -04:00
|
|
|
assert_nil Testball.new <=> Object.new
|
2014-07-03 14:54:14 -05:00
|
|
|
end
|
|
|
|
|
2013-04-13 17:46:11 -05:00
|
|
|
def test_formula_spec_integration
|
2014-12-28 21:43:04 -05:00
|
|
|
f = formula do
|
2015-08-03 13:09:07 +01:00
|
|
|
homepage "http://example.com"
|
|
|
|
url "http://example.com/test-0.1.tbz"
|
|
|
|
mirror "http://example.org/test-0.1.tbz"
|
2016-03-20 14:12:15 +08:00
|
|
|
sha256 TEST_SHA256
|
2013-04-13 17:46:11 -05:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
head "http://example.com/test.git", :tag => "foo"
|
2013-04-13 17:46:11 -05:00
|
|
|
|
|
|
|
devel do
|
2015-08-03 13:09:07 +01:00
|
|
|
url "http://example.com/test-0.2.tbz"
|
|
|
|
mirror "http://example.org/test-0.2.tbz"
|
2013-12-09 15:57:50 -06:00
|
|
|
sha256 TEST_SHA256
|
2013-04-13 17:46:11 -05:00
|
|
|
end
|
2014-12-28 21:43:04 -05:00
|
|
|
end
|
2012-04-05 21:09:24 -05:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
assert_equal "http://example.com", f.homepage
|
|
|
|
assert_version_equal "0.1", f.version
|
2014-10-29 23:32:38 -05:00
|
|
|
assert_predicate f, :stable?
|
2012-04-05 21:09:24 -05:00
|
|
|
|
2014-12-27 16:31:38 -05:00
|
|
|
assert_version_equal "0.1", f.stable.version
|
|
|
|
assert_version_equal "0.2", f.devel.version
|
|
|
|
assert_version_equal "HEAD", f.head.version
|
2012-07-10 21:45:17 -05:00
|
|
|
end
|
2013-04-10 22:14:53 -05:00
|
|
|
|
2015-07-31 16:04:52 +08:00
|
|
|
def test_formula_set_active_spec
|
|
|
|
f = formula do
|
2015-08-03 13:09:07 +01:00
|
|
|
url "foo"
|
|
|
|
version "1.0"
|
2015-07-31 16:04:52 +08:00
|
|
|
revision 1
|
|
|
|
|
|
|
|
devel do
|
2015-08-03 13:09:07 +01:00
|
|
|
url "foo"
|
|
|
|
version "1.0beta"
|
2015-07-31 16:04:52 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_equal :stable, f.active_spec_sym
|
|
|
|
assert_equal f.stable, f.send(:active_spec)
|
|
|
|
assert_equal "1.0_1", f.pkg_version.to_s
|
|
|
|
f.set_active_spec(:devel)
|
|
|
|
assert_equal :devel, f.active_spec_sym
|
|
|
|
assert_equal f.devel, f.send(:active_spec)
|
|
|
|
assert_equal "1.0beta_1", f.pkg_version.to_s
|
|
|
|
assert_raises(FormulaSpecificationError) { f.set_active_spec(:head) }
|
|
|
|
end
|
|
|
|
|
2013-04-16 01:43:26 -05:00
|
|
|
def test_path
|
2015-08-03 13:09:07 +01:00
|
|
|
name = "foo-bar"
|
2016-02-26 19:43:49 +08:00
|
|
|
assert_equal Pathname.new("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/Formula/#{name}.rb"), Formulary.core_path(name)
|
2013-04-16 01:43:26 -05:00
|
|
|
end
|
2013-04-10 22:14:53 -05:00
|
|
|
|
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
|
2015-08-03 13:09:07 +01:00
|
|
|
f = formula { url "foo-1.0" }
|
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
|
|
|
|
2015-08-03 13:09:07 +01: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
|
2015-08-03 13:09:07 +01:00
|
|
|
f = formula { url "foo-1.0" }
|
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
|
|
|
|
2015-08-03 13:09:07 +01: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
|
2015-08-03 13:09:07 +01:00
|
|
|
url "foo-1.0"
|
|
|
|
depends_on "foo"
|
|
|
|
devel { url "foo-1.1" }
|
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
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
%w[stable devel head].each do |spec|
|
|
|
|
assert_equal "foo", f.class.send(spec).deps.first.name
|
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
|
|
|
|
end
|
2014-03-05 20:12:51 -06:00
|
|
|
|
|
|
|
def test_simple_version
|
2015-08-03 13:09:07 +01:00
|
|
|
assert_equal PkgVersion.parse("1.0"), formula { url "foo-1.0.bar" }.pkg_version
|
2014-03-05 20:12:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_version_with_revision
|
|
|
|
f = formula do
|
2015-08-03 13:09:07 +01:00
|
|
|
url "foo-1.0.bar"
|
2014-03-05 20:12:51 -06:00
|
|
|
revision 1
|
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
assert_equal PkgVersion.parse("1.0_1"), f.pkg_version
|
2014-03-05 20:12:51 -06:00
|
|
|
end
|
|
|
|
|
2016-06-22 10:41:24 +03:00
|
|
|
def test_head_uses_revisions
|
2014-06-19 21:35:47 -05:00
|
|
|
f = formula("test", Pathname.new(__FILE__).expand_path, :head) do
|
2015-08-03 13:09:07 +01:00
|
|
|
url "foo-1.0.bar"
|
2014-03-05 20:12:51 -06:00
|
|
|
revision 1
|
2015-08-03 13:09:07 +01:00
|
|
|
head "foo"
|
2014-03-05 20:12:51 -06:00
|
|
|
end
|
|
|
|
|
2016-06-22 10:41:24 +03:00
|
|
|
assert_equal PkgVersion.parse("HEAD_1"), f.pkg_version
|
2014-03-05 20:12:51 -06:00
|
|
|
end
|
2014-07-02 15:21:40 -05:00
|
|
|
|
2016-07-11 14:52:05 +03:00
|
|
|
def test_update_head_version
|
|
|
|
initial_env = ENV.to_hash
|
|
|
|
|
|
|
|
f = formula do
|
|
|
|
head "foo", :using => :git
|
|
|
|
end
|
|
|
|
|
|
|
|
cached_location = f.head.downloader.cached_location
|
|
|
|
cached_location.mkpath
|
|
|
|
|
|
|
|
%w[AUTHOR COMMITTER].each do |role|
|
|
|
|
ENV["GIT_#{role}_NAME"] = "brew tests"
|
|
|
|
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
|
|
|
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
|
|
|
|
end
|
|
|
|
|
|
|
|
cached_location.cd do
|
|
|
|
FileUtils.touch "LICENSE"
|
|
|
|
shutup do
|
|
|
|
system "git", "init"
|
|
|
|
system "git", "add", "--all"
|
|
|
|
system "git", "commit", "-m", "Initial commit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
f.update_head_version
|
|
|
|
assert_equal Version.create("HEAD-5658946"), f.head.version
|
|
|
|
ensure
|
|
|
|
ENV.replace(initial_env)
|
|
|
|
cached_location.rmtree
|
|
|
|
end
|
|
|
|
|
2014-08-10 16:47:34 -05:00
|
|
|
def test_legacy_options
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
|
|
|
|
def options
|
|
|
|
[["--foo", "desc"], ["--bar", "desc"]]
|
|
|
|
end
|
|
|
|
|
|
|
|
option "baz"
|
|
|
|
end
|
|
|
|
|
|
|
|
assert f.option_defined?("foo")
|
|
|
|
assert f.option_defined?("bar")
|
|
|
|
assert f.option_defined?("baz")
|
|
|
|
end
|
2015-07-20 21:46:05 +02:00
|
|
|
|
|
|
|
def test_desc
|
|
|
|
f = formula do
|
|
|
|
desc "a formula"
|
|
|
|
url "foo-1.0"
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "a formula", f.desc
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_post_install_defined
|
|
|
|
f1 = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def post_install; end
|
2015-07-20 21:46:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
f2 = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
end
|
|
|
|
|
|
|
|
assert f1.post_install_defined?
|
|
|
|
refute f2.post_install_defined?
|
|
|
|
end
|
2015-12-27 00:01:04 +01:00
|
|
|
|
|
|
|
def test_test_defined
|
|
|
|
f1 = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
|
|
|
|
def test; end
|
|
|
|
end
|
|
|
|
|
|
|
|
f2 = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
end
|
|
|
|
|
|
|
|
assert f1.test_defined?
|
|
|
|
refute f2.test_defined?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_test_fixtures
|
|
|
|
f1 = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal Pathname.new("#{HOMEBREW_LIBRARY}/Homebrew/test/fixtures/foo"),
|
|
|
|
f1.test_fixtures("foo")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_hash
|
|
|
|
f1 = formula("foo") do
|
|
|
|
url "foo-1.0"
|
|
|
|
end
|
|
|
|
|
|
|
|
h = f1.to_hash
|
|
|
|
assert h.is_a?(Hash), "Formula#to_hash should return a Hash"
|
|
|
|
assert_equal "foo", h["name"]
|
|
|
|
assert_equal "foo", h["full_name"]
|
|
|
|
assert_equal "1.0", h["versions"]["stable"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_hash_bottle
|
|
|
|
f1 = formula("foo") do
|
|
|
|
url "foo-1.0"
|
|
|
|
|
|
|
|
bottle do
|
|
|
|
cellar :any
|
2016-07-16 21:07:42 +01:00
|
|
|
sha256 TEST_SHA256 => Utils::Bottles.tag
|
2015-12-27 00:01:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
h = f1.to_hash
|
|
|
|
assert h.is_a?(Hash), "Formula#to_hash should return a Hash"
|
|
|
|
assert h["versions"]["bottle"], "The hash should say the formula is bottled"
|
|
|
|
end
|
2015-12-29 12:57:48 +01:00
|
|
|
|
|
|
|
def test_eligible_kegs_for_cleanup
|
|
|
|
f1 = Class.new(Testball) { version "0.1" }.new
|
|
|
|
f2 = Class.new(Testball) { version "0.2" }.new
|
|
|
|
f3 = Class.new(Testball) { version "0.3" }.new
|
|
|
|
|
|
|
|
shutup do
|
|
|
|
f1.brew { f1.install }
|
|
|
|
f2.brew { f2.install }
|
|
|
|
f3.brew { f3.install }
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_predicate f1, :installed?
|
|
|
|
assert_predicate f2, :installed?
|
|
|
|
assert_predicate f3, :installed?
|
|
|
|
|
2016-07-29 15:53:34 -06:00
|
|
|
assert_equal f3.installed_kegs.sort_by(&:version)[0..1],
|
|
|
|
f3.eligible_kegs_for_cleanup.sort_by(&:version)
|
2015-12-29 12:57:48 +01:00
|
|
|
ensure
|
|
|
|
[f1, f2, f3].each(&:clear_cache)
|
|
|
|
f3.rack.rmtree
|
|
|
|
end
|
2016-01-09 11:06:17 +00:00
|
|
|
|
2016-07-16 15:31:03 +03:00
|
|
|
def test_eligible_kegs_for_cleanup_head_installed
|
|
|
|
f = formula do
|
|
|
|
version "0.1"
|
|
|
|
head "foo"
|
|
|
|
end
|
|
|
|
|
|
|
|
stable_prefix = f.installed_prefix
|
|
|
|
stable_prefix.mkpath
|
|
|
|
|
|
|
|
[["000000_1", 1], ["111111", 2], ["111111_1", 2]].each do |pkg_version_suffix, stamp|
|
|
|
|
prefix = f.prefix("HEAD-#{pkg_version_suffix}")
|
|
|
|
prefix.mkpath
|
|
|
|
tab = Tab.empty
|
|
|
|
tab.tabfile = prefix.join("INSTALL_RECEIPT.json")
|
|
|
|
tab.source_modified_time = stamp
|
|
|
|
tab.write
|
|
|
|
end
|
|
|
|
|
|
|
|
eligible_kegs = f.installed_kegs - [Keg.new(f.prefix("HEAD-111111_1"))]
|
|
|
|
assert_equal eligible_kegs, f.eligible_kegs_for_cleanup
|
|
|
|
ensure
|
|
|
|
f.rack.rmtree
|
|
|
|
end
|
|
|
|
|
2016-01-09 11:06:17 +00:00
|
|
|
def test_pour_bottle
|
|
|
|
f_false = formula("foo") do
|
|
|
|
url "foo-1.0"
|
|
|
|
def pour_bottle?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
refute f_false.pour_bottle?
|
|
|
|
|
|
|
|
f_true = formula("foo") do
|
|
|
|
url "foo-1.0"
|
|
|
|
def pour_bottle?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert f_true.pour_bottle?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pour_bottle_dsl
|
|
|
|
f_false = formula("foo") do
|
|
|
|
url "foo-1.0"
|
|
|
|
pour_bottle? do
|
|
|
|
reason "false reason"
|
|
|
|
satisfy { var == etc }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
refute f_false.pour_bottle?
|
|
|
|
|
|
|
|
f_true = formula("foo") do
|
|
|
|
url "foo-1.0"
|
|
|
|
pour_bottle? do
|
|
|
|
reason "true reason"
|
|
|
|
satisfy { var == var }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert f_true.pour_bottle?
|
|
|
|
end
|
2010-03-16 22:33:13 -07:00
|
|
|
end
|
2016-06-27 16:36:12 +03:00
|
|
|
|
|
|
|
class OutdatedVersionsTests < Homebrew::TestCase
|
|
|
|
attr_reader :outdated_prefix, :same_prefix, :greater_prefix, :head_prefix
|
|
|
|
attr_reader :f
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@f = formula { url "foo"; version "1.20" }
|
|
|
|
@outdated_prefix = HOMEBREW_CELLAR/"#{f.name}/1.11"
|
|
|
|
@same_prefix = HOMEBREW_CELLAR/"#{f.name}/1.20"
|
|
|
|
@greater_prefix = HOMEBREW_CELLAR/"#{f.name}/1.21"
|
|
|
|
@head_prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD"
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2016-07-22 12:59:08 +03:00
|
|
|
@f.rack.rmtree if @f.rack.exist?
|
2016-06-27 16:36:12 +03:00
|
|
|
end
|
|
|
|
|
2016-07-22 12:59:08 +03:00
|
|
|
def setup_tab_for_prefix(prefix, options = {})
|
2016-06-27 16:36:12 +03:00
|
|
|
prefix.mkpath
|
|
|
|
tab = Tab.empty
|
|
|
|
tab.tabfile = prefix.join("INSTALL_RECEIPT.json")
|
2016-07-22 12:59:08 +03:00
|
|
|
tab.source["tap"] = options[:tap] if options[:tap]
|
|
|
|
tab.source["versions"] = options[:versions] if options[:versions]
|
|
|
|
tab.source_modified_time = options[:source_modified_time].to_i
|
|
|
|
tab.write unless options[:no_write]
|
2016-06-27 16:36:12 +03:00
|
|
|
tab
|
|
|
|
end
|
|
|
|
|
2016-07-22 12:59:08 +03:00
|
|
|
def reset_outdated_versions
|
|
|
|
f.instance_variable_set(:@outdated_versions, nil)
|
2016-08-01 16:31:36 +03:00
|
|
|
f.instance_variable_set(:@outdated_versions_head_fetched, nil)
|
2016-07-22 12:59:08 +03:00
|
|
|
end
|
|
|
|
|
2016-06-27 16:36:12 +03:00
|
|
|
def test_greater_different_tap_installed
|
2016-07-22 12:59:08 +03:00
|
|
|
setup_tab_for_prefix(greater_prefix, :tap => "user/repo")
|
2016-06-27 16:36:12 +03:00
|
|
|
assert_predicate f.outdated_versions, :empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_greater_same_tap_installed
|
|
|
|
f.instance_variable_set(:@tap, CoreTap.instance)
|
2016-07-22 12:59:08 +03:00
|
|
|
setup_tab_for_prefix(greater_prefix, :tap => "homebrew/core")
|
2016-06-27 16:36:12 +03:00
|
|
|
assert_predicate f.outdated_versions, :empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_outdated_different_tap_installed
|
2016-07-22 12:59:08 +03:00
|
|
|
setup_tab_for_prefix(outdated_prefix, :tap => "user/repo")
|
2016-06-27 16:36:12 +03:00
|
|
|
refute_predicate f.outdated_versions, :empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_outdated_same_tap_installed
|
|
|
|
f.instance_variable_set(:@tap, CoreTap.instance)
|
2016-07-22 12:59:08 +03:00
|
|
|
setup_tab_for_prefix(outdated_prefix, :tap => "homebrew/core")
|
2016-06-27 16:36:12 +03:00
|
|
|
refute_predicate f.outdated_versions, :empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_same_head_installed
|
|
|
|
f.instance_variable_set(:@tap, CoreTap.instance)
|
2016-07-22 12:59:08 +03:00
|
|
|
setup_tab_for_prefix(head_prefix, :tap => "homebrew/core")
|
2016-06-27 16:36:12 +03:00
|
|
|
assert_predicate f.outdated_versions, :empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_different_head_installed
|
|
|
|
f.instance_variable_set(:@tap, CoreTap.instance)
|
2016-07-22 12:59:08 +03:00
|
|
|
setup_tab_for_prefix(head_prefix, :tap => "user/repo")
|
2016-06-27 16:36:12 +03:00
|
|
|
assert_predicate f.outdated_versions, :empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mixed_taps_greater_version_installed
|
|
|
|
f.instance_variable_set(:@tap, CoreTap.instance)
|
2016-07-22 12:59:08 +03:00
|
|
|
setup_tab_for_prefix(outdated_prefix, :tap => "homebrew/core")
|
|
|
|
setup_tab_for_prefix(greater_prefix, :tap => "user/repo")
|
2016-06-27 16:36:12 +03:00
|
|
|
|
|
|
|
assert_predicate f.outdated_versions, :empty?
|
|
|
|
|
2016-07-22 12:59:08 +03:00
|
|
|
setup_tab_for_prefix(greater_prefix, :tap => "homebrew/core")
|
|
|
|
reset_outdated_versions
|
2016-06-27 16:36:12 +03:00
|
|
|
|
|
|
|
assert_predicate f.outdated_versions, :empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mixed_taps_outdated_version_installed
|
|
|
|
f.instance_variable_set(:@tap, CoreTap.instance)
|
|
|
|
|
|
|
|
extra_outdated_prefix = HOMEBREW_CELLAR/"#{f.name}/1.0"
|
|
|
|
|
|
|
|
setup_tab_for_prefix(outdated_prefix)
|
2016-07-22 12:59:08 +03:00
|
|
|
setup_tab_for_prefix(extra_outdated_prefix, :tap => "homebrew/core")
|
|
|
|
reset_outdated_versions
|
2016-06-27 16:36:12 +03:00
|
|
|
|
|
|
|
refute_predicate f.outdated_versions, :empty?
|
|
|
|
|
2016-07-22 12:59:08 +03:00
|
|
|
setup_tab_for_prefix(outdated_prefix, :tap => "user/repo")
|
|
|
|
reset_outdated_versions
|
2016-06-27 16:36:12 +03:00
|
|
|
|
|
|
|
refute_predicate f.outdated_versions, :empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_same_version_tap_installed
|
|
|
|
f.instance_variable_set(:@tap, CoreTap.instance)
|
2016-07-22 12:59:08 +03:00
|
|
|
setup_tab_for_prefix(same_prefix, :tap => "homebrew/core")
|
|
|
|
|
|
|
|
assert_predicate f.outdated_versions, :empty?
|
|
|
|
|
|
|
|
setup_tab_for_prefix(same_prefix, :tap => "user/repo")
|
|
|
|
reset_outdated_versions
|
2016-06-27 16:36:12 +03:00
|
|
|
|
|
|
|
assert_predicate f.outdated_versions, :empty?
|
2016-07-22 12:59:08 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_outdated_installed_head_less_than_stable
|
|
|
|
tab = setup_tab_for_prefix(head_prefix, :versions => { "stable" => "1.0" })
|
|
|
|
refute_predicate f.outdated_versions, :empty?
|
2016-06-27 16:36:12 +03:00
|
|
|
|
2016-07-22 12:59:08 +03:00
|
|
|
# Tab.for_keg(head_prefix) will be fetched from CACHE but we write it anyway
|
|
|
|
tab.source["versions"] = { "stable" => f.version.to_s }
|
|
|
|
tab.write
|
|
|
|
reset_outdated_versions
|
2016-06-27 16:36:12 +03:00
|
|
|
|
|
|
|
assert_predicate f.outdated_versions, :empty?
|
|
|
|
end
|
2016-07-22 12:59:08 +03:00
|
|
|
|
|
|
|
def test_outdated_fetch_head
|
|
|
|
outdated_stable_prefix = HOMEBREW_CELLAR.join("testball/1.0")
|
|
|
|
head_prefix_a = HOMEBREW_CELLAR.join("testball/HEAD")
|
|
|
|
head_prefix_b = HOMEBREW_CELLAR.join("testball/HEAD-aaaaaaa_1")
|
|
|
|
head_prefix_c = HOMEBREW_CELLAR.join("testball/HEAD-5658946")
|
|
|
|
|
|
|
|
setup_tab_for_prefix(outdated_stable_prefix)
|
|
|
|
tab_a = setup_tab_for_prefix(head_prefix_a, :versions => { "stable" => "1.0" })
|
|
|
|
setup_tab_for_prefix(head_prefix_b)
|
|
|
|
|
|
|
|
initial_env = ENV.to_hash
|
|
|
|
testball_repo = HOMEBREW_PREFIX.join("testball_repo")
|
|
|
|
testball_repo.mkdir
|
|
|
|
|
|
|
|
@f = formula("testball") do
|
|
|
|
url "foo"
|
|
|
|
version "2.10"
|
|
|
|
head "file://#{testball_repo}", :using => :git
|
|
|
|
end
|
|
|
|
|
|
|
|
%w[AUTHOR COMMITTER].each do |role|
|
|
|
|
ENV["GIT_#{role}_NAME"] = "brew tests"
|
|
|
|
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
|
|
|
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
|
|
|
|
end
|
|
|
|
|
|
|
|
testball_repo.cd do
|
|
|
|
FileUtils.touch "LICENSE"
|
|
|
|
shutup do
|
|
|
|
system "git", "init"
|
|
|
|
system "git", "add", "--all"
|
|
|
|
system "git", "commit", "-m", "Initial commit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
refute_predicate f.outdated_versions(:fetch_head => true), :empty?
|
|
|
|
|
|
|
|
tab_a.source["versions"] = { "stable" => f.version.to_s }
|
|
|
|
tab_a.write
|
|
|
|
reset_outdated_versions
|
|
|
|
refute_predicate f.outdated_versions(:fetch_head => true), :empty?
|
|
|
|
|
|
|
|
head_prefix_a.rmtree
|
|
|
|
reset_outdated_versions
|
|
|
|
refute_predicate f.outdated_versions(:fetch_head => true), :empty?
|
|
|
|
|
|
|
|
setup_tab_for_prefix(head_prefix_c, :source_modified_time => 1)
|
|
|
|
reset_outdated_versions
|
|
|
|
assert_predicate f.outdated_versions(:fetch_head => true), :empty?
|
|
|
|
ensure
|
|
|
|
ENV.replace(initial_env)
|
|
|
|
testball_repo.rmtree if testball_repo.exist?
|
|
|
|
outdated_stable_prefix.rmtree if outdated_stable_prefix.exist?
|
|
|
|
head_prefix_b.rmtree if head_prefix.exist?
|
|
|
|
head_prefix_c.rmtree if head_prefix_c.exist?
|
|
|
|
FileUtils.rm_rf HOMEBREW_CACHE/"testball--git"
|
|
|
|
FileUtils.rm_rf HOMEBREW_CELLAR/"testball"
|
|
|
|
end
|
2016-06-27 16:36:12 +03:00
|
|
|
end
|