From 97cce3677968d2ecad39fcf904767be0b63435c8 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Thu, 3 Apr 2025 19:28:02 -0400 Subject: [PATCH] Make os available in cask livecheck blocks Casks now support an `os` DSL method, similar to `arch`. This makes it available in `livecheck` blocks, like we do with `arch`. --- Library/Homebrew/cask/dsl.rb | 1 + Library/Homebrew/livecheck.rb | 5 +++-- Library/Homebrew/test/livecheck_spec.rb | 26 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index 6dc120b395..497e41f775 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -80,6 +80,7 @@ module Cask :homepage, :language, :name, + :os, :sha256, :staged_path, :url, diff --git a/Library/Homebrew/livecheck.rb b/Library/Homebrew/livecheck.rb index 019612ef17..d4b5e6922b 100644 --- a/Library/Homebrew/livecheck.rb +++ b/Library/Homebrew/livecheck.rb @@ -194,9 +194,10 @@ class Livecheck end delegate url_options: :@options - delegate version: :@package_or_resource delegate arch: :@package_or_resource - private :version, :arch + delegate os: :@package_or_resource + delegate version: :@package_or_resource + private :arch, :os, :version # Returns a `Hash` of all instance variable values. # @return [Hash] sig { returns(T::Hash[String, T.untyped]) } diff --git a/Library/Homebrew/test/livecheck_spec.rb b/Library/Homebrew/test/livecheck_spec.rb index ba5bde56e0..82983557d8 100644 --- a/Library/Homebrew/test/livecheck_spec.rb +++ b/Library/Homebrew/test/livecheck_spec.rb @@ -182,6 +182,32 @@ RSpec.describe Livecheck do end end + describe "#os" do + let(:c_os) do + Cask::Cask.new("c-os") do + os macos: "macos", linux: "linux" + + version "0.0.1" + + url "https://brew.sh/test-0.0.1.dmg" + name "Test" + desc "Test cask" + homepage "https://brew.sh" + + livecheck do + url "https://brew.sh/#{os}" + end + end + end + + [:needs_macos, :needs_linux].each do |needs_os| + os_value = needs_os.to_s.delete_prefix("needs_") + it "delegates `os` in `livecheck` block to `package_or_resource`", needs_os do + expect(c_os.livecheck.url).to eq("https://brew.sh/#{os_value}") + end + end + end + describe "#to_hash" do it "returns a Hash of all instance variables" do expect(livecheck_f.to_hash).to eq(