mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
feat: add linux tests
This commit is contained in:
parent
c34b71655c
commit
32b9afd7cd
@ -63,10 +63,23 @@ module OS
|
||||
def self.languages
|
||||
return @languages if @languages.present?
|
||||
|
||||
os_langs = Utils.popen_read("localectl", "list-locales")
|
||||
os_langs = os_langs.scan(/[^ \n"(),]+/).map { |item| item.split(".").first.tr("_", "-") }
|
||||
locale_variables = ENV.keys.grep(/^(?:LC_\S+|LANG|LANGUAGE)\Z/).sort
|
||||
ctl_ret = Utils.popen_read("localectl", "list-locales")
|
||||
if ctl_ret.present?
|
||||
list = ctl_ret.scan(/[^ \n"(),]+/)
|
||||
elsif locale_variables.present?
|
||||
keys = locale_variables.select { |var| ENV.fetch(var) }
|
||||
list = keys.map { |key| ENV.fetch(key) }
|
||||
else
|
||||
list = ["en_US.utf8"]
|
||||
end
|
||||
|
||||
@languages = os_langs
|
||||
@languages = list.map { |item| item.split(".").first.tr("_", "-") }
|
||||
end
|
||||
|
||||
sig { returns(T.nilable(String)) }
|
||||
def self.language
|
||||
languages.first
|
||||
end
|
||||
end
|
||||
end
|
||||
|
36
Library/Homebrew/test/os/linux_spec.rb
Normal file
36
Library/Homebrew/test/os/linux_spec.rb
Normal file
@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "locale"
|
||||
require "os/linux"
|
||||
|
||||
RSpec.describe OS::Linux do
|
||||
describe "::languages", :needs_linux do
|
||||
it "returns a list of all languages" do
|
||||
expect(described_class.languages).not_to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe "::language", :needs_linux do
|
||||
it "returns the first item from #languages" do
|
||||
expect(described_class.language).to eq(described_class.languages.first)
|
||||
end
|
||||
end
|
||||
|
||||
describe "::'os_version'", :needs_linux do
|
||||
it "returns the OS version" do
|
||||
expect(described_class.os_version).not_to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe "::'wsl?'" do
|
||||
it "returns the WSL state" do
|
||||
expect(described_class.wsl?).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe "::'wsl_version'", :needs_linux do
|
||||
it "returns the WSL version" do
|
||||
expect(described_class.wsl_version).to match(Version::NULL)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user