| 
									
										
										
										
											2010-03-16 22:13:18 -07:00
										 |  |  | require 'testing_env' | 
					
						
							|  |  |  | require 'test/testball' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | class MockFormula < Formula | 
					
						
							| 
									
										
										
										
											2010-03-16 22:13:18 -07:00
										 |  |  |   def initialize url | 
					
						
							| 
									
										
										
										
											2012-08-07 15:19:08 -05:00
										 |  |  |     @stable = SoftwareSpec.new(url) | 
					
						
							| 
									
										
										
										
											2010-03-16 22:13:18 -07:00
										 |  |  |     super 'test' | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | class TestZip < Formula | 
					
						
							| 
									
										
										
										
											2010-03-16 22:13:18 -07:00
										 |  |  |   def initialize | 
					
						
							| 
									
										
										
										
											2012-08-07 15:19:08 -05:00
										 |  |  |     @homepage = 'http://example.com/' | 
					
						
							| 
									
										
										
										
											2010-03-16 22:13:18 -07:00
										 |  |  |     zip=HOMEBREW_CACHE.parent+'test-0.1.zip' | 
					
						
							| 
									
										
										
										
											2012-04-16 23:52:47 -05:00
										 |  |  |     Kernel.system '/usr/bin/zip', '-q', '-0', zip, ABS__FILE__ | 
					
						
							| 
									
										
										
										
											2012-08-07 15:19:08 -05:00
										 |  |  |     @stable = SoftwareSpec.new "file://#{zip}" | 
					
						
							| 
									
										
										
										
											2010-03-16 22:13:18 -07:00
										 |  |  |     super 'testzip' | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  | # All other tests so far -- feel free to break them out into | 
					
						
							|  |  |  | # separate TestCase classes. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BeerTasting < Test::Unit::TestCase | 
					
						
							| 
									
										
										
										
											2012-07-10 16:01:02 -05:00
										 |  |  |   include VersionAssertions | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   def test_supported_compressed_types | 
					
						
							|  |  |  |     assert_nothing_raised do | 
					
						
							|  |  |  |       MockFormula.new 'test-0.1.tar.gz' | 
					
						
							|  |  |  |       MockFormula.new 'test-0.1.tar.bz2' | 
					
						
							| 
									
										
										
										
											2011-08-26 14:30:27 -05:00
										 |  |  |       MockFormula.new 'test-0.1.tar.xz' | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |       MockFormula.new 'test-0.1.tgz' | 
					
						
							|  |  |  |       MockFormula.new 'test-0.1.bgz' | 
					
						
							| 
									
										
										
										
											2011-08-26 14:30:27 -05:00
										 |  |  |       MockFormula.new 'test-0.1.txz' | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |       MockFormula.new 'test-0.1.zip' | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   FOOBAR='foo-bar' | 
					
						
							|  |  |  |   def test_formula_funcs | 
					
						
							|  |  |  |     classname=Formula.class_s(FOOBAR) | 
					
						
							|  |  |  |     path=Formula.path(FOOBAR) | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |     assert_equal "FooBar", classname | 
					
						
							|  |  |  |     assert_match Regexp.new("^#{HOMEBREW_PREFIX}/Library/Formula"), path.to_s | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-06 14:27:56 -08:00
										 |  |  |     path=HOMEBREW_PREFIX+"Library/Formula/#{FOOBAR}.rb" | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |     path.dirname.mkpath | 
					
						
							|  |  |  |     File.open(path, 'w') do |f| | 
					
						
							|  |  |  |       f << %{
 | 
					
						
							|  |  |  |         require 'formula' | 
					
						
							|  |  |  |         class #{classname} < Formula | 
					
						
							| 
									
										
										
										
											2012-08-07 15:19:08 -05:00
										 |  |  |           url '' | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |           def initialize(*args) | 
					
						
							|  |  |  |             @homepage = 'http://example.com/' | 
					
						
							|  |  |  |             super | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |     assert_not_nil Formula.factory(FOOBAR) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   def test_zip | 
					
						
							|  |  |  |     nostdout { assert_nothing_raised { TestZip.new.brew {} } } | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   # needs resurrecting | 
					
						
							|  |  |  |   # def test_no_ARGV_dupes | 
					
						
							|  |  |  |   #   ARGV.reset | 
					
						
							|  |  |  |   #   ARGV << 'foo' << 'foo' | 
					
						
							|  |  |  |   #   n=0 | 
					
						
							|  |  |  |   #   ARGV.named.each{|f| n+=1 if f == 'foo'} | 
					
						
							|  |  |  |   #   assert_equal 1, n | 
					
						
							|  |  |  |   # end | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   def test_brew_h | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     require 'cmd/info' | 
					
						
							|  |  |  |     require 'cmd/prune' | 
					
						
							|  |  |  |     require 'cleaner' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |     nostdout do | 
					
						
							|  |  |  |       assert_nothing_raised do | 
					
						
							| 
									
										
										
										
											2012-04-13 21:47:33 -05:00
										 |  |  |         f=TestBallWithRealPath.new | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |         Homebrew.info_formula f | 
					
						
							|  |  |  |         Homebrew.prune | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |         #TODO test diy function too | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_brew_cleanup | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     require 'cmd/cleanup' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-01 14:42:30 -06:00
										 |  |  |     f1 = TestBall.new | 
					
						
							|  |  |  |     f1.instance_eval { @version = Version.new("0.1") } | 
					
						
							|  |  |  |     f1.active_spec.instance_eval { @version = Version.new("0.1") } | 
					
						
							|  |  |  |     f2 = TestBall.new | 
					
						
							|  |  |  |     f2.instance_eval { @version = Version.new("0.2") } | 
					
						
							|  |  |  |     f2.active_spec.instance_eval { @version = Version.new("0.2") } | 
					
						
							|  |  |  |     f3 = TestBall.new | 
					
						
							|  |  |  |     f3.instance_eval { @version = Version.new("0.3") } | 
					
						
							|  |  |  |     f3.active_spec.instance_eval { @version = Version.new("0.3") } | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     nostdout do | 
					
						
							|  |  |  |       f1.brew { f1.install } | 
					
						
							|  |  |  |       f2.brew { f2.install } | 
					
						
							|  |  |  |       f3.brew { f3.install } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert f1.installed? | 
					
						
							|  |  |  |     assert f2.installed? | 
					
						
							|  |  |  |     assert f3.installed? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     nostdout do | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       Homebrew.cleanup_formula f3 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert !f1.installed? | 
					
						
							|  |  |  |     assert !f2.installed? | 
					
						
							|  |  |  |     assert f3.installed? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_pathname_plus_yeast | 
					
						
							|  |  |  |     nostdout do | 
					
						
							|  |  |  |       assert_nothing_raised do | 
					
						
							|  |  |  |         assert !Pathname.getwd.rmdir_if_possible | 
					
						
							|  |  |  |         assert !Pathname.getwd.abv.empty? | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |         abcd=orig_abcd=HOMEBREW_CACHE+'abcd' | 
					
						
							|  |  |  |         FileUtils.cp ABS__FILE__, abcd | 
					
						
							| 
									
										
										
										
											2012-02-17 23:07:16 -08:00
										 |  |  |         installed_paths=HOMEBREW_PREFIX.install abcd | 
					
						
							|  |  |  |         abcd = installed_paths[0] | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |         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) | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |         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? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         HOMEBREW_CACHE.chmod_R 0777
 | 
					
						
							| 
									
										
										
										
											2012-04-16 16:43:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         abcd.unlink # teardown | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 22:15:52 -08:00
										 |  |  |   def test_pathname_properties | 
					
						
							| 
									
										
										
										
											2010-11-09 13:00:33 +00:00
										 |  |  |     foo1 = HOMEBREW_CACHE/'foo-0.1.tar.gz' | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 22:15:52 -08:00
										 |  |  |     assert_equal '.tar.gz', foo1.extname | 
					
						
							|  |  |  |     assert_equal 'foo-0.1', foo1.stem | 
					
						
							| 
									
										
										
										
											2012-07-10 16:01:02 -05:00
										 |  |  |     assert_version_equal '0.1', foo1.version | 
					
						
							| 
									
										
										
										
											2012-01-12 20:08:35 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     foo1 = HOMEBREW_CACHE/'foo-0.1.cpio.gz' | 
					
						
							|  |  |  |     assert_equal '.cpio.gz', foo1.extname | 
					
						
							|  |  |  |     assert_equal 'foo-0.1', foo1.stem | 
					
						
							| 
									
										
										
										
											2012-07-10 16:01:02 -05:00
										 |  |  |     assert_version_equal '0.1', foo1.version | 
					
						
							| 
									
										
										
										
											2010-03-09 22:15:52 -08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   class MockMockFormula < Struct.new(:name); end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_formula_equality | 
					
						
							|  |  |  |     f = MockFormula.new('http://example.com/test-0.1.tgz') | 
					
						
							|  |  |  |     g = MockMockFormula.new('test') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert f == f | 
					
						
							|  |  |  |     assert f == g | 
					
						
							|  |  |  |     assert f.eql? f | 
					
						
							|  |  |  |     assert (not (f.eql? g)) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  | end |