tests: refactor formula file creation (#370)

This commit is contained in:
Andrea Kao 2016-06-22 05:37:17 -07:00 committed by Mike McQuaid
parent 2d8b4376df
commit 8b31167a43

View File

@ -6,6 +6,7 @@ require "formula"
class IntegrationCommandTests < Homebrew::TestCase class IntegrationCommandTests < Homebrew::TestCase
def setup def setup
@formula_files = []
@cmd_id_index = 0 # Assign unique IDs to invocations of `cmd_output`. @cmd_id_index = 0 # Assign unique IDs to invocations of `cmd_output`.
(HOMEBREW_PREFIX/"bin").mkpath (HOMEBREW_PREFIX/"bin").mkpath
FileUtils.touch HOMEBREW_PREFIX/"bin/brew" FileUtils.touch HOMEBREW_PREFIX/"bin/brew"
@ -13,6 +14,7 @@ class IntegrationCommandTests < Homebrew::TestCase
def teardown def teardown
(HOMEBREW_PREFIX/"bin").rmtree (HOMEBREW_PREFIX/"bin").rmtree
@formula_files.each(&:unlink)
end end
def cmd_id_from_args(args) def cmd_id_from_args(args)
@ -44,7 +46,7 @@ class IntegrationCommandTests < Homebrew::TestCase
ENV["HOMEBREW_BREW_FILE"] = HOMEBREW_PREFIX/"bin/brew" ENV["HOMEBREW_BREW_FILE"] = HOMEBREW_PREFIX/"bin/brew"
ENV["HOMEBREW_INTEGRATION_TEST"] = cmd_id_from_args(args) ENV["HOMEBREW_INTEGRATION_TEST"] = cmd_id_from_args(args)
ENV["HOMEBREW_TEST_TMPDIR"] = TEST_TMPDIR ENV["HOMEBREW_TEST_TMPDIR"] = TEST_TMPDIR
env.each_pair { |k,v| ENV[k] = v } env.each_pair { |k, v| ENV[k] = v }
read, write = IO.pipe read, write = IO.pipe
begin begin
@ -80,6 +82,48 @@ class IntegrationCommandTests < Homebrew::TestCase
output output
end end
def setup_test_formula(name, content = nil)
formula_path = CoreTap.new.formula_dir/"#{name}.rb"
@formula_files << formula_path
case name
when "testball"
content = <<-EOS.undent
desc "Some test"
homepage "https://example.com/#{name}"
url "file://#{File.expand_path("..", __FILE__)}/tarballs/#{name}-0.1.tbz"
sha256 "#{TESTBALL_SHA256}"
option "with-foo", "Build with foo"
#{content}
def install
(prefix/"foo"/"test").write("test") if build.with? "foo"
prefix.install Dir["*"]
end
# something here
EOS
when "foo"
content = <<-EOS.undent
url "https://example.com/#{name}-1.0"
EOS
when "bar"
content = <<-EOS.undent
url "https://example.com/#{name}-1.0"
depends_on "foo"
EOS
end
formula_path.write <<-EOS.undent
class #{Formulary.class_s(name)} < Formula
#{content}
end
EOS
formula_path
end
def testball def testball
"#{File.expand_path("..", __FILE__)}/testball.rb" "#{File.expand_path("..", __FILE__)}/testball.rb"
end end
@ -175,12 +219,9 @@ class IntegrationCommandTests < Homebrew::TestCase
cmd("install", "--build-bottle", testball) cmd("install", "--build-bottle", testball)
assert_match "Formula not from core or any taps", assert_match "Formula not from core or any taps",
cmd_fail("bottle", "--no-revision", testball) cmd_fail("bottle", "--no-revision", testball)
formula_file = CoreTap.new.formula_dir/"testball.rb"
formula_file.write <<-EOS.undent setup_test_formula "testball"
class Testball < Formula
url "https://example.com/testball-0.1.tar.gz"
end
EOS
# `brew bottle` should not fail with dead symlink # `brew bottle` should not fail with dead symlink
# https://github.com/Homebrew/legacy-homebrew/issues/49007 # https://github.com/Homebrew/legacy-homebrew/issues/49007
(HOMEBREW_CELLAR/"testball/0.1").cd do (HOMEBREW_CELLAR/"testball/0.1").cd do
@ -191,7 +232,6 @@ class IntegrationCommandTests < Homebrew::TestCase
ensure ensure
cmd("uninstall", "--force", "testball") cmd("uninstall", "--force", "testball")
cmd("cleanup", "--force", "--prune=all") cmd("cleanup", "--force", "--prune=all")
formula_file.unlink unless formula_file.nil?
FileUtils.rm_f Dir["testball-0.1*.bottle.tar.gz"] FileUtils.rm_f Dir["testball-0.1*.bottle.tar.gz"]
end end
@ -210,21 +250,14 @@ class IntegrationCommandTests < Homebrew::TestCase
end end
def test_readall def test_readall
repo = CoreTap.new formula_file = setup_test_formula "testball"
formula_file = repo.formula_dir/"foo.rb" alias_file = CoreTap.new.alias_dir/"foobar"
formula_file.write <<-EOS.undent
class Foo < Formula
url "https://example.com/foo-1.0.tar.gz"
end
EOS
alias_file = repo.alias_dir/"bar"
alias_file.parent.mkpath alias_file.parent.mkpath
FileUtils.ln_s formula_file, alias_file FileUtils.ln_s formula_file, alias_file
cmd("readall", "--aliases", "--syntax") cmd("readall", "--aliases", "--syntax")
cmd("readall", "homebrew/core") cmd("readall", "homebrew/core")
ensure ensure
formula_file.unlink unless formula_file.nil? alias_file.parent.rmtree
repo.alias_dir.rmtree
end end
def test_tap def test_tap
@ -257,28 +290,13 @@ class IntegrationCommandTests < Homebrew::TestCase
end end
def test_missing def test_missing
repo = CoreTap.new setup_test_formula "foo"
foo_file = repo.formula_dir/"foo.rb" setup_test_formula "bar"
foo_file.write <<-EOS.undent
class Foo < Formula
url "https://example.com/foo-1.0"
end
EOS
bar_file = repo.formula_dir/"bar.rb"
bar_file.write <<-EOS.undent
class Bar < Formula
url "https://example.com/bar-1.0"
depends_on "foo"
end
EOS
(HOMEBREW_CELLAR/"bar/1.0").mkpath (HOMEBREW_CELLAR/"bar/1.0").mkpath
assert_match "foo", cmd("missing") assert_match "foo", cmd("missing")
ensure ensure
(HOMEBREW_CELLAR/"bar").rmtree (HOMEBREW_CELLAR/"bar").rmtree
foo_file.unlink
bar_file.unlink
end end
def test_doctor def test_doctor
@ -300,78 +318,46 @@ class IntegrationCommandTests < Homebrew::TestCase
end end
def test_cat def test_cat
formula_file = CoreTap.new.formula_dir/"testball.rb" formula_file = setup_test_formula "testball"
content = <<-EOS.undent assert_equal formula_file.read.chomp, cmd("cat", "testball")
class Testball < Formula
url "https://example.com/testball-0.1.tar.gz"
end
EOS
formula_file.write content
assert_equal content.chomp, cmd("cat", "testball")
ensure
formula_file.unlink
end end
def test_desc def test_desc
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
desc "Some test"
url "https://example.com/testball-0.1.tar.gz"
end
EOS
assert_equal "testball: Some test", cmd("desc", "testball") assert_equal "testball: Some test", cmd("desc", "testball")
assert_match "Pick one, and only one", cmd_fail("desc", "--search", "--name") assert_match "Pick one, and only one", cmd_fail("desc", "--search", "--name")
assert_match "You must provide a search term", cmd_fail("desc", "--search") assert_match "You must provide a search term", cmd_fail("desc", "--search")
refute_predicate HOMEBREW_CACHE.join("desc_cache.json"), desc_cache = HOMEBREW_CACHE/"desc_cache.json"
:exist?, "Cached file should not exist" refute_predicate desc_cache, :exist?, "Cached file should not exist"
cmd("desc", "--description", "testball") cmd("desc", "--description", "testball")
assert_predicate HOMEBREW_CACHE.join("desc_cache.json"), assert_predicate desc_cache, :exist?, "Cached file should not exist"
:exist?, "Cached file should exist"
FileUtils.rm HOMEBREW_CACHE.join("desc_cache.json")
ensure ensure
formula_file.unlink desc_cache.unlink
end end
def test_edit def test_edit
(HOMEBREW_REPOSITORY/".git").mkpath (HOMEBREW_REPOSITORY/".git").mkpath
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
url "https://example.com/testball-0.1.tar.gz"
# something here
end
EOS
assert_match "# something here", assert_match "# something here",
cmd("edit", "testball", {"HOMEBREW_EDITOR" => "/bin/cat"}) cmd("edit", "testball", "HOMEBREW_EDITOR" => "/bin/cat")
ensure ensure
formula_file.unlink
(HOMEBREW_REPOSITORY/".git").unlink (HOMEBREW_REPOSITORY/".git").unlink
end end
def test_sh def test_sh
assert_match "Your shell has been configured", assert_match "Your shell has been configured",
cmd("sh", {"SHELL" => "/usr/bin/true"}) cmd("sh", "SHELL" => "/usr/bin/true")
end end
def test_info def test_info
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
url "https://example.com/testball-0.1.tar.gz"
end
EOS
assert_match "testball: stable 0.1", assert_match "testball: stable 0.1",
cmd("info", "testball") cmd("info", "testball")
ensure
formula_file.unlink
end end
def test_tap_readme def test_tap_readme
@ -384,12 +370,7 @@ class IntegrationCommandTests < Homebrew::TestCase
end end
def test_unpack def test_unpack
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
end
EOS
mktmpdir do |path| mktmpdir do |path|
cmd "unpack", "testball", "--destdir=#{path}" cmd "unpack", "testball", "--destdir=#{path}"
@ -398,60 +379,34 @@ class IntegrationCommandTests < Homebrew::TestCase
end end
ensure ensure
FileUtils.rm_f HOMEBREW_CACHE/"testball-0.1.tbz" FileUtils.rm_f HOMEBREW_CACHE/"testball-0.1.tbz"
formula_file.unlink
end end
def test_options def test_options
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball", <<-EOS.undent
formula_file.write <<-EOS.undent depends_on "bar" => :recommended
class Testball < Formula
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
option "with-foo", "foobar"
depends_on "bar" => :recommended
end
EOS EOS
assert_equal "--with-foo\n\tfoobar\n--without-bar\n\tBuild without bar support", assert_equal "--with-foo\n\tBuild with foo\n--without-bar\n\tBuild without bar support",
cmd_output("options", "testball").chomp cmd_output("options", "testball").chomp
ensure
formula_file.unlink
end end
def test_outdated def test_outdated
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
end
EOS
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
assert_equal "testball", cmd("outdated") assert_equal "testball", cmd("outdated")
ensure ensure
formula_file.unlink
FileUtils.rm_rf HOMEBREW_CELLAR/"testball" FileUtils.rm_rf HOMEBREW_CELLAR/"testball"
end end
def test_upgrade def test_upgrade
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
sha256 "#{TESTBALL_SHA256}"
def install
prefix.install Dir["*"]
end
end
EOS
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
cmd("upgrade") cmd("upgrade")
assert((HOMEBREW_CELLAR/"testball/0.1").directory?, assert((HOMEBREW_CELLAR/"testball/0.1").directory?,
"The latest version directory should be created") "The latest version directory should be created")
ensure ensure
formula_file.unlink
cmd("uninstall", "--force", testball) cmd("uninstall", "--force", testball)
cmd("cleanup", "--force", "--prune=all") cmd("cleanup", "--force", "--prune=all")
end end
@ -461,19 +416,13 @@ class IntegrationCommandTests < Homebrew::TestCase
apps_dir = Pathname.new(home).join("Applications") apps_dir = Pathname.new(home).join("Applications")
apps_dir.mkpath apps_dir.mkpath
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
url "https://example.com/testball-0.1.tar.gz"
end
EOS
source_dir = HOMEBREW_CELLAR/"testball/0.1/TestBall.app" source_dir = HOMEBREW_CELLAR/"testball/0.1/TestBall.app"
source_dir.mkpath source_dir.mkpath
assert_match "Linking: #{source_dir}", assert_match "Linking: #{source_dir}",
cmd("linkapps", "--local", {"HOME" => home}) cmd("linkapps", "--local", "HOME" => home)
ensure ensure
formula_file.unlink
FileUtils.rm_rf apps_dir FileUtils.rm_rf apps_dir
(HOMEBREW_CELLAR/"testball").rmtree (HOMEBREW_CELLAR/"testball").rmtree
end end
@ -483,12 +432,7 @@ class IntegrationCommandTests < Homebrew::TestCase
apps_dir = Pathname.new(home).join("Applications") apps_dir = Pathname.new(home).join("Applications")
apps_dir.mkpath apps_dir.mkpath
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
url "https://example.com/testball-0.1.tar.gz"
end
EOS
source_app = (HOMEBREW_CELLAR/"testball/0.1/TestBall.app") source_app = (HOMEBREW_CELLAR/"testball/0.1/TestBall.app")
source_app.mkpath source_app.mkpath
@ -496,25 +440,14 @@ class IntegrationCommandTests < Homebrew::TestCase
FileUtils.ln_s source_app, "#{apps_dir}/TestBall.app" FileUtils.ln_s source_app, "#{apps_dir}/TestBall.app"
assert_match "Unlinking: #{apps_dir}/TestBall.app", assert_match "Unlinking: #{apps_dir}/TestBall.app",
cmd("unlinkapps", "--local", {"HOME" => home}) cmd("unlinkapps", "--local", "HOME" => home)
ensure ensure
formula_file.unlink
apps_dir.rmtree apps_dir.rmtree
(HOMEBREW_CELLAR/"testball").rmtree (HOMEBREW_CELLAR/"testball").rmtree
end end
def test_pin_unpin def test_pin_unpin
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
sha256 "#{TESTBALL_SHA256}"
def install
prefix.install Dir["*"]
end
end
EOS
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
cmd("pin", "testball") cmd("pin", "testball")
@ -527,26 +460,12 @@ class IntegrationCommandTests < Homebrew::TestCase
assert((HOMEBREW_CELLAR/"testball/0.1").directory?, assert((HOMEBREW_CELLAR/"testball/0.1").directory?,
"The latest version directory should be created") "The latest version directory should be created")
ensure ensure
formula_file.unlink
cmd("uninstall", "--force", testball) cmd("uninstall", "--force", testball)
cmd("cleanup", "--force", "--prune=all") cmd("cleanup", "--force", "--prune=all")
end end
def test_reinstall def test_reinstall
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
sha256 "#{TESTBALL_SHA256}"
option "with-foo", "build with foo"
def install
(prefix/"foo"/"test").write("test") if build.with? "foo"
prefix.install Dir["*"]
end
end
EOS
cmd("install", "testball", "--with-foo") cmd("install", "testball", "--with-foo")
foo_dir = HOMEBREW_CELLAR/"testball/0.1/foo" foo_dir = HOMEBREW_CELLAR/"testball/0.1/foo"
@ -556,28 +475,17 @@ class IntegrationCommandTests < Homebrew::TestCase
cmd("reinstall", "testball") cmd("reinstall", "testball")
assert foo_dir.exist? assert foo_dir.exist?
ensure ensure
formula_file.unlink
cmd("uninstall", "--force", "testball") cmd("uninstall", "--force", "testball")
cmd("cleanup", "--force", "--prune=all") cmd("cleanup", "--force", "--prune=all")
end end
def test_home def test_home
setup_test_formula "testball"
assert_equal HOMEBREW_WWW, assert_equal HOMEBREW_WWW,
cmd("home", {"HOMEBREW_BROWSER" => "echo"}) cmd("home", "HOMEBREW_BROWSER" => "echo")
formula_file = CoreTap.new.formula_dir/"testball.rb"
formula_file.write <<-EOS.undent
class Testball < Formula
desc "Some test"
homepage "https://example.com/testball"
url "https://example.com/testball-0.1.tar.gz"
end
EOS
assert_equal Formula["testball"].homepage, assert_equal Formula["testball"].homepage,
cmd("home", "testball", {"HOMEBREW_BROWSER" => "echo"}) cmd("home", "testball", "HOMEBREW_BROWSER" => "echo")
ensure
formula_file.unlink
end end
def test_list def test_list
@ -596,7 +504,7 @@ class IntegrationCommandTests < Homebrew::TestCase
def test_create def test_create
url = "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz" url = "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
cmd("create", url, {"HOMEBREW_EDITOR" => "/bin/cat"}) cmd("create", url, "HOMEBREW_EDITOR" => "/bin/cat")
formula_file = CoreTap.new.formula_dir/"testball.rb" formula_file = CoreTap.new.formula_dir/"testball.rb"
assert formula_file.exist?, "The formula source should have been created" assert formula_file.exist?, "The formula source should have been created"
@ -607,85 +515,39 @@ class IntegrationCommandTests < Homebrew::TestCase
end end
def test_fetch def test_fetch
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
sha256 "#{TESTBALL_SHA256}"
end
EOS
cmd("fetch", "testball") cmd("fetch", "testball")
assert((HOMEBREW_CACHE/"testball-0.1.tbz").exist?, assert((HOMEBREW_CACHE/"testball-0.1.tbz").exist?,
"The tarball should have been cached") "The tarball should have been cached")
ensure ensure
formula_file.unlink
cmd("cleanup", "--force", "--prune=all") cmd("cleanup", "--force", "--prune=all")
end end
def test_deps def test_deps
formula_dir = CoreTap.new.formula_dir setup_test_formula "foo"
formula_file1 = formula_dir/"testball1.rb" setup_test_formula "bar"
formula_file2 = formula_dir/"testball2.rb" setup_test_formula "baz", <<-EOS.undent
formula_file3 = formula_dir/"testball3.rb" url "https://example.com/baz-1.0"
formula_file1.write <<-EOS.undent depends_on "bar"
class Testball1 < Formula
url "https://example.com/testball1-0.1.tar.gz"
depends_on "testball2"
end
EOS
formula_file2.write <<-EOS.undent
class Testball2 < Formula
url "https://example.com/testball2-0.1.tar.gz"
depends_on "testball3"
end
EOS
formula_file3.write <<-EOS.undent
class Testball3 < Formula
url "https://example.com/testball3-0.1.tar.gz"
end
EOS EOS
assert_equal "testball2\ntestball3", cmd("deps", "testball1") assert_equal "", cmd("deps", "foo")
assert_equal "testball3", cmd("deps", "testball2") assert_equal "foo", cmd("deps", "bar")
assert_equal "", cmd("deps", "testball3") assert_equal "bar\nfoo", cmd("deps", "baz")
ensure
formula_file1.unlink
formula_file2.unlink
formula_file3.unlink
end end
def test_uses def test_uses
formula_dir = CoreTap.new.formula_dir setup_test_formula "foo"
formula_file1 = formula_dir/"testball1.rb" setup_test_formula "bar"
formula_file2 = formula_dir/"testball2.rb" setup_test_formula "baz", <<-EOS.undent
formula_file3 = formula_dir/"testball3.rb" url "https://example.com/baz-1.0"
formula_file1.write <<-EOS.undent depends_on "bar"
class Testball1 < Formula
url "https://example.com/testball1-0.1.tar.gz"
depends_on "testball2"
end
EOS
formula_file2.write <<-EOS.undent
class Testball2 < Formula
url "https://example.com/testball2-0.1.tar.gz"
depends_on "testball3"
end
EOS
formula_file3.write <<-EOS.undent
class Testball3 < Formula
url "https://example.com/testball3-0.1.tar.gz"
end
EOS EOS
assert_equal "testball1\ntestball2", cmd("uses", "--recursive", "testball3") assert_equal "", cmd("uses", "baz")
assert_equal "testball2", cmd("uses", "testball3") assert_equal "baz", cmd("uses", "bar")
assert_equal "", cmd("uses", "testball1") assert_equal "bar\nbaz", cmd("uses", "--recursive", "foo")
ensure
formula_file1.unlink
formula_file2.unlink
formula_file3.unlink
end end
def test_log def test_log
@ -702,12 +564,7 @@ class IntegrationCommandTests < Homebrew::TestCase
def test_log_formula def test_log_formula
core_tap = CoreTap.new core_tap = CoreTap.new
formula_file = core_tap.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
url "https://example.com/testball-0.1.tar.gz"
end
EOS
core_tap.path.cd do core_tap.path.cd do
shutup do shutup do
@ -728,38 +585,23 @@ class IntegrationCommandTests < Homebrew::TestCase
assert_predicate shallow_tap.path/".git/shallow", :exist?, assert_predicate shallow_tap.path/".git/shallow", :exist?,
"A shallow clone should have been created." "A shallow clone should have been created."
ensure ensure
formula_file.unlink
(core_tap.path/".git").rmtree (core_tap.path/".git").rmtree
shallow_tap.path.rmtree shallow_tap.path.rmtree
end end
def test_leaves def test_leaves
formula_dir = CoreTap.new.formula_dir setup_test_formula "foo"
formula_file1 = formula_dir/"testball1.rb" setup_test_formula "bar"
formula_file2 = formula_dir/"testball2.rb"
formula_file1.write <<-EOS.undent
class Testball1 < Formula
url "https://example.com/testball1-0.1.tar.gz"
end
EOS
formula_file2.write <<-EOS.undent
class Testball2 < Formula
url "https://example.com/testball2-0.1.tar.gz"
depends_on "testball1"
end
EOS
assert_equal "", cmd("leaves") assert_equal "", cmd("leaves")
(HOMEBREW_CELLAR/"testball1/0.1/somedir").mkpath (HOMEBREW_CELLAR/"foo/0.1/somedir").mkpath
assert_equal "testball1", cmd("leaves") assert_equal "foo", cmd("leaves")
(HOMEBREW_CELLAR/"testball2/0.1/somedir").mkpath (HOMEBREW_CELLAR/"bar/0.1/somedir").mkpath
assert_equal "testball2", cmd("leaves") assert_equal "bar", cmd("leaves")
ensure ensure
(HOMEBREW_CELLAR/"testball1").rmtree (HOMEBREW_CELLAR/"foo").rmtree
(HOMEBREW_CELLAR/"testball2").rmtree (HOMEBREW_CELLAR/"bar").rmtree
formula_file1.unlink
formula_file2.unlink
end end
def test_prune def test_prune
@ -794,19 +636,12 @@ class IntegrationCommandTests < Homebrew::TestCase
FileUtils.chmod 0777, file FileUtils.chmod 0777, file
assert_match "I am #{cmd}", assert_match "I am #{cmd}",
cmd(cmd, {"PATH" => "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"}) cmd(cmd, "PATH" => "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}")
end end
end end
def test_search def test_search
formula_file = CoreTap.new.formula_dir/"testball.rb" setup_test_formula "testball"
formula_file.write <<-EOS.undent
class Testball < Formula
desc "Some test"
url "https://example.com/testball-0.1.tar.gz"
end
EOS
desc_cache = HOMEBREW_CACHE/"desc_cache.json" desc_cache = HOMEBREW_CACHE/"desc_cache.json"
refute_predicate desc_cache, :exist?, "Cached file should not exist" refute_predicate desc_cache, :exist?, "Cached file should not exist"
@ -832,6 +667,5 @@ class IntegrationCommandTests < Homebrew::TestCase
assert_predicate desc_cache, :exist?, "Cached file should exist" assert_predicate desc_cache, :exist?, "Cached file should exist"
ensure ensure
desc_cache.unlink desc_cache.unlink
formula_file.unlink
end end
end end