aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2013-04-15 15:59:19 -0500
committerJack Nagel2013-04-15 16:04:35 -0500
commitee5e60edf2cddf65cbc0c32be216718c373c58a2 (patch)
tree5b63ae41faa76c117f6158ae90f9f6c8fdb85e99 /Library
parent496220991e664cea5336867c831156956742920e (diff)
downloadhomebrew-ee5e60edf2cddf65cbc0c32be216718c373c58a2.tar.bz2
Don't create MacOS.version multiple times
Diffstat (limited to 'Library')
-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