aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2013-04-15 15:59:19 -0500
committerJack Nagel2013-04-15 16:04:35 -0500
commitd504d50dcbf3b5744f4c415ad37fe4b8f06e18ad (patch)
tree55659a28d16827e960c2eda5f73bd816d85bed57
parent466a32df02c647b8c4eb268fabacc03526e490d4 (diff)
downloadbrew-d504d50dcbf3b5744f4c415ad37fe4b8f06e18ad.tar.bz2
Don't create MacOS.version multiple times
-rw-r--r--Library/Homebrew/macos.rb22
-rw-r--r--Library/Homebrew/test/test_version_subclasses.rb35
2 files changed, 49 insertions, 8 deletions
diff --git a/Library/Homebrew/macos.rb b/Library/Homebrew/macos.rb
index bb24d7a3c..5c475a72d 100644
--- a/Library/Homebrew/macos.rb
+++ b/Library/Homebrew/macos.rb
@@ -5,19 +5,25 @@ module MacOS extend self
# This can be compared to numerics, strings, or symbols
# using the standard Ruby Comparable methods.
def version
- Version.new(MACOS_VERSION)
+ @version ||= Version.new(MACOS_VERSION)
end
def cat
- # PowerPC builds per processor, not per OS
- return Hardware::CPU.family if Hardware::CPU.type == :ppc
+ @cat ||= uncached_cat
+ end
- if version == :mountain_lion then :mountain_lion
- elsif version == :lion then :lion
- elsif version == :snow_leopard
+ def uncached_cat
+ case MacOS.version
+ when 10.8
+ :mountain_lion
+ when 10.7
+ :lion
+ when 10.6
Hardware.is_64_bit? ? :snow_leopard : :snow_leopard_32
- elsif version == :leopard then :leopard
- else nil
+ when 10.5
+ :leopard
+ else
+ Hardware::CPU.family if Hardware::CPU.type == :ppc
end
end
diff --git a/Library/Homebrew/test/test_version_subclasses.rb b/Library/Homebrew/test/test_version_subclasses.rb
index 6b18246ba..07af63a6f 100644
--- a/Library/Homebrew/test/test_version_subclasses.rb
+++ b/Library/Homebrew/test/test_version_subclasses.rb
@@ -1,6 +1,7 @@
require 'testing_env'
require 'version'
require 'os/mac/version'
+require 'hardware'
class MacOSVersionTests < Test::Unit::TestCase
def setup
@@ -39,4 +40,38 @@ class MacOSVersionTests < Test::Unit::TestCase
assert_operator @v, :===, Version.new(10.7)
assert_operator @v, :<, Version.new(10.8)
end
+
+ def test_cat_tiger
+ MacOS.stubs(:version).returns(MacOS::Version.new(10.4))
+ Hardware::CPU.stubs(:type).returns(:ppc)
+ Hardware::CPU.stubs(:family).returns(:foo)
+ assert_equal :foo, MacOS.uncached_cat
+ end
+
+ def test_cat_leopard
+ MacOS.stubs(:version).returns(MacOS::Version.new(10.5))
+ assert_equal :leopard, MacOS.uncached_cat
+ end
+
+ def test_cat_snow_leopard_32
+ MacOS.stubs(:version).returns(MacOS::Version.new(10.6))
+ Hardware.stubs(:is_64_bit?).returns(false)
+ assert_equal :snow_leopard_32, MacOS.uncached_cat
+ end
+
+ def test_cat_snow_leopard_64
+ MacOS.stubs(:version).returns(MacOS::Version.new(10.6))
+ Hardware.stubs(:is_64_bit?).returns(true)
+ assert_equal :snow_leopard, MacOS.uncached_cat
+ end
+
+ def test_cat_lion
+ MacOS.stubs(:version).returns(MacOS::Version.new(10.7))
+ assert_equal :lion, MacOS.uncached_cat
+ end
+
+ def test_cat_mountain_lion
+ MacOS.stubs(:version).returns(MacOS::Version.new(10.8))
+ assert_equal :mountain_lion, MacOS.uncached_cat
+ end
end