63 lines
2.4 KiB
Ruby
Raw Normal View History

2024-03-13 21:55:59 -07:00
# frozen_string_literal: true
require "tapioca/dsl"
2024-03-15 15:56:01 -07:00
require "sorbet/tapioca/compilers/args"
2024-03-13 21:55:59 -07:00
RSpec.describe Tapioca::Compilers::Args do
let(:compiler) { described_class.new(Tapioca::Dsl::Pipeline.new(requested_constants: []), RBI::Tree.new, Homebrew) }
let(:list_parser) do
require "cmd/list"
2024-03-15 12:58:59 -07:00
Homebrew::Cmd::List.parser
2024-03-13 21:55:59 -07:00
end
2024-03-21 22:20:05 -07:00
# Good testing candidate because it has multiple for each of `switch`, `flag` and `comma_array` args:
2024-03-13 21:55:59 -07:00
let(:update_python_resources_parser) do
require "dev-cmd/update-python-resources"
2024-03-21 22:20:05 -07:00
Homebrew::DevCmd::UpdatePythonResources.parser
2024-03-13 21:55:59 -07:00
end
describe "#args_table" do
it "returns a mapping of list args to default values" do
2024-11-30 13:52:46 -08:00
expect(compiler.args_table(list_parser)).to contain_exactly(
:"1?", :built_from_source?, :cask?, :casks?, :d?, :debug?, :formula?, :formulae?, :full_name?, :h?, :help?,
:installed_as_dependency?, :installed_on_request?, :l?, :multiple?, :pinned?, :poured_from_bottle?, :q?,
:quiet?, :r?, :t?, :v?, :verbose?, :versions?
)
2024-03-13 21:55:59 -07:00
end
2024-03-21 22:20:05 -07:00
it "returns a mapping of update-python-resources args to default values" do
2024-11-30 13:52:46 -08:00
expect(compiler.args_table(update_python_resources_parser)).to contain_exactly(
update-python-resources: add option to ignore errors This is particularly useful for third-party Python formulae that have a ton of resources, not all of which may adhere to homebrew/core's strict policies. See #19240 for context. I've also added logic that ignores `--ignore-errors` on `homebrew/core`, although I personally think this new behavior is also useful for mainline formula creation. Before: error out on a single non-conforming resource, zero resource blocks added to formula, scary stacktrace. After: all conforming resources added, all non-conforming resources identified in comments, error message at end, `brew` exits non-zero without scary stacktrace:- ``` % brew update-python-resources --ignore-errors gromgit/test/auto-coder || echo OOPS ==> Retrieving PyPI dependencies for "auto-coder==0.1.243"... ==> Retrieving PyPI dependencies for excluded ""... ==> Getting PyPI info for "aiohappyeyeballs==2.4.4" [200+ resource lines elided] ==> Getting PyPI info for "zhipuai==2.1.5.20250106" ==> Updating resource blocks Error: Unable to resolve some dependencies. Please check /opt/homebrew/Library/Taps/gromgit/homebrew-test/Formula/auto-coder.rb for RESOURCE-ERROR comments. OOPS % brew cat gromgit/test/auto-coder | ggrep -C10 RESOURCE-ERROR license "Apache-2.0" depends_on "python@3.11" # Additional dependency # resource "" do # url "" # sha256 "" # end # RESOURCE-ERROR: Unable to resolve "azure-cognitiveservices-speech==1.42.0" (no suitable source distribution on PyPI) # RESOURCE-ERROR: Unable to resolve "ray==2.42.0" (no suitable source distribution on PyPI) resource "aiohappyeyeballs" do url "https://files.pythonhosted.org/packages/7f/55/e4373e888fdacb15563ef6fa9fa8c8252476ea071e96fb46defac9f18bf2/aiohappyeyeballs-2.4.4.tar.gz" sha256 "5fdd7d87889c63183afc18ce9271f9b0a7d32c2303e394468dd45d514a757745" end resource "aiohttp" do url "https://files.pythonhosted.org/packages/37/4b/952d49c73084fb790cb5c6ead50848c8e96b4980ad806cf4d2ad341eaa03/aiohttp-3.11.12.tar.gz" sha256 "7603ca26d75b1b86160ce1bbe2787a0b706e592af5b2504e12caa88a217767b0" end ```
2025-02-06 21:20:55 +08:00
:d?, :debug?, :exclude_packages, :extra_packages, :h?, :help?, :ignore_errors?, :ignore_non_pypi_packages?,
2024-11-30 13:52:46 -08:00
:install_dependencies?, :p?, :package_name, :print_only?, :q?, :quiet?, :s?, :silent?, :v?, :verbose?,
:version
)
2024-03-13 21:55:59 -07:00
end
end
describe "#comma_arrays" do
it "returns an empty list when there are no comma_array args" do
expect(compiler.comma_arrays(list_parser)).to eq([])
end
it "returns the comma_array args when they exist" do
expect(compiler.comma_arrays(update_python_resources_parser)).to eq([:extra_packages, :exclude_packages])
end
end
describe "#get_return_type" do
let(:comma_arrays) { compiler.comma_arrays(update_python_resources_parser) }
it "returns the correct type for switches" do
2024-11-30 13:52:46 -08:00
expect(compiler.get_return_type(:silent?, comma_arrays)).to eq("T::Boolean")
2024-03-13 21:55:59 -07:00
end
it "returns the correct type for flags" do
2024-11-30 13:52:46 -08:00
expect(compiler.get_return_type(:package_name, comma_arrays)).to eq("T.nilable(String)")
2024-03-13 21:55:59 -07:00
end
it "returns the correct type for comma_arrays" do
2024-11-30 13:52:46 -08:00
expect(compiler.get_return_type(:extra_packages, comma_arrays)).to eq("T.nilable(T::Array[String])")
2024-03-13 21:55:59 -07:00
end
end
end