aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/.bundle/config1
-rw-r--r--Library/Homebrew/test/Gemfile.lock42
-rw-r--r--Library/Homebrew/test/PATH_spec.rb115
-rw-r--r--Library/Homebrew/test/cask/artifact/binary_spec.rb31
-rw-r--r--Library/Homebrew/test/cask/cask_spec.rb4
-rw-r--r--Library/Homebrew/test/cask/cli/install_spec.rb14
-rw-r--r--Library/Homebrew/test/cask/cli/reinstall_spec.rb23
-rw-r--r--Library/Homebrew/test/cask/cli/search_spec.rb6
-rw-r--r--Library/Homebrew/test/cask/cli/style_spec.rb2
-rw-r--r--Library/Homebrew/test/cask/cli/uninstall_spec.rb21
-rw-r--r--Library/Homebrew/test/cask/installer_spec.rb10
-rw-r--r--Library/Homebrew/test/cask/pkg_spec.rb9
-rw-r--r--Library/Homebrew/test/cmd/bundle_spec.rb2
-rw-r--r--Library/Homebrew/test/cmd/install_spec.rb12
-rw-r--r--Library/Homebrew/test/cmd/search_remote_tap_spec.rb14
-rw-r--r--Library/Homebrew/test/compiler_selector_spec.rb12
-rw-r--r--Library/Homebrew/test/dev-cmd/audit_spec.rb426
-rw-r--r--Library/Homebrew/test/dev-cmd/pull_spec.rb4
-rw-r--r--Library/Homebrew/test/diagnostic_spec.rb25
-rw-r--r--Library/Homebrew/test/formula_spec.rb18
-rw-r--r--Library/Homebrew/test/gpg2_requirement_spec.rb2
-rw-r--r--Library/Homebrew/test/gpg_spec.rb7
-rw-r--r--Library/Homebrew/test/hardware_spec.rb47
-rw-r--r--Library/Homebrew/test/missing_formula_spec.rb2
-rw-r--r--Library/Homebrew/test/os/linux/osxfuse_requirement_spec.rb9
-rw-r--r--Library/Homebrew/test/os/mac/hardware_spec.rb56
-rw-r--r--Library/Homebrew/test/os/mac/osxfuse_requirement_spec.rb36
-rw-r--r--Library/Homebrew/test/requirement_spec.rb10
-rw-r--r--Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb2
-rw-r--r--Library/Homebrew/test/rubocops/components_order_cop_spec.rb163
-rw-r--r--Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb87
-rw-r--r--Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb27
-rw-r--r--Library/Homebrew/test/rubocops/homepage_cop_spec.rb124
-rw-r--r--Library/Homebrew/test/spec_helper.rb5
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-non-executable-binary.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/naked_non_executable2
-rw-r--r--Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb1
-rw-r--r--Library/Homebrew/test/utils/github_spec.rb13
-rw-r--r--Library/Homebrew/test/utils/shell_spec.rb56
-rw-r--r--Library/Homebrew/test/utils_spec.rb8
-rw-r--r--Library/Homebrew/test/version_spec.rb5
41 files changed, 1163 insertions, 299 deletions
diff --git a/Library/Homebrew/test/.bundle/config b/Library/Homebrew/test/.bundle/config
index e451829e9..20549341c 100644
--- a/Library/Homebrew/test/.bundle/config
+++ b/Library/Homebrew/test/.bundle/config
@@ -1,3 +1,4 @@
---
BUNDLE_PATH: "../vendor/bundle"
BUNDLE_DISABLE_SHARED_GEMS: "true"
+BUNDLE_BIN: "../bin"
diff --git a/Library/Homebrew/test/Gemfile.lock b/Library/Homebrew/test/Gemfile.lock
index 4d4eefd7d..1f6adae93 100644
--- a/Library/Homebrew/test/Gemfile.lock
+++ b/Library/Homebrew/test/Gemfile.lock
@@ -2,51 +2,53 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.3.0)
- codecov (0.1.9)
+ codecov (0.1.10)
json
simplecov
url
diff-lcs (1.3)
docile (1.1.5)
- json (2.0.3)
- parallel (1.10.0)
- parallel_tests (2.13.0)
+ json (2.1.0)
+ parallel (1.11.2)
+ parallel_tests (2.14.1)
parallel
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
- rainbow (2.2.1)
- rspec (3.5.0)
- rspec-core (~> 3.5.0)
- rspec-expectations (~> 3.5.0)
- rspec-mocks (~> 3.5.0)
- rspec-core (3.5.4)
- rspec-support (~> 3.5.0)
- rspec-expectations (3.5.0)
+ rainbow (2.2.2)
+ rake
+ rake (12.0.0)
+ rspec (3.6.0)
+ rspec-core (~> 3.6.0)
+ rspec-expectations (~> 3.6.0)
+ rspec-mocks (~> 3.6.0)
+ rspec-core (3.6.0)
+ rspec-support (~> 3.6.0)
+ rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
- rspec-support (~> 3.5.0)
+ rspec-support (~> 3.6.0)
rspec-its (1.2.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
- rspec-mocks (3.5.0)
+ rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
- rspec-support (~> 3.5.0)
- rspec-support (3.5.0)
+ rspec-support (~> 3.6.0)
+ rspec-support (3.6.0)
rspec-wait (0.0.9)
rspec (>= 3, < 4)
- rubocop (0.47.1)
+ rubocop (0.48.1)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
- simplecov (0.13.0)
+ simplecov (0.14.1)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
- unicode-display_width (1.1.3)
+ unicode-display_width (1.2.1)
url (0.3.2)
PLATFORMS
@@ -62,4 +64,4 @@ DEPENDENCIES
simplecov
BUNDLED WITH
- 1.14.5
+ 1.14.6
diff --git a/Library/Homebrew/test/PATH_spec.rb b/Library/Homebrew/test/PATH_spec.rb
new file mode 100644
index 000000000..68233c23c
--- /dev/null
+++ b/Library/Homebrew/test/PATH_spec.rb
@@ -0,0 +1,115 @@
+require "PATH"
+
+describe PATH do
+ describe "#initialize" do
+ it "can take multiple arguments" do
+ expect(described_class.new("/path1", "/path2")).to eq("/path1:/path2")
+ end
+
+ it "can parse a mix of arrays and arguments" do
+ expect(described_class.new(["/path1", "/path2"], "/path3")).to eq("/path1:/path2:/path3")
+ end
+
+ it "splits an existing PATH" do
+ expect(described_class.new("/path1:/path2")).to eq(["/path1", "/path2"])
+ end
+
+ it "removes duplicates" do
+ expect(described_class.new("/path1", "/path1")).to eq("/path1")
+ end
+ end
+
+ describe "#to_ary" do
+ it "returns a PATH array" do
+ expect(described_class.new("/path1", "/path2").to_ary).to eq(["/path1", "/path2"])
+ end
+ end
+
+ describe "#to_str" do
+ it "returns a PATH string" do
+ expect(described_class.new("/path1", "/path2").to_str).to eq("/path1:/path2")
+ end
+ end
+
+ describe "#prepend" do
+ it "prepends a path to a PATH" do
+ expect(described_class.new("/path1").prepend("/path2").to_str).to eq("/path2:/path1")
+ end
+
+ it "removes duplicates" do
+ expect(described_class.new("/path1").prepend("/path1").to_str).to eq("/path1")
+ end
+ end
+
+ describe "#append" do
+ it "prepends a path to a PATH" do
+ expect(described_class.new("/path1").append("/path2").to_str).to eq("/path1:/path2")
+ end
+
+ it "removes duplicates" do
+ expect(described_class.new("/path1").append("/path1").to_str).to eq("/path1")
+ end
+ end
+
+ describe "#insert" do
+ it "inserts a path at a given index" do
+ expect(described_class.new("/path1").insert(0, "/path2").to_str).to eq("/path2:/path1")
+ end
+
+ it "can insert multiple paths" do
+ expect(described_class.new("/path1").insert(0, "/path2", "/path3")).to eq("/path2:/path3:/path1")
+ end
+ end
+
+ describe "#include?" do
+ it "returns true if a path is included" do
+ path = described_class.new("/path1", "/path2")
+ expect(path).to include("/path1")
+ expect(path).to include("/path2")
+ end
+
+ it "returns false if a path is not included" do
+ expect(described_class.new("/path1")).not_to include("/path2")
+ end
+
+ it "returns false if the given string contains a separator" do
+ expect(described_class.new("/path1", "/path2")).not_to include("/path1:")
+ end
+ end
+
+ describe "#each" do
+ it "loops through each path" do
+ enum = described_class.new("/path1", "/path2").each
+
+ expect(enum.next).to eq("/path1")
+ expect(enum.next).to eq("/path2")
+ end
+ end
+
+ describe "#select" do
+ it "returns an object of the same class instead of an Array" do
+ expect(described_class.new.select { true }).to be_a(described_class)
+ end
+ end
+
+ describe "#reject" do
+ it "returns an object of the same class instead of an Array" do
+ expect(described_class.new.reject { true }).to be_a(described_class)
+ end
+ end
+
+ describe "#existing" do
+ it "returns a new PATH without non-existent paths" do
+ allow(File).to receive(:directory?).with("/path1").and_return(true)
+ allow(File).to receive(:directory?).with("/path2").and_return(false)
+
+ path = described_class.new("/path1", "/path2")
+ expect(path.existing.to_ary).to eq(["/path1"])
+ expect(path.to_ary).to eq(["/path1", "/path2"])
+ end
+
+ it "returns nil instead of an empty #{described_class}" do
+ expect(described_class.new.existing).to be nil
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb
index 69bde3438..ee62e6439 100644
--- a/Library/Homebrew/test/cask/artifact/binary_spec.rb
+++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb
@@ -6,9 +6,7 @@ describe Hbc::Artifact::Binary, :cask do
end
end
}
- let(:expected_path) {
- Hbc.binarydir.join("binary")
- }
+ let(:expected_path) { Hbc.binarydir.join("binary") }
before(:each) do
Hbc.binarydir.mkpath
@@ -26,15 +24,28 @@ describe Hbc::Artifact::Binary, :cask do
expect(expected_path.readlink).to exist
end
- it "makes the binary executable" do
- expect(FileUtils).to receive(:chmod).with("+x", cask.staged_path.join("binary"))
+ context "when the binary is not executable" do
+ let(:cask) {
+ Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-non-executable-binary.rb").tap do |cask|
+ shutup do
+ InstallHelper.install_without_artifacts(cask)
+ end
+ end
+ }
- shutup do
- Hbc::Artifact::Binary.new(cask).install_phase
- end
+ let(:expected_path) { Hbc.binarydir.join("naked_non_executable") }
- expect(expected_path).to be_a_symlink
- expect(expected_path.readlink).to be_executable
+ it "makes the binary executable" do
+ expect(FileUtils).to receive(:chmod)
+ .with("+x", cask.staged_path.join("naked_non_executable")).and_call_original
+
+ shutup do
+ Hbc::Artifact::Binary.new(cask).install_phase
+ end
+
+ expect(expected_path).to be_a_symlink
+ expect(expected_path.readlink).to be_executable
+ end
end
it "avoids clobbering an existing binary by linking over it" do
diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb
index 2ab966f82..3736f3c01 100644
--- a/Library/Homebrew/test/cask/cask_spec.rb
+++ b/Library/Homebrew/test/cask/cask_spec.rb
@@ -85,8 +85,8 @@ describe Hbc::Cask, :cask do
it "proposes a versioned metadata directory name for each instance" do
cask_token = "local-caffeine"
c = Hbc::CaskLoader.load(cask_token)
- metadata_path = Hbc.caskroom.join(cask_token, ".metadata", c.version)
- expect(c.metadata_versioned_container_path.to_s).to eq(metadata_path.to_s)
+ metadata_timestamped_path = Hbc.caskroom.join(cask_token, ".metadata", c.version)
+ expect(c.metadata_versioned_path.to_s).to eq(metadata_timestamped_path.to_s)
end
end
diff --git a/Library/Homebrew/test/cask/cli/install_spec.rb b/Library/Homebrew/test/cask/cli/install_spec.rb
index 5a40017e8..219b9522e 100644
--- a/Library/Homebrew/test/cask/cli/install_spec.rb
+++ b/Library/Homebrew/test/cask/cli/install_spec.rb
@@ -1,4 +1,18 @@
describe Hbc::CLI::Install, :cask do
+ it "displays the installation progress" do
+ output = Regexp.new <<-EOS.undent
+ ==> Downloading file:.*caffeine.zip
+ ==> Verifying checksum for Cask local-caffeine
+ ==> Installing Cask local-caffeine
+ ==> Moving App 'Caffeine.app' to '.*Caffeine.app'.
+ .*local-caffeine was successfully installed!
+ EOS
+
+ expect {
+ Hbc::CLI::Install.run("local-caffeine")
+ }.to output(output).to_stdout
+ end
+
it "allows staging and activation of multiple Casks at once" do
shutup do
Hbc::CLI::Install.run("local-transmission", "local-caffeine")
diff --git a/Library/Homebrew/test/cask/cli/reinstall_spec.rb b/Library/Homebrew/test/cask/cli/reinstall_spec.rb
index e573a3470..8885fa199 100644
--- a/Library/Homebrew/test/cask/cli/reinstall_spec.rb
+++ b/Library/Homebrew/test/cask/cli/reinstall_spec.rb
@@ -1,4 +1,27 @@
describe Hbc::CLI::Reinstall, :cask do
+ it "displays the reinstallation progress" do
+ caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")
+
+ shutup do
+ Hbc::Installer.new(caffeine).install
+ end
+
+ output = Regexp.new <<-EOS.undent
+ ==> Downloading file:.*caffeine.zip
+ Already downloaded: .*local-caffeine--1.2.3.zip
+ ==> Verifying checksum for Cask local-caffeine
+ ==> Uninstalling Cask local-caffeine
+ ==> Removing App '.*Caffeine.app'.
+ ==> Installing Cask local-caffeine
+ ==> Moving App 'Caffeine.app' to '.*Caffeine.app'.
+ .*local-caffeine was successfully installed!
+ EOS
+
+ expect {
+ Hbc::CLI::Reinstall.run("local-caffeine")
+ }.to output(output).to_stdout
+ end
+
it "allows reinstalling a Cask" do
shutup do
Hbc::CLI::Install.run("local-transmission")
diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb
index 9843a6de6..00fcf7382 100644
--- a/Library/Homebrew/test/cask/cli/search_spec.rb
+++ b/Library/Homebrew/test/cask/cli/search_spec.rb
@@ -3,7 +3,7 @@ describe Hbc::CLI::Search, :cask do
expect {
Hbc::CLI::Search.run("local")
}.to output(<<-EOS.undent).to_stdout
- ==> Partial matches
+ ==> Partial Matches
local-caffeine
local-transmission
EOS
@@ -42,13 +42,13 @@ describe Hbc::CLI::Search, :cask do
it "accepts a regexp argument" do
expect {
Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/")
- }.to output("==> Regexp matches\nlocal-caffeine\n").to_stdout
+ }.to output("==> Regexp Matches\nlocal-caffeine\n").to_stdout
end
it "Returns both exact and partial matches" do
expect {
Hbc::CLI::Search.run("test-opera")
- }.to output(/^==> Exact match\ntest-opera\n==> Partial matches\ntest-opera-mail/).to_stdout
+ }.to output(/^==> Exact Match\ntest-opera\n==> Partial Matches\ntest-opera-mail/).to_stdout
end
it "does not search the Tap name" do
diff --git a/Library/Homebrew/test/cask/cli/style_spec.rb b/Library/Homebrew/test/cask/cli/style_spec.rb
index ca17c5e46..d41636beb 100644
--- a/Library/Homebrew/test/cask/cli/style_spec.rb
+++ b/Library/Homebrew/test/cask/cli/style_spec.rb
@@ -81,7 +81,7 @@ describe Hbc::CLI::Style, :cask do
end
context "version" do
- it "matches `HOMEBREW_RUBOCOP_VERSION`" do
+ it "matches `HOMEBREW_RUBOCOP_VERSION`", :needs_network do
stdout, status = Open3.capture2("gem", "dependency", "rubocop-cask", "--version", HOMEBREW_RUBOCOP_CASK_VERSION, "--pipe", "--remote")
expect(status).to be_a_success
diff --git a/Library/Homebrew/test/cask/cli/uninstall_spec.rb b/Library/Homebrew/test/cask/cli/uninstall_spec.rb
index fb196ee72..4089c47b4 100644
--- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb
+++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb
@@ -1,4 +1,21 @@
describe Hbc::CLI::Uninstall, :cask do
+ it "displays the uninstallation progress" do
+ caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")
+
+ shutup do
+ Hbc::Installer.new(caffeine).install
+ end
+
+ output = Regexp.new <<-EOS.undent
+ ==> Uninstalling Cask local-caffeine
+ ==> Removing App '.*Caffeine.app'.
+ EOS
+
+ expect {
+ Hbc::CLI::Uninstall.run("local-caffeine")
+ }.to output(output).to_stdout
+ end
+
it "shows an error when a bad Cask is provided" do
expect {
Hbc::CLI::Uninstall.run("notacask")
@@ -13,7 +30,9 @@ describe Hbc::CLI::Uninstall, :cask do
it "tries anyway on a non-present Cask when --force is given" do
expect {
- Hbc::CLI::Uninstall.run("local-caffeine", "--force")
+ shutup do
+ Hbc::CLI::Uninstall.run("local-caffeine", "--force")
+ end
}.not_to raise_error
end
diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb
index 7dd5b2bda..59d61bbdd 100644
--- a/Library/Homebrew/test/cask/installer_spec.rb
+++ b/Library/Homebrew/test/cask/installer_spec.rb
@@ -336,9 +336,8 @@ describe Hbc::Installer, :cask do
Hbc::Installer.new(caffeine).install
end
- m_path = caffeine.metadata_path(:now, true)
- expect(caffeine.metadata_path(:now, false)).to eq(m_path)
- expect(caffeine.metadata_path(:latest)).to eq(m_path)
+ m_path = caffeine.metadata_timestamped_path(timestamp: :now, create: true)
+ expect(caffeine.metadata_timestamped_path(timestamp: :latest)).to eq(m_path)
end
it "generates and finds a metadata subdirectory for an installed Cask" do
@@ -349,9 +348,8 @@ describe Hbc::Installer, :cask do
end
subdir_name = "Casks"
- m_subdir = caffeine.metadata_subdir(subdir_name, :now, true)
- expect(caffeine.metadata_subdir(subdir_name, :now, false)).to eq(m_subdir)
- expect(caffeine.metadata_subdir(subdir_name, :latest)).to eq(m_subdir)
+ m_subdir = caffeine.metadata_subdir(subdir_name, timestamp: :now, create: true)
+ expect(caffeine.metadata_subdir(subdir_name, timestamp: :latest)).to eq(m_subdir)
end
end
diff --git a/Library/Homebrew/test/cask/pkg_spec.rb b/Library/Homebrew/test/cask/pkg_spec.rb
index 9930cd00f..e507ceda0 100644
--- a/Library/Homebrew/test/cask/pkg_spec.rb
+++ b/Library/Homebrew/test/cask/pkg_spec.rb
@@ -36,7 +36,12 @@ describe Hbc::Pkg, :cask do
it "forgets the pkg" do
allow(fake_system_command).to receive(:run!).with(
"/usr/sbin/pkgutil",
- args: ["--export-plist", "my.fake.pkg"],
+ args: ["--pkg-info-plist", "my.fake.pkg"],
+ ).and_return(empty_response)
+
+ expect(fake_system_command).to receive(:run!).with(
+ "/usr/sbin/pkgutil",
+ args: ["--files", "my.fake.pkg"],
).and_return(empty_response)
expect(fake_system_command).to receive(:run!).with(
@@ -139,7 +144,7 @@ describe Hbc::Pkg, :cask do
expect(fake_system_command).to receive(:run!).with(
"/usr/sbin/pkgutil",
- args: ["--export-plist", pkg_id],
+ args: ["--pkg-info-plist", pkg_id],
).and_return(
Hbc::SystemCommand::Result.new(nil, pkg_info_plist, nil, 0),
)
diff --git a/Library/Homebrew/test/cmd/bundle_spec.rb b/Library/Homebrew/test/cmd/bundle_spec.rb
index 13f13485c..286ddba97 100644
--- a/Library/Homebrew/test/cmd/bundle_spec.rb
+++ b/Library/Homebrew/test/cmd/bundle_spec.rb
@@ -1,6 +1,6 @@
describe "brew bundle", :integration_test, :needs_test_cmd_taps do
describe "check" do
- it "checks if a Brewfile's dependencies are satisfied" do
+ it "checks if a Brewfile's dependencies are satisfied", :needs_network do
setup_remote_tap "homebrew/bundle"
HOMEBREW_REPOSITORY.cd do
diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb
index c1240a30e..b819c17be 100644
--- a/Library/Homebrew/test/cmd/install_spec.rb
+++ b/Library/Homebrew/test/cmd/install_spec.rb
@@ -77,7 +77,7 @@ describe "brew install", :integration_test do
EOS
expect { brew "install", "testball1" }
- .to output(/first `brew unlink testball1`/).to_stderr
+ .to output(/`brew upgrade testball1`/).to_stderr
.and not_to_output.to_stdout
.and be_a_failure
@@ -217,10 +217,9 @@ describe "brew install", :integration_test do
depends_on NonFatalRequirement
EOS
- # FIXME: This should output to STDERR.
expect { brew "install", "testball1" }
- .to output(/NonFatalRequirement unsatisfied!/).to_stdout
- .and not_to_output.to_stderr
+ .to output(/NonFatalRequirement unsatisfied!/).to_stderr
+ .and output(/built in/).to_stdout
.and be_a_success
end
@@ -234,10 +233,9 @@ describe "brew install", :integration_test do
depends_on FatalRequirement
EOS
- # FIXME: This should output to STDERR.
expect { brew "install", "testball1" }
- .to output(/FatalRequirement unsatisfied!/).to_stdout
- .and output(/An unsatisfied requirement failed this build./).to_stderr
+ .to output(/FatalRequirement unsatisfied!/).to_stderr
+ .and not_to_output.to_stdout
.and be_a_failure
end
end
diff --git a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb
index 99c2cc20b..b0beb122c 100644
--- a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb
+++ b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb
@@ -1,19 +1,21 @@
require "cmd/search"
describe Homebrew do
- specify "#search_tap" do
+ specify "#search_taps" do
json_response = {
- "tree" => [
+ "items" => [
{
- "path" => "Formula/not-a-formula.rb",
- "type" => "blob",
+ "path" => "Formula/some-formula.rb",
+ "repository" => {
+ "full_name" => "Homebrew/homebrew-foo",
+ },
},
],
}
allow(GitHub).to receive(:open).and_yield(json_response)
- expect(described_class.search_tap("homebrew", "not-a-tap", "not-a-formula"))
- .to eq(["homebrew/not-a-tap/not-a-formula"])
+ expect(described_class.search_taps("some-formula"))
+ .to match(["homebrew/foo/some-formula"])
end
end
diff --git a/Library/Homebrew/test/compiler_selector_spec.rb b/Library/Homebrew/test/compiler_selector_spec.rb
index 0f6f6b5f2..18efbfd42 100644
--- a/Library/Homebrew/test/compiler_selector_spec.rb
+++ b/Library/Homebrew/test/compiler_selector_spec.rb
@@ -3,7 +3,7 @@ require "software_spec"
describe CompilerSelector do
subject { described_class.new(software_spec, versions, compilers) }
- let(:compilers) { [:clang, :gcc, :llvm, :gnu] }
+ let(:compilers) { [:clang, :gcc, :gnu] }
let(:software_spec) { SoftwareSpec.new }
let(:cc) { :clang }
let(:versions) do
@@ -28,7 +28,6 @@ describe CompilerSelector do
describe "#compiler" do
it "raises an error if no matching compiler can be found" do
software_spec.fails_with(:clang)
- software_spec.fails_with(:llvm)
software_spec.fails_with(:gcc)
software_spec.fails_with(gcc: "4.8")
software_spec.fails_with(gcc: "4.7")
@@ -45,11 +44,6 @@ describe CompilerSelector do
expect(subject.compiler).to eq(:gcc)
end
- it "returns clang if it fails with llvm" do
- software_spec.fails_with(:llvm)
- expect(subject.compiler).to eq(:clang)
- end
-
it "returns clang if it fails with gcc" do
software_spec.fails_with(:gcc)
expect(subject.compiler).to eq(:clang)
@@ -68,13 +62,11 @@ describe CompilerSelector do
it "returns gcc if it fails with clang and llvm" do
software_spec.fails_with(:clang)
- software_spec.fails_with(:llvm)
expect(subject.compiler).to eq(:gcc)
end
it "returns clang if it fails with gcc and llvm" do
software_spec.fails_with(:gcc)
- software_spec.fails_with(:llvm)
expect(subject.compiler).to eq(:clang)
end
@@ -87,7 +79,6 @@ describe CompilerSelector do
example "returns a lower version of gcc if it fails with the highest version" do
software_spec.fails_with(:clang)
software_spec.fails_with(:gcc)
- software_spec.fails_with(:llvm)
software_spec.fails_with(gcc: "4.8")
expect(subject.compiler).to eq("gcc-4.7")
end
@@ -102,7 +93,6 @@ describe CompilerSelector do
allow(versions).to receive(:gcc_build_version).and_return(Version::NULL)
software_spec.fails_with(:clang)
- software_spec.fails_with(:llvm)
software_spec.fails_with(gcc: "4.8")
software_spec.fails_with(gcc: "4.7")
diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb
index a6bb22837..b07ffaadc 100644
--- a/Library/Homebrew/test/dev-cmd/audit_spec.rb
+++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb
@@ -5,6 +5,13 @@ RSpec::Matchers.alias_matcher :have_data, :be_data
RSpec::Matchers.alias_matcher :have_end, :be_end
RSpec::Matchers.alias_matcher :have_trailing_newline, :be_trailing_newline
+module Count
+ def self.increment
+ @count ||= 0
+ @count += 1
+ end
+end
+
describe FormulaText do
let(:dir) { mktmpdir }
@@ -141,100 +148,6 @@ describe FormulaAuditor do
fa.audit_file
expect(fa.problems).to eq([])
end
-
- specify "strict: ordering issue" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- url "http://example.com/foo-1.0.tgz"
- homepage "http://example.com"
- end
- EOS
-
- fa.audit_file
- expect(fa.problems)
- .to eq(["`homepage` (line 3) should be put before `url` (line 2)"])
- end
-
- specify "strict: resource placement" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- url "https://example.com/foo-1.0.tgz"
-
- resource "foo2" do
- url "https://example.com/foo-2.0.tgz"
- end
-
- depends_on "openssl"
- end
- EOS
-
- fa.audit_file
- expect(fa.problems)
- .to eq(["`depends_on` (line 8) should be put before `resource` (line 4)"])
- end
-
- specify "strict: plist placement" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- url "https://example.com/foo-1.0.tgz"
-
- test do
- expect(shell_output("./dogs")).to match("Dogs are terrific")
- end
-
- def plist
- end
- end
- EOS
-
- fa.audit_file
- expect(fa.problems)
- .to eq(["`plist block` (line 8) should be put before `test block` (line 4)"])
- end
-
- specify "strict: url outside of stable block" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- url "http://example.com/foo-1.0.tgz"
- stable do
- # stuff
- end
- end
- EOS
-
- fa.audit_file
- expect(fa.problems).to eq(["`url` should be put inside `stable block`"])
- end
-
- specify "strict: head and head do" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- head "http://example.com/foo.git"
- head do
- # stuff
- end
- end
- EOS
-
- fa.audit_file
- expect(fa.problems).to eq(["Should not have both `head` and `head do`"])
- end
-
- specify "strict: bottle and bottle do" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- url "http://example.com/foo-1.0.tgz"
- bottle do
- # bottles go here
- end
- bottle :unneeded
- end
- EOS
-
- fa.audit_file
- expect(fa.problems)
- .to eq(["Should not have `bottle :unneeded/:disable` and `bottle do`"])
- end
end
describe "#audit_class" do
@@ -303,7 +216,7 @@ describe FormulaAuditor do
end
end
- describe "#audit_line" do
+ describe "#line_problems" do
specify "pkgshare" do
fa = formula_auditor "foo", <<-EOS.undent, strict: true
class Foo < Formula
@@ -311,25 +224,25 @@ describe FormulaAuditor do
end
EOS
- fa.audit_line 'ohai "#{share}/foo"', 3
+ fa.line_problems 'ohai "#{share}/foo"', 3
expect(fa.problems.shift).to eq("Use \#{pkgshare} instead of \#{share}/foo")
- fa.audit_line 'ohai "#{share}/foo/bar"', 3
+ fa.line_problems 'ohai "#{share}/foo/bar"', 3
expect(fa.problems.shift).to eq("Use \#{pkgshare} instead of \#{share}/foo")
- fa.audit_line 'ohai share/"foo"', 3
+ fa.line_problems 'ohai share/"foo"', 3
expect(fa.problems.shift).to eq('Use pkgshare instead of (share/"foo")')
- fa.audit_line 'ohai share/"foo/bar"', 3
+ fa.line_problems 'ohai share/"foo/bar"', 3
expect(fa.problems.shift).to eq('Use pkgshare instead of (share/"foo")')
- fa.audit_line 'ohai "#{share}/foo-bar"', 3
+ fa.line_problems 'ohai "#{share}/foo-bar"', 3
expect(fa.problems).to eq([])
- fa.audit_line 'ohai share/"foo-bar"', 3
+ fa.line_problems 'ohai share/"foo-bar"', 3
expect(fa.problems).to eq([])
- fa.audit_line 'ohai share/"bar"', 3
+ fa.line_problems 'ohai share/"bar"', 3
expect(fa.problems).to eq([])
end
@@ -344,11 +257,11 @@ describe FormulaAuditor do
end
EOS
- fa.audit_line 'ohai "#{share}/foolibc++"', 3
+ fa.line_problems 'ohai "#{share}/foolibc++"', 3
expect(fa.problems.shift)
.to eq("Use \#{pkgshare} instead of \#{share}/foolibc++")
- fa.audit_line 'ohai share/"foolibc++"', 3
+ fa.line_problems 'ohai share/"foolibc++"', 3
expect(fa.problems.shift)
.to eq('Use pkgshare instead of (share/"foolibc++")')
end
@@ -360,7 +273,7 @@ describe FormulaAuditor do
end
EOS
- fa.audit_line "class Foo<Formula", 1
+ fa.line_problems "class Foo<Formula", 1
expect(fa.problems.shift)
.to eq("Use a space in class inheritance: class Foo < Formula")
end
@@ -368,10 +281,10 @@ describe FormulaAuditor do
specify "default template" do
fa = formula_auditor "foo", "class Foo < Formula; url '/foo-1.0.tgz'; end"
- fa.audit_line '# system "cmake", ".", *std_cmake_args', 3
+ fa.line_problems '# system "cmake", ".", *std_cmake_args', 3
expect(fa.problems.shift).to eq("Commented cmake call found")
- fa.audit_line "# PLEASE REMOVE", 3
+ fa.line_problems "# PLEASE REMOVE", 3
expect(fa.problems.shift).to eq("Please remove default template comments")
end
end
@@ -409,77 +322,66 @@ describe FormulaAuditor do
.to eq(["Don't recommend setuid in the caveats, suggest sudo instead."])
end
- describe "#audit_homepage" do
- specify "homepage URLs" do
- fa = formula_auditor "foo", <<-EOS.undent, online: true
+ describe "#audit_keg_only_style" do
+ specify "keg_only_needs_downcasing" do
+ fa = formula_auditor "foo", <<-EOS.undent, strict: true
class Foo < Formula
- homepage "ftp://example.com/foo"
url "http://example.com/foo-1.0.tgz"
+
+ keg_only "Because why not"
end
EOS
- fa.audit_homepage
+ fa.audit_keg_only_style
expect(fa.problems)
- .to eq(["The homepage should start with http or https (URL is #{fa.formula.homepage})."])
-
- formula_homepages = {
- "bar" => "http://www.freedesktop.org/wiki/bar",
- "baz" => "http://www.freedesktop.org/wiki/Software/baz",
- "qux" => "https://code.google.com/p/qux",
- "quux" => "http://github.com/quux",
- "corge" => "http://savannah.nongnu.org/corge",
- "grault" => "http://grault.github.io/",
- "garply" => "http://www.gnome.org/garply",
- "sf1" => "http://foo.sourceforge.net/",
- "sf2" => "http://foo.sourceforge.net",
- "sf3" => "http://foo.sf.net/",
- "sf4" => "http://foo.sourceforge.io/",
- "waldo" => "http://www.gnu.org/waldo",
- }
-
- formula_homepages.each do |name, homepage|
- fa = formula_auditor name, <<-EOS.undent
- class #{Formulary.class_s(name)} < Formula
- homepage "#{homepage}"
- url "http://example.com/#{name}-1.0.tgz"
- end
- EOS
+ .to eq(["'Because' from the keg_only reason should be 'because'.\n"])
+ end
- fa.audit_homepage
- if homepage =~ %r{http:\/\/www\.freedesktop\.org}
- if homepage =~ /Software/
- expect(fa.problems.first).to match(
- "#{homepage} should be styled " \
- "`https://wiki.freedesktop.org/www/Software/project_name`",
- )
- else
- expect(fa.problems.first).to match(
- "#{homepage} should be styled " \
- "`https://wiki.freedesktop.org/project_name`",
- )
- end
- elsif homepage =~ %r{https:\/\/code\.google\.com}
- expect(fa.problems.first)
- .to match("#{homepage} should end with a slash")
- elsif homepage =~ /foo\.(sf|sourceforge)\.net/
- expect(fa.problems.first)
- .to match("#{homepage} should be `https://foo.sourceforge.io/`")
- else
- expect(fa.problems.first)
- .to match("Please use https:// for #{homepage}")
+ specify "keg_only_redundant_period" do
+ fa = formula_auditor "foo", <<-EOS.undent, strict: true
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+
+ keg_only "because this line ends in a period."
end
- end
+ EOS
+
+ fa.audit_keg_only_style
+ expect(fa.problems)
+ .to eq(["keg_only reason should not end with a period."])
+ end
+
+ specify "keg_only_handles_block_correctly" do
+ fa = formula_auditor "foo", <<-EOS.undent, strict: true
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+
+ keg_only <<-EOF.undent
+ this line starts with a lowercase word.
+
+ This line does not but that shouldn't be a
+ problem
+ EOF
+ end
+ EOS
+
+ fa.audit_keg_only_style
+ expect(fa.problems)
+ .to eq([])
end
- specify "missing homepage" do
- fa = formula_auditor "foo", <<-EOS.undent, online: true
+ specify "keg_only_handles_whitelist_correctly" do
+ fa = formula_auditor "foo", <<-EOS.undent, strict: true
class Foo < Formula
url "http://example.com/foo-1.0.tgz"
+
+ keg_only "Apple ships foo in the CLT package"
end
EOS
- fa.audit_homepage
- expect(fa.problems.first).to match("Formula should have a homepage.")
+ fa.audit_keg_only_style
+ expect(fa.problems)
+ .to eq([])
end
end
@@ -517,5 +419,203 @@ describe FormulaAuditor do
expect(fa.problems.first)
.to match('xcodebuild should be passed an explicit "SYMROOT"')
end
+
+ specify "disallow go get usage" do
+ fa = formula_auditor "foo", <<-EOS.undent
+ class Foo <Formula
+ url "http://example.com/foo-1.0.tgz"
+
+ def install
+ system "go", "get", "bar"
+ end
+ end
+ EOS
+ fa.audit_text
+ expect(fa.problems.first)
+ .to match("Formulae should not use `go get`. If non-vendored resources are required use `go_resource`s.")
+ end
+ end
+
+ describe "#audit_revision_and_version_scheme" do
+ let(:origin_tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" }
+ let(:formula_subpath) { "Formula/foo#{@foo_version}.rb" }
+ let(:origin_formula_path) { origin_tap_path/formula_subpath }
+ let(:tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-bar" }
+ let(:formula_path) { tap_path/formula_subpath }
+
+ before(:each) do
+ @foo_version = Count.increment
+
+ origin_formula_path.write <<-EOS.undent
+ class Foo#{@foo_version} < Formula
+ url "https://example.com/foo-1.0.tar.gz"
+ revision 2
+ version_scheme 1
+ end
+ EOS
+
+ origin_tap_path.mkpath
+ origin_tap_path.cd do
+ shutup do
+ system "git", "init"
+ system "git", "add", "--all"
+ system "git", "commit", "-m", "init"
+ end
+ end
+
+ tap_path.mkpath
+ tap_path.cd do
+ shutup do
+ system "git", "clone", origin_tap_path, "."
+ end
+ end
+ end
+
+ subject do
+ fa = described_class.new(Formulary.factory(formula_path))
+ fa.audit_revision_and_version_scheme
+ fa.problems.first
+ end
+
+ def formula_gsub(before, after = "")
+ text = formula_path.read
+ text.gsub! before, after
+ formula_path.unlink
+ formula_path.write text
+ end
+
+ def formula_gsub_commit(before, after = "")
+ text = origin_formula_path.read
+ text.gsub!(before, after)
+ origin_formula_path.unlink
+ origin_formula_path.write text
+
+ origin_tap_path.cd do
+ shutup do
+ system "git", "commit", "-am", "commit"
+ end
+ end
+
+ tap_path.cd do
+ shutup do
+ system "git", "fetch"
+ system "git", "reset", "--hard", "origin/master"
+ end
+ end
+ end
+
+ context "revisions" do
+ context "should not be removed when first committed above 0" do
+ it { is_expected.to be_nil }
+ end
+
+ context "should not decrease with the same version" do
+ before { formula_gsub_commit "revision 2", "revision 1" }
+
+ it { is_expected.to match("revision should not decrease (from 2 to 1)") }
+ end
+
+ context "should not be removed with the same version" do
+ before { formula_gsub_commit "revision 2" }
+
+ it { is_expected.to match("revision should not decrease (from 2 to 0)") }
+ end
+
+ context "should not decrease with the same, uncommitted version" do
+ before { formula_gsub "revision 2", "revision 1" }
+
+ it { is_expected.to match("revision should not decrease (from 2 to 1)") }
+ end
+
+ context "should be removed with a newer version" do
+ before { formula_gsub_commit "foo-1.0.tar.gz", "foo-1.1.tar.gz" }
+
+ it { is_expected.to match("'revision 2' should be removed") }
+ end
+
+ context "should not warn on an newer version revision removal" do
+ before do
+ formula_gsub_commit "revision 2", ""
+ formula_gsub_commit "foo-1.0.tar.gz", "foo-1.1.tar.gz"
+ end
+
+ it { is_expected.to be_nil }
+ end
+
+ context "should only increment by 1 with an uncommitted version" do
+ before do
+ formula_gsub "foo-1.0.tar.gz", "foo-1.1.tar.gz"
+ formula_gsub "revision 2", "revision 4"
+ end
+
+ it { is_expected.to match("revisions should only increment by 1") }
+ end
+
+ context "should not warn on past increment by more than 1" do
+ before do
+ formula_gsub_commit "revision 2", "# no revision"
+ formula_gsub_commit "foo-1.0.tar.gz", "foo-1.1.tar.gz"
+ formula_gsub_commit "# no revision", "revision 3"
+ end
+
+ it { is_expected.to be_nil }
+ end
+ end
+
+ context "version_schemes" do
+ context "should not decrease with the same version" do
+ before { formula_gsub_commit "version_scheme 1" }
+
+ it { is_expected.to match("version_scheme should not decrease (from 1 to 0)") }
+ end
+
+ context "should not decrease with a new version" do
+ before do
+ formula_gsub_commit "foo-1.0.tar.gz", "foo-1.1.tar.gz"
+ formula_gsub_commit "version_scheme 1", ""
+ formula_gsub_commit "revision 2", ""
+ end
+
+ it { is_expected.to match("version_scheme should not decrease (from 1 to 0)") }
+ end
+
+ context "should only increment by 1" do
+ before do
+ formula_gsub_commit "version_scheme 1", "# no version_scheme"
+ formula_gsub_commit "foo-1.0.tar.gz", "foo-1.1.tar.gz"
+ formula_gsub_commit "revision 2", ""
+ formula_gsub_commit "# no version_scheme", "version_scheme 3"
+ end
+
+ it { is_expected.to match("version_schemes should only increment by 1") }
+ end
+ end
+
+ context "versions" do
+ context "uncommitted should not decrease" do
+ before { formula_gsub "foo-1.0.tar.gz", "foo-0.9.tar.gz" }
+
+ it { is_expected.to match("stable version should not decrease (from 1.0 to 0.9)") }
+ end
+
+ context "committed can decrease" do
+ before do
+ formula_gsub_commit "revision 2"
+ formula_gsub_commit "foo-1.0.tar.gz", "foo-0.9.tar.gz"
+ end
+
+ it { is_expected.to be_nil }
+ end
+
+ context "can decrease with version_scheme increased" do
+ before do
+ formula_gsub "revision 2"
+ formula_gsub "foo-1.0.tar.gz", "foo-0.9.tar.gz"
+ formula_gsub "version_scheme 1", "version_scheme 2"
+ end
+
+ it { is_expected.to be_nil }
+ end
+ end
end
end
diff --git a/Library/Homebrew/test/dev-cmd/pull_spec.rb b/Library/Homebrew/test/dev-cmd/pull_spec.rb
index 3c0108df2..2ebe144bb 100644
--- a/Library/Homebrew/test/dev-cmd/pull_spec.rb
+++ b/Library/Homebrew/test/dev-cmd/pull_spec.rb
@@ -6,9 +6,7 @@ describe "brew pull", :integration_test do
.and be_a_failure
end
- it "fetches a patch from a GitHub commit or pull request and applies it" do
- skip "Requires network connection." if ENV["HOMEBREW_NO_GITHUB_API"]
-
+ it "fetches a patch from a GitHub commit or pull request and applies it", :needs_network do
CoreTap.instance.path.cd do
shutup do
system "git", "init"
diff --git a/Library/Homebrew/test/diagnostic_spec.rb b/Library/Homebrew/test/diagnostic_spec.rb
index 59560127c..c4373671e 100644
--- a/Library/Homebrew/test/diagnostic_spec.rb
+++ b/Library/Homebrew/test/diagnostic_spec.rb
@@ -7,7 +7,7 @@ describe Homebrew::Diagnostic::Checks do
end
specify "#check_path_for_trailing_slashes" do
- ENV["PATH"] += File::PATH_SEPARATOR + "/foo/bar/"
+ ENV["HOMEBREW_PATH"] += File::PATH_SEPARATOR + "/foo/bar/"
expect(subject.check_path_for_trailing_slashes)
.to match("Some directories in your path end in a slash")
end
@@ -41,6 +41,20 @@ describe Homebrew::Diagnostic::Checks do
end
end
+ specify "#check_access_lock_dir" do
+ begin
+ prev_mode = HOMEBREW_LOCK_DIR.stat.mode
+ mode = HOMEBREW_LOCK_DIR.stat.mode & 0777
+ HOMEBREW_LOCK_DIR.chmod 0555
+ expect(HOMEBREW_LOCK_DIR.stat.mode).not_to eq(prev_mode)
+
+ expect(subject.check_access_lock_dir)
+ .to match("#{HOMEBREW_LOCK_DIR} isn't writable.")
+ ensure
+ HOMEBREW_LOCK_DIR.chmod mode
+ end
+ end
+
specify "#check_access_logs" do
begin
mode = HOMEBREW_LOGS.stat.mode & 0777
@@ -110,8 +124,9 @@ describe Homebrew::Diagnostic::Checks do
specify "#check_user_path_3" do
begin
sbin = HOMEBREW_PREFIX/"sbin"
- ENV["PATH"] = "#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
- ENV["PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
+ ENV["HOMEBREW_PATH"] =
+ "#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
+ ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
(sbin/"something").mkpath
expect(subject.check_user_path_1).to be nil
@@ -137,7 +152,9 @@ describe Homebrew::Diagnostic::Checks do
file = "#{path}/foo-config"
FileUtils.touch file
FileUtils.chmod 0755, file
- ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
+ ENV["HOMEBREW_PATH"] =
+ ENV["PATH"] =
+ "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
expect(subject.check_for_config_scripts)
.to match('"config" scripts exist')
diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb
index 2309c36fb..1f98ca525 100644
--- a/Library/Homebrew/test/formula_spec.rb
+++ b/Library/Homebrew/test/formula_spec.rb
@@ -10,7 +10,6 @@ RSpec::Matchers.alias_matcher :supersede_an_installed_formula, :be_supersedes_an
RSpec::Matchers.alias_matcher :have_changed_alias, :be_alias_changed
RSpec::Matchers.alias_matcher :have_option_defined, :be_option_defined
-RSpec::Matchers.alias_matcher :have_post_install_defined, :be_post_install_defined
RSpec::Matchers.alias_matcher :have_test_defined, :be_test_defined
RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle
@@ -624,23 +623,6 @@ describe Formula do
expect(f.desc).to eq("a formula")
end
- specify "#post_install_defined?" do
- f1 = formula do
- url "foo-1.0"
-
- def post_install
- # do nothing
- end
- end
-
- f2 = formula do
- url "foo-1.0"
- end
-
- expect(f1).to have_post_install_defined
- expect(f2).not_to have_post_install_defined
- end
-
specify "#test_defined?" do
f1 = formula do
url "foo-1.0"
diff --git a/Library/Homebrew/test/gpg2_requirement_spec.rb b/Library/Homebrew/test/gpg2_requirement_spec.rb
index d7767abd3..a5501c84e 100644
--- a/Library/Homebrew/test/gpg2_requirement_spec.rb
+++ b/Library/Homebrew/test/gpg2_requirement_spec.rb
@@ -9,7 +9,7 @@ describe GPG2Requirement do
ENV["PATH"] = dir/"bin"
(dir/"bin/gpg").write <<-EOS.undent
#!/bin/bash
- echo 2.0.30
+ echo 2.1.20
EOS
FileUtils.chmod 0755, dir/"bin/gpg"
diff --git a/Library/Homebrew/test/gpg_spec.rb b/Library/Homebrew/test/gpg_spec.rb
index aa00d79f5..160e55379 100644
--- a/Library/Homebrew/test/gpg_spec.rb
+++ b/Library/Homebrew/test/gpg_spec.rb
@@ -13,7 +13,12 @@ describe Gpg do
shutup do
subject.create_test_key(dir)
end
- expect(dir/".gnupg/secring.gpg").to exist
+
+ if subject.version == Version.create("2.0")
+ expect(dir/".gnupg/secring.gpg").to be_a_file
+ else
+ expect(dir/".gnupg/pubring.kbx").to be_a_file
+ end
end
end
end
diff --git a/Library/Homebrew/test/hardware_spec.rb b/Library/Homebrew/test/hardware_spec.rb
index c5f8daf4e..de8d77e68 100644
--- a/Library/Homebrew/test/hardware_spec.rb
+++ b/Library/Homebrew/test/hardware_spec.rb
@@ -36,5 +36,52 @@ module Hardware
).to include(described_class.family)
end
end
+
+ describe "::can_run?" do
+ it "reports that Intel machines can run Intel executables" do
+ allow(Hardware::CPU).to receive(:type).and_return :intel
+ allow(Hardware::CPU).to receive(:bits).and_return 64
+ expect(Hardware::CPU.can_run?(:i386)).to be true
+ expect(Hardware::CPU.can_run?(:x86_64)).to be true
+ end
+
+ it "reports that PowerPC machines can run PowerPC executables" do
+ allow(Hardware::CPU).to receive(:type).and_return :ppc
+ allow(Hardware::CPU).to receive(:bits).and_return 64
+ expect(Hardware::CPU.can_run?(:ppc)).to be true
+ expect(Hardware::CPU.can_run?(:ppc64)).to be true
+ end
+
+ it "reports that 32-bit Intel machines can't run x86_64 executables" do
+ allow(Hardware::CPU).to receive(:type).and_return :intel
+ allow(Hardware::CPU).to receive(:bits).and_return 32
+ expect(Hardware::CPU.can_run?(:x86_64)).to be false
+ end
+
+ it "reports that 32-bit PowerPC machines can't run ppc64 executables" do
+ allow(Hardware::CPU).to receive(:type).and_return :ppc
+ allow(Hardware::CPU).to receive(:bits).and_return 32
+ expect(Hardware::CPU.can_run?(:ppc64)).to be false
+ end
+
+ it "identifies that Intel and PowerPC machines can't run each others' executables" do
+ allow(Hardware::CPU).to receive(:type).and_return :ppc
+ expect(Hardware::CPU.can_run?(:i386)).to be false
+ expect(Hardware::CPU.can_run?(:x86_64)).to be false
+
+ allow(Hardware::CPU).to receive(:type).and_return :intel
+ expect(Hardware::CPU.can_run?(:ppc)).to be false
+ expect(Hardware::CPU.can_run?(:ppc64)).to be false
+ end
+
+ it "returns false for unknown CPU types" do
+ allow(Hardware::CPU).to receive(:type).and_return :dunno
+ expect(Hardware::CPU.can_run?(:i386)).to be false
+ end
+
+ it "returns false for unknown arches" do
+ expect(Hardware::CPU.can_run?(:blah)).to be false
+ end
+ end
end
end
diff --git a/Library/Homebrew/test/missing_formula_spec.rb b/Library/Homebrew/test/missing_formula_spec.rb
index 215cf17f7..69bb3e70d 100644
--- a/Library/Homebrew/test/missing_formula_spec.rb
+++ b/Library/Homebrew/test/missing_formula_spec.rb
@@ -139,7 +139,7 @@ describe Homebrew::MissingFormula do
end
context "::deleted_reason" do
- subject { described_class.deleted_reason(formula) }
+ subject { described_class.deleted_reason(formula, silent: true) }
before do
Tap.clear_cache
diff --git a/Library/Homebrew/test/os/linux/osxfuse_requirement_spec.rb b/Library/Homebrew/test/os/linux/osxfuse_requirement_spec.rb
new file mode 100644
index 000000000..c45af2fa7
--- /dev/null
+++ b/Library/Homebrew/test/os/linux/osxfuse_requirement_spec.rb
@@ -0,0 +1,9 @@
+require "requirements/osxfuse_requirement"
+
+describe OsxfuseRequirement do
+ subject { described_class.new([]) }
+
+ describe "#message" do
+ its(:message) { is_expected.to match("libfuse is required to install this formula") }
+ end
+end
diff --git a/Library/Homebrew/test/os/mac/hardware_spec.rb b/Library/Homebrew/test/os/mac/hardware_spec.rb
new file mode 100644
index 000000000..fa577ba7d
--- /dev/null
+++ b/Library/Homebrew/test/os/mac/hardware_spec.rb
@@ -0,0 +1,56 @@
+require "hardware"
+require "extend/os/mac/hardware/cpu"
+
+describe Hardware::CPU do
+ describe "::can_run?" do
+ it "reports that Intel Macs can run Intel executables" do
+ allow(Hardware::CPU).to receive(:type).and_return :intel
+ allow(Hardware::CPU).to receive(:bits).and_return 64
+ expect(Hardware::CPU.can_run?(:i386)).to be true
+ expect(Hardware::CPU.can_run?(:x86_64)).to be true
+ end
+
+ it "reports that PowerPC Macs can run PowerPC executables" do
+ allow(Hardware::CPU).to receive(:type).and_return :ppc
+ allow(Hardware::CPU).to receive(:bits).and_return 64
+ expect(Hardware::CPU.can_run?(:ppc)).to be true
+ expect(Hardware::CPU.can_run?(:ppc64)).to be true
+ end
+
+ it "reports that 32-bit Intel Macs can't run x86_64 executables" do
+ allow(Hardware::CPU).to receive(:type).and_return :intel
+ allow(Hardware::CPU).to receive(:bits).and_return 32
+ expect(Hardware::CPU.can_run?(:x86_64)).to be false
+ end
+
+ it "reports that 32-bit PowerPC Macs can't run ppc64 executables" do
+ allow(Hardware::CPU).to receive(:type).and_return :ppc
+ allow(Hardware::CPU).to receive(:bits).and_return 32
+ expect(Hardware::CPU.can_run?(:ppc64)).to be false
+ end
+
+ it "reports that Intel Macs can only run 32-bit PowerPC executables on 10.6 and older" do
+ allow(Hardware::CPU).to receive(:type).and_return :intel
+ allow(OS::Mac).to receive(:version).and_return OS::Mac::Version.new "10.6"
+ expect(Hardware::CPU.can_run?(:ppc)).to be true
+
+ allow(OS::Mac).to receive(:version).and_return OS::Mac::Version.new "10.7"
+ expect(Hardware::CPU.can_run?(:ppc)).to be false
+ end
+
+ it "reports that PowerPC Macs can't run Intel executables" do
+ allow(Hardware::CPU).to receive(:type).and_return :ppc
+ expect(Hardware::CPU.can_run?(:i386)).to be false
+ expect(Hardware::CPU.can_run?(:x86_64)).to be false
+ end
+
+ it "returns false for unknown CPU types" do
+ allow(Hardware::CPU).to receive(:type).and_return :dunno
+ expect(Hardware::CPU.can_run?(:i386)).to be false
+ end
+
+ it "returns false for unknown arches" do
+ expect(Hardware::CPU.can_run?(:blah)).to be false
+ end
+ end
+end
diff --git a/Library/Homebrew/test/os/mac/osxfuse_requirement_spec.rb b/Library/Homebrew/test/os/mac/osxfuse_requirement_spec.rb
new file mode 100644
index 000000000..06d3d885e
--- /dev/null
+++ b/Library/Homebrew/test/os/mac/osxfuse_requirement_spec.rb
@@ -0,0 +1,36 @@
+require "requirements/osxfuse_requirement"
+
+describe OsxfuseRequirement do
+ subject { described_class.new([]) }
+
+ describe "::binary_osxfuse_installed?" do
+ it "returns false if fuse.h does not exist" do
+ allow(File).to receive(:exist?).and_return(false)
+ expect(described_class).not_to be_binary_osxfuse_installed
+ end
+
+ it "returns false if osxfuse include directory is a symlink" do
+ allow(File).to receive(:exist?).and_return(true)
+ allow(File).to receive(:symlink?).and_return(true)
+ expect(described_class).not_to be_binary_osxfuse_installed
+ end
+ end
+
+ describe "environment" do
+ it "adds the fuse directories to the appropriate paths" do
+ expect(ENV).to receive(:append_path).with("PKG_CONFIG_PATH", any_args)
+ expect(ENV).to receive(:append_path).with("HOMEBREW_LIBRARY_PATHS", any_args)
+ expect(ENV).to receive(:append_path).with("HOMEBREW_INCLUDE_PATHS", any_args)
+ subject.modify_build_environment
+ end
+ end
+end
+
+describe NonBinaryOsxfuseRequirement do
+ subject { described_class.new([]) }
+
+ describe "#message" do
+ msg = /osxfuse is already installed from the binary distribution/
+ its(:message) { is_expected.to match(msg) }
+ end
+end
diff --git a/Library/Homebrew/test/requirement_spec.rb b/Library/Homebrew/test/requirement_spec.rb
index 110a7ac4f..959041cf4 100644
--- a/Library/Homebrew/test/requirement_spec.rb
+++ b/Library/Homebrew/test/requirement_spec.rb
@@ -146,17 +146,13 @@ describe Requirement do
end
describe "#build?" do
- context "#build true is specified" do
- let(:klass) do
- Class.new(described_class) do
- build true
- end
- end
+ context ":build tag is specified" do
+ subject { described_class.new([:build]) }
it { is_expected.to be_a_build_requirement }
end
- context "#build ommitted" do
+ context "#build omitted" do
it { is_expected.not_to be_a_build_requirement }
end
end
diff --git a/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb
index 5be2d6cf5..a775b0b17 100644
--- a/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb
@@ -3,7 +3,7 @@ require "rubocop/rspec/support"
require_relative "../../extend/string"
require_relative "../../rubocops/bottle_block_cop"
-describe RuboCop::Cop::Homebrew::CorrectBottleBlock do
+describe RuboCop::Cop::FormulaAuditStrict::BottleBlock do
subject(:cop) { described_class.new }
context "When auditing Bottle Block" do
diff --git a/Library/Homebrew/test/rubocops/components_order_cop_spec.rb b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb
new file mode 100644
index 000000000..25467c635
--- /dev/null
+++ b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb
@@ -0,0 +1,163 @@
+require "rubocop"
+require "rubocop/rspec/support"
+require_relative "../../extend/string"
+require_relative "../../rubocops/components_order_cop"
+
+describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do
+ subject(:cop) { described_class.new }
+
+ context "When auditing formula components order" do
+ it "When url precedes homepage" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ homepage "http://example.com"
+ end
+ EOS
+
+ expected_offenses = [{ message: "`homepage` (line 3) should be put before `url` (line 2)",
+ severity: :convention,
+ line: 3,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When `resource` precedes `depends_on`" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "https://example.com/foo-1.0.tgz"
+
+ resource "foo2" do
+ url "https://example.com/foo-2.0.tgz"
+ end
+
+ depends_on "openssl"
+ end
+ EOS
+
+ expected_offenses = [{ message: "`depends_on` (line 8) should be put before `resource` (line 4)",
+ severity: :convention,
+ line: 8,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When `test` precedes `plist`" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "https://example.com/foo-1.0.tgz"
+
+ test do
+ expect(shell_output("./dogs")).to match("Dogs are terrific")
+ end
+
+ def plist
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "`plist` (line 8) should be put before `test` (line 4)",
+ severity: :convention,
+ line: 8,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When only one of many `depends_on` precedes `conflicts_with`" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ depends_on "autoconf" => :build
+ conflicts_with "visionmedia-watch"
+ depends_on "automake" => :build
+ depends_on "libtool" => :build
+ depends_on "pkg-config" => :build
+ depends_on "gettext"
+ end
+ EOS
+
+ expected_offenses = [{ message: "`depends_on` (line 4) should be put before `conflicts_with` (line 3)",
+ severity: :convention,
+ line: 4,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ def expect_offense(expected, actual)
+ expect(actual.message).to eq(expected[:message])
+ expect(actual.severity).to eq(expected[:severity])
+ expect(actual.line).to eq(expected[:line])
+ expect(actual.column).to eq(expected[:column])
+ end
+ end
+
+ context "When auditing formula components order with autocorrect" do
+ it "When url precedes homepage" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ homepage "http://example.com"
+ end
+ EOS
+ correct_source = <<-EOS.undent
+ class Foo < Formula
+ homepage "http://example.com"
+ url "http://example.com/foo-1.0.tgz"
+ end
+ EOS
+
+ corrected_source = autocorrect_source(cop, source)
+ expect(corrected_source).to eq(correct_source)
+ end
+
+ it "When `resource` precedes `depends_on`" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "https://example.com/foo-1.0.tgz"
+
+ resource "foo2" do
+ url "https://example.com/foo-2.0.tgz"
+ end
+
+ depends_on "openssl"
+ end
+ EOS
+ correct_source = <<-EOS.undent
+ class Foo < Formula
+ url "https://example.com/foo-1.0.tgz"
+
+ depends_on "openssl"
+
+ resource "foo2" do
+ url "https://example.com/foo-2.0.tgz"
+ end
+ end
+ EOS
+ corrected_source = autocorrect_source(cop, source)
+ expect(corrected_source).to eq(correct_source)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb
new file mode 100644
index 000000000..fd635a126
--- /dev/null
+++ b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb
@@ -0,0 +1,87 @@
+require "rubocop"
+require "rubocop/rspec/support"
+require_relative "../../extend/string"
+require_relative "../../rubocops/components_redundancy_cop"
+
+describe RuboCop::Cop::FormulaAuditStrict::ComponentsRedundancy do
+ subject(:cop) { described_class.new }
+
+ context "When auditing formula components common errors" do
+ it "When url outside stable block" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ stable do
+ # stuff
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "`url` should be put inside `stable` block",
+ severity: :convention,
+ line: 2,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When both `head` and `head do` are present" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ head "http://example.com/foo.git"
+ head do
+ # stuff
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "`head` and `head do` should not be simultaneously present",
+ severity: :convention,
+ line: 3,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When both `bottle :modifier` and `bottle do` are present" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ bottle do
+ # bottles go here
+ end
+ bottle :unneeded
+ end
+ EOS
+
+ expected_offenses = [{ message: "`bottle :modifier` and `bottle do` should not be simultaneously present",
+ severity: :convention,
+ line: 3,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ def expect_offense(expected, actual)
+ expect(actual.message).to eq(expected[:message])
+ expect(actual.severity).to eq(expected[:severity])
+ expect(actual.line).to eq(expected[:line])
+ expect(actual.column).to eq(expected[:column])
+ end
+ end
+end
diff --git a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb
index 04c4c27da..432b15e3c 100644
--- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb
@@ -3,7 +3,7 @@ require "rubocop/rspec/support"
require_relative "../../extend/string"
require_relative "../../rubocops/formula_desc_cop"
-describe RuboCop::Cop::Homebrew::FormulaDesc do
+describe RuboCop::Cop::FormulaAuditStrict::Desc do
subject(:cop) { described_class.new }
context "When auditing formula desc" do
@@ -51,6 +51,31 @@ describe RuboCop::Cop::Homebrew::FormulaDesc do
end
end
+ it "When desc is multiline string" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ desc '#{"bar"*10}'\
+ '#{"foo"*21}'
+ end
+ EOS
+
+ msg = <<-EOS.undent
+ Description is too long. "name: desc" should be less than 80 characters.
+ Length is calculated as Foo + desc. (currently 98)
+ EOS
+ expected_offenses = [{ message: msg,
+ severity: :convention,
+ line: 3,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
it "When wrong \"command-line\" usage in desc" do
source = <<-EOS.undent
class Foo < Formula
diff --git a/Library/Homebrew/test/rubocops/homepage_cop_spec.rb b/Library/Homebrew/test/rubocops/homepage_cop_spec.rb
new file mode 100644
index 000000000..c03efd825
--- /dev/null
+++ b/Library/Homebrew/test/rubocops/homepage_cop_spec.rb
@@ -0,0 +1,124 @@
+require "rubocop"
+require "rubocop/rspec/support"
+require_relative "../../extend/string"
+require_relative "../../rubocops/homepage_cop"
+
+describe RuboCop::Cop::FormulaAudit::Homepage do
+ subject(:cop) { described_class.new }
+
+ context "When auditing homepage" do
+ it "When there is no homepage" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ end
+ EOS
+
+ expected_offenses = [{ message: "Formula should have a homepage.",
+ severity: :convention,
+ line: 1,
+ column: 0,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "Homepage with ftp" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ homepage "ftp://example.com/foo"
+ url "http://example.com/foo-1.0.tgz"
+ end
+ EOS
+
+ expected_offenses = [{ message: "The homepage should start with http or https (URL is ftp://example.com/foo).",
+ severity: :convention,
+ line: 2,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "Homepage URLs" do
+ formula_homepages = {
+ "bar" => "http://www.freedesktop.org/wiki/bar",
+ "baz" => "http://www.freedesktop.org/wiki/Software/baz",
+ "qux" => "https://code.google.com/p/qux",
+ "quux" => "http://github.com/quux",
+ "corge" => "http://savannah.nongnu.org/corge",
+ "grault" => "http://grault.github.io/",
+ "garply" => "http://www.gnome.org/garply",
+ "sf1" => "http://foo.sourceforge.net/",
+ "sf2" => "http://foo.sourceforge.net",
+ "sf3" => "http://foo.sf.net/",
+ "sf4" => "http://foo.sourceforge.io/",
+ "waldo" => "http://www.gnu.org/waldo",
+ }
+
+ formula_homepages.each do |name, homepage|
+ source = <<-EOS.undent
+ class #{name.capitalize} < Formula
+ homepage "#{homepage}"
+ url "http://example.com/#{name}-1.0.tgz"
+ end
+ EOS
+
+ inspect_source(cop, source)
+ if homepage =~ %r{http:\/\/www\.freedesktop\.org}
+ if homepage =~ /Software/
+ expected_offenses = [{ message: "#{homepage} should be styled " \
+ "`https://wiki.freedesktop.org/www/Software/project_name`",
+ severity: :convention,
+ line: 2,
+ column: 2,
+ source: source }]
+ else
+ expected_offenses = [{ message: "#{homepage} should be styled " \
+ "`https://wiki.freedesktop.org/project_name`",
+ severity: :convention,
+ line: 2,
+ column: 2,
+ source: source }]
+ end
+ elsif homepage =~ %r{https:\/\/code\.google\.com}
+ expected_offenses = [{ message: "#{homepage} should end with a slash",
+ severity: :convention,
+ line: 2,
+ column: 2,
+ source: source }]
+ elsif homepage =~ /foo\.(sf|sourceforge)\.net/
+ expected_offenses = [{ message: "#{homepage} should be `https://foo.sourceforge.io/`",
+ severity: :convention,
+ line: 2,
+ column: 2,
+ source: source }]
+ else
+ expected_offenses = [{ message: "Please use https:// for #{homepage}",
+ severity: :convention,
+ line: 2,
+ column: 2,
+ source: source }]
+ end
+ expected_offenses.zip([cop.offenses.last]).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ end
+
+ def expect_offense(expected, actual)
+ expect(actual.message).to eq(expected[:message])
+ expect(actual.severity).to eq(expected[:severity])
+ expect(actual.line).to eq(expected[:line])
+ expect(actual.column).to eq(expected[:column])
+ end
+ end
+end
diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb
index 2f6274fd1..e193b91a0 100644
--- a/Library/Homebrew/test/spec_helper.rb
+++ b/Library/Homebrew/test/spec_helper.rb
@@ -61,6 +61,10 @@ RSpec.configure do |config|
skip "Python not installed." unless which("python")
end
+ config.before(:each, :needs_network) do
+ skip "Requires network connection." unless ENV["HOMEBREW_TEST_ONLINE"]
+ end
+
config.around(:each) do |example|
begin
TEST_DIRECTORIES.each(&:mkpath)
@@ -89,6 +93,7 @@ RSpec.configure do |config|
HOMEBREW_PREFIX/"opt",
HOMEBREW_PREFIX/"Caskroom",
HOMEBREW_LIBRARY/"Taps/caskroom",
+ HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-bar",
HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-bundle",
HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo",
HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-services",
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-non-executable-binary.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-non-executable-binary.rb
new file mode 100644
index 000000000..4bd2f0882
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-non-executable-binary.rb
@@ -0,0 +1,9 @@
+cask 'with-non-executable-binary' do
+ version '1.2.3'
+ sha256 'd5b2dfbef7ea28c25f7a77cd7fa14d013d82b626db1d82e00e25822464ba19e2'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/naked_non_executable"
+ homepage 'http://example.com/with-binary'
+
+ binary "naked_non_executable"
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/naked_non_executable b/Library/Homebrew/test/support/fixtures/cask/naked_non_executable
new file mode 100644
index 000000000..039e4d006
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/naked_non_executable
@@ -0,0 +1,2 @@
+#!/bin/sh
+exit 0
diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb
index b037068d2..ae1854f58 100644
--- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb
+++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb
@@ -72,6 +72,7 @@ RSpec.shared_context "integration test" do
env.merge!(
"PATH" => path,
+ "HOMEBREW_PATH" => path,
"HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew",
"HOMEBREW_INTEGRATION_TEST" => command_id_from_args(args),
"HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR,
diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb
new file mode 100644
index 000000000..9b539262f
--- /dev/null
+++ b/Library/Homebrew/test/utils/github_spec.rb
@@ -0,0 +1,13 @@
+require "utils/github"
+
+describe GitHub do
+ describe "::search_code", :needs_network do
+ it "searches code" do
+ results = subject.search_code("repo:Homebrew/brew", "path:/", "filename:readme", "language:markdown")
+
+ expect(results.count).to eq(1)
+ expect(results.first["name"]).to eq("README.md")
+ expect(results.first["path"]).to eq("README.md")
+ end
+ end
+end
diff --git a/Library/Homebrew/test/utils/shell_spec.rb b/Library/Homebrew/test/utils/shell_spec.rb
index c44bd8253..d32f9928f 100644
--- a/Library/Homebrew/test/utils/shell_spec.rb
+++ b/Library/Homebrew/test/utils/shell_spec.rb
@@ -1,92 +1,92 @@
require "utils/shell"
describe Utils::Shell do
- describe "::shell_profile" do
+ describe "::profile" do
it "returns ~/.bash_profile by default" do
ENV["SHELL"] = "/bin/another_shell"
- expect(subject.shell_profile).to eq("~/.bash_profile")
+ expect(subject.profile).to eq("~/.bash_profile")
end
it "returns ~/.bash_profile for Sh" do
ENV["SHELL"] = "/bin/another_shell"
- expect(subject.shell_profile).to eq("~/.bash_profile")
+ expect(subject.profile).to eq("~/.bash_profile")
end
it "returns ~/.bash_profile for Bash" do
ENV["SHELL"] = "/bin/bash"
- expect(subject.shell_profile).to eq("~/.bash_profile")
+ expect(subject.profile).to eq("~/.bash_profile")
end
it "returns ~/.zshrc for Zsh" do
ENV["SHELL"] = "/bin/zsh"
- expect(subject.shell_profile).to eq("~/.zshrc")
+ expect(subject.profile).to eq("~/.zshrc")
end
it "returns ~/.kshrc for Ksh" do
ENV["SHELL"] = "/bin/ksh"
- expect(subject.shell_profile).to eq("~/.kshrc")
+ expect(subject.profile).to eq("~/.kshrc")
end
end
- describe "::path_to_shell" do
+ describe "::from_path" do
it "supports a raw command name" do
- expect(subject.path_to_shell("bash")).to eq(:bash)
+ expect(subject.from_path("bash")).to eq(:bash)
end
it "supports full paths" do
- expect(subject.path_to_shell("/bin/bash")).to eq(:bash)
+ expect(subject.from_path("/bin/bash")).to eq(:bash)
end
it "supports versions" do
- expect(subject.path_to_shell("zsh-5.2")).to eq(:zsh)
+ expect(subject.from_path("zsh-5.2")).to eq(:zsh)
end
it "strips newlines" do
- expect(subject.path_to_shell("zsh-5.2\n")).to eq(:zsh)
+ expect(subject.from_path("zsh-5.2\n")).to eq(:zsh)
end
it "returns nil when input is invalid" do
- expect(subject.path_to_shell("")).to be nil
- expect(subject.path_to_shell("@@@@@@")).to be nil
- expect(subject.path_to_shell("invalid_shell-4.2")).to be nil
+ expect(subject.from_path("")).to be nil
+ expect(subject.from_path("@@@@@@")).to be nil
+ expect(subject.from_path("invalid_shell-4.2")).to be nil
end
end
specify "::sh_quote" do
- expect(subject.sh_quote("")).to eq("''")
- expect(subject.sh_quote("\\")).to eq("\\\\")
- expect(subject.sh_quote("\n")).to eq("'\n'")
- expect(subject.sh_quote("$")).to eq("\\$")
- expect(subject.sh_quote("word")).to eq("word")
+ expect(subject.send(:sh_quote, "")).to eq("''")
+ expect(subject.send(:sh_quote, "\\")).to eq("\\\\")
+ expect(subject.send(:sh_quote, "\n")).to eq("'\n'")
+ expect(subject.send(:sh_quote, "$")).to eq("\\$")
+ expect(subject.send(:sh_quote, "word")).to eq("word")
end
specify "::csh_quote" do
- expect(subject.csh_quote("")).to eq("''")
- expect(subject.csh_quote("\\")).to eq("\\\\")
+ expect(subject.send(:csh_quote, "")).to eq("''")
+ expect(subject.send(:csh_quote, "\\")).to eq("\\\\")
# note this test is different than for sh
- expect(subject.csh_quote("\n")).to eq("'\\\n'")
- expect(subject.csh_quote("$")).to eq("\\$")
- expect(subject.csh_quote("word")).to eq("word")
+ expect(subject.send(:csh_quote, "\n")).to eq("'\\\n'")
+ expect(subject.send(:csh_quote, "$")).to eq("\\$")
+ expect(subject.send(:csh_quote, "word")).to eq("word")
end
- describe "::prepend_path_in_shell_profile" do
+ describe "::prepend_path_in_profile" do
let(:path) { "/my/path" }
it "supports Tcsh" do
ENV["SHELL"] = "/bin/tcsh"
- expect(subject.prepend_path_in_shell_profile(path))
+ expect(subject.prepend_path_in_profile(path))
.to start_with("echo 'setenv PATH #{path}:$")
end
it "supports Bash" do
ENV["SHELL"] = "/bin/bash"
- expect(subject.prepend_path_in_shell_profile(path))
+ expect(subject.prepend_path_in_profile(path))
.to start_with("echo 'export PATH=\"#{path}:$")
end
it "supports Fish" do
ENV["SHELL"] = "/usr/local/bin/fish"
- expect(subject.prepend_path_in_shell_profile(path))
+ expect(subject.prepend_path_in_profile(path))
.to start_with("echo 'set -g fish_user_paths \"#{path}\" $fish_user_paths' >>")
end
end
diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb
index 314c299a8..be224990a 100644
--- a/Library/Homebrew/test/utils_spec.rb
+++ b/Library/Homebrew/test/utils_spec.rb
@@ -189,7 +189,13 @@ describe "globally-scoped helper methods" do
specify "#which_editor" do
ENV["HOMEBREW_EDITOR"] = "vemate"
- expect(which_editor).to eq("vemate")
+ ENV["HOMEBREW_PATH"] = dir
+
+ editor = "#{dir}/vemate"
+ FileUtils.touch editor
+ FileUtils.chmod 0755, editor
+
+ expect(which_editor).to eql editor
end
specify "#gzip" do
diff --git a/Library/Homebrew/test/version_spec.rb b/Library/Homebrew/test/version_spec.rb
index d3d63a25c..41e05019c 100644
--- a/Library/Homebrew/test/version_spec.rb
+++ b/Library/Homebrew/test/version_spec.rb
@@ -433,6 +433,11 @@ describe Version do
.to be_detected_from("https://homebrew.bintray.com/bottles/imagemagick-6.7.5-7.lion.bottle.1.tar.gz")
end
+ specify "date-based version style" do
+ expect(Version.create("2017-04-17"))
+ .to be_detected_from("https://example.com/dada-v2017-04-17.tar.gz")
+ end
+
specify "dash version style" do
expect(Version.create("3.4"))
.to be_detected_from("http://www.antlr.org/download/antlr-3.4-complete.jar")