Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update test suite.

* Break single test case class into several test cases.
* Fix broken arch test.
* Make update tests optional (seem to only work for mxcl).
* Add more tests.
* Move fixtures to separate folder.
  • Loading branch information...
commit 8d02ae74312e1203d99a3af3a6630a3379e3edc6 1 parent e828256
Adam Vandenberg authored January 29, 2010
57  Library/Homebrew/test/fixtures/updater_fixture.yaml
... ...
@@ -0,0 +1,57 @@
  1
+update_git_pull_output_without_formulae_changes: |
  2
+  remote: counting objects: 58, done.
  3
+  remote: Compressing objects: 100% (35/35), done.
  4
+  remote: Total 39 (delta 20), reused 0 (delta 0)
  5
+  Unpacking objects: 100% (39/39), done.
  6
+  From git://github.com/mxcl/homebrew
  7
+   * branch            master -> FETCH_HEAD
  8
+  Updating 14ef7f9..f414bc8
  9
+  Fast forward
  10
+   Library/Homebrew/ARGV+yeast.rb                |   35 ++--
  11
+   Library/Homebrew/beer_events.rb               |  181 +++++++++++++
  12
+   Library/Homebrew/hardware.rb                  |   71 ++++++
  13
+   Library/Homebrew/hw.model.c                   |   17 --
  14
+   README                                        |  337 +++++++++++++------------
  15
+   bin/brew                                      |  137 ++++++++---
  16
+   40 files changed, 1107 insertions(+), 426 deletions(-)
  17
+   create mode 100644 Library/Homebrew/beer_events.rb
  18
+   create mode 100644 Library/Homebrew/hardware.rb
  19
+   delete mode 100644 Library/Homebrew/hw.model.c
  20
+   delete mode 100644 Library/Homebrew/hw.model.rb
  21
+update_git_pull_output_with_formulae_changes: |
  22
+  remote: counting objects: 58, done.
  23
+  remote: Compressing objects: 100% (35/35), done.
  24
+  remote: Total 39 (delta 20), reused 0 (delta 0)
  25
+  Unpacking objects: 100% (39/39), done.
  26
+  From git://github.com/mxcl/homebrew
  27
+   * branch            master -> FETCH_HEAD
  28
+  Updating 14ef7f9..f414bc8
  29
+  Fast forward
  30
+   Library/Contributions/brew_bash_completion.sh |    6 +-
  31
+   Library/Formula/antiword.rb                   |   13 +
  32
+   Library/Formula/bash-completion.rb            |   25 ++
  33
+   Library/Formula/xar.rb                        |   19 ++
  34
+   Library/Formula/yajl.rb                       |    2 +-
  35
+   Library/Homebrew/ARGV+yeast.rb                |   35 ++--
  36
+   Library/Homebrew/beer_events.rb               |  181 +++++++++++++
  37
+   Library/Homebrew/hardware.rb                  |   71 ++++++
  38
+   Library/Homebrew/hw.model.c                   |   17 --
  39
+   Library/Homebrew/pathname+yeast.rb            |   28 ++-
  40
+   Library/Homebrew/unittest.rb                  |  106 ++++++++-
  41
+   Library/Homebrew/utils.rb                     |   36 ++-
  42
+   README                                        |  337 +++++++++++++------------
  43
+   bin/brew                                      |  137 ++++++++---
  44
+   40 files changed, 1107 insertions(+), 426 deletions(-)
  45
+   create mode 100644 Library/Formula/antiword.rb
  46
+   create mode 100644 Library/Formula/bash-completion.rb
  47
+   create mode 100644 Library/Formula/ddrescue.rb
  48
+   create mode 100644 Library/Formula/dict.rb
  49
+   create mode 100644 Library/Formula/lua.rb
  50
+   delete mode 100644 Library/Formula/antiword.rb
  51
+   delete mode 100644 Library/Formula/bash-completion.rb
  52
+   delete mode 100644 Library/Formula/xar.rb
  53
+   delete mode 100644 Library/Formula/yajl.rb
  54
+   create mode 100644 Library/Homebrew/beer_events.rb
  55
+   create mode 100644 Library/Homebrew/hardware.rb
  56
+   delete mode 100644 Library/Homebrew/hw.model.c
  57
+   delete mode 100644 Library/Homebrew/hw.model.rb
299  Library/Homebrew/test/test_bucket.rb
... ...
@@ -0,0 +1,299 @@
  1
+# All other tests so far -- feel free to break them out into
  2
+# separate TestCase classes.
  3
+
  4
+class BeerTasting < Test::Unit::TestCase
  5
+  def test_put_columns_empty
  6
+    assert_nothing_raised do
  7
+      # Issue #217 put columns with new results fails.
  8
+      puts_columns []
  9
+    end
  10
+  end
  11
+
  12
+  def test_supported_compressed_types
  13
+    assert_nothing_raised do
  14
+      MockFormula.new 'test-0.1.tar.gz'
  15
+      MockFormula.new 'test-0.1.tar.bz2'
  16
+      MockFormula.new 'test-0.1.tgz'
  17
+      MockFormula.new 'test-0.1.bgz'
  18
+      MockFormula.new 'test-0.1.zip'
  19
+    end
  20
+  end
  21
+
  22
+  def test_prefix
  23
+    nostdout do
  24
+      TestBall.new.brew do |f|
  25
+        assert_equal File.expand_path(f.prefix), (HOMEBREW_CELLAR+f.name+'0.1').to_s
  26
+        assert_kind_of Pathname, f.prefix
  27
+      end
  28
+    end
  29
+  end
  30
+  
  31
+  def test_no_version
  32
+    assert_nil Pathname.new("http://example.com/blah.tar").version
  33
+    assert_nil Pathname.new("arse").version
  34
+  end
  35
+  
  36
+  def test_bad_version
  37
+    assert_raises(RuntimeError) {f=TestBadVersion.new}
  38
+  end
  39
+  
  40
+  def test_install
  41
+    f=TestBall.new
  42
+    
  43
+    assert_equal Formula.path(f.name), f.path
  44
+    assert !f.installed?
  45
+    
  46
+    nostdout do
  47
