2012-10-20 20:54:11 -05:00
|
|
|
require 'testing_env'
|
|
|
|
require 'test/testball'
|
|
|
|
require 'keg'
|
|
|
|
require 'stringio'
|
|
|
|
|
|
|
|
class LinkTests < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
@formula = TestBall.new
|
|
|
|
shutup do
|
|
|
|
@formula.brew { @formula.install }
|
|
|
|
end
|
|
|
|
@keg = Keg.for @formula.prefix
|
|
|
|
@keg.unlink
|
|
|
|
|
|
|
|
@old_stdout = $stdout
|
|
|
|
$stdout = StringIO.new
|
|
|
|
|
|
|
|
FileUtils.mkpath HOMEBREW_PREFIX/"bin"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_linking_keg
|
2012-10-23 17:09:57 -05:00
|
|
|
assert_equal 3, @keg.link
|
2012-10-20 20:54:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_unlinking_keg
|
|
|
|
@keg.link
|
2012-10-23 17:09:57 -05:00
|
|
|
assert_equal 3, @keg.unlink
|
2012-10-20 20:54:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_link_dry_run
|
|
|
|
mode = OpenStruct.new
|
|
|
|
mode.dry_run = true
|
|
|
|
|
2012-10-23 17:09:57 -05:00
|
|
|
assert_equal 0, @keg.link(mode)
|
2012-10-20 20:54:11 -05:00
|
|
|
assert !@keg.linked?
|
|
|
|
|
2012-10-23 17:09:57 -05:00
|
|
|
['hiworld', 'helloworld', 'goodbye_cruel_world'].each do |file|
|
|
|
|
assert_match "/private/tmp/testbrew/prefix/bin/#{file}", $stdout.string
|
|
|
|
end
|
|
|
|
assert_equal 3, $stdout.string.lines.count
|
2012-10-20 20:54:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_linking_fails_when_already_linked
|
|
|
|
@keg.link
|
|
|
|
assert_raise RuntimeError, "Cannot link testball" do
|
|
|
|
@keg.link
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_linking_fails_when_files_exist
|
|
|
|
FileUtils.touch HOMEBREW_PREFIX/"bin/helloworld"
|
|
|
|
assert_raise RuntimeError do
|
|
|
|
@keg.link
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_link_overwrite
|
|
|
|
FileUtils.touch HOMEBREW_PREFIX/"bin/helloworld"
|
|
|
|
mode = OpenStruct.new
|
|
|
|
mode.overwrite = true
|
2012-10-23 17:09:57 -05:00
|
|
|
assert_equal 3, @keg.link(mode)
|
2012-10-20 20:54:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_link_overwrite_dryrun
|
|
|
|
FileUtils.touch HOMEBREW_PREFIX/"bin/helloworld"
|
|
|
|
mode = OpenStruct.new
|
|
|
|
mode.overwrite = true
|
|
|
|
mode.dry_run = true
|
|
|
|
|
2012-10-23 17:09:57 -05:00
|
|
|
assert_equal 0, @keg.link(mode)
|
2012-10-20 20:54:11 -05:00
|
|
|
assert !@keg.linked?
|
|
|
|
|
2012-10-23 17:09:57 -05:00
|
|
|
assert_equal "/private/tmp/testbrew/prefix/bin/helloworld\n", $stdout.string
|
2012-10-20 20:54:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
@keg.unlink
|
|
|
|
@keg.rmtree
|
|
|
|
|
|
|
|
$stdout = @old_stdout
|
|
|
|
|
|
|
|
FileUtils.rmtree HOMEBREW_PREFIX/"bin"
|
|
|
|
end
|
|
|
|
end
|