#!/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' require 'hardware.rb' require 'refresh_brew' # these are defined in global.rb, but we don't want to break our actual # homebrew tree, and we do want to test everything :) HOMEBREW_PREFIX=Pathname.new '/private/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 Called backticks in pwd `#{HOMEBREW_PREFIX}' and command `#{cmd}'" end end end def nostdout if ARGV.include? '-V' yield end begin require 'stringio' tmpo=$stdout tmpe=$stderr $stdout=StringIO.new yield ensure $stdout=tmpo end end module ExtendArgvPlusYeast def stick_an_arg_in_thar @named=nil unshift 'foo' end end ARGV.extend ExtendArgvPlusYeast class BeerTasting #{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.stick_an_arg_in_thar 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_lame_version_style f=MockFormula.new 'http://kent.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz' assert_equal '398-2', f.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 # these will raise if we don't recognise your mac, but that prolly # indicates something went wrong rather than we don't know def test_hardware_cpu_type assert [:intel, :ppc].include?(Hardware.cpu_type) end def test_hardware_intel_family if Hardware.cpu_type == :intel assert [:core, :core2, :penryn, :nehalem].include?(Hardware.intel_family) end 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 def test_arch_for_command arches=arch_for_command '/usr/bin/svn' if `sw_vers -productVersion` =~ /10\.(\d)\.(\d+)/ and $1.to_i >= 6 assert_equal 3, arches.count assert arches.include?(:x86_64) else assert_equal 2, arches.count end assert arches.include?(:i386) assert arches.include?(:ppc7400) end def test_pathname_plus_yeast nostdout do assert_nothing_raised do assert !Pathname.getwd.rmdir_if_possible assert !Pathname.getwd.abv.empty? abcd=orig_abcd=HOMEBREW_CACHE+'abcd' FileUtils.cp ABS__FILE__, abcd abcd=HOMEBREW_PREFIX.install abcd 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) 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? foo1=HOMEBREW_CACHE+'foo-0.1.tar.gz' FileUtils.cp ABS__FILE__, foo1 assert foo1.file? assert_equal '.tar.gz', foo1.extname assert_equal 'foo-0.1', foo1.stem assert_equal '0.1', foo1.version HOMEBREW_CACHE.chmod_R 0777 end end assert_raises(RuntimeError) {Pathname.getwd.install 'non_existant_file'} end def test_formula_class_func assert_equal Formula.class_s('s-lang'), 'SLang' assert_equal Formula.class_s('pkg-config'), 'PkgConfig' assert_equal Formula.class_s('foo_bar'), 'FooBar' end def test_version_style_rc f=MockFormula.new 'http://ftp.mozilla.org/pub/mozilla.org/js/js-1.8.0-rc1.tar.gz' assert_equal '1.8.0-rc1', f.version end def test_updater_update_homebrew_without_any_changes outside_prefix do updater = RefreshBrewMock.new updater.in_prefix_expect("git pull origin masterbrew", "Already up-to-date.\n") assert_equal false, updater.update_from_masterbrew! assert updater.updated_formulae.empty? end end def test_updater_update_homebrew_without_formulae_changes outside_prefix do updater = RefreshBrewMock.new output = fixture('update_git_pull_output_without_formulae_changes') updater.in_prefix_expect("git pull origin masterbrew", output) assert_equal true, updater.update_from_masterbrew! assert !updater.pending_formulae_changes? assert updater.updated_formulae.empty? end end def test_updater_update_homebrew_with_formulae_changes outside_prefix do updater = RefreshBrewMock.new output = fixture('update_git_pull_output_with_formulae_changes') updater.in_prefix_expect("git pull origin masterbrew", output) assert_equal true, updater.update_from_masterbrew! assert updater.pending_formulae_changes? assert_equal %w{ antiword bash-completion xar yajl }, updater.updated_formulae end end def test_updater_returns_current_revision outside_prefix do updater = RefreshBrewMock.new updater.in_prefix_expect('git log -l -1 --pretty=format:%H', 'the-revision-hash') assert_equal 'the-revision-hash', updater.current_revision end end private OUTSIDE_PREFIX = '/tmp' def outside_prefix Dir.chdir(OUTSIDE_PREFIX) { yield } end def fixture(name) self.class.fixture_data[name] end def self.fixture_data unless @fixture_data require 'yaml' @fixture_data = YAML.load(DATA) end @fixture_data end end __END__ update_git_pull_output_without_formulae_changes: | remote: Counting objects: 58, done. remote: Compressing objects: 100% (35/35), done. remote: Total 39 (delta 20), reused 0 (delta 0) Unpacking objects: 100% (39/39), done. From git://github.com/mxcl/homebrew * branch masterbrew -> FETCH_HEAD Updating 14ef7f9..f414bc8 Fast forward Library/Homebrew/ARGV+yeast.rb | 35 ++-- Library/Homebrew/beer_events.rb | 181 +++++++++++++ Library/Homebrew/hardware.rb | 71 ++++++ Library/Homebrew/hw.model.c | 17 -- README | 337 +++++++++++++------------ bin/brew | 137 ++++++++--- 40 files changed, 1107 insertions(+), 426 deletions(-) create mode 100644 Library/Homebrew/beer_events.rb create mode 100644 Library/Homebrew/hardware.rb delete mode 100644 Library/Homebrew/hw.model.c delete mode 100644 Library/Homebrew/hw.model.rb update_git_pull_output_with_formulae_changes: | remote: Counting objects: 58, done. remote: Compressing objects: 100% (35/35), done. remote: Total 39 (delta 20), reused 0 (delta 0) Unpacking objects: 100% (39/39), done. From git://github.com/mxcl/homebrew * branch masterbrew -> FETCH_HEAD Updating 14ef7f9..f414bc8 Fast forward Library/Contributions/brew_bash_completion.sh | 6 +- Library/Formula/antiword.rb | 13 + Library/Formula/bash-completion.rb | 25 ++ Library/Formula/xar.rb | 19 ++ Library/Formula/yajl.rb | 2 +- Library/Homebrew/ARGV+yeast.rb | 35 ++-- Library/Homebrew/beer_events.rb | 181 +++++++++++++ Library/Homebrew/hardware.rb | 71 ++++++ Library/Homebrew/hw.model.c | 17 -- Library/Homebrew/pathname+yeast.rb | 28 ++- Library/Homebrew/unittest.rb | 106 ++++++++- Library/Homebrew/utils.rb | 36 ++- README | 337 +++++++++++++------------ bin/brew | 137 ++++++++--- 40 files changed, 1107 insertions(+), 426 deletions(-) create mode 100644 Library/Formula/antiword.rb create mode 100644 Library/Formula/bash-completion.rb create mode 100644 Library/Formula/ddrescue.rb create mode 100644 Library/Formula/dict.rb create mode 100644 Library/Formula/lua.rb delete mode 100644 Library/Formula/antiword.rb delete mode 100644 Library/Formula/bash-completion.rb delete mode 100644 Library/Formula/xar.rb delete mode 100644 Library/Formula/yajl.rb create mode 100644 Library/Homebrew/beer_events.rb create mode 100644 Library/Homebrew/hardware.rb delete mode 100644 Library/Homebrew/hw.model.c delete mode 100644 Library/Homebrew/hw.model.rb