diff options
| author | Max Howell | 2009-08-10 16:48:30 +0100 |
|---|---|---|
| committer | Max Howell | 2009-08-10 18:11:17 +0100 |
| commit | 760c083c0c0c9934e4118b4669c8c8dfd0a3587d (patch) | |
| tree | 0ed76c2d20225ff1fe7e07490bc17a8932d60bab /Library/Homebrew/unittest.rb | |
| parent | 5a396fd8b48835e826fe3193bd88e2274be60206 (diff) | |
| download | brew-0.4.tar.bz2 | |
Refactor0.4
Large refactor to Formula, mostly improving reliability and error handling but
also layout and readability.
General improvements so testing can be more complete.
Patches are automatically downloaded and applied for Formula that return a
list of urls from Formula::patches.
Split out the brew command logic to facilitate testing.
Facility from Adam Vandenberg to allow selective cleaning of files, added
because Python doesn't work when stripped.
Diffstat (limited to 'Library/Homebrew/unittest.rb')
| -rwxr-xr-x | Library/Homebrew/unittest.rb | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/Library/Homebrew/unittest.rb b/Library/Homebrew/unittest.rb index 878b05ab9..1bee7b3a6 100755 --- a/Library/Homebrew/unittest.rb +++ b/Library/Homebrew/unittest.rb @@ -1,9 +1,8 @@ #!/usr/bin/ruby $:.unshift File.dirname(__FILE__) +require 'pathname+yeast' require 'formula' require 'keg' -require 'pathname+yeast' -require 'stringio' require 'utils' # these are defined in env.rb usually, but we don't want to break our actual @@ -17,6 +16,7 @@ HOMEBREW_CELLAR.mkpath raise "HOMEBREW_CELLAR couldn't be created!" unless HOMEBREW_CELLAR.directory? at_exit { HOMEBREW_PREFIX.parent.rmtree } require 'test/unit' # must be after at_exit +require 'ARGV+yeast' # needs to be after test/unit to avoid conflict with OptionsParser class MockFormula <Formula @@ -26,12 +26,16 @@ class MockFormula <Formula end end +class MostlyAbstractFormula <AbstractFormula + @url='' +end + class TestBall <Formula def initialize @url="file:///#{Pathname.new(__FILE__).parent.realpath}/testball-0.1.tbz" super "testball" end - + def install prefix.install "bin" prefix.install "libexec" @@ -51,16 +55,28 @@ class TestBallOverrideBrew <Formula super "foo" end def brew - puts "We can't override brew" + # We can't override brew end end +class TestScriptFileFormula <ScriptFileFormula + @url="file:///#{Pathname.new(__FILE__).realpath}" + @version="1" + + def initialize + super + @name='test-script-formula' + end +end def nostdout - tmp=$stdout + require 'stringio' + tmpo=$stdout + tmpe=$stderr $stdout=StringIO.new yield - $stdout=tmp +ensure + $stdout=tmpo end @@ -162,9 +178,10 @@ class BeerTasting <Test::Unit::TestCase def test_install f=TestBall.new + assert_equal Formula.path(f.name), f.path assert !f.installed? - nostdout do + nostdout do f.brew do f.install end @@ -180,17 +197,29 @@ class BeerTasting <Test::Unit::TestCase assert !(f.prefix+'main.c').exist? assert f.installed? - keg=Keg.new f - keg.ln + keg=Keg.new f.prefix + keg.link assert_equal 2, HOMEBREW_PREFIX.children.length assert (HOMEBREW_PREFIX+'bin').directory? assert_equal 3, (HOMEBREW_PREFIX+'bin').children.length - keg.rm - assert !keg.path.exist? + keg.uninstall + assert !keg.exist? assert !f.installed? end + def test_script_install + f=TestScriptFileFormula.new + + nostdout do + f.brew do + f.install + end + end + + assert_equal 1, f.bin.children.length + end + def test_md5 assert_nothing_raised { nostdout { TestBallValidMd5.new.brew {} } } end @@ -213,10 +242,17 @@ class BeerTasting <Test::Unit::TestCase path.dirname.mkpath `echo "require 'brewkit'; class #{classname} <Formula; @url=''; end" > #{path}` - assert_not_nil Formula.create(FOOBAR) + assert_not_nil Formula.factory(FOOBAR) end def test_cant_override_brew assert_raises(RuntimeError) { TestBallOverrideBrew.new } end + + def test_abstract_formula + f=MostlyAbstractFormula.new + assert_nil f.name + assert_raises(RuntimeError) { f.prefix } + nostdout { assert_raises(ExecutionError) { f.brew } } + end end |
