formula_creator: test GitHub repo call for archive|releases URLs

This commit is contained in:
Anatoli Babenia 2025-06-18 15:07:44 +01:00 committed by Mike McQuaid
parent 76470c0d8a
commit f738fce3d9
No known key found for this signature in database
2 changed files with 29 additions and 15 deletions

View File

@ -3,6 +3,7 @@
require "digest" require "digest"
require "erb" require "erb"
require "utils/github"
module Homebrew module Homebrew
# Class for generating a formula from a template. # Class for generating a formula from a template.

View File

@ -5,35 +5,48 @@ require "formula_creator"
RSpec.describe Homebrew::FormulaCreator do RSpec.describe Homebrew::FormulaCreator do
describe ".new" do describe ".new" do
tests = { tests = {
"generic tarball URL": { "generic tarball URL": {
url: "http://digit-labs.org/files/tools/synscan/releases/synscan-5.02.tar.gz", url: "http://digit-labs.org/files/tools/synscan/releases/synscan-5.02.tar.gz",
name: "synscan", name: "synscan",
version: "5.02", version: "5.02",
}, },
"gitweb URL": { "gitweb URL": {
url: "http://www.codesrc.com/gitweb/index.cgi?p=libzipper.git;a=summary", url: "http://www.codesrc.com/gitweb/index.cgi?p=libzipper.git;a=summary",
name: "libzipper", name: "libzipper",
}, },
"GitHub repo URL": { "GitHub repo URL with .git": {
url: "https://github.com/abitrolly/lapce.git", url: "https://github.com/Homebrew/brew.git",
name: "lapce", name: "brew",
head: true, head: true,
fetch: true,
github_user: "Homebrew",
github_repo: "brew",
}, },
"GitHub archive URL": { "GitHub archive URL": {
url: "https://github.com/abitrolly/lapce/archive/v0.3.0.tar.gz", url: "https://github.com/Homebrew/brew/archive/4.5.7.tar.gz",
name: "lapce", name: "brew",
version: "0.3.0", version: "4.5.7",
fetch: true,
github_user: "Homebrew",
github_repo: "brew",
}, },
"GitHub download URL": { "GitHub releases URL": {
url: "https://github.com/stella-emu/stella/releases/download/6.7/stella-6.7-src.tar.xz", url: "https://github.com/stella-emu/stella/releases/download/6.7/stella-6.7-src.tar.xz",
name: "stella", name: "stella",
version: "6.7", version: "6.7",
fetch: true,
github_user: "stella-emu",
github_repo: "stella",
}, },
} }
tests.each do |description, test| tests.each do |description, test|
it "parses #{description}" do it "parses #{description}" do
formula_creator = described_class.new(url: test.fetch(:url)) fetch = test.fetch(:fetch, false)
allow(GitHub).to receive(:repository).with(test.fetch(:github_user), test.fetch(:github_repo)) if fetch
formula_creator = described_class.new(url: test.fetch(:url), fetch:)
expect(formula_creator.name).to eq(test.fetch(:name)) expect(formula_creator.name).to eq(test.fetch(:name))
if (version = test[:version]) if (version = test[:version])
expect(formula_creator.version).to eq(version) expect(formula_creator.version).to eq(version)