Skip to content

Commit

Permalink
api/formula: Add tests for internal JSON v3
Browse files Browse the repository at this point in the history
These tests cover both generating and loading formulae from the JSON
bundle. The tests are not comprehensive but they do provide a nice
sanity check that things are working as expected.
  • Loading branch information
apainintheneck committed Feb 19, 2024
1 parent cca046e commit a155b13
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 0 deletions.
125 changes: 125 additions & 0 deletions Library/Homebrew/test/api/internal_tap_json/formula_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# frozen_string_literal: true

describe "Internal Tap JSON -- Formula" do
let(:internal_tap_json) { File.read(TEST_FIXTURE_DIR/"internal_tap_json/homebrew-core.json").chomp }
let(:tap_git_head) { "9977471165641744a829d3e494fa563407503297" }

context "when generating JSON", :needs_macos do
before do
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")
end
end

it "creates the expected hash" do
api_hash = CoreTap.instance.to_api_hash
api_hash["tap_git_head"] = tap_git_head # tricky to mock

expect(JSON.generate(api_hash)).to eq(internal_tap_json)
end
end

context "when loading JSON" do
before do
ENV.delete("HOMEBREW_NO_INSTALL_FROM_API")
ENV["HOMEBREW_INTERNAL_JSON_V3"] = "1"

allow(Homebrew::API).to receive(:fetch_json_api_file)
.with("internal/v3/homebrew-core.jws.json")
.and_return(JSON.parse(internal_tap_json), false)
end

it "loads tap aliases" do
expect(CoreTap.instance.alias_table).to eq({
"fennel-lang" => "fennel",
"ponyc-lang" => "ponyc",
})
end

it "loads formula renames" do
expect(CoreTap.instance.formula_renames).to eq({
"advancemenu" => "advancemame",
"amtk" => "libgedit-amtk",
"annie" => "lux",
"antlr2" => "antlr@2",
"romanesco" => "fennel",
})
end

it "loads tap migrations" do
expect(CoreTap.instance.tap_migrations).to eq({
"adobe-air-sdk" => "homebrew/cask",
"android-ndk" => "homebrew/cask",
"android-platform-tools" => "homebrew/cask",
"android-sdk" => "homebrew/cask",
"app-engine-go-32" => "homebrew/cask/google-cloud-sdk",
})
end

it "loads tap git head" do
expect(Homebrew::API::Formula.tap_git_head)
.to eq(tap_git_head)
end

context "when loading formulae" do
let(:fennel_metadata) do
{
"aliases" => ["fennel-lang"],
"dependencies" => ["lua"],
"desc" => "Lua Lisp Language",
"full_name" => "fennel",
"homepage" => "https://fennel-lang.org",
"installed" => [],
"license" => "MIT",
"name" => "fennel",
"ruby_source_path" => "Formula/f/fennel.rb",
"tap" => "homebrew/core",
"tap_git_head" => tap_git_head,
"versions" => { "bottle"=>true, "head"=>nil, "stable"=>"1.4.0" },
}
end

let(:ponyc_metadata) do
{
"aliases" => ["ponyc-lang"],
"desc" => "Object-oriented, actor-model, capabilities-secure programming language",
"full_name" => "ponyc",
"homepage" => "https://www.ponylang.io/",
"license" => "BSD-2-Clause",
"name" => "ponyc",
"ruby_source_path" => "Formula/p/ponyc.rb",
"tap" => "homebrew/core",
"tap_git_head" => tap_git_head,
"uses_from_macos" => [{ "llvm"=>[:build, :test] }, "zlib"],
"uses_from_macos_bounds" => [{}, {}],
"versions" => { "bottle"=>true, "head"=>nil, "stable"=>"0.58.1" },
}
end

it "loads fennel" do
fennel = Formulary.factory("fennel")
expect(fennel.to_hash).to include(**fennel_metadata)
end

it "loads fennel from rename" do
fennel = Formulary.factory("romanesco")
expect(fennel.to_hash).to include(**fennel_metadata)
end

