Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rylan12 committed Jul 3, 2024
1 parent 90c4cd0 commit 53c4dc6
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 64 deletions.
8 changes: 4 additions & 4 deletions Library/Homebrew/test/cmd/autoremove_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
before do
# Make testball1 poured from a bottle
install_test_formula "testball1"
tab = Tab.for_name("testball1")
tab = Tab.for_formula_name("testball1")
tab.poured_from_bottle = true
tab.write
tab.write_formula_file

# Make testball2 poured from a bottle and an unused dependency
install_test_formula "testball2"
tab = Tab.for_name("testball2")
tab = Tab.for_formula_name("testball2")
tab.installed_on_request = false
tab.installed_as_dependency = true
tab.poured_from_bottle = true
tab.write
tab.write_formula_file
end

it "only removes unused dependencies", :integration_test do
Expand Down
22 changes: 11 additions & 11 deletions Library/Homebrew/test/formula_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@
oldname_prefix.mkpath
oldname_tab = Tab.empty
oldname_tab.tabfile = oldname_prefix/Tab::FILENAME
oldname_tab.write
oldname_tab.write_formula_file

expect(f).not_to need_migration

oldname_tab.tabfile.unlink
oldname_tab.source["tap"] = "homebrew/core"
oldname_tab.write
oldname_tab.write_formula_file

expect(f).to need_migration

Expand Down Expand Up @@ -348,7 +348,7 @@
tab = Tab.empty
tab.tabfile = head_prefix/Tab::FILENAME
tab.source["versions"] = { "stable" => "1.0" }
tab.write
tab.write_formula_file

expect(f.latest_installed_prefix).to eq(stable_prefix)
end
Expand Down Expand Up @@ -380,7 +380,7 @@
tab = Tab.empty
tab.tabfile = prefix/Tab::FILENAME
tab.source_modified_time = stamp
tab.write
tab.write_formula_file
end

prefix = HOMEBREW_CELLAR/f.name/"HEAD-222222_2"
Expand Down Expand Up @@ -887,9 +887,9 @@ def post_install
formula = Class.new(Testball).new

formula.brew { formula.install }
tab = Tab.create(formula, DevelopmentTools.default_compiler, :libcxx)
tab = Tab.create_from_formula(formula, DevelopmentTools.default_compiler, :libcxx)
tab.runtime_dependencies = ["foo"]
tab.write
tab.write_formula_file

keg = Keg.for(formula.latest_installed_prefix)
keg.link
Expand Down Expand Up @@ -1068,7 +1068,7 @@ class FooVariations < Formula

[f1, f2, f3, f4].each do |f|
f.brew { f.install }
Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
Tab.create_from_formula(f, DevelopmentTools.default_compiler, :libcxx).write_formula_file
end

expect(f1).to be_latest_version_installed
Expand Down Expand Up @@ -1108,7 +1108,7 @@ class FooVariations < Formula
tab = Tab.empty
tab.tabfile = prefix/Tab::FILENAME
tab.source_modified_time = 1
tab.write
tab.write_formula_file
end

eligible_kegs = f.installed_kegs - [Keg.new(f.prefix("HEAD-111111_1")), Keg.new(f.prefix("0.1"))]
Expand Down Expand Up @@ -1345,7 +1345,7 @@ def setup_tab_for_prefix(prefix, options = {})
tab.source["tap"] = options[:tap] if options[:tap]
tab.source["versions"] = options[:versions] if options[:versions]
tab.source_modified_time = options[:source_modified_time].to_i
tab.write unless options[:no_write]
tab.write_formula_file unless options[:no_write]
tab
end

Expand Down Expand Up @@ -1502,7 +1502,7 @@ def setup_tab_for_prefix(prefix, options = {})
expect(f.outdated_kegs).not_to be_empty

tab.source["versions"] = { "stable" => f.version.to_s }
tab.write
tab.write_formula_file
described_class.clear_cache

expect(f.outdated_kegs).to be_empty
Expand Down Expand Up @@ -1541,7 +1541,7 @@ def setup_tab_for_prefix(prefix, options = {})
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty

