diff options
| -rwxr-xr-x | Library/Homebrew/shims/super/cc | 9 | ||||
| -rw-r--r-- | Library/Homebrew/test/cleanup_spec.rb | 130 | ||||
| -rw-r--r-- | Library/Homebrew/test/cleanup_test.rb | 96 | ||||
| -rw-r--r-- | Library/Homebrew/test/os/mac/x11_requirement_test.rb | 13 | ||||
| -rw-r--r-- | Library/Homebrew/test/sandbox_spec.rb | 78 | ||||
| -rw-r--r-- | Library/Homebrew/test/sandbox_test.rb | 73 | ||||
| -rw-r--r-- | Library/Homebrew/test/x11_requirement_spec.rb | 13 |
7 files changed, 221 insertions, 191 deletions
diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index b0ea705e8..1400788ba 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -206,10 +206,6 @@ class Cmd end def keep?(path) - # The logic in this method will eventually become the default, - # but is currently opt-in. - return keep_orig?(path) unless ENV["HOMEBREW_EXPERIMENTAL_FILTER_FLAGS_ON_DEPS"] - # Allow references to self if formula_prefix && path.start_with?("#{formula_prefix}/") true @@ -226,11 +222,6 @@ class Cmd end end - # The original less-smart version of keep_orig; will eventually be removed - def keep_orig?(path) - path.start_with?(prefix, cellar, tmpdir) || !path.start_with?("/opt/local", "/opt/boxen/homebrew", "/opt/X11", "/sw", "/usr/X11") - end - def cflags args = [] diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb new file mode 100644 index 000000000..b0e824767 --- /dev/null +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -0,0 +1,130 @@ +require "test/support/fixtures/testball" +require "cleanup" +require "fileutils" +require "pathname" + +describe Homebrew::Cleanup do + let(:ds_store) { Pathname.new("#{HOMEBREW_PREFIX}/Library/.DS_Store") } + + around(:each) do |example| + begin + FileUtils.touch ds_store + + example.run + ensure + FileUtils.rm_f ds_store + end + end + + describe "::cleanup" do + it "removes .DS_Store files" do + shutup do + described_class.cleanup + end + + expect(ds_store).not_to exist + end + + it "doesn't remove anything if `--dry-run` is specified" do + ARGV << "--dry-run" + + shutup do + described_class.cleanup + end + + expect(ds_store).to exist + end + end + + specify "::cleanup_formula" do + f1 = Class.new(Testball) do + version "1.0" + end.new + + f2 = Class.new(Testball) do + version "0.2" + version_scheme 1 + end.new + + f3 = Class.new(Testball) do + version "0.3" + version_scheme 1 + end.new + + f4 = Class.new(Testball) do + version "0.1" + version_scheme 2 + end.new + + shutup do + [f1, f2, f3, f4].each do |f| + f.brew do + f.install + end + + Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write + end + end + + expect(f1).to be_installed + expect(f2).to be_installed + expect(f3).to be_installed + expect(f4).to be_installed + + shutup do + described_class.cleanup_formula f3 + end + + expect(f1).not_to be_installed + expect(f2).not_to be_installed + expect(f3).to be_installed + expect(f4).to be_installed + end + + specify "::cleanup_logs" do + path = (HOMEBREW_LOGS/"delete_me") + path.mkpath + ARGV << "--prune=all" + + shutup do + described_class.cleanup_logs + end + + expect(path).not_to exist + end + + describe "::cleanup_cache" do + it "cleans up incomplete downloads" do + incomplete = (HOMEBREW_CACHE/"something.incomplete") + incomplete.mkpath + + shutup do + described_class.cleanup_cache + end + + expect(incomplete).not_to exist + end + + it "cleans up 'java_cache'" do + java_cache = (HOMEBREW_CACHE/"java_cache") + java_cache.mkpath + + shutup do + described_class.cleanup_cache + end + + expect(java_cache).not_to exist + end + + it "cleans up 'npm_cache'" do + npm_cache = (HOMEBREW_CACHE/"npm_cache") + npm_cache.mkpath + + shutup do + described_class.cleanup_cache + end + + expect(npm_cache).not_to exist + end + end +end diff --git a/Library/Homebrew/test/cleanup_test.rb b/Library/Homebrew/test/cleanup_test.rb deleted file mode 100644 index bc7a6713c..000000000 --- a/Library/Homebrew/test/cleanup_test.rb +++ /dev/null @@ -1,96 +0,0 @@ -require "testing_env" -require "test/support/fixtures/testball" -require "cleanup" -require "fileutils" -require "pathname" -require "testing_env" - -class CleanupTests < Homebrew::TestCase - def setup - super - @ds_store = Pathname.new "#{HOMEBREW_PREFIX}/Library/.DS_Store" - FileUtils.touch @ds_store - end - - def teardown - FileUtils.rm_f @ds_store - super - end - - def test_cleanup - shutup { Homebrew::Cleanup.cleanup } - refute_predicate @ds_store, :exist? - end - - def test_cleanup_dry_run - ARGV << "--dry-run" - shutup { Homebrew::Cleanup.cleanup } - assert_predicate @ds_store, :exist? - end - - def test_cleanup_formula - f1 = Class.new(Testball) do - version "1.0" - end.new - f2 = Class.new(Testball) do - version "0.2" - version_scheme 1 - end.new - f3 = Class.new(Testball) do - version "0.3" - version_scheme 1 - end.new - f4 = Class.new(Testball) do - version "0.1" - version_scheme 2 - end.new - - shutup do - [f1, f2, f3, f4].each do |f| - f.brew { f.install } - Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write - end - end - - assert_predicate f1, :installed? - assert_predicate f2, :installed? - assert_predicate f3, :installed? - assert_predicate f4, :installed? - - shutup { Homebrew::Cleanup.cleanup_formula f3 } - - refute_predicate f1, :installed? - refute_predicate f2, :installed? - assert_predicate f3, :installed? - assert_predicate f4, :installed? - end - - def test_cleanup_logs - path = (HOMEBREW_LOGS/"delete_me") - path.mkpath - ARGV << "--prune=all" - shutup { Homebrew::Cleanup.cleanup_logs } - refute_predicate path, :exist? - end - - def test_cleanup_cache_incomplete_downloads - incomplete = (HOMEBREW_CACHE/"something.incomplete") - incomplete.mkpath - shutup { Homebrew::Cleanup.cleanup_cache } - refute_predicate incomplete, :exist? - end - - def test_cleanup_cache_java_cache - java_cache = (HOMEBREW_CACHE/"java_cache") - java_cache.mkpath - shutup { Homebrew::Cleanup.cleanup_cache } - refute_predicate java_cache, :exist? - end - - def test_cleanup_cache_npm_cache - npm_cache = (HOMEBREW_CACHE/"npm_cache") - npm_cache.mkpath - shutup { Homebrew::Cleanup.cleanup_cache } - refute_predicate npm_cache, :exist? - end -end diff --git a/Library/Homebrew/test/os/mac/x11_requirement_test.rb b/Library/Homebrew/test/os/mac/x11_requirement_test.rb deleted file mode 100644 index 102937cb5..000000000 --- a/Library/Homebrew/test/os/mac/x11_requirement_test.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "testing_env" -require "requirements/x11_requirement" - -class OSMacX11RequirementTests < Homebrew::TestCase - def test_satisfied - MacOS::XQuartz.stubs(:version).returns("2.7.5") - MacOS::XQuartz.stubs(:installed?).returns(true) - assert_predicate X11Requirement.new, :satisfied? - - MacOS::XQuartz.stubs(:installed?).returns(false) - refute_predicate X11Requirement.new, :satisfied? - end -end diff --git a/Library/Homebrew/test/sandbox_spec.rb b/Library/Homebrew/test/sandbox_spec.rb new file mode 100644 index 000000000..98634bf3c --- /dev/null +++ b/Library/Homebrew/test/sandbox_spec.rb @@ -0,0 +1,78 @@ +require "sandbox" + +RSpec::Matchers.define_negated_matcher :not_matching, :matching + +describe Sandbox do + let(:dir) { @dir = Pathname.new(Dir.mktmpdir) } + let(:file) { dir/"foo" } + + before(:each) do + skip "Sandbox not implemented." unless described_class.available? + end + + after(:each) do + dir.rmtree unless @dir.nil? + end + + specify "#formula?" do + f = formula { url "foo-1.0" } + f2 = formula { url "bar-1.0" } + allow(f2).to receive(:tap).and_return(Tap.fetch("test/tap")) + + ENV["HOMEBREW_SANDBOX"] = "1" + expect(described_class).to be_formula(f), "Formulae should be sandboxed if --sandbox was passed." + + ENV.delete("HOMEBREW_SANDBOX") + expect(described_class).to be_formula(f), "Formulae should be sandboxed if in a sandboxed tap." + expect(described_class).not_to be_formula(f2), "Formulae should not be sandboxed if not in a sandboxed tap." + end + + specify "#test?" do + ENV.delete("HOMEBREW_NO_SANDBOX") + expect(described_class).to be_test, "Tests should be sandboxed unless --no-sandbox was passed." + end + + specify "#allow_write" do + subject.allow_write file + subject.exec "touch", file + + expect(file).to exist + end + + describe "#exec" do + it "fails when writing to file not specified with ##allow_write" do + shutup do + expect { + subject.exec "touch", file + }.to raise_error(ErrorDuringExecution) + end + + expect(file).not_to exist + end + + it "complains on failure" do + ENV["HOMEBREW_VERBOSE"] = "1" + + expect(Utils).to receive(:popen_read).and_return("foo") + + expect { subject.exec "false" } + .to raise_error(ErrorDuringExecution) + .and output(/foo/).to_stdout + end + + it "ignores bogus Python error" do + ENV["HOMEBREW_VERBOSE"] = "1" + + with_bogus_error = <<-EOS.undent + foo + Mar 17 02:55:06 sandboxd[342]: Python(49765) deny file-write-unlink /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/errors.pyc + bar + EOS + expect(Utils).to receive(:popen_read).and_return(with_bogus_error) + + expect { subject.exec "false" } + .to raise_error(ErrorDuringExecution) + .and output(a_string_matching(/foo/).and(matching(/bar/).and(not_matching(/Python/)))).to_stdout + end + end +end diff --git a/Library/Homebrew/test/sandbox_test.rb b/Library/Homebrew/test/sandbox_test.rb deleted file mode 100644 index a633defce..000000000 --- a/Library/Homebrew/test/sandbox_test.rb +++ /dev/null @@ -1,73 +0,0 @@ -require "testing_env" -require "sandbox" - -class SandboxTest < Homebrew::TestCase - def setup - super - skip "sandbox not implemented" unless Sandbox.available? - @sandbox = Sandbox.new - @dir = Pathname.new(mktmpdir) - @file = @dir/"foo" - end - - def test_formula? - f = formula { url "foo-1.0" } - f2 = formula { url "bar-1.0" } - f2.stubs(:tap).returns(Tap.fetch("test/tap")) - - ENV["HOMEBREW_SANDBOX"] = "1" - assert Sandbox.formula?(f), - "Formulae should be sandboxed if --sandbox was passed." - - ENV.delete("HOMEBREW_SANDBOX") - assert Sandbox.formula?(f), - "Formulae should be sandboxed if in a sandboxed tap." - refute Sandbox.formula?(f2), - "Formulae should not be sandboxed if not in a sandboxed tap." - end - - def test_test? - ENV.delete("HOMEBREW_NO_SANDBOX") - assert Sandbox.test?, - "Tests should be sandboxed unless --no-sandbox was passed." - end - - def test_allow_write - @sandbox.allow_write @file - @sandbox.exec "touch", @file - assert_predicate @file, :exist? - end - - def test_deny_write - shutup do - assert_raises(ErrorDuringExecution) { @sandbox.exec "touch", @file } - end - refute_predicate @file, :exist? - end - - def test_complains_on_failure - Utils.expects(popen_read: "foo") - ENV["HOMEBREW_VERBOSE"] = "1" - out, _err = capture_io do - assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } - end - assert_match "foo", out - end - - def test_ignores_bogus_python_error - with_bogus_error = <<-EOS.undent - foo - Mar 17 02:55:06 sandboxd[342]: Python(49765) deny file-write-unlink /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/errors.pyc - bar - EOS - Utils.expects(popen_read: with_bogus_error) - ENV["HOMEBREW_VERBOSE"] = "1" - out, _err = capture_io do - assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } - end - refute_predicate out, :empty? - assert_match "foo", out - assert_match "bar", out - refute_match "Python", out - end -end diff --git a/Library/Homebrew/test/x11_requirement_spec.rb b/Library/Homebrew/test/x11_requirement_spec.rb index f60c8bffe..bc02dc75a 100644 --- a/Library/Homebrew/test/x11_requirement_spec.rb +++ b/Library/Homebrew/test/x11_requirement_spec.rb @@ -33,4 +33,17 @@ describe X11Requirement do subject.modify_build_environment end end + + describe "#satisfied?", :needs_macos do + it "returns true if X11 is installed" do + expect(MacOS::XQuartz).to receive(:version).and_return("2.7.5") + expect(MacOS::XQuartz).to receive(:installed?).and_return(true) + expect(subject).to be_satisfied + end + + it "returns false if X11 is not installed" do + expect(MacOS::XQuartz).to receive(:installed?).and_return(false) + expect(subject).not_to be_satisfied + end + end end |
