Add predicate methods for specs and stop testing internals

This commit is contained in:
Jack Nagel 2014-10-29 23:32:38 -05:00
parent 1753362024
commit 1a487fa2b3
4 changed files with 71 additions and 75 deletions

View File

@ -65,6 +65,18 @@ class Formula
end end
end end
def stable?
active_spec == stable
end
def devel?
active_spec == devel
end
def head?
active_spec == head
end
def bottle def bottle
Bottle.new(self, active_spec.bottle_specification) if active_spec.bottled? Bottle.new(self, active_spec.bottle_specification) if active_spec.bottled?
end end

View File

@ -437,9 +437,10 @@ class FormulaInstaller
args << "--cc=#{ARGV.cc}" if ARGV.cc args << "--cc=#{ARGV.cc}" if ARGV.cc
args << "--env=#{ARGV.env}" if ARGV.env args << "--env=#{ARGV.env}" if ARGV.env
case formula.active_spec if formula.head?
when formula.head then args << "--HEAD" args << "--HEAD"
when formula.devel then args << "--devel" elsif formula.devel?
args << "--devel"
end end
formula.options.each do |opt| formula.options.each do |opt|

View File

@ -91,7 +91,7 @@ class FormulaTests < Homebrew::TestCase
f.rack.rmtree f.rack.rmtree
end end
def test_installed_prefix_head_active_spec def test_installed_prefix_head
f = formula("test", Pathname.new(__FILE__).expand_path, :head) do f = formula("test", Pathname.new(__FILE__).expand_path, :head) do
head 'foo' head 'foo'
devel do devel do
@ -103,7 +103,7 @@ class FormulaTests < Homebrew::TestCase
assert_equal prefix, f.installed_prefix assert_equal prefix, f.installed_prefix
end end
def test_installed_prefix_devel_active_spec def test_installed_prefix_devel
f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do
head 'foo' head 'foo'
devel do devel do
@ -171,7 +171,7 @@ class FormulaTests < Homebrew::TestCase
assert_equal 'http://example.com', f.homepage assert_equal 'http://example.com', f.homepage
assert_version_equal '0.1', f.version assert_version_equal '0.1', f.version
assert_equal f.stable, f.active_spec assert_predicate f, :stable?
assert_instance_of SoftwareSpec, f.stable assert_instance_of SoftwareSpec, f.stable
assert_instance_of SoftwareSpec, f.devel assert_instance_of SoftwareSpec, f.devel

View File

@ -2,115 +2,98 @@ require 'testing_env'
require 'formula' require 'formula'
class FormulaSpecSelectionTests < Homebrew::TestCase class FormulaSpecSelectionTests < Homebrew::TestCase
def assert_spec_selected(spec)
assert_equal @_f.send(spec), @_f.active_spec
end
def assert_spec_unset(spec)
assert_nil @_f.send(spec)
end
def test_selects_stable_by_default def test_selects_stable_by_default
formula do f = formula {
url 'foo-1.0' url "foo-1.0"
devel { url 'foo-1.1a' } devel { url "foo-1.1a" }
head 'foo' head "foo"
end }
assert_spec_selected :stable assert_predicate f, :stable?
end end
def test_selects_stable_when_exclusive def test_selects_stable_when_exclusive
formula do f = formula { url "foo-1.0" }
url 'foo-1.0' assert_predicate f, :stable?
end
assert_spec_selected :stable
end end
def test_selects_devel_before_head def test_selects_devel_before_head
formula do f = formula {
devel { url 'foo-1.1a' } devel { url "foo-1.1a" }
head 'foo' head "foo"
end }
assert_spec_selected :devel assert_predicate f, :devel?
end end
def test_selects_devel_when_exclusive def test_selects_devel_when_exclusive
formula do f = formula { devel { url "foo-1.1a" } }
devel { url 'foo-1.1a' } assert_predicate f, :devel?
end
assert_spec_selected :devel
end end
def test_selects_head_when_exclusive def test_selects_head_when_exclusive
formula do f = formula { head "foo" }
head 'foo' assert_predicate f, :head?
end
assert_spec_selected :head
end end
def test_incomplete_spec_not_selected def test_incomplete_spec_not_selected
formula do f = formula {
sha1 TEST_SHA1 sha1 TEST_SHA1
version '1.0' version "1.0"
head 'foo' head "foo"
end }
assert_spec_selected :head assert_predicate f, :head?
end end
def test_incomplete_stable_not_set def test_incomplete_stable_not_set
formula do f = formula {
sha1 TEST_SHA1 sha1 TEST_SHA1
devel { url 'foo-1.1a' } devel { url "foo-1.1a" }
head 'foo' head "foo"
end }
assert_spec_unset :stable assert_nil f.stable
assert_spec_selected :devel assert_predicate f, :devel?
end end
def test_selects_head_when_requested def test_selects_head_when_requested
formula("test", Pathname.new(__FILE__).expand_path, :head) do f = formula("test", Pathname.new(__FILE__).expand_path, :head) {
url 'foo-1.0' url "foo-1.0"
devel { url 'foo-1.1a' } devel { url "foo-1.1a" }
head 'foo' head "foo"
end }
assert_spec_selected :head assert_predicate f, :head?
end end
def test_selects_devel_when_requested def test_selects_devel_when_requested
formula("test", Pathname.new(__FILE__).expand_path, :devel) do f = formula("test", Pathname.new(__FILE__).expand_path, :devel) {
url 'foo-1.0' url "foo-1.0"
devel { url 'foo-1.1a' } devel { url "foo-1.1a" }
head 'foo' head "foo"
end }
assert_spec_selected :devel assert_predicate f, :devel?
end end
def test_incomplete_devel_not_set def test_incomplete_devel_not_set
formula do f = formula {
url 'foo-1.0' url "foo-1.0"
devel { version '1.1a' } devel { version "1.1a" }
head 'foo' head "foo"
end }
assert_spec_unset :devel assert_nil f.devel
assert_spec_selected :stable assert_predicate f, :stable?
end end
def test_does_not_raise_for_missing_spec def test_does_not_raise_for_missing_spec
formula("test", Pathname.new(__FILE__).expand_path, :devel) do f = formula("test", Pathname.new(__FILE__).expand_path, :devel) {
url 'foo-1.0' url "foo-1.0"
head 'foo' head "foo"
end }
assert_spec_selected :stable assert_predicate f, :stable?
end end
end end