brew/Library/Homebrew/test/unittest.rb

108 lines
2.5 KiB
Ruby
Raw Normal View History

2009-05-21 00:04:43 +01:00
#!/usr/bin/ruby
# 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__)
$:.push(File.expand_path(__FILE__+'/../..'))
require 'extend/pathname'
# 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 :)
HOMEBREW_PREFIX=Pathname.new '/private/tmp/testbrew/prefix'
2009-09-29 20:35:10 +01:00
HOMEBREW_REPOSITORY=HOMEBREW_PREFIX
HOMEBREW_CACHE=HOMEBREW_PREFIX.parent+"cache"
HOMEBREW_CELLAR=HOMEBREW_PREFIX.parent+"cellar"
HOMEBREW_USER_AGENT="Homebrew"
HOMEBREW_WWW='http://example.com'
MACOS_VERSION=10.6
2009-09-01 12:05:26 +01:00
(HOMEBREW_PREFIX+'Library'+'Formula').mkpath
Dir.chdir HOMEBREW_PREFIX
at_exit { HOMEBREW_PREFIX.parent.rmtree }
2009-09-01 12:05:26 +01:00
require 'utils'
require 'formula'
require 'keg'
require 'brew.h'
# 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
class BuildError <ExecutionError; end
2009-07-31 02:57:08 +01:00
require 'test/unit' # must be after at_exit
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
@url=url
@homepage = 'http://example.com/'
2009-06-05 23:39:56 +01:00
super 'test'
end
end
class MostlyAbstractFormula <Formula
@url=''
@homepage = 'http://example.com/'
end
2009-07-31 02:57:08 +01:00
class TestBall <Formula
# 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"
@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
zip=HOMEBREW_CACHE.parent+'test-0.1.zip'
Kernel.system '/usr/bin/zip', '-0', zip, ABS__FILE__
@url="file://#{zip}"
@homepage = 'http://example.com/'
2009-08-10 18:16:12 +01:00
super 'testzip'
end
end
2009-07-31 14:17:56 +01:00
class TestBallOverrideBrew <Formula
def initialize
super "foo"
end
def brew
end
end
module ExtendArgvPlusYeast
def reset
@named = nil
@downcased_unique_named = nil
@formulae = nil
@kegs = nil
ARGV.shift while ARGV.length > 0
end
end
ARGV.extend ExtendArgvPlusYeast
require 'test/test_bucket'