Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macos_version: add KERNEL_MAJOR_VERSIONS map #18674

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Library/Homebrew/macos_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ def initialize(version)
el_capitan: "10.11",
}.freeze

sig { params(macos_version: MacOSVersion).returns(Version) }
def self.kernel_major_version(macos_version)
version_major = macos_version.major.to_i
if version_major > 10
Version.new((version_major + 9).to_s)
else
version_minor = macos_version.minor.to_i
Version.new((version_minor + 4).to_s)
end
end

sig { params(version: Symbol).returns(T.attached_class) }
def self.from_symbol(version)
str = SYMBOLS.fetch(version) { raise MacOSVersion::Error, 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
Loading