100 Commits

Author SHA1 Message Date
Mike McQuaid
e9f55a8f71
tests: default to API mode enabled.
While we're here, also add `brew tests --no-parallel` which I relied
on during testing.

Pretty much anywhere we rely on a stubbed formula on disk to work: we
need to disable the API.
2025-06-10 15:53:27 +01:00
Carlo Cabrera
fe1f330e60
Revert "Deprecate installing casks/formulae from paths." 2024-09-27 10:17:04 +08:00
Mike McQuaid
bbdea29a0f
Deprecate installing casks/formulae from paths.
We've already disabled installing casks/formulae from URLs and we
regularly tell people not to install from paths so let's just deprecate
this behaviour entirely.

Even Homebrew developers do not need to work this way.
2024-09-26 20:25:07 +01:00
apainintheneck
a3e917afe1 Refactor method to remove extra tap requires
We were selectively requiring the tap.rb file in a few places for
performance reasons. The main method we were referencing was the
`Tap.cmd_directories` method which uses `Pathname` and the `TAP_DIRECTORY`
constant internally. `Tap.cmd_directories` is mostly used in the `Commands`
module and that is loaded very early on in the program so it made sense
to move that command to that module. To facilitate that I moved the
`TAP_DIRECTORY` constant to the top-level and renamed it to
`HOMEBREW_TAP_DIRECTORY`. It now lies in the tap_constants.rb file.

A nice bonus of this refactor is that it speeds up loading external
commands since the tap.rb file is no longer required by default in
those cases.
2024-08-10 13:49:10 -07:00
Bo Anderson
10cbf191dc
Add env to disable finding packages from paths 2024-07-25 11:37:44 +01:00
Rylan Polster
b563d9920b
FormulaURILoader: use regex to validate refs before attempting to cast 2024-07-15 14:07:55 -04:00
Rylan Polster
8b0a4a98bf
Restrict direct url installs to the file:// scheme 2024-07-13 13:30:36 -04:00
apainintheneck
16e605e056 Load tap migration renames from API with short names
This is a follow-up to 484498e. I added loading for tap migration
renames from the API but it apparently only worked for full names.

There was a bug in both the code and the tests which prevented
loading by short names. This fixes those bugs so everything should
be good now.
2024-07-01 18:53:31 -07:00
apainintheneck
fb3b13e3c3 Add tests
Check for the following:
- Tap migration rename to core tap can be loaded by short name
- Tap migration rename to core tap can be loaded by long name
- Tap migration renam that clashes with existing core tap short name
  is ignored in favor of loading the cask/formula from the core tap
2024-06-30 13:55:41 -07:00
Philippe Eberli
20fb068085 Fix migrations of formulae and casks to non homebrew taps 2024-06-08 16:29:23 +02:00
apainintheneck
226239da4c tests: remove unnecessary cache clearing
This PR removes all remaining unnecessary cache clearing in tests
from the codebase since we now clear all cachable classes between
tests making this functionally unnecessary.

Original PR to automatically clear caches:
- https://github.com/Homebrew/brew/pull/16746

I also moved the `Utils::Analytics` module to use cachable so
that we don't have to clear caches specifically in tests anymore.
2024-03-31 18:38:03 -07:00
apainintheneck
74aea8e92d spec_helper: add :no_api test scope
This sets the HOMEBREW_NO_INSTALL_FROM_API environment variable
to prevent the selected tests from using the API. We will need
this as we transition to having the API be enabled by default
when running the tests but it's also nice as a sanity check
with the :needs_utils_curl scope in a few places.
2024-03-19 22:18:02 -07:00
apainintheneck
ad35db4b24 tests: fix tests that make unexpected network calls
These were found with the Utils::Curl check and just turning
off the network on my computer and running the entire test suite.
2024-03-18 20:57:35 -07:00
apainintheneck
b66097fa3d spec_helper: add check for unexpected network calls
Any test that is not tagged as :needs_network and that makes
a call to an unapproved method in the `Utils::Curl` module
will raise an error unless that method gets mocked somehow.

