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__)
|
|
|
|
|
2009-10-23 16:40:55 +01:00
|
|
|
$:.push(File.expand_path(__FILE__+'/../..'))
|
2009-10-15 12:36:09 +01:00
|
|
|
require 'extend/pathname'
|
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-09-29 20:35:10 +01:00
|
|
|
HOMEBREW_REPOSITORY=HOMEBREW_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-11-12 01:33:14 +00:00
|
|
|
HOMEBREW_WWW='http://example.com'
|
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-11-12 01:33:14 +00:00
|
|
|
require 'utils'
|
|
|
|
require 'hardware'
|
|
|
|
require 'formula'
|
|
|
|
require 'download_strategy'
|
|
|
|
require 'keg'
|
|
|
|
require 'utils'
|
|
|
|
require 'brew.h'
|
|
|
|
require 'hardware'
|
|
|
|
require 'update'
|
|
|
|
|
2009-11-09 17:44:29 +00:00
|
|
|
# for some reason our utils.rb safe_system behaves completely differently
|
|
|
|
# during these tests. This is worrying for sure.
|
|
|
|
def safe_system *args
|
|
|
|
Kernel.system *args
|
|
|
|
end
|
|
|
|
|
|
|
|
class ExecutionError <RuntimeError
|
|
|
|
attr :status
|
|
|
|
|
|
|
|
def initialize cmd, args=[], status=nil
|
|
|
|
super "Failure while executing: #{cmd} #{args*' '}"
|
|
|
|
@status = status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-12-18 16:38:48 -08:00
|
|
|
class BuildError <ExecutionError; end
|
2009-11-09 17:44:29 +00:00
|
|
|
|
2009-07-31 02:57:08 +01:00
|
|
|
require 'test/unit' # must be after at_exit
|
2009-10-15 12:36:09 +01:00
|
|
|
require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
|
|
|
|
ARGV.extend(HomebrewArgvExtension)
|
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-09-25 21:04:57 +02:00
|
|
|
@homepage = 'http://example.com/'
|
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=''
|
2009-09-25 21:04:57 +02:00
|
|
|
@homepage = 'http://example.com/'
|
2009-08-10 16:48:30 +01:00
|
|
|
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-09-25 21:04:57 +02:00
|
|
|
@homepage = 'http://example.com/'
|
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-09-25 21:04:57 +02:00
|
|
|
@homepage = 'http://example.com/'
|
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
|
|
|
|
@name='test-script-formula'
|
2009-09-25 21:04:57 +02:00
|
|
|
@homepage = 'http://example.com/'
|
|
|
|
super
|
2009-08-10 16:48:30 +01:00
|
|
|
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?
|
2009-09-20 17:54:10 +02:00
|
|
|
@expect.keys.sort == @called.sort
|
2009-09-11 19:39:13 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
|
|
|
"#<#{self.class.name} #{object_id}>"
|
|
|
|
end
|
2009-09-08 00:02:28 +02: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-10-24 18:09:43 +01:00
|
|
|
@named = nil
|
|
|
|
@downcased_unique_named = nil
|
|
|
|
@formulae = nil
|
|
|
|
@kegs = nil
|
|
|
|
ARGV.shift while ARGV.length > 0
|
2009-09-05 14:30:56 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
ARGV.extend ExtendArgvPlusYeast
|
|
|
|
|
2010-01-29 10:41:03 -08:00
|
|
|
require 'test/test_versions'
|
|
|
|
require 'test/test_checksums'
|
|
|
|
require 'test/test_updater' unless ARGV.include? "--skip-update"
|
|
|
|
require 'test/test_bucket'
|
|
|
|
require 'test/test_inreplace'
|