From 0f5365eb28d3840aa0432e5c67736632cba071b6 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sat, 5 Oct 2024 18:42:51 -0700 Subject: [PATCH] Fix cask token error in `brew api-readall-test` ``` $ brew api-readall-test Generating formulae API ... and mocking formula API loader. Read core formulae and saw no failures! Generating cask API ...Warning: Cask font-rounded-mplus was renamed to font-rounded-m+. and mocking cask API loader. Read core casks and saw 1 failure! Readall Failures: Casks ----------------------- >> font-rounded-mplus : key not found: "font-rounded-mplus" /usr/local/Homebrew/Library/Homebrew/cask/cask_loader.rb:318:in `fetch' ``` The problem was that `font-rounded-mplus` got renamed to `font-rounded-m+` and we were getting the cask tokens from the file names instead of the cask definitions directly. I'm not entirely sure why the cask token name from the core cask tap are wrong here but changing the order and basing it on the cask that was loaded seems to work. --- Rakefile | 2 +- lib/hd-utils/stub-api/cask.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index df47ed3..01228a7 100644 --- a/Rakefile +++ b/Rakefile @@ -90,7 +90,7 @@ end namespace "test" do task :"api-readall-test" do - cmd "brew", "api-readall-test" + cmd "brew", "api-readall-test", "--verbose" end task :"branch-compare" do diff --git a/lib/hd-utils/stub-api/cask.rb b/lib/hd-utils/stub-api/cask.rb index 74ea2d1..a9200a0 100644 --- a/lib/hd-utils/stub-api/cask.rb +++ b/lib/hd-utils/stub-api/cask.rb @@ -13,13 +13,11 @@ module StubAPI module Cask abort "The core cask tap needs to be installed locally to mock the API!" unless CoreCaskTap.instance.installed? - NAMES = CoreCaskTap.instance.cask_tokens.freeze - print "Generating cask API ..." # Generate json representation of all casks. ::Cask::Cask.generating_hash! - JSON = NAMES.to_h do |cask_name| + JSON = CoreCaskTap.instance.cask_tokens.to_h do |cask_name| cask = ::Cask::CaskLoader.load(cask_name) json = JSON.generate(cask.to_hash_with_variations) hash = JSON.parse(json) @@ -27,6 +25,8 @@ module Cask end.freeze ::Cask::Cask.generated_hash! + NAMES = JSON.keys.freeze + private_constant :NAMES, :JSON def self.names