tab_a.source["versions"] = { "stable" => f.version.to_s }
tab_a.write
tab_a.write_formula_file
described_class.clear_cache
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/test/installed_dependents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def setup_test_keg(name, version, &block)
describe "::find_some_installed_dependents" do
def setup_test_keg(name, version, &block)
keg = super
Tab.create(keg.to_formula, DevelopmentTools.default_compiler, :libcxx).write
Tab.create_from_formula(keg.to_formula, DevelopmentTools.default_compiler, :libcxx).write_formula_file
keg
end

Expand All @@ -53,7 +53,7 @@ def setup_test_keg(name, version, &block)
def alter_tab(keg)
tab = keg.tab
yield tab
tab.write
tab.write_formula_file
end

# 1.1.6 is the earliest version of Homebrew that generates correct runtime
Expand Down
10 changes: 5 additions & 5 deletions Library/Homebrew/test/migrator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

old_tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
old_tab.source["path"] = "/oldname"
old_tab.write
old_tab.write_formula_file

keg.link
keg.optlink
Expand Down Expand Up @@ -67,7 +67,7 @@
tab = Tab.empty
tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
tab.source["tap"] = "homebrew/core"
tab.write
tab.write_formula_file

expect do
described_class.new(new_formula, "oldname")
Expand Down Expand Up @@ -151,7 +151,7 @@
tab = Tab.empty
tab.tabfile = HOMEBREW_CELLAR/"newname/0.1/INSTALL_RECEIPT.json"
tab.source["path"] = "/path/that/must/be/changed/by/update_tabs"
tab.write
tab.write_formula_file
migrator.update_tabs
expect(Tab.for_keg(new_keg_record).source["path"]).to eq(new_formula.path.to_s)
end
Expand All @@ -160,7 +160,7 @@
tab = Tab.empty
tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
tab.source["path"] = old_formula.path.to_s
tab.write
tab.write_formula_file

migrator.migrate

Expand Down Expand Up @@ -205,7 +205,7 @@
tab = Tab.empty
tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
tab.source["path"] = "/should/be/the/same"
tab.write
tab.write_formula_file
migrator = described_class.new(new_formula, "oldname")
tab.tabfile.delete
migrator.backup_old_tabs
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/sbom_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"declared_directly" => true,
}
end
expect(Tab).to receive(:runtime_deps_hash).and_return(runtime_deps_hash)
expect(Tab).to receive(:formula_runtime_deps_hash).and_return(runtime_deps_hash)
tab = Tab.create(f, DevelopmentTools.default_compiler, :libcxx)

expect(Formulary).to receive(:factory).with("beanstalkd").and_return(beanstalkd)
Expand Down
53 changes: 53 additions & 0 deletions Library/Homebrew/test/support/fixtures/cask_receipt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"homebrew_version": "4.3.7",
"loaded_from_api": false,
"caskfile_only": true,
"installed_as_dependency": false,
"installed_on_request": true,
"time": 1719289256,
"runtime_dependencies": {
"cask": [
{
"full_name": "bar",
"version": "2.0",
"declared_directly": true
}
],
"formula": [
{
"full_name": "baz",
"version": "3.0",
"revision": 0,
"pkg_version": "3.0",
"declared_directly": true
}
],
"macos": {
">=": [
"12"
]
}
},
"source": {
"path": "/opt/homebrew/Library/Taps/homebrew/homebrew-cask/Casks/f/foo.rb",
"tap": "homebrew/cask",
"tap_git_head": "8b79aa759500f0ffdf65a23e12950cbe3bf8fe17",
"version": "1.2.3"
},
"arch": "arm64",
"uninstall_artifacts": [
{
"app": [
"Foo.app"
]
}
],
"built_on": {
"os": "Macintosh",
"os_version": "macOS 14",
"cpu_family": "arm_firestorm_icestorm",
"xcode": "15.4",
"clt": "15.3.0.0.1.1708646388",
"preferred_perl": "5.34"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ class #{Formulary.class_s(name)} < Formula
keg = Formula[name].prefix
keg.mkpath

tab = Tab.for_name(name)
tab = Tab.for_formula_name(name)
tab.tabfile ||= keg/Tab::FILENAME
tab_attributes.each do |key, value|
tab.instance_variable_set(:"@#{key}", value)
end
tab.write
tab.write_formula_file

formula_path
end
Expand Down
Loading

0 comments on commit 53c4dc6

Please sign in to comment.