Skip to content

Commit

Permalink
macos_version: define a method instead
Browse files Browse the repository at this point in the history
  • Loading branch information
carlocab committed Oct 31, 2024
1 parent 5ae4f25 commit 0dc64a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
23 changes: 9 additions & 14 deletions Library/Homebrew/macos_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,15 @@ def initialize(version)
el_capitan: "10.11",
}.freeze

# Map of macOS version strings to kernel major versions.
# https://en.wikipedia.org/wiki/MacOS_version_history#Releases
KERNEL_MAJOR_VERSIONS = {
"15" => "24",
"14" => "23",
"13" => "22",
"12" => "21",
"11" => "20",
"10.15" => "19",
"10.14" => "18",
"10.13" => "17",
"10.12" => "16",
"10.11" => "15",
}.freeze
def self.kernel_major_version(macos_version)
version_major = macos_version.major.to_i
if version_major > 10
T.must(superclass).new((version_major + 9).to_s)
else
version_minor = macos_version.minor.to_i
T.must(superclass).new((version_minor + 4).to_s)
end
end

sig { params(version: Symbol).returns(T.attached_class) }
def self.from_symbol(version)
Expand Down
12 changes: 12 additions & 0 deletions Library/Homebrew/test/macos_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
let(:big_sur_major) { described_class.new("11.0") }
let(:big_sur_update) { described_class.new("11.1") }

describe ".kernel_major_version" do
it "returns the kernel major version" do
expect(described_class.kernel_major_version(version)).to eq "18"
expect(described_class.kernel_major_version(big_sur_major)).to eq "20"
expect(described_class.kernel_major_version(big_sur_update)).to eq "20"
end

it "matches the major version returned by OS.kernel_version", :needs_macos do
expect(described_class.kernel_major_version(OS::Mac.version)).to eq OS.kernel_version.major
end
end

specify "comparison with Symbol" do
expect(version).to be > :high_sierra
expect(version).to eq :mojave
Expand Down

0 comments on commit 0dc64a5

Please sign in to comment.