+      f.brew do
  48
+        f.install
  49
+      end
  50
+    end
  51
+    
  52
+    assert_match Regexp.new("^#{HOMEBREW_CELLAR}/"), f.prefix.to_s
  53
+    
  54
+    assert f.bin.directory?
  55
+    assert_equal 3, f.bin.children.length
  56
+    libexec=f.prefix+'libexec'
  57
+    assert libexec.directory?
  58
+    assert_equal 1, libexec.children.length
  59
+    assert !(f.prefix+'main.c').exist?
  60
+    assert f.installed?
  61
+    
  62
+    keg=Keg.new f.prefix
  63
+    keg.link
  64
+    assert_equal 2, HOMEBREW_PREFIX.children.length
  65
+    assert (HOMEBREW_PREFIX+'bin').directory?
  66
+    assert_equal 3, (HOMEBREW_PREFIX+'bin').children.length
  67
+    
  68
+    keg.uninstall
  69
+    assert !keg.exist?
  70
+    assert !f.installed?
  71
+  end
  72
+  
  73
+  def test_script_install
  74
+    f=TestScriptFileFormula.new
  75
+    
  76
+    nostdout do
  77
+      f.brew do
  78
+        f.install
  79
+      end
  80
+    end
  81
+    
  82
+    assert_equal 1, f.bin.children.length
  83
+  end
  84
+
  85
+  FOOBAR='foo-bar'
  86
+  def test_formula_funcs
  87
+    classname=Formula.class_s(FOOBAR)
  88
+    path=Formula.path(FOOBAR)
  89
+    
  90
+    assert_equal "FooBar", classname
  91
+    assert_match Regexp.new("^#{HOMEBREW_PREFIX}/Library/Formula"), path.to_s
  92
+
  93
+    path=HOMEBREW_PREFIX+'Library'+'Formula'+"#{FOOBAR}.rb"
  94
+    path.dirname.mkpath
  95
+    File.open(path, 'w') do |f|
  96
+      f << %{
  97
+        require 'formula'
  98
+        class #{classname} < Formula
  99
+          @url=''
  100
+          def initialize(*args)
  101
+            @homepage = 'http://example.com/'
  102
+            super
  103
+          end
  104
+        end
  105
+      }
  106
+    end
  107
+    
  108
+    assert_not_nil Formula.factory(FOOBAR)
  109
+  end
  110
+  
  111
+  def test_cant_override_brew
  112
+    assert_raises(RuntimeError) { TestBallOverrideBrew.new }
  113
+  end
  114
+  
  115
+  def test_abstract_formula
  116
+    f=MostlyAbstractFormula.new
  117
+    assert_equal '__UNKNOWN__', f.name
  118
+    assert_raises(RuntimeError) { f.prefix }
  119
+    nostdout { assert_raises(RuntimeError) { f.brew } }
  120
+  end
  121
+
  122
+  def test_zip
  123
+    nostdout { assert_nothing_raised { TestZip.new.brew {} } }
  124
+  end
  125
+  
  126
+  # needs resurrecting
  127
+  # def test_no_ARGV_dupes
  128
+  #   ARGV.reset
  129
+  #   ARGV << 'foo' << 'foo'
  130
+  #   n=0
  131
+  #   ARGV.named.each{|f| n+=1 if f == 'foo'}
  132
+  #   assert_equal 1, n
  133
+  # end
  134
+  
  135
+  def test_ARGV
  136
+    assert_raises(FormulaUnspecifiedError) { ARGV.formulae }
  137
+    assert_raises(KegUnspecifiedError) { ARGV.kegs }
  138
+    assert ARGV.named.empty?
  139
+    
  140
+    (HOMEBREW_CELLAR+'mxcl'+'10.0').mkpath
  141
+    
  142
+    ARGV.reset
  143
+    ARGV.unshift 'mxcl'
  144
+    assert_equal 1, ARGV.named.length
  145
+    assert_equal 1, ARGV.kegs.length
  146
+    assert_raises(FormulaUnavailableError) { ARGV.formulae }
  147
+  end
  148
+  
  149
+  # these will raise if we don't recognise your mac, but that prolly 
  150
+  # indicates something went wrong rather than we don't know
  151
+  def test_hardware_cpu_type
  152
+    assert [:intel, :ppc].include?(Hardware.cpu_type)
  153
+  end
  154
+  
  155
+  def test_hardware_intel_family
  156
+    if Hardware.cpu_type == :intel
  157
+      assert [:core, :core2, :penryn, :nehalem].include?(Hardware.intel_family)
  158
+    end
  159
+  end
  160
+  
  161
+  def test_brew_h
  162
+    nostdout do
  163
+      assert_nothing_raised do
  164
+        f=TestBall.new
  165
+        make f.url
  166
+        info f.name
  167
+        clean f
  168
+        prune
  169
+        #TODO test diy function too
  170
+      end
  171
+    end
  172
+  end
  173
+
  174
+  def test_brew_cleanup
  175
+    f1=TestBall.new
  176
+    f1.instance_eval { @version = "0.1" }
  177
+    f2=TestBall.new
  178
+    f2.instance_eval { @version = "0.2" }
  179
+    f3=TestBall.new
  180
+    f3.instance_eval { @version = "0.3" }
  181
+
  182
+    nostdout do
  183
+      f1.brew { f1.install }
  184
+      f2.brew { f2.install }
  185
+      f3.brew { f3.install }
  186
+    end
  187
+
  188
+    assert f1.installed?
  189
+    assert f2.installed?
  190
+    assert f3.installed?
  191
+
  192
+    nostdout do
  193
+      cleanup f3
  194
+    end
  195
+
  196
+    assert !f1.installed?
  197
+    assert !f2.installed?
  198
+    assert f3.installed?
  199
+  end
  200
+
  201
+  def test_my_float_assumptions
  202
+    # this may look ridiculous but honestly there's code in brewit that depends on 
  203
+    # this behaviour so I wanted to be certain Ruby floating points are behaving
  204
+    f='10.6'.to_f
  205
+    assert_equal 10.6, f
  206
+    assert f >= 10.6
  207
