2009-05-21 00:04:43 +01:00
|
|
|
#!/usr/bin/ruby
|
2009-08-31 16:01:36 +01:00
|
|
|
# This software is in the public domain, furnished "as is", without technical
|
|
|
|
# support, and with no warranty, express or implied, as to its usefulness for
|
|
|
|
# any purpose.
|
|
|
|
|
2009-09-01 12:05:26 +01:00
|
|
|
ABS__FILE__=File.expand_path(__FILE__)
|
|
|
|
|
|
|
|
$:.unshift File.dirname(ABS__FILE__)
|
2009-08-10 16:48:30 +01:00
|
|
|
require 'pathname+yeast'
|
2009-07-24 15:10:01 +01:00
|
|
|
require 'formula'
|
2009-08-21 20:30:13 +01:00
|
|
|
require 'download_strategy'
|
2009-07-31 02:57:08 +01:00
|
|
|
require 'keg'
|
2009-07-31 02:51:17 +01:00
|
|
|
require 'utils'
|
2009-09-01 12:05:26 +01:00
|
|
|
require 'brew.h'
|
2009-09-17 18:39:47 +01:00
|
|
|
require 'hardware'
|
|
|
|
require 'update'
|
2009-07-31 02:51:17 +01:00
|
|
|
|
2009-09-04 15:28:18 +01:00
|
|
|
# these are defined in global.rb, but we don't want to break our actual
|
2009-07-31 02:57:08 +01:00
|
|
|
# homebrew tree, and we do want to test everything :)
|
2009-09-08 00:02:28 +02:00
|
|
|
HOMEBREW_PREFIX=Pathname.new '/private/tmp/testbrew/prefix'
|
2009-08-04 00:43:16 +01:00
|
|
|
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-09-23 07:56:07 -07:00
|
|
|
MACOS_VERSION=10.6
|
2009-06-02 13:39:39 +01:00
|
|
|
|
2009-09-01 12:05:26 +01:00
|
|
|
(HOMEBREW_PREFIX+'Library'+'Formula').mkpath
|
|
|
|
Dir.chdir HOMEBREW_PREFIX
|
2009-08-04 01:31:32 +01:00
|
|
|
at_exit { HOMEBREW_PREFIX.parent.rmtree }
|
2009-09-01 12:05:26 +01:00
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
require 'test/unit' # must be after at_exit
|
2009-08-10 16:48:30 +01:00
|
|
|
require 'ARGV+yeast' # needs to be after test/unit to avoid conflict with OptionsParser
|
2009-07-31 02:57:08 +01:00
|
|
|
|
|
|
|
|
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-08-21 20:20:44 +01:00
|
|
|
class MostlyAbstractFormula <Formula
|
2009-08-10 16:48:30 +01:00
|
|
|
@url=''
|
|
|
|
end
|
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
class TestBall <Formula
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
# name parameter required for some Formula::factory
|
|
|
|
def initialize name=nil
|
2009-09-01 12:05:26 +01:00
|
|
|
@url="file:///#{Pathname.new(ABS__FILE__).parent.realpath}/testball-0.1.tbz"
|
2009-07-31 02:57:08 +01:00
|
|
|
super "testball"
|
|
|
|
end
|
|
|
|
def install
|
|
|
|
prefix.install "bin"
|
|
|
|
prefix.install "libexec"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-10 18:16:12 +01:00
|
|
|
class TestZip <Formula
|
|
|
|
def initialize
|
2009-08-11 12:20:55 -07:00
|
|
|
zip=HOMEBREW_CACHE.parent+'test-0.1.zip'
|
2009-09-23 16:44:10 +01:00
|
|
|
Kernel.system '/usr/bin/zip', '-0', zip, ABS__FILE__
|
2009-08-11 12:20:55 -07:00
|
|
|
@url="file://#{zip}"
|
2009-08-10 18:16:12 +01:00
|
|
|
super 'testzip'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-21 20:20:44 +01:00
|
|
|
class TestBadVersion <TestBall
|
|
|
|
@version="versions can't have spaces"
|
|
|
|
end
|
|
|
|
|
2009-07-31 14:17:56 +01:00
|
|
|
class TestBallOverrideBrew <Formula
|
|
|
|
def initialize
|
|
|
|
super "foo"
|
|
|
|
end
|
|
|
|
def brew
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
class TestScriptFileFormula <ScriptFileFormula
|
2009-09-22 12:31:53 -04:00
|
|
|
url "file:///#{Pathname.new(ABS__FILE__).realpath}"
|
|
|
|
version "1"
|
2009-08-10 16:48:30 +01:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@name='test-script-formula'
|
|
|
|
end
|
|
|
|
end
|
2009-07-31 02:57:08 +01:00
|
|
|
|
2009-09-08 00:02:28 +02:00
|
|
|
class RefreshBrewMock < RefreshBrew
|
2009-09-11 19:39:13 +02:00
|
|
|
def in_prefix_expect(expect, returns = '')
|
|
|
|
@expect ||= {}
|
|
|
|
@expect[expect] = returns
|
2009-09-08 00:02:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def `(cmd)
|
2009-09-11 19:39:13 +02:00
|
|
|
if Dir.pwd == HOMEBREW_PREFIX.to_s and @expect.has_key?(cmd)
|
|
|
|
(@called ||= []) << cmd
|
|
|
|
@expect[cmd]
|
2009-09-08 00:02:28 +02:00
|
|
|
else
|
2009-09-11 19:39:13 +02:00
|
|
|
raise "#{inspect} Unexpectedly called backticks in pwd `#{HOMEBREW_PREFIX}' and command `#{cmd}'"
|
2009-09-08 00:02:28 +02:00
|
|
|
end
|
|
|
|
end
|
2009-09-11 19:39:13 +02:00
|
|
|
|
|
|
|
def expectations_met?
|
|
|
|
@expect.keys == @called
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
|
|
|
"#<#{self.class.name} #{object_id}>"
|
|
|
|
end
|
2009-09-08 00:02:28 +02:00
|
|
|
end
|
|
|
|
|
2009-06-15 01:16:00 +01:00
|
|
|
def nostdout
|
2009-08-11 12:20:55 -07:00
|
|
|
if ARGV.include? '-V'
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
require 'stringio'
|
|
|
|
tmpo=$stdout
|
|
|
|
tmpe=$stderr
|
|
|
|
$stdout=StringIO.new
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
$stdout=tmpo
|
|
|
|
end
|
2009-06-15 01:16:00 +01:00
|
|
|
end
|
|
|
|
|
2009-09-05 14:30:56 +01:00
|
|
|
module ExtendArgvPlusYeast
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
def reset
|
2009-09-05 14:30:56 +01:00
|
|
|
@named=nil
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
@formulae=nil
|
|
|
|
@kegs=nil
|
|
|
|
while ARGV.count > 0
|
|
|
|
ARGV.shift
|
|
|
|
end
|
2009-09-05 14:30:56 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
ARGV.extend ExtendArgvPlusYeast
|
|
|
|
|
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-08-08 14:24:26 +01:00
|
|
|
def test_version_github
|
|
|
|
r=MockFormula.new "http://github.com/lloyd/yajl/tarball/1.0.5"
|
|
|
|
assert_equal '1.0.5', 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
|
|
|
|
2009-08-22 15:53:35 +01:00
|
|
|
def test_no_version
|
|
|
|
assert_nil Pathname.new("http://example.com/blah.tar").version
|
|
|
|
assert_nil Pathname.new("arse").version
|
|
|
|
end
|
|
|
|
|
2009-08-21 20:20:44 +01:00
|
|
|
def test_bad_version
|
|
|
|
assert_raises(RuntimeError) {f=TestBadVersion.new}
|
|
|
|
end
|
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
def test_install
|
|
|
|
f=TestBall.new
|
2009-07-31 14:04:24 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
assert_equal Formula.path(f.name), f.path
|
2009-07-31 14:04:24 +01:00
|
|
|
assert !f.installed?
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
nostdout do
|
2009-07-31 02:57:08 +01:00
|
|
|
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
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
keg=Keg.new f.prefix
|
|
|
|
keg.link
|
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
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
keg.uninstall
|
|
|
|
assert !keg.exist?
|
2009-07-31 14:17:56 +01:00
|
|
|
assert !f.installed?
|
2009-07-31 02:57:08 +01:00
|
|
|
end
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
def test_script_install
|
|
|
|
f=TestScriptFileFormula.new
|
|
|
|
|
|
|
|
nostdout do
|
|
|
|
f.brew do
|
|
|
|
f.install
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 1, f.bin.children.length
|
|
|
|
end
|
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
def test_md5
|
2009-09-07 15:26:43 +02:00
|
|
|
valid_md5 = Class.new(TestBall) do
|
|
|
|
@md5='71aa838a9e4050d1876a295a9e62cbe6'
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nothing_raised { nostdout { valid_md5.new.brew {} } }
|
2009-07-31 02:57:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_badmd5
|
2009-09-07 15:26:43 +02:00
|
|
|
invalid_md5 = Class.new(TestBall) do
|
|
|
|
@md5='61aa838a9e4050d1876a295a9e62cbe6'
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
nostdout { invalid_md5.new.brew {} }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_sha1
|
|
|
|
valid_sha1 = Class.new(TestBall) do
|
|
|
|
@sha1='6ea8a98acb8f918df723c2ae73fe67d5664bfd7e'
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nothing_raised { nostdout { valid_sha1.new.brew {} } }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_badsha1
|
|
|
|
invalid_sha1 = Class.new(TestBall) do
|
|
|
|
@sha1='7ea8a98acb8f918df723c2ae73fe67d5664bfd7e'
|
|
|
|
end
|
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
assert_raises RuntimeError do
|
2009-09-07 15:26:43 +02:00
|
|
|
nostdout { invalid_sha1.new.brew {} }
|
2009-07-31 02:57:08 +01:00
|
|
|
end
|
|
|
|
end
|
2009-09-07 16:10:50 +02:00
|
|
|
|
|
|
|
def test_sha256
|
|
|
|
valid_sha256 = Class.new(TestBall) do
|
|
|
|
@sha256='ccbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8'
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
|
|
|
nostdout { valid_sha256.new.brew {} }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_badsha256
|
|
|
|
invalid_sha256 = Class.new(TestBall) do
|
|
|
|
@sha256='dcbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8'
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
nostdout { invalid_sha256.new.brew {} }
|
|
|
|
end
|
|
|
|
end
|
2009-07-31 14:04:24 +01:00
|
|
|
|
|
|
|
FOOBAR='foo-bar'
|
|
|
|
def test_formula_funcs
|
2009-09-11 14:22:46 +01:00
|
|
|
classname=Formula.class_s(FOOBAR)
|
2009-07-31 14:04:24 +01:00
|
|
|
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}`
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
assert_not_nil Formula.factory(FOOBAR)
|
2009-07-31 14:04:24 +01:00
|
|
|
end
|
2009-07-31 14:17:56 +01:00
|
|
|
|
|
|
|
def test_cant_override_brew
|
|
|
|
assert_raises(RuntimeError) { TestBallOverrideBrew.new }
|
|
|
|
end
|
2009-08-10 16:48:30 +01:00
|
|
|
|
|
|
|
def test_abstract_formula
|
2009-08-22 17:26:15 +01:00
|
|
|
f=MostlyAbstractFormula.new
|
|
|
|
assert_equal '__UNKNOWN__', f.name
|
2009-08-10 16:48:30 +01:00
|
|
|
assert_raises(RuntimeError) { f.prefix }
|
2009-08-22 17:26:15 +01:00
|
|
|
nostdout { assert_raises(RuntimeError) { f.brew } }
|
2009-08-10 16:48:30 +01:00
|
|
|
end
|
2009-08-07 15:49:58 +01:00
|
|
|
|
2009-08-10 18:16:12 +01:00
|
|
|
def test_zip
|
|
|
|
nostdout { assert_nothing_raised { TestZip.new.brew {} } }
|
|
|
|
end
|
|
|
|
|
2009-08-07 15:49:58 +01:00
|
|
|
def test_no_ARGV_dupes
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
ARGV.reset
|
|
|
|
ARGV.unshift 'foo'
|
|
|
|
ARGV.unshift 'foo'
|
2009-08-07 15:49:58 +01:00
|
|
|
n=0
|
|
|
|
ARGV.named.each{|arg| n+=1 if arg == 'foo'}
|
|
|
|
assert_equal 1, n
|
|
|
|
end
|
2009-08-11 01:30:39 +01:00
|
|
|
|
|
|
|
def test_ARGV
|
|
|
|
assert_raises(UsageError) { ARGV.named }
|
|
|
|
assert_raises(UsageError) { ARGV.formulae }
|
|
|
|
assert_raises(UsageError) { ARGV.kegs }
|
|
|
|
assert ARGV.named_empty?
|
|
|
|
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
(HOMEBREW_CELLAR+'mxcl'+'10.0').mkpath
|
2009-08-11 01:30:39 +01:00
|
|
|
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
ARGV.reset
|
|
|
|
ARGV.unshift 'mxcl'
|
2009-08-11 01:30:39 +01:00
|
|
|
assert_equal 1, ARGV.named.length
|
|
|
|
assert_equal 1, ARGV.kegs.length
|
|
|
|
assert_raises(FormulaUnavailableError) { ARGV.formulae }
|
|
|
|
end
|
2009-08-12 13:43:20 +01:00
|
|
|
|
|
|
|
def test_version_dir
|
|
|
|
d=HOMEBREW_CELLAR+'foo-0.1.9'
|
|
|
|
d.mkpath
|
|
|
|
assert_equal '0.1.9', d.version
|
|
|
|
end
|
2009-08-30 15:49:38 +01:00
|
|
|
|
2009-09-11 12:51:36 +01:00
|
|
|
def test_lame_version_style
|
|
|
|
f=MockFormula.new 'http://kent.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz'
|
|
|
|
assert_equal '398-2', f.version
|
|
|
|
end
|
|
|
|
|
2009-08-30 15:49:38 +01:00
|
|
|
def test_ruby_version_style
|
|
|
|
f=MockFormula.new 'ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p243.tar.gz'
|
|
|
|
assert_equal '1.9.1-p243', f.version
|
|
|
|
end
|
2009-09-01 12:05:26 +01:00
|
|
|
|
2009-09-02 13:17:15 -06:00
|
|
|
# these will raise if we don't recognise your mac, but that prolly
|
|
|
|
# indicates something went wrong rather than we don't know
|
|
|
|
def test_hardware_cpu_type
|
|
|
|
assert [:intel, :ppc].include?(Hardware.cpu_type)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_hardware_intel_family
|
|
|
|
if Hardware.cpu_type == :intel
|
|
|
|
assert [:core, :core2, :penryn, :nehalem].include?(Hardware.intel_family)
|
|
|
|
end
|
2009-09-01 12:05:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_brew_h
|
|
|
|
nostdout do
|
|
|
|
assert_nothing_raised do
|
|
|
|
f=TestBall.new
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
make f.url
|
2009-09-01 12:05:26 +01:00
|
|
|
info f.name
|
|
|
|
clean f
|
|
|
|
prune
|
|
|
|
#TODO test diy function too
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-09-02 14:15:44 +01:00
|
|
|
|
|
|
|
def test_my_float_assumptions
|
|
|
|
# this may look ridiculous but honestly there's code in brewit that depends on
|
|
|
|
# this behaviour so I wanted to be certain Ruby floating points are behaving
|
|
|
|
f='10.6'.to_f
|
|
|
|
assert_equal 10.6, f
|
|
|
|
assert f >= 10.6
|
|
|
|
assert f <= 10.6
|
|
|
|
assert_equal 10.5, f-0.1
|
|
|
|
assert_equal 10.7, f+0.1
|
|
|
|
end
|
2009-09-02 14:31:28 +01:00
|
|
|
|
2009-09-08 15:31:28 -07:00
|
|
|
def test_arch_for_command
|
|
|
|
arches=arch_for_command '/usr/bin/svn'
|
2009-09-17 00:24:59 +02:00
|
|
|
if `sw_vers -productVersion` =~ /10\.(\d+)/ and $1.to_i >= 6
|
2009-09-13 13:21:22 +02:00
|
|
|
assert_equal 3, arches.count
|
|
|
|
assert arches.include?(:x86_64)
|
|
|
|
else
|
|
|
|
assert_equal 2, arches.count
|
|
|
|
end
|
2009-09-08 15:31:28 -07:00
|
|
|
assert arches.include?(:i386)
|
|
|
|
assert arches.include?(:ppc7400)
|
|
|
|
end
|
|
|
|
|
2009-09-02 14:31:28 +01:00
|
|
|
def test_pathname_plus_yeast
|
|
|
|
nostdout do
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert !Pathname.getwd.rmdir_if_possible
|
|
|
|
assert !Pathname.getwd.abv.empty?
|
|
|
|
|
|
|
|
abcd=orig_abcd=HOMEBREW_CACHE+'abcd'
|
|
|
|
FileUtils.cp ABS__FILE__, abcd
|
|
|
|
abcd=HOMEBREW_PREFIX.install abcd
|
|
|
|
assert (HOMEBREW_PREFIX+orig_abcd.basename).exist?
|
|
|
|
assert abcd.exist?
|
|
|
|
assert_equal HOMEBREW_PREFIX+'abcd', abcd
|
|
|
|
|
|
|
|
assert_raises(RuntimeError) {abcd.write 'CONTENT'}
|
|
|
|
abcd.unlink
|
|
|
|
abcd.write 'HELLOWORLD'
|
|
|
|
assert_equal 'HELLOWORLD', File.read(abcd)
|
|
|
|
|
|
|
|
assert !orig_abcd.exist?
|
|
|
|
rv=abcd.cp orig_abcd
|
|
|
|
assert orig_abcd.exist?
|
|
|
|
assert_equal rv, orig_abcd
|
|
|
|
|
|
|
|
orig_abcd.unlink
|
|
|
|
assert !orig_abcd.exist?
|
|
|
|
abcd.cp HOMEBREW_CACHE
|
|
|
|
assert orig_abcd.exist?
|
|
|
|
|
|
|
|
foo1=HOMEBREW_CACHE+'foo-0.1.tar.gz'
|
|
|
|
FileUtils.cp ABS__FILE__, foo1
|
|
|
|
assert foo1.file?
|
|
|
|
|
|
|
|
assert_equal '.tar.gz', foo1.extname
|
|
|
|
assert_equal 'foo-0.1', foo1.stem
|
|
|
|
assert_equal '0.1', foo1.version
|
|
|
|
|
|
|
|
HOMEBREW_CACHE.chmod_R 0777
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raises(RuntimeError) {Pathname.getwd.install 'non_existant_file'}
|
|
|
|
end
|
2009-09-11 14:22:46 +01:00
|
|
|
|
2009-09-23 07:56:07 -07:00
|
|
|
def test_omega_version_style
|
|
|
|
f=MockFormula.new 'http://www.alcyone.com/binaries/omega/omega-0.80.2-src.tar.gz'
|
|
|
|
assert_equal '0.80.2', f.version
|
|
|
|
end
|
|
|
|
|
2009-09-11 14:22:46 +01:00
|
|
|
def test_formula_class_func
|
|
|
|
assert_equal Formula.class_s('s-lang'), 'SLang'
|
|
|
|
assert_equal Formula.class_s('pkg-config'), 'PkgConfig'
|
|
|
|
assert_equal Formula.class_s('foo_bar'), 'FooBar'
|
|
|
|
end
|
2009-09-01 09:17:44 -05:00
|
|
|
|
|
|
|
def test_version_style_rc
|
|
|
|
f=MockFormula.new 'http://ftp.mozilla.org/pub/mozilla.org/js/js-1.8.0-rc1.tar.gz'
|
|
|
|
assert_equal '1.8.0-rc1', f.version
|
|
|
|
end
|
2009-09-08 00:02:28 +02:00
|
|
|
|
|
|
|
def test_updater_update_homebrew_without_any_changes
|
2009-09-11 10:52:32 +02:00
|
|
|
outside_prefix do
|
|
|
|
updater = RefreshBrewMock.new
|
2009-09-18 14:32:21 +01:00
|
|
|
updater.in_prefix_expect("git checkout master")
|
|
|
|
updater.in_prefix_expect("git pull origin master", "Already up-to-date.\n")
|
2009-09-11 10:52:32 +02:00
|
|
|
|
|
|
|
assert_equal false, updater.update_from_masterbrew!
|
2009-09-11 19:39:13 +02:00
|
|
|
assert updater.expectations_met?
|
2009-09-11 10:52:32 +02:00
|
|
|
assert updater.updated_formulae.empty?
|
|
|
|
end
|
2009-09-08 00:02:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_updater_update_homebrew_without_formulae_changes
|
2009-09-11 10:52:32 +02:00
|
|
|
outside_prefix do
|
|
|
|
updater = RefreshBrewMock.new
|
2009-09-18 14:32:21 +01:00
|
|
|
updater.in_prefix_expect("git checkout master")
|
2009-09-11 10:52:32 +02:00
|
|
|
output = fixture('update_git_pull_output_without_formulae_changes')
|
2009-09-18 14:32:21 +01:00
|
|
|
updater.in_prefix_expect("git pull origin master", output)
|
2009-09-11 10:52:32 +02:00
|
|
|
|
|
|
|
assert_equal true, updater.update_from_masterbrew!
|
|
|
|
assert !updater.pending_formulae_changes?
|
|
|
|
assert updater.updated_formulae.empty?
|
|
|
|
end
|
2009-09-08 00:02:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_updater_update_homebrew_with_formulae_changes
|
2009-09-11 10:52:32 +02:00
|
|
|
outside_prefix do
|
|
|
|
updater = RefreshBrewMock.new
|
2009-09-18 14:32:21 +01:00
|
|
|
updater.in_prefix_expect("git checkout master")
|
2009-09-11 10:52:32 +02:00
|
|
|
output = fixture('update_git_pull_output_with_formulae_changes')
|
2009-09-18 14:32:21 +01:00
|
|
|
updater.in_prefix_expect("git pull origin master", output)
|
2009-09-11 10:52:32 +02:00
|
|
|
|
|
|
|
assert_equal true, updater.update_from_masterbrew!
|
|
|
|
assert updater.pending_formulae_changes?
|
|
|
|
assert_equal %w{ antiword bash-completion xar yajl }, updater.updated_formulae
|
|
|
|
end
|
2009-09-08 00:02:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_updater_returns_current_revision
|
2009-09-11 10:52:32 +02:00
|
|
|
outside_prefix do
|
|
|
|
updater = RefreshBrewMock.new
|
|
|
|
updater.in_prefix_expect('git log -l -1 --pretty=format:%H', 'the-revision-hash')
|
|
|
|
assert_equal 'the-revision-hash', updater.current_revision
|
|
|
|
end
|
2009-09-08 00:02:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2009-09-11 10:52:32 +02:00
|
|
|
OUTSIDE_PREFIX = '/tmp'
|
|
|
|
def outside_prefix
|
|
|
|
Dir.chdir(OUTSIDE_PREFIX) { yield }
|
|
|
|
end
|
|
|
|
|
2009-09-08 00:02:28 +02:00
|
|
|
def fixture(name)
|
|
|
|
self.class.fixture_data[name]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.fixture_data
|
|
|
|
unless @fixture_data
|
|
|
|
require 'yaml'
|
|
|
|
@fixture_data = YAML.load(DATA)
|
|
|
|
end
|
|
|
|
@fixture_data
|
|
|
|
end
|
2009-07-31 14:04:24 +01:00
|
|
|
end
|
2009-09-08 00:02:28 +02:00
|
|
|
|
|
|
|
__END__
|
|
|
|
update_git_pull_output_without_formulae_changes: |
|
|
|
|
remote: Counting objects: 58, done.
|
|
|
|
remote: Compressing objects: 100% (35/35), done.
|
|
|
|
remote: Total 39 (delta 20), reused 0 (delta 0)
|
|
|
|
Unpacking objects: 100% (39/39), done.
|
|
|
|
From git://github.com/mxcl/homebrew
|
2009-09-18 14:32:21 +01:00
|
|
|
* branch master -> FETCH_HEAD
|
2009-09-08 00:02:28 +02:00
|
|
|
Updating 14ef7f9..f414bc8
|
|
|
|
Fast forward
|
|
|
|
Library/Homebrew/ARGV+yeast.rb | 35 ++--
|
|
|
|
Library/Homebrew/beer_events.rb | 181 +++++++++++++
|
|
|
|
Library/Homebrew/hardware.rb | 71 ++++++
|
|
|
|
Library/Homebrew/hw.model.c | 17 --
|
|
|
|
README | 337 +++++++++++++------------
|
|
|
|
bin/brew | 137 ++++++++---
|
|
|
|
40 files changed, 1107 insertions(+), 426 deletions(-)
|
|
|
|
create mode 100644 Library/Homebrew/beer_events.rb
|
|
|
|
create mode 100644 Library/Homebrew/hardware.rb
|
|
|
|
delete mode 100644 Library/Homebrew/hw.model.c
|
|
|
|
delete mode 100644 Library/Homebrew/hw.model.rb
|
|
|
|
update_git_pull_output_with_formulae_changes: |
|
|
|
|
remote: Counting objects: 58, done.
|
|
|
|
remote: Compressing objects: 100% (35/35), done.
|
|
|
|
remote: Total 39 (delta 20), reused 0 (delta 0)
|
|
|
|
Unpacking objects: 100% (39/39), done.
|
|
|
|
From git://github.com/mxcl/homebrew
|
2009-09-18 14:32:21 +01:00
|
|
|
* branch master -> FETCH_HEAD
|
2009-09-08 00:02:28 +02:00
|
|
|
Updating 14ef7f9..f414bc8
|
|
|
|
Fast forward
|
|
|
|
Library/Contributions/brew_bash_completion.sh | 6 +-
|
|
|
|
Library/Formula/antiword.rb | 13 +
|
|
|
|
Library/Formula/bash-completion.rb | 25 ++
|
|
|
|
Library/Formula/xar.rb | 19 ++
|
|
|
|
Library/Formula/yajl.rb | 2 +-
|
|
|
|
Library/Homebrew/ARGV+yeast.rb | 35 ++--
|
|
|
|
Library/Homebrew/beer_events.rb | 181 +++++++++++++
|
|
|
|
Library/Homebrew/hardware.rb | 71 ++++++
|
|
|
|
Library/Homebrew/hw.model.c | 17 --
|
|
|
|
Library/Homebrew/pathname+yeast.rb | 28 ++-
|
|
|
|
Library/Homebrew/unittest.rb | 106 ++++++++-
|
|
|
|
Library/Homebrew/utils.rb | 36 ++-
|
|
|
|
README | 337 +++++++++++++------------
|
|
|
|
bin/brew | 137 ++++++++---
|
|
|
|
40 files changed, 1107 insertions(+), 426 deletions(-)
|
|
|
|
create mode 100644 Library/Formula/antiword.rb
|
|
|
|
create mode 100644 Library/Formula/bash-completion.rb
|
|
|
|
create mode 100644 Library/Formula/ddrescue.rb
|
|
|
|
create mode 100644 Library/Formula/dict.rb
|
|
|
|
create mode 100644 Library/Formula/lua.rb
|
|
|
|
delete mode 100644 Library/Formula/antiword.rb
|
|
|
|
delete mode 100644 Library/Formula/bash-completion.rb
|
|
|
|
delete mode 100644 Library/Formula/xar.rb
|
|
|
|
delete mode 100644 Library/Formula/yajl.rb
|
|
|
|
create mode 100644 Library/Homebrew/beer_events.rb
|
|
|
|
create mode 100644 Library/Homebrew/hardware.rb
|
|
|
|
delete mode 100644 Library/Homebrew/hw.model.c
|
|
|
|
delete mode 100644 Library/Homebrew/hw.model.rb
|