1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
|
#!/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__)
$:.push(File.expand_path(__FILE__+'/../..'))
require 'extend/pathname'
require 'utils'
require 'hardware'
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 }
# for some reason our utils.rb safe_system behaves completely differently
# during these tests. This is worrying for sure.
def safe_system *args
Kernel.system *args
end
class ExecutionError <RuntimeError
attr :status
def initialize cmd, args=[], status=nil
super "Failure while executing: #{cmd} #{args*' '}"
@status = status
end
end
class BuildError <ExecutionError
end
require 'test/unit' # must be after at_exit
require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
ARGV.extend(HomebrewArgvExtension)
class MockFormula <Formula
def initialize url
@url=url
@homepage = 'http://example.com/'
super 'test'
end
end
class MostlyAbstractFormula <Formula
@url=''
@homepage = 'http://example.com/'
end
class TestBall <Formula
# name parameter required for some Formula::factory
def initialize name=nil
@url="file:///#{Pathname.new(ABS__FILE__).parent.realpath}/testball-0.1.tbz"
@homepage = 'http://example.com/'
super "testball"
end
def install
prefix.install "bin"
prefix.install "libexec"
end
end
class TestZip <Formula
def initialize
zip=HOMEBREW_CACHE.parent+'test-0.1.zip'
Kernel.system '/usr/bin/zip', '-0', zip, ABS__FILE__
@url="file://#{zip}"
@homepage = 'http://example.com/'
super 'testzip'
end
end
class TestBadVersion <TestBall
@version="versions can't have spaces"
end
class TestBallOverrideBrew <Formula
def initialize
super "foo"
end
def brew
end
end
class TestScriptFileFormula <ScriptFileFormula
url "file:///#{Pathname.new(ABS__FILE__).realpath}"
version "1"
def initialize
@name='test-script-formula'
@homepage = 'http://example.com/'
super
end
end
class RefreshBrewMock < RefreshBrew
def in_prefix_expect(expect, returns = '')
@expect ||= {}
@expect[expect] = returns
end
def `(cmd)
if Dir.pwd == HOMEBREW_PREFIX.to_s and @expect.has_key?(cmd)
(@called ||= []) << cmd
@expect[cmd]
else
raise "#{inspect} Unexpectedly called backticks in pwd `#{HOMEBREW_PREFIX}' and command `#{cmd}'"
end
end
def expectations_met?
@expect.keys.sort == @called.sort
end
def inspect
"#<#{self.class.name} #{object_id}>"
end
end
module ExtendArgvPlusYeast
def reset
@named = nil
@downcased_unique_named = nil
@formulae = nil
@kegs = nil
ARGV.shift while ARGV.length > 0
end
end
ARGV.extend ExtendArgvPlusYeast
class BeerTasting <Test::Unit::TestCase
def test_version_all_dots
r=MockFormula.new "http://example.com/foo.bar.la.1.14.zip"
assert_equal '1.14', r.version
end
def test_version_underscore_separator
r=MockFormula.new "http://example.com/grc_1.1.tar.gz"
assert_equal '1.1', r.version
end
def test_boost_version_style
r=MockFormula.new "http://example.com/boost_1_39_0.tar.bz2"
assert_equal '1.39.0', r.version
end
def test_erlang_version_style
r=MockFormula.new "http://erlang.org/download/otp_src_R13B.tar.gz"
assert_equal 'R13B', r.version
end
def test_p7zip_version_style
r=MockFormula.new "http://kent.dl.sourceforge.net/sourceforge/p7zip/p7zip_9.04_src_all.tar.bz2"
assert_equal '9.04', r.version
end
def test_gloox_beta_style
r=MockFormula.new "http://camaya.net/download/gloox-1.0-beta7.tar.bz2"
assert_equal '1.0-beta7', r.version
end
def test_astyle_verson_style
r=MockFormula.new "http://kent.dl.sourceforge.net/sourceforge/astyle/astyle_1.23_macosx.tar.gz"
assert_equal '1.23', r.version
end
def test_version_libvorbis
r=MockFormula.new "http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.2rc1.tar.bz2"
assert_equal '1.2.2rc1', r.version
end
def test_dos2unix
r=MockFormula.new "http://www.sfr-fresh.com/linux/misc/dos2unix-3.1.tar.gz"
assert_equal '3.1', r.version
end
def test_version_internal_dash
r=MockFormula.new "http://example.com/foo-arse-1.1-2.tar.gz"
assert_equal '1.1-2', r.version
end
def test_version_single_digit
r=MockFormula.new "http://example.com/foo_bar.45.tar.gz"
assert_equal '45', r.version
end
def test_noseparator_single_digit
r=MockFormula.new "http://example.com/foo_bar45.tar.gz"
assert_equal '45', r.version
end
def test_version_developer_that_hates_us_format
r=MockFormula.new "http://example.com/foo-bar-la.1.2.3.tar.gz"
assert_equal '1.2.3', r.version
end
def test_version_regular
r=MockFormula.new "http://example.com/foo_bar-1.21.tar.gz"
assert_equal '1.21', r.version
end
def test_version_github
r=MockFormula.new "http://github.com/lloyd/yajl/tarball/1.0.5"
assert_equal '1.0.5', r.version
end
def test_yet_another_version
r=MockFormula.new "http://example.com/mad-0.15.1b.tar.gz"
assert_equal '0.15.1b', r.version
end
def test_supported_compressed_types
assert_nothing_raised do
MockFormula.new 'test-0.1.tar.gz'
MockFormula.new 'test-0.1.tar.bz2'
MockFormula.new 'test-0.1.tgz'
MockFormula.new 'test-0.1.bgz'
MockFormula.new 'test-0.1.zip'
end
end
def test_prefix
nostdout do
TestBall.new.brew do |f|
assert_equal File.expand_path(f.prefix), (HOMEBREW_CELLAR+f.name+'0.1').to_s
assert_kind_of Pathname, f.prefix
end
end
end
def test_no_version
assert_nil Pathname.new("http://example.com/blah.tar").version
assert_nil Pathname.new("arse").version
end
def test_bad_version
assert_raises(RuntimeError) {f=TestBadVersion.new}
end
def test_install
f=TestBall.new
assert_equal Formula.path(f.name), f.path
assert !f.installed?
nostdout do
f.brew do
f.install
end
end
assert_match Regexp.new("^#{HOMEBREW_CELLAR}/"), f.prefix.to_s
assert f.bin.directory?
assert_equal 3, f.bin.children.length
libexec=f.prefix+'libexec'
assert libexec.directory?
assert_equal 1, libexec.children.length
assert !(f.prefix+'main.c').exist?
assert f.installed?
keg=Keg.new f.prefix
keg.link
assert_equal 2, HOMEBREW_PREFIX.children.length
assert (HOMEBREW_PREFIX+'bin').directory?
assert_equal 3, (HOMEBREW_PREFIX+'bin').children.length
keg.uninstall
assert !keg.exist?
assert !f.installed?
end
def test_script_install
f=TestScriptFileFormula.new
nostdout do
f.brew do
f.install
end
end
assert_equal 1, f.bin.children.length
end
def test_md5
valid_md5 = Class.new(TestBall) do
@md5='71aa838a9e4050d1876a295a9e62cbe6'
end
assert_nothing_raised { nostdout { valid_md5.new.brew {} } }
end
def test_badmd5
invalid_md5 = Class.new(TestBall) do
@md5='61aa838a9e4050d1876a295a9e62cbe6'
end
assert_raises RuntimeError do
nostdout { invalid_md5.new.brew {} }
end
end
def test_sha1
valid_sha1 = Class.new(TestBall) do
@sha1='6ea8a98acb8f918df723c2ae73fe67d5664bfd7e'
end
assert_nothing_raised { nostdout { valid_sha1.new.brew {} } }
end
def test_badsha1
invalid_sha1 = Class.new(TestBall) do
@sha1='7ea8a98acb8f918df723c2ae73fe67d5664bfd7e'
end
assert_raises RuntimeError do
nostdout { invalid_sha1.new.brew {} }
end
end
def test_sha256
valid_sha256 = Class.new(TestBall) do
@sha256='ccbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8'
end
assert_nothing_raised do
nostdout { valid_sha256.new.brew {} }
end
end
def test_badsha256
invalid_sha256 = Class.new(TestBall) do
@sha256='dcbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8'
end
assert_raises RuntimeError do
nostdout { invalid_sha256.new.brew {} }
end
end
FOOBAR='foo-bar'
def test_formula_funcs
classname=Formula.class_s(FOOBAR)
path=Formula.path(FOOBAR)
assert_equal "FooBar", classname
assert_match Regexp.new("^#{HOMEBREW_PREFIX}/Library/Formula"), path.to_s
path=HOMEBREW_PREFIX+'Library'+'Formula'+"#{FOOBAR}.rb"
path.dirname.mkpath
File.open(path, 'w') do |f|
f << %{
require 'formula'
class #{classname} < Formula
@url=''
def initialize(*args)
@homepage = 'http://example.com/'
super
end
end
}
end
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
# needs resurrecting
ARGV.reset
ARGV.unshift 'foo'
ARGV.unshift 'foo'
# n=0
# ARGV.named.each{|f| n+=1 if f.name == 'foo'}
# assert_equal 1, n
end
def test_ARGV
assert_raises(FormulaUnspecifiedError) { ARGV.formulae }
assert_raises(KegUnspecifiedError) { ARGV.kegs }
assert ARGV.named.empty?
(HOMEBREW_CELLAR+'mxcl'+'10.0').mkpath
ARGV.reset
ARGV.unshift 'mxcl'
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 f.url
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+)/ and $1.to_i >= 6
assert_equal 3, arches.length
assert arches.include?(:x86_64)
else
assert_equal 2, arches.length
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_class_names
assert_equal 'ShellFm', Formula.class_s('shell.fm')
assert_equal 'Fooxx', Formula.class_s('foo++')
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
|