+    assert f <= 10.6
  208
+    assert_equal 10.5, f-0.1
  209
+    assert_equal 10.7, f+0.1
  210
+  end
  211
+
  212
+  def test_arch_for_command
  213
+    arches=archs_for_command '/usr/bin/svn'
  214
+    if `sw_vers -productVersion` =~ /10\.(\d+)/ and $1.to_i >= 6
  215
+      assert_equal 3, arches.length
  216
+      assert arches.include?(:x86_64)
  217
+    else
  218
+      assert_equal 2, arches.length
  219
+    end
  220
+    assert arches.include?(:i386)
  221
+    assert arches.include?(:ppc7400)
  222
+  end
  223
+
  224
+  def test_pathname_version
  225
+    d=HOMEBREW_CELLAR+'foo-0.1.9'
  226
+    d.mkpath
  227
+    assert_equal '0.1.9', d.version
  228
+  end
  229
+  
  230
+  def test_pathname_plus_yeast
  231
+    nostdout do
  232
+      assert_nothing_raised do
  233
+        assert !Pathname.getwd.rmdir_if_possible
  234
+        assert !Pathname.getwd.abv.empty?
  235
+        
  236
+        abcd=orig_abcd=HOMEBREW_CACHE+'abcd'
  237
+        FileUtils.cp ABS__FILE__, abcd
  238
+        abcd=HOMEBREW_PREFIX.install abcd
  239
+        assert (HOMEBREW_PREFIX+orig_abcd.basename).exist?
  240
+        assert abcd.exist?
  241
+        assert_equal HOMEBREW_PREFIX+'abcd', abcd
  242
+
  243
+        assert_raises(RuntimeError) {abcd.write 'CONTENT'}
  244
+        abcd.unlink
  245
+        abcd.write 'HELLOWORLD'
  246
+        assert_equal 'HELLOWORLD', File.read(abcd)
  247
+        
  248
+        assert !orig_abcd.exist?
  249
+        rv=abcd.cp orig_abcd
  250
+        assert orig_abcd.exist?
  251
+        assert_equal rv, orig_abcd
  252
+
  253
+        orig_abcd.unlink
  254
+        assert !orig_abcd.exist?
  255
+        abcd.cp HOMEBREW_CACHE
  256
+        assert orig_abcd.exist?
  257
+
  258
+        foo1=HOMEBREW_CACHE+'foo-0.1.tar.gz'
  259
+        FileUtils.cp ABS__FILE__, foo1
  260
+        assert foo1.file?
  261
+        
  262
+        assert_equal '.tar.gz', foo1.extname
  263
+        assert_equal 'foo-0.1', foo1.stem
  264
+        assert_equal '0.1', foo1.version
  265
+        
  266
+        HOMEBREW_CACHE.chmod_R 0777
  267
+      end
  268
+    end
  269
+    
  270
+    assert_raises(RuntimeError) {Pathname.getwd.install 'non_existant_file'}
  271
+  end
  272
+  
  273
+  def test_formula_class_func
  274
+    assert_equal Formula.class_s('s-lang'), 'SLang'
  275
+    assert_equal Formula.class_s('pkg-config'), 'PkgConfig'
  276
+    assert_equal Formula.class_s('foo_bar'), 'FooBar'
  277
+  end
  278
+  
  279
+  def test_class_names
  280
+    assert_equal 'ShellFm', Formula.class_s('shell.fm')
  281
+    assert_equal 'Fooxx', Formula.class_s('foo++')
  282
+  end
  283
+      
  284
+  def test_ENV_options
  285
+    require 'extend/ENV'
  286
+    ENV.extend(HomebrewEnvExtension)
  287
+
  288
+    ENV.gcc_4_0
  289
+    ENV.gcc_4_2
  290
+    ENV.O3
  291
+    ENV.minimal_optimization
  292
+    ENV.no_optimization
  293
+    ENV.libxml2
  294
+    ENV.x11
  295
+    ENV.enable_warnings
  296
+    assert !ENV.cc.empty?
  297
+    assert !ENV.cxx.empty?
  298
+  end
  299
+end
57  Library/Homebrew/test/test_checksums.rb
... ...
@@ -0,0 +1,57 @@
  1
+class ChecksumTests < Test::Unit::TestCase
  2
+  def test_md5
  3
+    valid_md5 = Class.new(TestBall) do
  4
+      @md5='71aa838a9e4050d1876a295a9e62cbe6'
  5
+    end
  6
+
  7
+    assert_nothing_raised { nostdout { valid_md5.new.brew {} } }
  8
+  end
  9
+  
  10
+  def test_badmd5
  11
+    invalid_md5 = Class.new(TestBall) do
  12
+      @md5='61aa838a9e4050d1876a295a9e62cbe6'
  13
+    end
  14
+
  15
+    assert_raises RuntimeError do
  16
+      nostdout { invalid_md5.new.brew {} }
  17
+    end
  18
+  end
  19
+
  20
+  def test_sha1
  21
+    valid_sha1 = Class.new(TestBall) do
  22
+      @sha1='6ea8a98acb8f918df723c2ae73fe67d5664bfd7e'
  23
+    end
  24
+
  25
+    assert_nothing_raised { nostdout { valid_sha1.new.brew {} } }
  26
+  end
  27
+
  28
+  def test_badsha1
  29
+    invalid_sha1 = Class.new(TestBall) do
  30
+      @sha1='7ea8a98acb8f918df723c2ae73fe67d5664bfd7e'
  31
+    end
  32
+
  33
+    assert_raises RuntimeError do
  34
+      nostdout { invalid_sha1.new.brew {} }
  35
+    end
  36
+  end
  37
+
  38
+  def test_sha256
  39
+    valid_sha256 = Class.new(TestBall) do
  40
+      @sha256='ccbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8'
  41
+    end
  42
+
  43
+    assert_nothing_raised do
  44
+      nostdout { valid_sha256.new.brew {} }
  45
+    end
  46
+  end
  47
+
  48
+  def test_badsha256
  49
+    invalid_sha256 = Class.new(TestBall) do
  50
+      @sha256='dcbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8'
  51
+    end
  52