tests: add exceptions for tests that use curl to download local files

These are acceptable ways to use curl in local, non-network tests.
For those edge cases we allow you to bypass the check with :needs_utils_curl.
2024-03-18 20:57:23 -07:00
Markus Reiter
a24da6b072
Remove FromDefaultNameLoader to avoid warning twice. 2024-03-06 23:14:28 +01:00
Markus Reiter
e3a102efd4
Make Tap::new private. 2024-03-06 15:10:14 +01:00
Markus Reiter
3da0f8c4a6
Fix loading casks/formulae from relative paths. 2024-03-01 04:05:15 +01:00
apainintheneck
cd5b93a2f2 internal json v3: parse ruby source checksum correctly
Currently we are including this in the API but not actually
parsing and loading it correctly from the JSON. I think this
was an oversight when addressing feedback and refactoring
the JSON shape. Not a big deal, of course, because I'm the
only person using it right now.

I found this out while testing installs using the API and I got
this error while running `brew reinstall tree`.

```
Warning: Cannot verify integrity of '60fc4212023d3fef00e6de4b9f3f0d63402cf3eca00778d09f4f2d3481b524a1--tree.rb'.
No checksum was provided.
```
2024-02-28 21:34:31 -08:00
Markus Reiter
0684a16293
Pass warn in FromNameLoader. 2024-02-22 22:12:07 +01:00
Markus Reiter
e0743a1436
Reapply "Refactor Formulary::loader_for."
This reverts commit 24683525cb5abf3cc79a9e0e268fa6efd0af558b.
2024-02-22 18:24:57 +01:00
Markus Reiter
9cfc7ef9bd
Clear all tap caches before each test. 2024-02-22 17:56:47 +01:00
Douglas Eichelberger
26eda5a303
git grep -l '^describe' | xargs gsed -i 's|^describe|RSpec.describe|g' 2024-02-19 13:57:27 +00:00
apainintheneck
e96313f6ed formulary_spec: update API tests to avoid mocking
Stop mocking the formulary loader method. We just need to set the
environment variable so that it knows to load things from the API.

Fix spec that doesn't work with the `CoreTap.formula_names`.
That method assumes that we always have a valid `ruby_source_path`
in the API JSON even though that was optional for a while after
launching the API if my memory serves me. It's probably fine
to assume this should always be set though and I changed it to use
`Hash#fetch` to give use better error messages if something goes wrong in the future.

Remove unused `allow(x).to receive(y).and_call_original` in tap spec.
2024-02-17 13:00:50 -08:00
Mike McQuaid
24683525cb
Revert "Refactor Formulary::loader_for." 2024-02-16 13:41:54 +00:00
Markus Reiter
adbd11a0db
Fix flaky tests. 2024-02-16 10:49:32 +01:00
Markus Reiter
18150d9629
Demonstrate flaky tests. 2024-02-16 10:39:21 +01:00
Markus Reiter
c5a877d7db
Simplify test. 2024-02-14 20:28:07 +01:00
Markus Reiter
4641690674
Refactor Formulary::loader_for. 2024-02-14 20:28:06 +01:00
Markus Reiter
228ebe0c32
Add tests for formula migration warnings to default tap. 2024-02-13 21:27:36 +01:00
apainintheneck
70ffc31338 formulary: update logic and add regression test 2024-02-11 13:09:53 -08:00
Rylan Polster
40d3ab6a5d
Add tests and fix brew typecheck 2023-12-16 20:01:47 -05:00
Bo Anderson
5692c8ecbf
Fix style violations under newer RuboCop 2023-12-14 05:47:12 +00:00
Rylan Polster
aa316109d9
Pass new tap to TapLoader
Co-authored-by: Alexander Mancevice <alexander.mancevice@hey.com>
2023-11-13 14:02:50 -05:00
Rylan Polster
237a42974b
Pass original tap to formula when loaded from the API via TapLoader 2023-11-13 13:40:44 -05:00
Mike McQuaid
b3c33d34ab
Various sharding fixes
- Load paths with no API when needed (e.g. for `brew edit`)
- Use no API mode for `brew log` as it's needed there
- Define sharding format for homebrew-cask and homebrew-core inside
  `Tap` methods
