#!/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. ABS__FILE__=File.expand_path(__FILE__) $:.unshift File.dirname(ABS__FILE__) require 'pathname+yeast' require 'formula' require 'download_strategy' require 'keg' require 'utils' require 'brew.h' # these are defined in bin/brew, but we don't want to break our actual # homebrew tree, and we do want to test everything :) HOMEBREW_PREFIX=Pathname.new '/tmp/testbrew/prefix' HOMEBREW_CACHE=HOMEBREW_PREFIX.parent+"cache" HOMEBREW_CELLAR=HOMEBREW_PREFIX.parent+"cellar" HOMEBREW_USER_AGENT="Homebrew" (HOMEBREW_PREFIX+'Library'+'Formula').mkpath Dir.chdir HOMEBREW_PREFIX 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 #{path}` 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_equal '__UNKNOWN__', f.name assert_raises(RuntimeError) { f.prefix } nostdout { assert_raises(RuntimeError) { f.brew } } end def test_zip nostdout { assert_nothing_raised { TestZip.new.brew {} } } end def test_no_ARGV_dupes ARGV.unshift'foo' ARGV.unshift'foo' n=0 ARGV.named.each{|arg| n+=1 if arg == 'foo'} assert_equal 1, n end def test_ARGV assert_raises(UsageError) { ARGV.named } assert_raises(UsageError) { ARGV.formulae } assert_raises(UsageError) { ARGV.kegs } assert ARGV.named_empty? (HOMEBREW_CELLAR+'foo'+'0.1').mkpath ARGV.unshift 'foo' assert_equal 1, ARGV.named.length assert_equal 1, ARGV.kegs.length assert_raises(FormulaUnavailableError) { ARGV.formulae } end def test_version_dir d=HOMEBREW_CELLAR+'foo-0.1.9' d.mkpath assert_equal '0.1.9', d.version end 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 def test_hw_model require 'hw.model.rb' # this will raise if we don't recognise your mac, but that prolly # indicates something went wrong rather than we don't know assert %w[core1 core2 xeon ppc].include?(hw_model.to_s) end def test_brew_h nostdout do assert_nothing_raised do f=TestBall.new make 'http://example.com/testball-0.1.tbz' info f.name clean f prune #TODO test diy function too end end 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 end