+
  53
+    assert_raises RuntimeError do
  54
+      nostdout { invalid_sha256.new.brew {} }
  55
+    end
  56
+  end
  57
+end
33  Library/Homebrew/test/test_inreplace.rb
... ...
@@ -0,0 +1,33 @@
  1
+class InreplaceTest < Test::Unit::TestCase
  2
+  def test_change_make_var
  3
+    # Replace flag
  4
+    s1="FLAG = abc"
  5
+    s1.extend(HomebrewInreplaceExtension)
  6
+    s1.change_make_var! "FLAG", "def"
  7
+    assert_equal "FLAG=def", s1
  8
+  end
  9
+    
  10
+  def test_change_make_var_append
  11
+    # Append to flag
  12
+    s1="FLAG = abc"
  13
+    s1.extend(HomebrewInreplaceExtension)
  14
+    s1.change_make_var! "FLAG", "\\1 def"
  15
+    assert_equal "FLAG=abc def", s1
  16
+  end
  17
+
  18
+  def test_remove_make_var
  19
+    # Replace flag
  20
+    s1="FLAG = abc\nFLAG2 = def"
  21
+    s1.extend(HomebrewInreplaceExtension)
  22
+    s1.remove_make_var! "FLAG"
  23
+    assert_equal "FLAG=\nFLAG2 = def", s1
  24
+  end
  25
+
  26
+  def test_remove_make_vars
  27
+    # Replace flag
  28
+    s1="FLAG = abc\nFLAG2 = def"
  29
+    s1.extend(HomebrewInreplaceExtension)
  30
+    s1.remove_make_var! ["FLAG", "FLAG2"]
  31
+    assert_equal "FLAG=\nFLAG2=", s1
  32
+  end
  33
+end
67  Library/Homebrew/test/test_updater.rb
... ...
@@ -0,0 +1,67 @@
  1
+class UpdaterTests < Test::Unit::TestCase
  2
+  OUTSIDE_PREFIX = '/tmp'
  3
+  def outside_prefix
  4
+    Dir.chdir(OUTSIDE_PREFIX) { yield }
  5
+  end
  6
+  
  7
+  def fixture(name)
  8
+    self.class.fixture_data[name]
  9
+  end
  10
+  
  11
+  def self.fixture_data
  12
+    unless @fixture_data
  13
+      require 'yaml'
  14
+      @fixture_data = YAML.load_file(Pathname.new(ABS__FILE__).parent.realpath + 'fixtures/updater_fixture.yaml')
  15
+    end
  16
+    @fixture_data
  17
+  end
  18
+
  19
+  def test_update_homebrew_without_any_changes
  20
+    outside_prefix do
  21
+      updater = RefreshBrewMock.new
  22
+      updater.in_prefix_expect("git checkout master")
  23
+      updater.in_prefix_expect("git pull origin master", "Already up-to-date.\n")
  24
+      
  25
+      assert_equal false, updater.update_from_masterbrew!
  26
+      assert updater.expectations_met?
  27
+      assert updater.updated_formulae.empty?
  28
+      assert updater.added_formulae.empty?
  29
+    end
  30
+  end
  31
+  
  32
+  def test_update_homebrew_without_formulae_changes
  33
+    outside_prefix do
  34
+      updater = RefreshBrewMock.new
  35
+      updater.in_prefix_expect("git checkout master")
  36
+      output = fixture('update_git_pull_output_without_formulae_changes')
  37
+      updater.in_prefix_expect("git pull origin master", output)
  38
+      
  39
+      assert_equal true, updater.update_from_masterbrew!
  40
+      assert !updater.pending_formulae_changes?
  41
+      assert updater.updated_formulae.empty?
  42
+      assert updater.added_formulae.empty?
  43
+    end
  44
+  end
  45
+  
  46
+  def test_update_homebrew_with_formulae_changes
  47
+    outside_prefix do
  48
+      updater = RefreshBrewMock.new
  49
+      updater.in_prefix_expect("git checkout master")
  50
+      output = fixture('update_git_pull_output_with_formulae_changes')
  51
+      updater.in_prefix_expect("git pull origin master", output)
  52
+      
  53
+      assert_equal true, updater.update_from_masterbrew!
  54
+      assert updater.pending_formulae_changes?
  55
+      assert_equal %w{ xar yajl }, updater.updated_formulae
  56
+      assert_equal %w{ antiword bash-completion ddrescue dict lua }, updater.added_formulae
  57
+    end
  58
+  end
  59
+  
  60
+  def test_updater_returns_current_revision
  61
+    outside_prefix do
  62
+      updater = RefreshBrewMock.new
  63
+      updater.in_prefix_expect('git log -l -1 --pretty=format:%H', 'the-revision-hash')
  64
+      assert_equal 'the-revision-hash', updater.current_revision
  65
+    end
  66
+  end
  67
+end
106  Library/Homebrew/test/test_versions.rb
... ...
@@ -0,0 +1,106 @@
  1
+class VersionTests < Test::Unit::TestCase
  2
+  def test_version_all_dots
  3
+    r=MockFormula.new "http://example.com/foo.bar.la.1.14.zip"
  4
+    assert_equal '1.14', r.version
  5
+  end
  6
+
  7
+  def test_version_underscore_separator
  8
+    r=MockFormula.new "http://example.com/grc_1.1.tar.gz"
  9
+    assert_equal '1.1', r.version
  10
+  end
  11
+
  12
+  def test_boost_version_style
  13
+    r=MockFormula.new "http://example.com/boost_1_39_0.tar.bz2"
  14
+    assert_equal '1.39.0', r.version
  15
+  end
  16
+
  17
+  def test_erlang_version_style
  18
+    r=MockFormula.new "http://erlang.org/download/otp_src_R13B.tar.gz"
  19
+    assert_equal 'R13B', r.version
  20
+  end
  21
+  
  22
+  def test_p7zip_version_style
  23
+    r=MockFormula.new "http://kent.dl.sourceforge.net/sourceforge/p7zip/p7zip_9.04_src_all.tar.bz2"
  24
+    assert_equal '9.04', r.version
  25
+  end
  26