- Create new formulae/casks in location defined by these `Tap` methods
- Fix a bug in Formulary that made sharded formulae lookup less
  efficient (and possibly broke it for core and some API usage)
- Fix various other hardcoded Formula/Cask directory assumptions

Co-authored-by: Bo Anderson <mail@boanderson.me>
2023-08-04 16:43:13 +01:00
Douglas Eichelberger
479ca5e314 Fix test 2023-07-24 07:01:57 -07:00
Bo Anderson
dc7a47d0ac
test: drop deprecated uses_from_macos_elements checks 2023-07-07 20:35:54 +01:00
Bo Anderson
d1b923f314
Introduce UsesFromMacOSDependency
Add Formula#declared_deps and SoftwareSpec#declared_deps
2023-07-04 13:40:55 +01:00
apainintheneck
f2adbf6613 service: change custom name DSL
After some discussion, we decided to change the DSL to get rid of
the `plist_name` and `service_name` methods which aren't meaningful
for most users.

The new DSL looks like this:

```rb
service do
  name macos: "name", linux: "name"
end
```

I also updated some specs here to reflect these changes.

There was some talk about maybe deprecating `plist_name` and `service_name`
but I think that's outside of the scope of this PR so I'm leaving
them as is for now. One benefit of this is that everything here is backwards
compatible.
2023-05-17 21:54:32 -07:00
Bo Anderson
44f058edb5
Refactor formula, cask and Ruby source downloads to use shared code 2023-04-27 23:23:07 +01:00
apainintheneck
d57f291a1e formulary: sub home placeholder in caveats
We set a placeholder for the home directory when generating
API JSON so we should substitute the actual home directory
back in when printing caveats locally. This allows people
to use `Dir.home` in caveats and have it display correctly
no matter the platform or operating system.
2023-04-22 10:17:16 -07:00
Douglas Eichelberger
9075cbae62 brew style --fix 2023-04-21 09:58:50 -07:00
Douglas Eichelberger
ac1e6ded9a git grep -l '# typed: false' | xargs gsed -i 's|# typed: false||g' 2023-04-21 09:57:47 -07:00
apainintheneck
e83a2562bb Update service and formulary specs 2023-03-22 00:01:58 -07:00
apainintheneck
d42e9b40d5 formulary: add test for loading service blocks from API 2023-03-19 00:09:16 -07:00
Issy Long
3a83b5492c
rubocop: Clean up Style/BlockDelimiters excludes and autofix offenses
- The defaults of using "do ... end" for multi-line blocks everywhere is
  good, better than switching everything to braces everywhere.
2023-03-08 23:54:22 +00:00
Mike McQuaid
f280ce069b
Support loading formulae/casks from subdirectories
Previously, we required all formulae and casks to be in a specific
formula or cask directory but did not check any subdirectories.

This commit allows using subdirectories for official taps, the only
ones likely to be big enough to warrant sharding in this way and to
avoid potentially breaking backwards compatibility for existing taps.

This was inspired by the most recent issues with homebrew-cask.
2023-02-24 10:57:41 +00:00
Bo Anderson
cacd7194f6
Support link_overwrite and conflicts_with in API 2023-02-20 16:28:07 +00:00
Mike McQuaid
e0ba9a1249
Merge pull request #14617 from Bo98/api-reqs-oldname
formulary: support requirements, aliases etc from API
2023-02-14 11:54:55 +00:00
Bo Anderson
7c1b642035
formulary: fix uses_from_macos handling on macOS 2023-02-14 04:07:51 +00:00