it "loads ponyc" do
ponyc = Formulary.factory("ponyc")
expect(ponyc.to_hash).to include(**ponyc_metadata)
end

it "loads ponyc from alias" do
ponyc = Formulary.factory("ponyc-lang")
expect(ponyc.to_hash).to include(**ponyc_metadata)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"tap_git_head":"9977471165641744a829d3e494fa563407503297","aliases":{"fennel-lang":"fennel","ponyc-lang":"ponyc"},"renames":{"advancemenu":"advancemame","amtk":"libgedit-amtk","annie":"lux","antlr2":"antlr@2","romanesco":"fennel"},"tap_migrations":{"adobe-air-sdk":"homebrew/cask","android-ndk":"homebrew/cask","android-platform-tools":"homebrew/cask","android-sdk":"homebrew/cask","app-engine-go-32":"homebrew/cask/google-cloud-sdk"},"formulae":{"fennel":{"desc":"Lua Lisp Language","license":"MIT","homepage":"https://fennel-lang.org","urls":{"stable":{"url":"https://github.com/bakpakin/Fennel/archive/refs/tags/1.4.0.tar.gz","checksum":"161eb7f17f86e95de09070214d042fb25372f71ad266f451431f3109e87965c7"}},"post_install_defined":false,"ruby_source_path":"Formula/f/fennel.rb","ruby_source_sha256":"5856e655fd1cea11496d67bc27fb14fee5cfbdea63c697c3773c7f247581197d","dependencies":["lua"],"version":"1.4.0","bottle":{"files":{"all":{"cellar":":any_skip_relocation","sha256":"f46028597883cbc38864c61bd3fa402da9cb90ce97415d51a7b5279bc17f7bd0"}}}},"ponyc":{"desc":"Object-oriented, actor-model, capabilities-secure programming language","license":"BSD-2-Clause","homepage":"https://www.ponylang.io/","urls":{"stable":{"url":"https://github.com/ponylang/ponyc.git","tag":"0.58.1","revision":"fe3895eb4af494bf36d7690641bdfb5755db8350"}},"post_install_defined":false,"ruby_source_path":"Formula/p/ponyc.rb","ruby_source_sha256":"81d51c25d18710191beb62f9f380bae3d878aad815a65ec1ee2a3b132c1fadb3","build_dependencies":["cmake","[email protected]"],"uses_from_macos":[{"llvm":["build","test"]},"zlib"],"uses_from_macos_bounds":[{},{}],"version":"0.58.1","bottle":{"files":{"arm64_sonoma":{"cellar":":any_skip_relocation","sha256":"e3aecfcf02aea56d53d82691e2ad7a780f771023d7070271bfce96b17439a34d"},"arm64_ventura":{"cellar":":any_skip_relocation","sha256":"6ff83717191e16e4f852fb3be8f838afba312cc39e601bb5cebd2a618a328658"},"arm64_monterey":{"cellar":":any_skip_relocation","sha256":"25c91bce200583a96f4cea34f31393c8f10eadcab363cc7d4d864d15f5f97e25"},"sonoma":{"cellar":":any_skip_relocation","sha256":"5f4c550ce33e2970e0ada18a409755fa62936181289a21c15582ff80343866b6"},"ventura":{"cellar":":any_skip_relocation","sha256":"f26c799f45013685da779bf2008ebe1907f9b3a93d5f260ce271a3f3b628da50"},"monterey":{"cellar":":any_skip_relocation","sha256":"1cff10d068b36b18b253d235424c4f5aef71ff9ee44f2522c4b041dd4383ec30"},"x86_64_linux":{"cellar":":any_skip_relocation","sha256":"ab49318d75eed3ee932c8e5add22f252ec0c852aad94945022877f926e93899f"}}}}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Fennel < Formula
desc "Lua Lisp Language"
homepage "https://fennel-lang.org"
url "https://github.com/bakpakin/Fennel/archive/refs/tags/1.4.0.tar.gz"
sha256 "161eb7f17f86e95de09070214d042fb25372f71ad266f451431f3109e87965c7"
license "MIT"

bottle do
sha256 cellar: :any_skip_relocation, all: "f46028597883cbc38864c61bd3fa402da9cb90ce97415d51a7b5279bc17f7bd0"
end

depends_on "lua"

def install
system "make"
bin.install "fennel"

lua = Formula["lua"]
(share/"lua"/lua.version.major_minor).install "fennel.lua"
end

test do
assert_match "hello, world!", shell_output("#{bin}/fennel -e '(print \"hello, world!\")'")
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
class Ponyc < Formula
desc "Object-oriented, actor-model, capabilities-secure programming language"
homepage "https://www.ponylang.io/"
url "https://github.com/ponylang/ponyc.git",
tag: "0.58.1",
revision: "fe3895eb4af494bf36d7690641bdfb5755db8350"
license "BSD-2-Clause"

bottle do
sha256 cellar: :any_skip_relocation, arm64_sonoma: "e3aecfcf02aea56d53d82691e2ad7a780f771023d7070271bfce96b17439a34d"
sha256 cellar: :any_skip_relocation, arm64_ventura: "6ff83717191e16e4f852fb3be8f838afba312cc39e601bb5cebd2a618a328658"
sha256 cellar: :any_skip_relocation, arm64_monterey: "25c91bce200583a96f4cea34f31393c8f10eadcab363cc7d4d864d15f5f97e25"
sha256 cellar: :any_skip_relocation, sonoma: "5f4c550ce33e2970e0ada18a409755fa62936181289a21c15582ff80343866b6"
sha256 cellar: :any_skip_relocation, ventura: "f26c799f45013685da779bf2008ebe1907f9b3a93d5f260ce271a3f3b628da50"
sha256 cellar: :any_skip_relocation, monterey: "1cff10d068b36b18b253d235424c4f5aef71ff9ee44f2522c4b041dd4383ec30"
sha256 cellar: :any_skip_relocation, x86_64_linux: "ab49318d75eed3ee932c8e5add22f252ec0c852aad94945022877f926e93899f"
end

depends_on "cmake" => :build
depends_on "[email protected]" => :build

uses_from_macos "llvm" => [:build, :test]
uses_from_macos "zlib"

# We use LLVM to work around an error while building bundled `google-benchmark` with GCC
fails_with :gcc do
cause <<-EOS
.../src/gbenchmark/src/thread_manager.h:50:31: error: expected ')' before '(' token
50 | GUARDED_BY(GetBenchmarkMutex()) Result results;
| ^
EOS
end

def install
inreplace "CMakeLists.txt", "PONY_COMPILER=\"${CMAKE_C_COMPILER}\"", "PONY_COMPILER=\"#{ENV.cc}\"" if OS.linux?

ENV["CMAKE_FLAGS"] = "-DCMAKE_OSX_SYSROOT=#{MacOS.sdk_path}" if OS.mac?
ENV["MAKEFLAGS"] = "build_flags=-j#{ENV.make_jobs}"

system "make", "libs"
system "make", "configure"
system "make", "build"
system "make", "install", "DESTDIR=#{prefix}"
end

test do
# ENV["CC"] returns llvm_clang, which does not work in a test block.
ENV.clang

system "#{bin}/ponyc", "-rexpr", "#{prefix}/packages/stdlib"

(testpath/"test/main.pony").write <<~EOS
actor Main
new create(env: Env) =>
env.out.print("Hello World!")
EOS
system "#{bin}/ponyc", "test"
assert_equal "Hello World!", shell_output("./test1").strip
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"advancemenu": "advancemame",
"amtk": "libgedit-amtk",
"annie": "lux",
"antlr2": "antlr@2",
"romanesco": "fennel"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"adobe-air-sdk": "homebrew/cask",
"android-ndk": "homebrew/cask",
"android-platform-tools": "homebrew/cask",
"android-sdk": "homebrew/cask",
"app-engine-go-32": "homebrew/cask/google-cloud-sdk"
}

0 comments on commit a155b13

Please sign in to comment.