Skip to content

Commit

Permalink
test/cask/dsl_spec: fix test for certain locale settings
Browse files Browse the repository at this point in the history
As I mentioned in Homebrew#15146, two `Cask::DSL` tests failed on my local
machine, even on `master`. `git bisect` suggested that it was Homebrew#14998
that introduced those failures. It turned out that the tests here could
fail under certain locale settings, like this one below:

    $ defaults read -g AppleLanguages
    (
        "en-GB",
        "zh-Hans-SG"
    )

This is not actually a regression. With the aforementioned locale
settings, an explicit `let(:languages) { ["en"] }` setting would result
in locales being considered in the following order: `en`, `en-GB`,
`zh-Hans-SG`. For each of them, the `detect` method from `Locale` is
called, with `locale_groups` as `[["zh"], ["en-US"]]`, the list of
locales defined in the test cask.

    def detect(locale_groups)
      locale_groups.find { |locales| locales.any? { |locale| eql?(locale) } } ||
        locale_groups.find { |locales| locales.any? { |locale| include?(locale) } }
    end

Neither of `en` and `en-GB` satisfies the `detect` conditions. (Note
that `Locale.parse("en").include?("en-US")` evaluates to `false`.) But
`zh-Hans-SG` does (because `Locale.parse("zh-Hans-SG").include?("zh")`
is `true`). So, despite having `:languages` set to `en`, the Chinese
locale was still used.

This could be fixed by generalising the test cask's English locale
settings from `en-US` to `en`. This is already the case for most
existing casks:

    $ grep 'language "en.*", default: true' Casks/*.rb
    Casks/battle-net.rb:  language "en", default: true do
    Casks/cave-story.rb:  language "en", default: true do
    Casks/firefox.rb:  language "en", default: true do
    Casks/libreoffice-language-pack.rb:    language "en-GB", default: true do
    Casks/libreoffice-language-pack.rb:    language "en-GB", default: true do
    Casks/openoffice.rb:  language "en", default: true do
    Casks/seamonkey.rb:  language "en-US", default: true do
    Casks/thunderbird.rb:  language "en", default: true do
    Casks/wondershare-edrawmax.rb:  language "en", default: true do

Note that this should make the language stanza tests independent of
locale settings, because `zh` and `en` should be able to capture all the
test cases.

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
  • Loading branch information
ZhongRuoyu committed Apr 13, 2023
1 parent 5c56cb7 commit 1dd2e0c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Library/Homebrew/test/cask/dsl_spec.rb
Expand Up @@ -165,7 +165,7 @@
"zh-CN"
end

language "en-US", default: true do
language "en", default: true do
sha256 "xyz789"
"en-US"
end
Expand Down

0 comments on commit 1dd2e0c

Please sign in to comment.