diff options
| author | Baptiste Fontaine | 2015-12-29 12:57:48 +0100 |
|---|---|---|
| committer | Baptiste Fontaine | 2016-01-04 13:17:21 +0100 |
| commit | 9bdd6619e23f498320c3d3a6be8bd8d095a6d521 (patch) | |
| tree | 0883233991f02205056d00abcb7fd356194379e1 /Library/Homebrew/test | |
| parent | d7b6230aed1a277905605632d91868d89543af1a (diff) | |
| download | brew-9bdd6619e23f498320c3d3a6be8bd8d095a6d521.tar.bz2 | |
cleanup: move code away from cmd/
Closes Homebrew/homebrew#47484.
Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/test_cleanup.rb | 76 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_cmd_cleanup.rb | 30 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_formula.rb | 22 |
3 files changed, 98 insertions, 30 deletions
diff --git a/Library/Homebrew/test/test_cleanup.rb b/Library/Homebrew/test/test_cleanup.rb new file mode 100644 index 000000000..bccfa1e54 --- /dev/null +++ b/Library/Homebrew/test/test_cleanup.rb @@ -0,0 +1,76 @@ +require "testing_env" +require "testball" +require "cleanup" +require "fileutils" +require "pathname" + +class CleanupTests < Homebrew::TestCase + def setup + @ds_store = Pathname.new "#{HOMEBREW_PREFIX}/Library/.DS_Store" + FileUtils.touch @ds_store + end + + def teardown + FileUtils.rm_f @ds_store + ARGV.delete "--dry-run" + ARGV.delete "--prune=all" + 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) { version "0.1" }.new + f2 = Class.new(Testball) { version "0.2" }.new + f3 = Class.new(Testball) { version "0.3" }.new + + shutup do + f1.brew { f1.install } + f2.brew { f2.install } + f3.brew { f3.install } + end + + assert_predicate f1, :installed? + assert_predicate f2, :installed? + assert_predicate f3, :installed? + + shutup { Homebrew::Cleanup.cleanup_formula f3 } + + refute_predicate f1, :installed? + refute_predicate f2, :installed? + assert_predicate f3, :installed? + ensure + [f1, f2, f3].each(&:clear_cache) + f3.rack.rmtree + 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 +end diff --git a/Library/Homebrew/test/test_cmd_cleanup.rb b/Library/Homebrew/test/test_cmd_cleanup.rb deleted file mode 100644 index 109f27eba..000000000 --- a/Library/Homebrew/test/test_cmd_cleanup.rb +++ /dev/null @@ -1,30 +0,0 @@ -require "testing_env" -require "testball" -require "cmd/cleanup" - -class CleanupTests < Homebrew::TestCase - def test_cleanup - f1 = Class.new(Testball) { version "0.1" }.new - f2 = Class.new(Testball) { version "0.2" }.new - f3 = Class.new(Testball) { version "0.3" }.new - - shutup do - f1.brew { f1.install } - f2.brew { f2.install } - f3.brew { f3.install } - end - - assert_predicate f1, :installed? - assert_predicate f2, :installed? - assert_predicate f3, :installed? - - shutup { Homebrew.cleanup_formula(f3) } - - refute_predicate f1, :installed? - refute_predicate f2, :installed? - assert_predicate f3, :installed? - ensure - [f1, f2, f3].each(&:clear_cache) - f3.rack.rmtree - end -end diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb index e6b5396b8..8f372f6f7 100644 --- a/Library/Homebrew/test/test_formula.rb +++ b/Library/Homebrew/test/test_formula.rb @@ -1,5 +1,6 @@ require "testing_env" require "testball" +require "formula" class FormulaTests < Homebrew::TestCase def test_formula_instantiation @@ -345,4 +346,25 @@ class FormulaTests < Homebrew::TestCase assert h.is_a?(Hash), "Formula#to_hash should return a Hash" assert h["versions"]["bottle"], "The hash should say the formula is bottled" end + + def test_eligible_kegs_for_cleanup + f1 = Class.new(Testball) { version "0.1" }.new + f2 = Class.new(Testball) { version "0.2" }.new + f3 = Class.new(Testball) { version "0.3" }.new + + shutup do + f1.brew { f1.install } + f2.brew { f2.install } + f3.brew { f3.install } + end + + assert_predicate f1, :installed? + assert_predicate f2, :installed? + assert_predicate f3, :installed? + + assert_equal f3.installed_kegs[0..1], f3.eligible_kegs_for_cleanup + ensure + [f1, f2, f3].each(&:clear_cache) + f3.rack.rmtree + end end |
