brew/Library/Homebrew/test/os/linux/dependency_collector_spec.rb
Dawid Dziurla 59ce122e90
dependency_collector: make resource dep available at test-time too
There are formulae that use resource blocks for stuff that is needed in
test blocks. If a resource is a `.zip` archive, one needs `unzip`
utility in `PATH` to extract it, but its only available at build-time,
so one observes an error like that for example:

```
==> brew test psftools --verbose
Testing psftools
==> Downloading https://www.zone38.net/font/pc8x8.zip
Already downloaded: /github/home/.cache/Homebrew/downloads/ea5f6a485687368ff5bc99e4cc43a49b06e081baa51a97ee6ddcd8d1b82d7963--pc8x8.zip
==> Verifying ea5f6a485687368ff5bc99e4cc43a49b06e081baa51a97ee6ddcd8d1b82d7963--pc8x8.zip checksum
unzip -o /github/home/.cache/Homebrew/downloads/ea5f6a485687368ff5bc99e4cc43a49b06e081baa51a97ee6ddcd8d1b82d7963--pc8x8.zip -d /tmp/d20200304-21389-ui0wr0
Error: psftools: failed
undefined method `shelljoin' for nil:NilClass
```

Of course this issue affects Linux the most, because of higher
probability that the system lacks `unzip` for example.

With this commit, all resource guessed dependencies should be available
at build and test time.
2020-03-04 22:49:54 +01:00

52 lines
2.0 KiB
Ruby

# frozen_string_literal: true
require "dependency_collector"
describe DependencyCollector do
alias_matcher :be_a_build_requirement, :be_build
describe "#add" do
resource = Resource.new
context "when xz, unzip, and bzip2 are not available" do
it "creates a resource dependency from a '.xz' URL" do
resource.url("https://brew.sh/foo.xz")
allow_any_instance_of(Object).to receive(:which).with("xz")
expect(subject.add(resource)).to eq(Dependency.new("xz", [:build, :test]))
end
it "creates a resource dependency from a '.zip' URL" do
resource.url("https://brew.sh/foo.zip")
allow_any_instance_of(Object).to receive(:which).with("unzip")
expect(subject.add(resource)).to eq(Dependency.new("unzip", [:build, :test]))
end
it "creates a resource dependency from a '.bz2' URL" do
resource.url("https://brew.sh/foo.tar.bz2")
allow_any_instance_of(Object).to receive(:which).with("bzip2")
expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build, :test]))
end
end
context "when xz, zip, and bzip2 are available" do
it "does not create a resource dependency from a '.xz' URL" do
resource.url("https://brew.sh/foo.xz")
allow_any_instance_of(Object).to receive(:which).with("xz").and_return(Pathname.new("foo"))
expect(subject.add(resource)).to be nil
end
it "does not create a resource dependency from a '.zip' URL" do
resource.url("https://brew.sh/foo.zip")
allow_any_instance_of(Object).to receive(:which).with("unzip").and_return(Pathname.new("foo"))
expect(subject.add(resource)).to be nil
end
it "does not create a resource dependency from a '.bz2' URL" do
resource.url("https://brew.sh/foo.tar.bz2")
allow_any_instance_of(Object).to receive(:which).with("bzip2").and_return(Pathname.new("foo"))
expect(subject.add(resource)).to be nil
end
end
end
end