#!/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' require 'update' # 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_REPOSITORY=HOMEBREW_PREFIX HOMEBREW_CACHE=HOMEBREW_PREFIX.parent+"cache" HOMEBREW_CELLAR=HOMEBREW_PREFIX.parent+"cellar" HOMEBREW_USER_AGENT="Homebrew" MACOS_VERSION=10.6 (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 " 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 reset @named=nil @formulae=nil @kegs=nil while ARGV.count > 0 ARGV.shift end end end ARGV.extend ExtendArgvPlusYeast class BeerTasting = 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+)/ 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_omega_version_style f=MockFormula.new 'http://www.alcyone.com/binaries/omega/omega-0.80.2-src.tar.gz' assert_equal '0.80.2', f.version 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 checkout master") updater.in_prefix_expect("git pull origin master", "Already up-to-date.\n") assert_equal false, updater.update_from_masterbrew! assert updater.expectations_met? assert updater.updated_formulae.empty? assert updater.added_formulae.empty? end end def test_updater_update_homebrew_without_formulae_changes outside_prefix do updater = RefreshBrewMock.new updater.in_prefix_expect("git checkout master") output = fixture('update_git_pull_output_without_formulae_changes') updater.in_prefix_expect("git pull origin master", output) assert_equal true, updater.update_from_masterbrew! assert !updater.pending_formulae_changes? assert updater.updated_formulae.empty? assert updater.added_formulae.empty? end end def test_updater_update_homebrew_with_formulae_changes outside_prefix do updater = RefreshBrewMock.new updater.in_prefix_expect("git checkout master") output = fixture('update_git_pull_output_with_formulae_changes') updater.in_prefix_expect("git pull origin master", output) assert_equal true, updater.update_from_masterbrew! assert updater.pending_formulae_changes? assert_equal %w{ xar yajl }, updater.updated_formulae assert_equal %w{ antiword bash-completion ddrescue dict lua }, updater.added_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 def test_angband_version_style f = MockFormula.new 'http://rephial.org/downloads/3.0/angband-3.0.9b-src.tar.gz' assert_equal '3.0.9b', f.version 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 def test_ENV_options ENV.gcc_4_0_1 ENV.gcc_4_2 ENV.O3 ENV.minimal_optimization ENV.no_optimization ENV.libxml2 ENV.x11 ENV.enable_warnings assert !ENV.cc.empty? assert !ENV.cxx.empty? 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 master -> 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 master -> 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