New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load internal cask json v3 #16896
Draft
apainintheneck
wants to merge
3
commits into
master
Choose a base branch
from
load-internal-cask-json-v3
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+311
−26
Draft
Load internal cask json v3 #16896
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
Library/Homebrew/test/api/internal_tap_json/cask_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe "Internal Tap JSON -- Cask" do | ||
let(:internal_tap_json) { File.read(TEST_FIXTURE_DIR/"internal_tap_json/homebrew-cask.json").chomp } | ||
let(:tap_git_head) { "b26c1e550a8b7eed2dcd5306ea8f3da3848258b3" } | ||
|
||
context "when generating JSON", :needs_macos do | ||
before do | ||
FileUtils.rm_rf CoreCaskTap.instance.path | ||
cp_r(TEST_FIXTURE_DIR/"internal_tap_json/homebrew-cask", Tap::TAP_DIRECTORY/"homebrew") | ||
allow(Cask::Cask).to receive(:generating_hash?).and_return(true) | ||
end | ||
|
||
it "creates the expected hash" do | ||
api_hash = CoreCaskTap.instance.to_internal_api_hash | ||
api_hash["tap_git_head"] = tap_git_head # tricky to mock | ||
|
||
expect(JSON.pretty_generate(api_hash)).to eq(internal_tap_json) | ||
end | ||
end | ||
|
||
context "when loading JSON" do | ||
before do | ||
ENV["HOMEBREW_INTERNAL_JSON_V3"] = "1" | ||
ENV.delete("HOMEBREW_NO_INSTALL_FROM_API") | ||
|
||
allow(Homebrew::API).to receive(:fetch_json_api_file) | ||
.with("internal/v3/homebrew-cask.jws.json") | ||
.and_return([JSON.parse(internal_tap_json), false]) | ||
|
||
# `Tap.tap_migration_oldnames` looks for renames in every | ||
# tap so `CoreTap.tap_migrations` gets called and tries to | ||
# fetch stuff from the API. This just avoids errors. | ||
allow(Homebrew::API).to receive(:fetch_json_api_file) | ||
.with("internal/v3/homebrew-core.jws.json") | ||
.and_return([{ "tap_migrations" => {}, "formulae" => {}, "aliases" => {} }, false]) | ||
|
||
# To allow `cask_names.txt` to be written to the cache. | ||
(HOMEBREW_CACHE/"api").mkdir | ||
|
||
Homebrew::API::Cask.clear_cache | ||
end | ||
|
||
it "loads cask renames" do | ||
expect(CoreCaskTap.instance.cask_renames).to eq({ | ||
"ankerslicer" => "ankermake", | ||
"autodesk-fusion360" => "autodesk-fusion", | ||
"betterdummy" => "betterdisplay", | ||
"factor-lang" => "factor", | ||
"smlnj-lang" => "smlnj", | ||
}) | ||
end | ||
|
||
it "loads tap migrations" do | ||
expect(CoreCaskTap.instance.tap_migrations).to eq({ | ||
"azure-cli" => "homebrew/core", | ||
"basex" => "homebrew/core", | ||
"borgbackup" => "homebrew/core", | ||
"chronograf" => "homebrew/core", | ||
"consul" => "homebrew/core", | ||
}) | ||
end | ||
|
||
it "loads tap git head" do | ||
expect(Homebrew::API::Cask.tap_git_head) | ||
.to eq(tap_git_head) | ||
end | ||
|
||
context "when loading formulae" do | ||
let(:factor_metadata) do | ||
{ | ||
"token" => "factor", | ||
"name" => %w[Factor], | ||
"desc" => "Programming language", | ||
"homepage" => "https://factorcode.org/", | ||
"version" => "0.99", | ||
"ruby_source_path" => "Casks/f/factor.rb", | ||
"ruby_source_checksum" => { | ||
"sha256" => "a0dabe24c67269e5310b47639cf32e74f49959ba1be454b2c072805b1f04c7e5", | ||
}, | ||
} | ||
end | ||
|
||
let(:smlnj_metadata) do | ||
{ | ||
"token" => "smlnj", | ||
"name" => ["Standard ML of New Jersey"], | ||
"desc" => "Compiler for the Standard ML '97 programming language", | ||
"homepage" => "https://www.smlnj.org/", | ||
"version" => "110.99.4", | ||
"ruby_source_path" => "Casks/s/smlnj.rb", | ||
"ruby_source_checksum" => { | ||
"sha256" => "d47f46a88248272314a501741460d42a8c731030912a83ef58d3c7fd1e90034d", | ||
}, | ||
} | ||
end | ||
|
||
it "loads factor" do | ||
factor = Cask::CaskLoader.load("factor") | ||
expect(factor.to_h).to include(factor_metadata) | ||
expect(factor.sha256).to eq("8a7968b873b5e87c83b5d0f5ddb4d3d76a2460f5e5c14edac6b18fe5957bd7d6") | ||
expect(factor.url.to_s).to eq("https://downloads.factorcode.org/releases/0.99/factor-macosx-x86-64-0.99.dmg") | ||
end | ||
|
||
it "loads factor from rename" do | ||
factor = Cask::CaskLoader.load("factor-lang") | ||
expect(factor.to_h).to include(**factor_metadata) | ||
end | ||
|
||
it "loads smlnj" do | ||
smlnj = Cask::CaskLoader.load("smlnj") | ||
expect(smlnj.to_h).to include(**smlnj_metadata) | ||
expect(smlnj.sha256).to eq("2bf858017b8ba43a70b30527290ed9fbbc81d9eaac1abeba62469d95392019a3") | ||
expect(smlnj.url.to_s).to eq("http://smlnj.cs.uchicago.edu/dist/working/110.99.4/smlnj-amd64-110.99.4.pkg") | ||
end | ||
|
||
it "loads smlnj from rename" do | ||
smlnj = Cask::CaskLoader.load("smlnj-lang") | ||
expect(smlnj.to_h).to include(**smlnj_metadata) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,10 @@ | |
cp_r(TEST_FIXTURE_DIR/"internal_tap_json/homebrew-core", Tap::TAP_DIRECTORY/"homebrew") | ||
|
||
# NOTE: Symlinks can't be copied recursively so we create them manually here. | ||
(Tap::TAP_DIRECTORY/"homebrew/homebrew-core").tap do |core_tap| | ||
mkdir(core_tap/"Aliases") | ||
ln_s(core_tap/"Formula/f/fennel.rb", core_tap/"Aliases/fennel-lang") | ||
ln_s(core_tap/"Formula/p/ponyc.rb", core_tap/"Aliases/ponyc-lang") | ||
CoreTap.instance.path.tap do |core_tap_path| | ||
mkdir(core_tap_path/"Aliases") | ||
ln_s(core_tap_path/"Formula/f/fennel.rb", core_tap_path/"Aliases/fennel-lang") | ||
ln_s(core_tap_path/"Formula/p/ponyc.rb", core_tap_path/"Aliases/ponyc-lang") | ||
end | ||
end | ||
|
||
|
@@ -37,19 +37,15 @@ | |
# tap so `CoreCaskTap.tap_migrations` gets called and tries to | ||
# fetch stuff from the API. This just avoids errors. | ||
allow(Homebrew::API).to receive(:fetch_json_api_file) | ||
.with("cask_tap_migrations.jws.json", anything) | ||
.and_return([{}, false]) | ||
.with("internal/v3/homebrew-cask.jws.json") | ||
.and_return([{ "tap_migrations" => {}, "casks" => {} }, false]) | ||
|
||
# To allow `formula_names.txt` to be written to the cache. | ||
(HOMEBREW_CACHE/"api").mkdir | ||
|
||
Homebrew::API::Formula.clear_cache | ||
end | ||
|
||
after do | ||
Homebrew::API::Formula.clear_cache | ||
end | ||
Comment on lines
-49
to
-51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already clear all caches after each test. |
||
|
||
it "loads tap aliases" do | ||
expect(CoreTap.instance.alias_table).to eq({ | ||
"fennel-lang" => "fennel", | ||
|
76 changes: 76 additions & 0 deletions
76
Library/Homebrew/test/support/fixtures/internal_tap_json/homebrew-cask.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"tap_git_head": "b26c1e550a8b7eed2dcd5306ea8f3da3848258b3", | ||
"renames": { | ||
"ankerslicer": "ankermake", | ||
"autodesk-fusion360": "autodesk-fusion", | ||
"betterdummy": "betterdisplay", | ||
"factor-lang": "factor", | ||
"smlnj-lang": "smlnj" | ||
}, | ||
"tap_migrations": { | ||
"azure-cli": "homebrew/core", | ||
"basex": "homebrew/core", | ||
"borgbackup": "homebrew/core", | ||
"chronograf": "homebrew/core", | ||
"consul": "homebrew/core" | ||
}, | ||
"casks": { | ||
"factor": { | ||
"name": [ | ||
"Factor" | ||
], | ||
"desc": "Programming language", | ||
"homepage": "https://factorcode.org/", | ||
"url": "https://downloads.factorcode.org/releases/0.99/factor-macosx-x86-64-0.99.dmg", | ||
"version": "0.99", | ||
"sha256": "8a7968b873b5e87c83b5d0f5ddb4d3d76a2460f5e5c14edac6b18fe5957bd7d6", | ||
"artifacts": [ | ||
{ | ||
"suite": [ | ||
"factor" | ||
] | ||
} | ||
], | ||
"ruby_source_path": "Casks/f/factor.rb", | ||
"ruby_source_sha256": "a0dabe24c67269e5310b47639cf32e74f49959ba1be454b2c072805b1f04c7e5", | ||
"caveats": "To use factor, you may need to add the $APPDIR/factor directory\nto your PATH environment variable, e.g. (for Bash shell):\n export PATH=$APPDIR/factor:\"$PATH\"\n" | ||
}, | ||
"smlnj": { | ||
"name": [ | ||
"Standard ML of New Jersey" | ||
], | ||
"desc": "Compiler for the Standard ML '97 programming language", | ||
"homepage": "https://www.smlnj.org/", | ||
"url": "http://smlnj.cs.uchicago.edu/dist/working/110.99.4/smlnj-amd64-110.99.4.pkg", | ||
"version": "110.99.4", | ||
"sha256": "2bf858017b8ba43a70b30527290ed9fbbc81d9eaac1abeba62469d95392019a3", | ||
"artifacts": [ | ||
{ | ||
"uninstall": [ | ||
{ | ||
"pkgutil": "org.smlnj.amd64.pkg" | ||
} | ||
] | ||
}, | ||
{ | ||
"pkg": [ | ||
"smlnj-amd64-110.99.4.pkg" | ||
] | ||
}, | ||
{ | ||
"zap": [ | ||
{ | ||
"delete": "/usr/local/smlnj" | ||
} | ||
] | ||
} | ||
], | ||
"ruby_source_path": "Casks/s/smlnj.rb", | ||
"ruby_source_sha256": "d47f46a88248272314a501741460d42a8c731030912a83ef58d3c7fd1e90034d", | ||
"url_specs": { | ||
"verified": "smlnj.cs.uchicago.edu/" | ||
}, | ||
"caveats": "To use smlnj, you may need to add the /usr/local/smlnj/bin directory\nto your PATH environment variable, e.g. (for Bash shell):\n export PATH=/usr/local/smlnj/bin:\"$PATH\"\n" | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Library/Homebrew/test/support/fixtures/internal_tap_json/homebrew-cask/Casks/f/factor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
cask "factor" do | ||
version "0.99" | ||
sha256 "8a7968b873b5e87c83b5d0f5ddb4d3d76a2460f5e5c14edac6b18fe5957bd7d6" | ||
|
||
url "https://downloads.factorcode.org/releases/#{version}/factor-macosx-x86-64-#{version}.dmg" | ||
name "Factor" | ||
desc "Programming language" | ||
homepage "https://factorcode.org/" | ||
|
||
livecheck do | ||
url "https://downloads.factorcode.org/releases/" | ||
regex(%r{href=.*?(\d+(?:\.\d+)+)/}i) | ||
end | ||
|
||
suite "factor" | ||
|
||
caveats do | ||
path_environment_variable "#{appdir}/factor" | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be included in the hash because it's already the key of each object. Not sure how I missed this before.