+  
  27
+  def test_gloox_beta_style
  28
+    r=MockFormula.new "http://camaya.net/download/gloox-1.0-beta7.tar.bz2"
  29
+    assert_equal '1.0-beta7', r.version
  30
+  end
  31
+  
  32
+  def test_astyle_verson_style
  33
+    r=MockFormula.new "http://kent.dl.sourceforge.net/sourceforge/astyle/astyle_1.23_macosx.tar.gz"
  34
+    assert_equal '1.23', r.version
  35
+  end
  36
+  
  37
+  def test_version_libvorbis
  38
+    r=MockFormula.new "http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.2rc1.tar.bz2"
  39
+    assert_equal '1.2.2rc1', r.version
  40
+  end
  41
+  
  42
+  def test_version_dos2unix
  43
+    r=MockFormula.new "http://www.sfr-fresh.com/linux/misc/dos2unix-3.1.tar.gz"
  44
+    assert_equal '3.1', r.version
  45
+  end
  46
+
  47
+  def test_version_internal_dash
  48
+    r=MockFormula.new "http://example.com/foo-arse-1.1-2.tar.gz"
  49
+    assert_equal '1.1-2', r.version
  50
+  end
  51
+
  52
+  def test_version_single_digit
  53
+    r=MockFormula.new "http://example.com/foo_bar.45.tar.gz"
  54
+    assert_equal '45', r.version
  55
+  end
  56
+
  57
+  def test_noseparator_single_digit
  58
+    r=MockFormula.new "http://example.com/foo_bar45.tar.gz"
  59
+    assert_equal '45', r.version
  60
+  end
  61
+
  62
+  def test_version_developer_that_hates_us_format
  63
+    r=MockFormula.new "http://example.com/foo-bar-la.1.2.3.tar.gz"
  64
+    assert_equal '1.2.3', r.version
  65
+  end
  66
+
  67
+  def test_version_regular
  68
+    r=MockFormula.new "http://example.com/foo_bar-1.21.tar.gz"
  69
+    assert_equal '1.21', r.version
  70
+  end
  71
+
  72
+  def test_version_github
  73
+    r=MockFormula.new "http://github.com/lloyd/yajl/tarball/1.0.5"
  74
+    assert_equal '1.0.5', r.version
  75
+  end
  76
+
  77
+  def test_yet_another_version
  78
+    r=MockFormula.new "http://example.com/mad-0.15.1b.tar.gz"
  79
+    assert_equal '0.15.1b', r.version
  80
+  end
  81
+
  82
+  def test_lame_version_style
  83
+    f=MockFormula.new 'http://kent.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz'
  84
+    assert_equal '398-2', f.version
  85
+  end
  86
+  
  87
+  def test_ruby_version_style
  88
+    f=MockFormula.new 'ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p243.tar.gz'
  89
+    assert_equal '1.9.1-p243', f.version
  90
+  end
  91
+  
  92
+  def test_omega_version_style
  93
+    f=MockFormula.new 'http://www.alcyone.com/binaries/omega/omega-0.80.2-src.tar.gz'
  94
+    assert_equal '0.80.2', f.version
  95
+  end
  96
+
  97
+  def test_version_style_rc
  98
+    f=MockFormula.new 'http://ftp.mozilla.org/pub/mozilla.org/js/js-1.8.0-rc1.tar.gz'
  99
+    assert_equal '1.8.0-rc1', f.version
  100
+  end
  101
+  
  102
+  def test_angband_version_style
  103
+    f = MockFormula.new 'http://rephial.org/downloads/3.0/angband-3.0.9b-src.tar.gz'
  104
+    assert_equal '3.0.9b', f.version
  105
+  end
  106
+end
588  Library/Homebrew/test/unittest.rb
@@ -148,586 +148,8 @@ def reset
148 148
 end
149 149
 ARGV.extend ExtendArgvPlusYeast
150 150
 
