Skip to content

Commit 32b9afd

Browse files
committed
feat: add linux tests
1 parent c34b716 commit 32b9afd

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

Library/Homebrew/os/linux.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,23 @@ def self.wsl_version
6363
def self.languages
6464
return @languages if @languages.present?
6565

66-
os_langs = Utils.popen_read("localectl", "list-locales")
67-
os_langs = os_langs.scan(/[^ \n"(),]+/).map { |item| item.split(".").first.tr("_", "-") }
66+
locale_variables = ENV.keys.grep(/^(?:LC_\S+|LANG|LANGUAGE)\Z/).sort
67+
ctl_ret = Utils.popen_read("localectl", "list-locales")
68+
if ctl_ret.present?
69+
list = ctl_ret.scan(/[^ \n"(),]+/)
70+
elsif locale_variables.present?
71+
keys = locale_variables.select { |var| ENV.fetch(var) }
72+
list = keys.map { |key| ENV.fetch(key) }
73+
else
74+
list = ["en_US.utf8"]
75+
end
76+
77+
@languages = list.map { |item| item.split(".").first.tr("_", "-") }
78+
end
6879

69-
@languages = os_langs
80+
sig { returns(T.nilable(String)) }
81+
def self.language
82+
languages.first
7083
end
7184
end
7285
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
require "locale"
4+
require "os/linux"
5+
6+
RSpec.describe OS::Linux do
7+
describe "::languages", :needs_linux do
8+
it "returns a list of all languages" do
9+
expect(described_class.languages).not_to be_empty
10+
end
11+
end
12+
13+
describe "::language", :needs_linux do
14+
it "returns the first item from #languages" do
15+
expect(described_class.language).to eq(described_class.languages.first)
16+
end
17+
end
18+
19+
describe "::'os_version'", :needs_linux do
20+
it "returns the OS version" do
21+
expect(described_class.os_version).not_to be_empty
22+
end
23+
end
24+
25+
describe "::'wsl?'" do
26+
it "returns the WSL state" do
27+
expect(described_class.wsl?).to be(false)
28+
end
29+
end
30+
31+
describe "::'wsl_version'", :needs_linux do
32+
it "returns the WSL version" do
33+
expect(described_class.wsl_version).to match(Version::NULL)
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)