Only include differring versions

Move the resetting of `MacOS.version` to an `ensure` block.

Fix the tests by adding a test OS and new fixture that has a
different version for that test OS.
This commit is contained in:
Rylan Polster 2021-08-25 10:30:38 -04:00
parent 663cc40139
commit c3a8b3841e
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
3 changed files with 61 additions and 4 deletions

View File

@ -88,11 +88,13 @@ module Cask
MacOS::Version::SYMBOLS.each do |os_name, os_version|
MacOS.full_version = os_version
version_os_hash[os_name] = CaskLoader.load(token).version
cask = CaskLoader.load(token)
version_os_hash[os_name] = cask.version if cask.version != version
end
MacOS.full_version = actual_version
version_os_hash
ensure
MacOS.full_version = actual_version
end
end

View File

@ -84,7 +84,7 @@ describe Cask::Cmd::List, :cask do
end
describe "lists json" do
let(:casks) { ["local-caffeine", "local-transmission", "third-party/tap/third-party-cask"] }
let(:casks) { ["local-caffeine", "local-transmission", "multiple-versions", "third-party/tap/third-party-cask"] }
let(:expected_output) {
<<~EOS
[
@ -100,6 +100,8 @@ describe Cask::Cmd::List, :cask do
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip",
"appcast": null,
"version": "1.2.3",
"versions": {
},
"installed": "1.2.3",
"outdated": false,
"sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
@ -127,6 +129,8 @@ describe Cask::Cmd::List, :cask do
"url": "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg",
"appcast": null,
"version": "2.61",
"versions": {
},
"installed": "2.61",
"outdated": false,
"sha256": "e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68",
@ -142,6 +146,36 @@ describe Cask::Cmd::List, :cask do
"container": null,
"auto_updates": null
},
{
"token": "multiple-versions",
"full_token": "multiple-versions",
"tap": "homebrew/cask",
"name": [
],
"desc": null,
"homepage": "https://brew.sh/",
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip",
"appcast": null,
"version": "1.2.3",
"versions": {
"test_os": "1.2.0"
},
"installed": "1.2.3",
"outdated": false,
"sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
"artifacts": [
[
"Caffeine.app"
]
],
"caveats": null,
"depends_on": {
},
"conflicts_with": null,
"container": null,
"auto_updates": null
},
{
"token": "third-party-cask",
"full_token": "third-party/tap/third-party-cask",
@ -154,6 +188,8 @@ describe Cask::Cmd::List, :cask do
"url": "https://brew.sh/ThirdParty.dmg",
"appcast": null,
"version": "1.2.3",
"versions": {
},
"installed": "1.2.3",
"outdated": false,
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b",
@ -175,6 +211,11 @@ describe Cask::Cmd::List, :cask do
before do
casks.map(&Cask::CaskLoader.method(:load)).each(&InstallHelper.method(:install_with_caskfile))
# Add a test OS to ensure that all cask versions are listed regardless of OS.
symbols = MacOS::Version::SYMBOLS.dup
symbols[:test_os] = "10.9"
stub_const("MacOS::Version::SYMBOLS", symbols)
end
it "of all installed Casks" do
@ -185,7 +226,8 @@ describe Cask::Cmd::List, :cask do
it "of given Casks" do
expect {
described_class.run("--json", "local-caffeine", "local-transmission", "third-party/tap/third-party-cask")
described_class.run("--json", "local-caffeine", "local-transmission", "multiple-versions",
"third-party/tap/third-party-cask")
}.to output(expected_output).to_stdout
end
end

View File

@ -0,0 +1,13 @@
cask "multiple-versions" do
if MacOS.version == :test_os
version "1.2.0"
else
version "1.2.3"
end
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage "https://brew.sh/"
app "Caffeine.app"
end