151  
-
152  
-class BeerTasting <Test::Unit::TestCase
153  
-  def test_put_columns_empty
154  
-    assert_nothing_raised do
155  
-      # Issue #217 put columns with new results fails.
156  
-      puts_columns []
157  
-    end
158  
-  end
159  
-  
160  
-  def test_version_all_dots
161  
-    r=MockFormula.new "http://example.com/foo.bar.la.1.14.zip"
162  
-    assert_equal '1.14', r.version
163  
-  end
164  
-
165  
-  def test_version_underscore_separator
166  
-    r=MockFormula.new "http://example.com/grc_1.1.tar.gz"
167  
-    assert_equal '1.1', r.version
168  
-  end
169  
-
170  
-  def test_boost_version_style
171  
-    r=MockFormula.new "http://example.com/boost_1_39_0.tar.bz2"
172  
-    assert_equal '1.39.0', r.version
173  
-  end
174  
-
175  
-  def test_erlang_version_style
176  
-    r=MockFormula.new "http://erlang.org/download/otp_src_R13B.tar.gz"
177  
-    assert_equal 'R13B', r.version
178  
-  end
179  
-  
180  
-  def test_p7zip_version_style
181  
-    r=MockFormula.new "http://kent.dl.sourceforge.net/sourceforge/p7zip/p7zip_9.04_src_all.tar.bz2"
182  
-    assert_equal '9.04', r.version
183  
-  end
184  
-  
185  
-  def test_gloox_beta_style
186  
-    r=MockFormula.new "http://camaya.net/download/gloox-1.0-beta7.tar.bz2"
187  
-    assert_equal '1.0-beta7', r.version
188  
-  end
189  
-  
190  
-  def test_astyle_verson_style
191  
-    r=MockFormula.new "http://kent.dl.sourceforge.net/sourceforge/astyle/astyle_1.23_macosx.tar.gz"
192  
-    assert_equal '1.23', r.version
193  
-  end
194  
-  
195  
-  def test_version_libvorbis
196  
-    r=MockFormula.new "http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.2rc1.tar.bz2"
197  
-    assert_equal '1.2.2rc1', r.version
198  
-  end
199  
-  
200  
-  def test_dos2unix
201  
-    r=MockFormula.new "http://www.sfr-fresh.com/linux/misc/dos2unix-3.1.tar.gz"
202  
-    assert_equal '3.1', r.version
203  
-  end
204  
-
205  
-  def test_version_internal_dash
206  
-    r=MockFormula.new "http://example.com/foo-arse-1.1-2.tar.gz"
207  
-    assert_equal '1.1-2', r.version
208  
-  end
209  
-
210  
-  def test_version_single_digit
211  
-    r=MockFormula.new "http://example.com/foo_bar.45.tar.gz"
212  
-    assert_equal '45', r.version
213  
-  end
214  
-
215  
-  def test_noseparator_single_digit
216  
-    r=MockFormula.new "http://example.com/foo_bar45.tar.gz"
217  
-    assert_equal '45', r.version
218  
-  end
219  
-
220  
-  def test_version_developer_that_hates_us_format
221  
-    r=MockFormula.new "http://example.com/foo-bar-la.1.2.3.tar.gz"
222  
-    assert_equal '1.2.3', r.version
223  
-  end
224  
-
225  
-  def test_version_regular
226  
-    r=MockFormula.new "http://example.com/foo_bar-1.21.tar.gz"
227  
-    assert_equal '1.21', r.version
228  
-  end
229  
-
230  
-  def test_version_github
231  
-    r=MockFormula.new "http://github.com/lloyd/yajl/tarball/1.0.5"
232  
-    assert_equal '1.0.5', r.version
233  
-  end
234  
-
235  
-  def test_yet_another_version
236  
-    r=MockFormula.new "http://example.com/mad-0.15.1b.tar.gz"
237  
-    assert_equal '0.15.1b', r.version
238  
-  end
239  
-
240  
-  def test_supported_compressed_types
241  
-    assert_nothing_raised do
242  
-      MockFormula.new 'test-0.1.tar.gz'
243  
-      MockFormula.new 'test-0.1.tar.bz2'
244  
-      MockFormula.new 'test-0.1.tgz'
245  
-      MockFormula.new 'test-0.1.bgz'
246  
-      MockFormula.new 'test-0.1.zip'
247  
-    end
248  
-  end
249  
-
250  
-  def test_prefix
251  
-    nostdout do
252  
-      TestBall.new.brew do |f|
253  
-        assert_equal File.expand_path(f.prefix), (HOMEBREW_CELLAR+f.name+'0.1').to_s
254  
-        assert_kind_of Pathname, f.prefix
255  
-      end
256  
-    end
257  
-  end
258  
-  
259  
-  def test_no_version
260  
-    assert_nil Pathname.new("http://example.com/blah.tar").version
261  
-    assert_nil Pathname.new("arse").version
262  
-  end
263  
-  
264  
-  def test_bad_version
265  
-    assert_raises(RuntimeError) {f=TestBadVersion.new}
266  
-  end
267  
-  
268  
-  def test_install
269  
-    f=TestBall.new
270  
-    
271  
-    assert_equal Formula.path(f.name), f.path
272  
-    assert !f.installed?
273  
-    
274  
-    nostdout do
275  
-      f.brew do
276  
-        f.install
277  
-      end
278  
-    end
279  
-    
280  
-    assert_match Regexp.new("^#{HOMEBREW_CELLAR}/"), f.prefix.to_s
281  
-    
282  
-    assert f.bin.directory?
283  
-    assert_equal 3, f.bin.children.length
284  
-    libexec=f.prefix+'libexec'
285  
-    assert libexec.directory?
286  
-    assert_equal 1, libexec.children.length
287  
-    assert !(f.prefix+'main.c').exist?
288  
-    assert f.installed?
289  
-    
290  
-    keg=Keg.new f.prefix
291  
-    keg.link
292  
-    assert_equal 2, HOMEBREW_PREFIX.children.length
293  
-    assert (HOMEBREW_PREFIX+'bin').directory?
294  
-    assert_equal 3, (HOMEBREW_PREFIX+'bin').children.length
295  
-    
296  
-    keg.uninstall
297  
-    assert !keg.exist?
298  
-    assert !f.installed?
299  
-  end
300  
-  
301  
-  def test_script_install
302  
-    f=TestScriptFileFormula.new
303  
-    
304  
-    nostdout do
305  
-      f.brew do
306  
-        f.install
307  
-      end
308  
-    end
309  
-    
310  
-    assert_equal 1, f.bin.children.length
311  
-  end
312  
-
313  
-  def test_md5
314  
-    valid_md5 = Class.new(TestBall) do
315  
-      @md5='71aa838a9e4050d1876a295a9e62cbe6'
316  
-    end
317  
-
318  
-    assert_nothing_raised { nostdout { valid_md5.new.brew {} } }
319  
-  end
320  
-  
321  
-  def test_badmd5
322  
-    invalid_md5 = Class.new(TestBall) do
323  
-      @md5='61aa838a9e4050d1876a295a9e62cbe6'
324  
-    end
325  
-
326  
-    assert_raises RuntimeError do
327  
-      nostdout { invalid_md5.new.brew {} }
328  
-    end
329  
-  end
330  
-
331  
-  def test_sha1
332  
-    valid_sha1 = Class.new(TestBall) do
333  
-      @sha1='6ea8a98acb8f918df723c2ae73fe67d5664bfd7e'
334  
-    end
335  
-
336  
-    assert_nothing_raised { nostdout { valid_sha1.new.brew {} } }
337  
-  end
338  
-
339  
-  def test_badsha1
340  
-    invalid_sha1 = Class.new(TestBall) do
341  
-      @sha1='7ea8a98acb8f918df723c2ae73fe67d5664bfd7e'
342  
-    end
343  
-
344  
-    assert_raises RuntimeError do
345  
-      nostdout { invalid_sha1.new.brew {} }
346  
-    end
347  
-  end
348  
-
349  
-  def test_sha256
350  
-    valid_sha256 = Class.new(TestBall) do
351  
-      @sha256='ccbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8'
352  
-    end
353  
-
354  
-    assert_nothing_raised do
355  
-      nostdout { valid_sha256.new.brew {} }
356  
-    end
357  
-  end
358  
-
359  
-  def test_badsha256
360  
-    invalid_sha256 = Class.new(TestBall) do
361  
-      @sha256='dcbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8'
362  
-    end
363  
-
364  
-    assert_raises RuntimeError do
365  
-      nostdout { invalid_sha256.new.brew {} }
366  
-    end
367  
-  end
368  
-  
369  
-  FOOBAR='foo-bar'
370  
-  def test_formula_funcs
371  
-    classname=Formula.class_s(FOOBAR)
372  
-    path=Formula.path(FOOBAR)
373  
-    
374  
-    assert_equal "FooBar", classname
375  
-    assert_match Regexp.new("^#{HOMEBREW_PREFIX}/Library/Formula"), path.to_s
376  
-
377  
-    path=HOMEBREW_PREFIX+'Library'+'Formula'+"#{FOOBAR}.rb"
378  
-    path.dirname.mkpath
379  
-    File.open(path, 'w') do |f|
380  
-      f << %{
381  
-        require 'formula'
382  
-        class #{classname} < Formula
383  
-          @url=''
384  
-          def initialize(*args)
385  
-            @homepage = 'http://example.com/'
386  
-            super
387  
-          end
388  
-        end
389  
-      }
390  
-    end
391  
-    
392  
-    assert_not_nil Formula.factory(FOOBAR)
393  
-  end
394  
-  
395  
-  def test_cant_override_brew
396  
-    assert_raises(RuntimeError) { TestBallOverrideBrew.new }
397  
-  end
398  
-  
399  
-  def test_abstract_formula
400  
-    f=MostlyAbstractFormula.new
401  
-    assert_equal '__UNKNOWN__', f.name
402  
-    assert_raises(RuntimeError) { f.prefix }
403  
-    nostdout { assert_raises(RuntimeError) { f.brew } }
404  
-  end
405  
-
406  
-  def test_zip
407  
-    nostdout { assert_nothing_raised { TestZip.new.brew {} } }
408  
-  end
409  
-
410  
-  def test_no_ARGV_dupes
411  
-    # needs resurrecting
412  
-    ARGV.reset
413  
-    ARGV.unshift 'foo'
414  
-    ARGV.unshift 'foo'
415  
-#    n=0
416  
-#    ARGV.named.each{|f| n+=1 if f.name == 'foo'}
417  
-#    assert_equal 1, n
418  
-  end
419  
-  
420  
-  def test_ARGV
421  
-    assert_raises(FormulaUnspecifiedError) { ARGV.formulae }
422  
-    assert_raises(KegUnspecifiedError) { ARGV.kegs }
423  
-    assert ARGV.named.empty?
424  
-    
425  
-    (HOMEBREW_CELLAR+'mxcl'+'10.0').mkpath
426  
-    
427  
-    ARGV.reset
428  
-    ARGV.unshift 'mxcl'
429  
-    assert_equal 1, ARGV.named.length
430  
-    assert_equal 1, ARGV.kegs.length
431  
-    assert_raises(FormulaUnavailableError) { ARGV.formulae }
432  
-  end
433  
-  
434  
-  def test_version_dir
435  
-    d=HOMEBREW_CELLAR+'foo-0.1.9'
436  
-    d.mkpath
437  
-    assert_equal '0.1.9', d.version
438  
-  end
439  
-  
440  
-  def test_lame_version_style
441  
-    f=MockFormula.new 'http://kent.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz'
442  
-    assert_equal '398-2', f.version
443  
-  end
444  
-  
445  
-  def test_ruby_version_style
446  
-    f=MockFormula.new 'ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p243.tar.gz'
447  
-    assert_equal '1.9.1-p243', f.version
448  
-  end
449  
-  
450  
-  # these will raise if we don't recognise your mac, but that prolly 
451  
-  # indicates something went wrong rather than we don't know
452  
-  def test_hardware_cpu_type
453  
-    assert [:intel, :ppc].include?(Hardware.cpu_type)
454  
-  end
455  
-  
456  
-  def test_hardware_intel_family
457  
-    if Hardware.cpu_type == :intel
458  
-      assert [:core, :core2, :penryn, :nehalem].include?(Hardware.intel_family)
459  
-    end
460  
-  end
461  
-  
462  
-  def test_brew_h
463  
-    nostdout do
464  
-      assert_nothing_raised do
465  
-        f=TestBall.new
466  
-        make f.url
467  
-        info f.name
468  
-        clean f
469  
-        prune
470  
-        #TODO test diy function too
471  
-      end
472  
-    end
473  
-  end
474  
-
475  
-  def test_brew_cleanup
476  
-    f1=TestBall.new
477  
-    f1.instance_eval { @version = "0.1" }
478  
-    f2=TestBall.new
479  
-    f2.instance_eval { @version = "0.2" }
480  
-    f3=TestBall.new
481  
-    f3.instance_eval { @version = "0.3" }
482  
-
483  
-    nostdout do
484  
-      f1.brew { f1.install }
485  
-      f2.brew { f2.install }
486  
-      f3.brew { f3.install }
487  
-    end
488  
-
489  
-    assert f1.installed?
490  
-    assert f2.installed?
491  
-    assert f3.installed?
492  
-
493  
-    nostdout do
494  
-      cleanup f3
495  
-    end
496  
-
497  
-    assert !f1.installed?
498  
-    assert !f2.installed?
499  
-    assert f3.installed?
500  
-  end
501  
-
502  
-  def test_my_float_assumptions
503  
-    # this may look ridiculous but honestly there's code in brewit that depends on 
504  
-    # this behaviour so I wanted to be certain Ruby floating points are behaving
505  
-    f='10.6'.to_f
506  
-    assert_equal 10.6, f
507  
-    assert f >= 10.6
508  
-    assert f <= 10.6
509  
-    assert_equal 10.5, f-0.1
510  
-    assert_equal 10.7, f+0.1
511  
-  end
512  
-
513  
-  def test_arch_for_command
514  
-    arches=arch_for_command '/usr/bin/svn'
515  
-    if `sw_vers -productVersion` =~ /10\.(\d+)/ and $1.to_i >= 6
516  
-      assert_equal 3, arches.length
517  
-      assert arches.include?(:x86_64)
518  
-    else
519  
-      assert_equal 2, arches.length
520  
-    end
521  
-    assert arches.include?(:i386)
522  
-    assert arches.include?(:ppc7400)
523  
-  end
524  
-
525  
-  def test_pathname_plus_yeast
526  
-    nostdout do
527  
-      assert_nothing_raised do
528  
-        assert !Pathname.getwd.rmdir_if_possible
529  
-        assert !Pathname.getwd.abv.empty?
530  
-        
531  
-        abcd=orig_abcd=HOMEBREW_CACHE+'abcd'
532  
-        FileUtils.cp ABS__FILE__, abcd
533  
-        abcd=HOMEBREW_PREFIX.install abcd
534  
-        assert (HOMEBREW_PREFIX+orig_abcd.basename).exist?
535  
-        assert abcd.exist?
536  
-        assert_equal HOMEBREW_PREFIX+'abcd', abcd
537  
-
538  
-        assert_raises(RuntimeError) {abcd.write 'CONTENT'}
539  
-        abcd.unlink
540  
-        abcd.write 'HELLOWORLD'
541  
-        assert_equal 'HELLOWORLD', File.read(abcd)
542  
-        
543  
-        assert !orig_abcd.exist?
544  
-        rv=abcd.cp orig_abcd
545  
-        assert orig_abcd.exist?
546  
-        assert_equal rv, orig_abcd
547  
-
548  
-        orig_abcd.unlink
549  
-        assert !orig_abcd.exist?
550  
-        abcd.cp HOMEBREW_CACHE
551  
-        assert orig_abcd.exist?
552  
-
553  
-        foo1=HOMEBREW_CACHE+'foo-0.1.tar.gz'
554  
-        FileUtils.cp ABS__FILE__, foo1
555  
-        assert foo1.file?
556  
-        
557  
-        assert_equal '.tar.gz', foo1.extname
558  
-        assert_equal 'foo-0.1', foo1.stem
559  
-        assert_equal '0.1', foo1.version
560  
-        
561  
-        HOMEBREW_CACHE.chmod_R 0777
562  
-      end
563  
-    end
564  
-    
565  
-    assert_raises(RuntimeError) {Pathname.getwd.install 'non_existant_file'}
566  
-  end
567  
-  
568  
-  def test_omega_version_style
569  
-    f=MockFormula.new 'http://www.alcyone.com/binaries/omega/omega-0.80.2-src.tar.gz'
570  
-    assert_equal '0.80.2', f.version
571  
-  end
572  
-  
573  
-  def test_formula_class_func
574  
-    assert_equal Formula.class_s('s-lang'), 'SLang'
575  
-    assert_equal Formula.class_s('pkg-config'), 'PkgConfig'
576  
-    assert_equal Formula.class_s('foo_bar'), 'FooBar'
577  
-  end
578  
-  
579  
-  def test_version_style_rc
580  
-    f=MockFormula.new 'http://ftp.mozilla.org/pub/mozilla.org/js/js-1.8.0-rc1.tar.gz'
581  
-    assert_equal '1.8.0-rc1', f.version
582  
-  end
583  
-  
584  
-  def test_updater_update_homebrew_without_any_changes
585  
-    outside_prefix do
586  
-      updater = RefreshBrewMock.new
587  
-      updater.in_prefix_expect("git checkout master")
588  
-      updater.in_prefix_expect("git pull origin master", "Already up-to-date.\n")
589  
-      
590  
-      assert_equal false, updater.update_from_masterbrew!
591  
-      assert updater.expectations_met?
592  
-      assert updater.updated_formulae.empty?
593  
-      assert updater.added_formulae.empty?
594  
-    end
595  
-  end
596  
-  
597  
-  def test_updater_update_homebrew_without_formulae_changes
598  
-    outside_prefix do
599  
-      updater = RefreshBrewMock.new
600  
-      updater.in_prefix_expect("git checkout master")
601  
-      output = fixture('update_git_pull_output_without_formulae_changes')
602  
-      updater.in_prefix_expect("git pull origin master", output)
603  
-      
604  
-      assert_equal true, updater.update_from_masterbrew!
605  
-      assert !updater.pending_formulae_changes?
606  
-      assert updater.updated_formulae.empty?
607  
-      assert updater.added_formulae.empty?
608  
-    end
609  
-  end
610  
-  
611  
-  def test_updater_update_homebrew_with_formulae_changes
612  
-    outside_prefix do
613  
-      updater = RefreshBrewMock.new
614  
-      updater.in_prefix_expect("git checkout master")
615  
-      output = fixture('update_git_pull_output_with_formulae_changes')
616  
-      updater.in_prefix_expect("git pull origin master", output)
617  
-      
618  
-      assert_equal true, updater.update_from_masterbrew!
619  
-      assert updater.pending_formulae_changes?
620  
-      assert_equal %w{ xar yajl }, updater.updated_formulae
621  
-      assert_equal %w{ antiword bash-completion ddrescue dict lua }, updater.added_formulae
622  
-    end
623  
-  end
624  
-  
625  
-  def test_updater_returns_current_revision
626  
-    outside_prefix do
627  
-      updater = RefreshBrewMock.new
628  
-      updater.in_prefix_expect('git log -l -1 --pretty=format:%H', 'the-revision-hash')
629  
-      assert_equal 'the-revision-hash', updater.current_revision
630  
-    end
631  
-  end
632  
-  
633  
-  def test_class_names
634  
-    assert_equal 'ShellFm', Formula.class_s('shell.fm')
635  
-    assert_equal 'Fooxx', Formula.class_s('foo++')
636  
-  end
637  
-      
638  
-  def test_angband_version_style
639  
-    f = MockFormula.new 'http://rephial.org/downloads/3.0/angband-3.0.9b-src.tar.gz'
640  
-    assert_equal '3.0.9b', f.version
641  
-  end
642  
-  
643  
-  private
644  
-  
645  
-  OUTSIDE_PREFIX = '/tmp'
646  
-  def outside_prefix
647  
-    Dir.chdir(OUTSIDE_PREFIX) { yield }
648  
-  end
649  
-