language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
Homebrew
brew
10970a5c54c0723126bef3582f9e9a63d25e1b54.json
formula: clarify caveats usage.
Library/Homebrew/formula.rb
@@ -1026,7 +1026,9 @@ def run_post_install @prefix_returns_versioned_prefix = false end - # Tell the user about any caveats regarding this package. + # Tell the user about any Homebrew-specific caveats or locations regarding + # this package. These should not contain setup instructions that would apply + # to installation through a different package manager on a different OS. # @return [String] # <pre>def caveats # <<-EOS.undent
false
Other
Homebrew
brew
92710c50c65beccfc2fca744cc8ee1be19a87aad.json
Convert Download Strategies test to spec.
Library/Homebrew/test/download_strategies_spec.rb
@@ -0,0 +1,232 @@ +require "download_strategy" + +describe AbstractDownloadStrategy do + subject { described_class.new(name, resource) } + let(:name) { "foo" } + let(:url) { "http://example.com/foo.tar.gz" } + let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) } + let(:args) { %w[foo bar baz] } + + describe "#expand_safe_system_args" do + it "works with an explicit quiet flag" do + args << { quiet_flag: "--flag" } + expanded_args = subject.expand_safe_system_args(args) + expect(expanded_args).to eq(%w[foo bar baz --flag]) + end + + it "adds an implicit quiet flag" do + expanded_args = subject.expand_safe_system_args(args) + expect(expanded_args).to eq(%w[foo bar -q baz]) + end + + it "does not mutate the arguments" do + result = subject.expand_safe_system_args(args) + expect(args).to eq(%w[foo bar baz]) + expect(result).not_to be args + end + end + + specify "#source_modified_time" do + FileUtils.mktemp "mtime" do + FileUtils.touch "foo", mtime: Time.now - 10 + FileUtils.touch "bar", mtime: Time.now - 100 + FileUtils.ln_s "not-exist", "baz" + expect(subject.source_modified_time).to eq(File.mtime("foo")) + end + end +end + +describe VCSDownloadStrategy do + let(:url) { "http://example.com/bar" } + let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) } + + describe "#cached_location" do + it "returns the path of the cached resource" do + allow_any_instance_of(described_class).to receive(:cache_tag).and_return("foo") + downloader = described_class.new("baz", resource) + expect(downloader.cached_location).to eq(HOMEBREW_CACHE/"baz--foo") + end + end +end + +describe GitHubPrivateRepositoryDownloadStrategy do + subject { described_class.new("foo", resource) } + let(:url) { "https://github.com/owner/repo/archive/1.1.5.tar.gz" } + let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) } + + before(:each) do + ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token" + allow(GitHub).to receive(:repository).and_return({}) + end + + it "sets the @github_token instance variable" do + expect(subject.instance_variable_get(:@github_token)).to eq("token") + end + + it "parses the URL and sets the corresponding instance variables" do + expect(subject.instance_variable_get(:@owner)).to eq("owner") + expect(subject.instance_variable_get(:@repo)).to eq("repo") + expect(subject.instance_variable_get(:@filepath)).to eq("archive/1.1.5.tar.gz") + end + + its(:download_url) { is_expected.to eq("https://token@github.com/owner/repo/archive/1.1.5.tar.gz") } +end + +describe GitHubPrivateRepositoryReleaseDownloadStrategy do + subject { described_class.new("foo", resource) } + let(:url) { "https://github.com/owner/repo/releases/download/tag/foo_v0.1.0_darwin_amd64.tar.gz" } + let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) } + + before(:each) do + ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token" + allow(GitHub).to receive(:repository).and_return({}) + end + + it "parses the URL and sets the corresponding instance variables" do + expect(subject.instance_variable_get(:@owner)).to eq("owner") + expect(subject.instance_variable_get(:@repo)).to eq("repo") + expect(subject.instance_variable_get(:@tag)).to eq("tag") + expect(subject.instance_variable_get(:@filename)).to eq("foo_v0.1.0_darwin_amd64.tar.gz") + end + + describe "#download_url" do + it "returns the download URL for a given resource" do + allow(subject).to receive(:resolve_asset_id).and_return(456) + expect(subject.download_url).to eq("https://token@api.github.com/repos/owner/repo/releases/assets/456") + end + end + + specify "#resolve_asset_id" do + release_metadata = { + "assets" => [ + { + "id" => 123, + "name" => "foo_v0.1.0_linux_amd64.tar.gz", + }, + { + "id" => 456, + "name" => "foo_v0.1.0_darwin_amd64.tar.gz", + }, + ], + } + allow(subject).to receive(:fetch_release_metadata).and_return(release_metadata) + expect(subject.send(:resolve_asset_id)).to eq(456) + end + + describe "#fetch_release_metadata" do + it "fetches release metadata from GitHub" do + expected_release_url = "https://api.github.com/repos/owner/repo/releases/tags/tag" + expect(GitHub).to receive(:open).with(expected_release_url).and_return({}) + subject.send(:fetch_release_metadata) + end + end +end + +describe GitHubGitDownloadStrategy do + subject { described_class.new(name, resource) } + let(:name) { "brew" } + let(:url) { "https://github.com/homebrew/brew.git" } + let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) } + + it "parses the URL and sets the corresponding instance variables" do + expect(subject.instance_variable_get(:@user)).to eq("homebrew") + expect(subject.instance_variable_get(:@repo)).to eq("brew") + end +end + +describe GitDownloadStrategy do + subject { described_class.new(name, resource) } + let(:name) { "baz" } + let(:url) { "https://github.com/homebrew/foo" } + let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) } + let(:cached_location) { subject.cached_location } + + before(:each) do + @commit_id = 1 + FileUtils.mkpath cached_location + end + + def git_commit_all + shutup do + system "git", "add", "--all" + system "git", "commit", "-m", "commit number #{@commit_id}" + @commit_id += 1 + end + end + + def setup_git_repo + shutup do + system "git", "init" + system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" + end + FileUtils.touch "README" + git_commit_all + end + + describe "#source_modified_time" do + it "returns the right modification time" do + cached_location.cd do + setup_git_repo + end + expect(subject.source_modified_time.to_i).to eq(1_485_115_153) + end + end + + specify "#last_commit" do + cached_location.cd do + setup_git_repo + FileUtils.touch "LICENSE" + git_commit_all + end + expect(subject.last_commit).to eq("f68266e") + end + + describe "#fetch_last_commit" do + let(:url) { "file://#{remote_repo}" } + let(:version) { Version.create("HEAD") } + let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: version) } + let(:remote_repo) { HOMEBREW_PREFIX/"remote_repo" } + + before(:each) { remote_repo.mkpath } + + after(:each) { FileUtils.rm_rf remote_repo } + + it "fetches the hash of the last commit" do + remote_repo.cd do + setup_git_repo + FileUtils.touch "LICENSE" + git_commit_all + end + + subject.shutup! + expect(subject.fetch_last_commit).to eq("f68266e") + end + end +end + +describe DownloadStrategyDetector do + describe "::detect" do + subject { described_class.detect(url) } + let(:url) { Object.new } + + context "when given Git URL" do + let(:url) { "git://example.com/foo.git" } + it { is_expected.to eq(GitDownloadStrategy) } + end + + context "when given a GitHub Git URL" do + let(:url) { "https://github.com/homebrew/brew.git" } + it { is_expected.to eq(GitHubGitDownloadStrategy) } + end + + it "defaults to cURL" do + expect(subject).to eq(CurlDownloadStrategy) + end + + it "raises an error when passed an unrecognized strategy" do + expect { + described_class.detect("foo", Class.new) + }.to raise_error(TypeError) + end + end +end
true
Other
Homebrew
brew
92710c50c65beccfc2fca744cc8ee1be19a87aad.json
Convert Download Strategies test to spec.
Library/Homebrew/test/download_strategies_test.rb
@@ -1,245 +0,0 @@ -require "testing_env" -require "download_strategy" - -class ResourceDouble - attr_reader :url, :specs, :version, :mirrors - - def initialize(url = "http://example.com/foo.tar.gz", specs = {}) - @url = url - @specs = specs - @mirrors = [] - end -end - -class AbstractDownloadStrategyTests < Homebrew::TestCase - include FileUtils - - def setup - super - @name = "foo" - @resource = ResourceDouble.new - @strategy = AbstractDownloadStrategy.new(@name, @resource) - @args = %w[foo bar baz] - end - - def test_expand_safe_system_args_with_explicit_quiet_flag - @args << { quiet_flag: "--flag" } - expanded_args = @strategy.expand_safe_system_args(@args) - assert_equal %w[foo bar baz --flag], expanded_args - end - - def test_expand_safe_system_args_with_implicit_quiet_flag - expanded_args = @strategy.expand_safe_system_args(@args) - assert_equal %w[foo bar -q baz], expanded_args - end - - def test_expand_safe_system_args_does_not_mutate_argument - result = @strategy.expand_safe_system_args(@args) - assert_equal %w[foo bar baz], @args - refute_same @args, result - end - - def test_source_modified_time - mktemp "mtime" do - touch "foo", mtime: Time.now - 10 - touch "bar", mtime: Time.now - 100 - ln_s "not-exist", "baz" - assert_equal File.mtime("foo"), @strategy.source_modified_time - end - end -end - -class VCSDownloadStrategyTests < Homebrew::TestCase - def test_cache_filename - resource = ResourceDouble.new("http://example.com/bar") - strategy = Class.new(VCSDownloadStrategy) do - def cache_tag - "foo" - end - end - downloader = strategy.new("baz", resource) - assert_equal HOMEBREW_CACHE.join("baz--foo"), downloader.cached_location - end -end - -class GitHubPrivateRepositoryDownloadStrategyTests < Homebrew::TestCase - def setup - super - resource = ResourceDouble.new("https://github.com/owner/repo/archive/1.1.5.tar.gz") - ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token" - GitHub.stubs(:repository).returns {} - @strategy = GitHubPrivateRepositoryDownloadStrategy.new("foo", resource) - end - - def test_set_github_token - assert_equal "token", @strategy.instance_variable_get(:@github_token) - end - - def test_parse_url_pattern - assert_equal "owner", @strategy.instance_variable_get(:@owner) - assert_equal "repo", @strategy.instance_variable_get(:@repo) - assert_equal "archive/1.1.5.tar.gz", @strategy.instance_variable_get(:@filepath) - end - - def test_download_url - expected = "https://token@github.com/owner/repo/archive/1.1.5.tar.gz" - assert_equal expected, @strategy.download_url - end -end - -class GitHubPrivateRepositoryReleaseDownloadStrategyTests < Homebrew::TestCase - def setup - super - resource = ResourceDouble.new("https://github.com/owner/repo/releases/download/tag/foo_v0.1.0_darwin_amd64.tar.gz") - ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token" - GitHub.stubs(:repository).returns {} - @strategy = GitHubPrivateRepositoryReleaseDownloadStrategy.new("foo", resource) - end - - def test_parse_url_pattern - assert_equal "owner", @strategy.instance_variable_get(:@owner) - assert_equal "repo", @strategy.instance_variable_get(:@repo) - assert_equal "tag", @strategy.instance_variable_get(:@tag) - assert_equal "foo_v0.1.0_darwin_amd64.tar.gz", @strategy.instance_variable_get(:@filename) - end - - def test_download_url - @strategy.stubs(:resolve_asset_id).returns(456) - expected = "https://token@api.github.com/repos/owner/repo/releases/assets/456" - assert_equal expected, @strategy.download_url - end - - def test_resolve_asset_id - release_metadata = { - "assets" => [ - { - "id" => 123, - "name" => "foo_v0.1.0_linux_amd64.tar.gz", - }, - { - "id" => 456, - "name" => "foo_v0.1.0_darwin_amd64.tar.gz", - }, - ], - } - @strategy.stubs(:fetch_release_metadata).returns(release_metadata) - assert_equal 456, @strategy.send(:resolve_asset_id) - end - - def test_fetch_release_metadata - expected_release_url = "https://api.github.com/repos/owner/repo/releases/tags/tag" - github_mock = MiniTest::Mock.new - github_mock.expect :call, {}, [expected_release_url] - GitHub.stub :open, github_mock do - @strategy.send(:fetch_release_metadata) - end - github_mock.verify - end -end - -class GitDownloadStrategyTests < Homebrew::TestCase - include FileUtils - - def setup - super - resource = ResourceDouble.new("https://github.com/homebrew/foo") - @commit_id = 1 - @strategy = GitDownloadStrategy.new("baz", resource) - @cached_location = @strategy.cached_location - mkpath @cached_location - end - - def git_commit_all - shutup do - system "git", "add", "--all" - system "git", "commit", "-m", "commit number #{@commit_id}" - @commit_id += 1 - end - end - - def setup_git_repo - @cached_location.cd do - shutup do - system "git", "init" - system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" - end - touch "README" - git_commit_all - end - end - - def test_github_git_download_strategy_user_repo - resource = ResourceDouble.new("https://github.com/homebrew/brew.git") - strategy = GitHubGitDownloadStrategy.new("brew", resource) - - assert_equal strategy.instance_variable_get(:@user), "homebrew" - assert_equal strategy.instance_variable_get(:@repo), "brew" - end - - def test_source_modified_time - setup_git_repo - assert_equal 1_485_115_153, @strategy.source_modified_time.to_i - end - - def test_last_commit - setup_git_repo - @cached_location.cd do - touch "LICENSE" - git_commit_all - end - assert_equal "f68266e", @strategy.last_commit - end - - def test_fetch_last_commit - remote_repo = HOMEBREW_PREFIX.join("remote_repo") - remote_repo.mkdir - - resource = ResourceDouble.new("file://#{remote_repo}") - resource.instance_variable_set(:@version, Version.create("HEAD")) - @strategy = GitDownloadStrategy.new("baz", resource) - - remote_repo.cd do - shutup do - system "git", "init" - system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" - end - touch "README" - git_commit_all - touch "LICENSE" - git_commit_all - end - - @strategy.shutup! - assert_equal "f68266e", @strategy.fetch_last_commit - ensure - remote_repo.rmtree if remote_repo.directory? - end -end - -class DownloadStrategyDetectorTests < Homebrew::TestCase - def setup - super - @d = DownloadStrategyDetector.new - end - - def test_detect_git_download_startegy - @d = DownloadStrategyDetector.detect("git://example.com/foo.git") - assert_equal GitDownloadStrategy, @d - end - - def test_detect_github_git_download_strategy - @d = DownloadStrategyDetector.detect("https://github.com/homebrew/brew.git") - assert_equal GitHubGitDownloadStrategy, @d - end - - def test_default_to_curl_strategy - @d = DownloadStrategyDetector.detect(Object.new) - assert_equal CurlDownloadStrategy, @d - end - - def test_raises_when_passed_unrecognized_strategy - assert_raises(TypeError) do - DownloadStrategyDetector.detect("foo", Class.new) - end - end -end
true
Other
Homebrew
brew
5c185eaa4355810ccc6617cb078ee67d4fa0777c.json
Expand glob patterns.
Library/Homebrew/cask/lib/hbc/artifact/uninstall_base.rb
@@ -34,6 +34,10 @@ def self.expand_path_strings(path_strings) end end + def self.expand_glob(path_strings) + path_strings.flat_map(&Pathname.method(:glob)) + end + def self.remove_relative_path_strings(action, path_strings) relative = path_strings.map do |path_string| path_string if %r{/\.\.(?:/|\Z)}.match(path_string) || !%r{\A/}.match(path_string) @@ -54,6 +58,13 @@ def self.remove_undeletable_path_strings(action, path_strings) path_strings - undeletable end + def self.prepare_path_strings(action, path_strings, expand_tilde) + path_strings = expand_path_strings(path_strings) if expand_tilde + path_strings = remove_relative_path_strings(action, path_strings) + path_strings = expand_glob(path_strings) + remove_undeletable_path_strings(action, path_strings) + end + def dispatch_uninstall_directives(expand_tilde: true) directives_set = @cask.artifacts[stanza] ohai "Running #{stanza} process for #{@cask}; your password may be necessary" @@ -225,9 +236,7 @@ def uninstall_pkgutil(directives) def uninstall_delete(directives, expand_tilde = true) Array(directives[:delete]).concat(Array(directives[:trash])).flatten.each_slice(PATH_ARG_SLICE_SIZE) do |path_slice| ohai "Removing files: #{path_slice.utf8_inspect}" - path_slice = self.class.expand_path_strings(path_slice) if expand_tilde - path_slice = self.class.remove_relative_path_strings(:delete, path_slice) - path_slice = self.class.remove_undeletable_path_strings(:delete, path_slice) + path_slice = self.class.prepare_path_strings(:delete, path_slice, expand_tilde) @command.run!("/bin/rm", args: path_slice.unshift("-rf", "--"), sudo: true) end end @@ -238,11 +247,9 @@ def uninstall_trash(directives, expand_tilde = true) uninstall_delete(directives, expand_tilde) end - def uninstall_rmdir(directives, expand_tilde = true) - Array(directives[:rmdir]).flatten.each do |directory| - directory = self.class.expand_path_strings([directory]).first if expand_tilde - directory = self.class.remove_relative_path_strings(:rmdir, [directory]).first - directory = self.class.remove_undeletable_path_strings(:rmdir, [directory]).first + def uninstall_rmdir(directories, expand_tilde = true) + action = :rmdir + self.class.prepare_path_strings(action, Array(directories[action]).flatten, expand_tilde).each do |directory| next if directory.to_s.empty? ohai "Removing directory if empty: #{directory.to_s.utf8_inspect}" directory = Pathname.new(directory)
true
Other
Homebrew
brew
5c185eaa4355810ccc6617cb078ee67d4fa0777c.json
Expand glob patterns.
Library/Homebrew/cask/spec/cask/artifact/uninstall_spec.rb
@@ -7,7 +7,17 @@ Hbc::Artifact::Uninstall.new(cask, command: Hbc::FakeSystemCommand) } + let(:absolute_path) { Pathname.new("#{TEST_TMPDIR}/absolute_path") } + let(:path_with_tilde) { Pathname.new("#{TEST_TMPDIR}/path_with_tilde") } + let(:glob_path1) { Pathname.new("#{TEST_TMPDIR}/glob_path1") } + let(:glob_path2) { Pathname.new("#{TEST_TMPDIR}/glob_path2") } + before(:each) do + FileUtils.touch(absolute_path) + FileUtils.touch(path_with_tilde) + FileUtils.touch(glob_path1) + FileUtils.touch(glob_path2) + ENV["HOME"] = TEST_TMPDIR shutup do InstallHelper.install_without_artifacts(cask) end @@ -233,8 +243,10 @@ it "can uninstall" do Hbc::FakeSystemCommand.expects_command( sudo(%w[/bin/rm -rf --], - Pathname.new("/permissible/absolute/path"), - Pathname.new("~/permissible/path/with/tilde").expand_path), + absolute_path, + path_with_tilde, + glob_path1, + glob_path2), ) subject @@ -247,8 +259,10 @@ it "can uninstall" do Hbc::FakeSystemCommand.expects_command( sudo(%w[/bin/rm -rf --], - Pathname.new("/permissible/absolute/path"), - Pathname.new("~/permissible/path/with/tilde").expand_path), + absolute_path, + path_with_tilde, + glob_path1, + glob_path2), ) subject
true
Other
Homebrew
brew
5c185eaa4355810ccc6617cb078ee67d4fa0777c.json
Expand glob patterns.
Library/Homebrew/cask/spec/cask/artifact/zap_spec.rb
@@ -8,7 +8,17 @@ Hbc::Artifact::Zap.new(cask, command: Hbc::FakeSystemCommand) } + let(:absolute_path) { Pathname.new("#{TEST_TMPDIR}/absolute_path") } + let(:path_with_tilde) { Pathname.new("#{TEST_TMPDIR}/path_with_tilde") } + let(:glob_path1) { Pathname.new("#{TEST_TMPDIR}/glob_path1") } + let(:glob_path2) { Pathname.new("#{TEST_TMPDIR}/glob_path2") } + before(:each) do + FileUtils.touch(absolute_path) + FileUtils.touch(path_with_tilde) + FileUtils.touch(glob_path1) + FileUtils.touch(glob_path2) + ENV["HOME"] = TEST_TMPDIR shutup do InstallHelper.install_without_artifacts(cask) end @@ -234,8 +244,10 @@ it "can zap" do Hbc::FakeSystemCommand.expects_command( sudo(%w[/bin/rm -rf --], - Pathname.new("/permissible/absolute/path"), - Pathname.new("~/permissible/path/with/tilde").expand_path), + absolute_path, + path_with_tilde, + glob_path1, + glob_path2), ) subject @@ -248,8 +260,10 @@ it "can zap" do Hbc::FakeSystemCommand.expects_command( sudo(%w[/bin/rm -rf --], - Pathname.new("/permissible/absolute/path"), - Pathname.new("~/permissible/path/with/tilde").expand_path), + absolute_path, + path_with_tilde, + glob_path1, + glob_path2), ) subject
true
Other
Homebrew
brew
5c185eaa4355810ccc6617cb078ee67d4fa0777c.json
Expand glob patterns.
Library/Homebrew/test/support/fixtures/cask/Casks/with-installable.rb
@@ -11,8 +11,9 @@ quit: 'my.fancy.package.app', login_item: 'Fancy', delete: [ - '/permissible/absolute/path', - '~/permissible/path/with/tilde', + "#{TEST_TMPDIR}/absolute_path", + '~/path_with_tilde', + "#{TEST_TMPDIR}/glob_path*", 'impermissible/relative/path', '/another/impermissible/../relative/path', ],
true
Other
Homebrew
brew
5c185eaa4355810ccc6617cb078ee67d4fa0777c.json
Expand glob patterns.
Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-delete.rb
@@ -8,8 +8,9 @@ pkg 'Fancy.pkg' uninstall delete: [ - '/permissible/absolute/path', - '~/permissible/path/with/tilde', + "#{TEST_TMPDIR}/absolute_path", + '~/path_with_tilde', + "#{TEST_TMPDIR}/glob_path*", 'impermissible/relative/path', '/another/impermissible/../relative/path', ]
true
Other
Homebrew
brew
5c185eaa4355810ccc6617cb078ee67d4fa0777c.json
Expand glob patterns.
Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-trash.rb
@@ -8,8 +8,9 @@ pkg 'Fancy.pkg' uninstall trash: [ - '/permissible/absolute/path', - '~/permissible/path/with/tilde', + "#{TEST_TMPDIR}/absolute_path", + '~/path_with_tilde', + "#{TEST_TMPDIR}/glob_path*", 'impermissible/relative/path', '/another/impermissible/../relative/path', ]
true
Other
Homebrew
brew
5c185eaa4355810ccc6617cb078ee67d4fa0777c.json
Expand glob patterns.
Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-delete.rb
@@ -8,8 +8,9 @@ pkg 'Fancy.pkg' zap delete: [ - '/permissible/absolute/path', - '~/permissible/path/with/tilde', + "#{TEST_TMPDIR}/absolute_path", + '~/path_with_tilde', + "#{TEST_TMPDIR}/glob_path*", 'impermissible/relative/path', '/another/impermissible/../relative/path', ]
true
Other
Homebrew
brew
5c185eaa4355810ccc6617cb078ee67d4fa0777c.json
Expand glob patterns.
Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-trash.rb
@@ -8,8 +8,9 @@ pkg 'Fancy.pkg' zap trash: [ - '/permissible/absolute/path', - '~/permissible/path/with/tilde', + "#{TEST_TMPDIR}/absolute_path", + '~/path_with_tilde', + "#{TEST_TMPDIR}/glob_path*", 'impermissible/relative/path', '/another/impermissible/../relative/path', ]
true
Other
Homebrew
brew
e622116f277b49eec59f663417210c1770dd8c5a.json
.simplecov: require English with capital E On case-sensitive filesystems, require "english" will fail with "cannot load such file -- english"
Library/Homebrew/.simplecov
@@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require "english" +require "English" SimpleCov.start do coverage_dir File.expand_path("../test/coverage", File.realpath(__FILE__))
false
Other
Homebrew
brew
262f357d86f145fad3c78b3d843b32ac4e384f5e.json
Convert CompilerFailure test to spec.
Library/Homebrew/test/compiler_failure_spec.rb
@@ -0,0 +1,41 @@ +require "compilers" + +describe CompilerFailure do + matcher :fail_with do |expected| + match do |actual| + actual.fails_with?(expected) + end + end + + describe "::create" do + it "creates a failure when given a symbol" do + failure = described_class.create(:clang) + expect(failure).to fail_with(double("Compiler", name: :clang, version: 425)) + end + + it "can be given a build number in a block" do + failure = described_class.create(:clang) { build 211 } + expect(failure).to fail_with(double("Compiler", name: :clang, version: 210)) + expect(failure).not_to fail_with(double("Compiler", name: :clang, version: 318)) + end + + it "can be given an empty block" do + failure = described_class.create(:clang) {} + expect(failure).to fail_with(double("Compiler", name: :clang, version: 425)) + end + + it "creates a failure when given a hash" do + failure = described_class.create(gcc: "4.8") + expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8")) + expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8.1")) + expect(failure).not_to fail_with(double("Compiler", name: "gcc-4.7", version: "4.7")) + end + + it "creates a failure when given a hash and a block with aversion" do + failure = described_class.create(gcc: "4.8") { version "4.8.1" } + expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8")) + expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8.1")) + expect(failure).not_to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8.2")) + end + end +end
true
Other
Homebrew
brew
262f357d86f145fad3c78b3d843b32ac4e384f5e.json
Convert CompilerFailure test to spec.
Library/Homebrew/test/compiler_failure_test.rb
@@ -1,52 +0,0 @@ -require "testing_env" -require "compilers" - -class CompilerFailureTests < Homebrew::TestCase - Compiler = Struct.new(:name, :version) - - def assert_fails_with(compiler, failure) - assert_operator failure, :fails_with?, compiler - end - - def refute_fails_with(compiler, failure) - refute_operator failure, :fails_with?, compiler - end - - def compiler(name, version) - Compiler.new(name, version) - end - - def create(spec, &block) - CompilerFailure.create(spec, &block) - end - - def test_create_with_symbol - failure = create(:clang) - assert_fails_with compiler(:clang, 425), failure - end - - def test_create_with_block - failure = create(:clang) { build 211 } - assert_fails_with compiler(:clang, 210), failure - refute_fails_with compiler(:clang, 318), failure - end - - def test_create_with_block_without_build - failure = create(:clang) {} - assert_fails_with compiler(:clang, 425), failure - end - - def test_create_with_hash - failure = create(gcc: "4.8") - assert_fails_with compiler("gcc-4.8", "4.8"), failure - assert_fails_with compiler("gcc-4.8", "4.8.1"), failure - refute_fails_with compiler("gcc-4.7", "4.7"), failure - end - - def test_create_with_hash_and_version - failure = create(gcc: "4.8") { version "4.8.1" } - assert_fails_with compiler("gcc-4.8", "4.8"), failure - assert_fails_with compiler("gcc-4.8", "4.8.1"), failure - refute_fails_with compiler("gcc-4.8", "4.8.2"), failure - end -end
true
Other
Homebrew
brew
8736b6cee0d94c1927b7abaa3dbde0d3a0239b85.json
Convert Tty test to spec.
Library/Homebrew/test/utils/tty_spec.rb
@@ -0,0 +1,67 @@ +require "utils" + +describe Tty do + describe "::strip_ansi" do + it "removes ANSI escape codes from a string" do + expect(subject.strip_ansi("\033\[36;7mhello\033\[0m")).to eq("hello") + end + end + + describe "::width" do + it "returns an Integer" do + expect(subject.width).to be_kind_of(Integer) + end + + it "cannot be negative" do + expect(subject.width).to be >= 0 + end + end + + describe "::truncate" do + it "truncates the text to the terminal width, minus 4, to account for '==> '" do + allow(subject).to receive(:width).and_return(15) + + expect(subject.truncate("foobar something very long")).to eq("foobar some") + expect(subject.truncate("truncate")).to eq("truncate") + end + + it "doesn't truncate the text if the terminal is unsupported, i.e. the width is 0" do + allow(subject).to receive(:width).and_return(0) + expect(subject.truncate("foobar something very long")).to eq("foobar something very long") + end + end + + context "when $stdout is not a TTY" do + before(:each) do + allow($stdout).to receive(:tty?).and_return(false) + end + + it "returns an empty string for all colors" do + expect(subject.to_s).to eq("") + expect(subject.red.to_s).to eq("") + expect(subject.green.to_s).to eq("") + expect(subject.yellow.to_s).to eq("") + expect(subject.blue.to_s).to eq("") + expect(subject.magenta.to_s).to eq("") + expect(subject.cyan.to_s).to eq("") + expect(subject.default.to_s).to eq("") + end + end + + context "when $stdout is a TTY" do + before(:each) do + allow($stdout).to receive(:tty?).and_return(true) + end + + it "returns an empty string for all colors" do + expect(subject.to_s).to eq("") + expect(subject.red.to_s).to eq("\033[31m") + expect(subject.green.to_s).to eq("\033[32m") + expect(subject.yellow.to_s).to eq("\033[33m") + expect(subject.blue.to_s).to eq("\033[34m") + expect(subject.magenta.to_s).to eq("\033[35m") + expect(subject.cyan.to_s).to eq("\033[36m") + expect(subject.default.to_s).to eq("\033[39m") + end + end +end
true
Other
Homebrew
brew
8736b6cee0d94c1927b7abaa3dbde0d3a0239b85.json
Convert Tty test to spec.
Library/Homebrew/test/utils/tty_test.rb
@@ -1,46 +0,0 @@ -require "testing_env" -require "utils" - -class TtyTests < Homebrew::TestCase - def test_strip_ansi - assert_equal "hello", Tty.strip_ansi("\033\[36;7mhello\033\[0m") - end - - def test_width - assert_kind_of Integer, Tty.width - end - - def test_truncate - Tty.stubs(:width).returns 15 - assert_equal "foobar some", Tty.truncate("foobar something very long") - assert_equal "truncate", Tty.truncate("truncate") - - # When the terminal is unsupported, we report 0 width - Tty.stubs(:width).returns 0 - assert_equal "foobar something very long", Tty.truncate("foobar something very long") - end - - def test_no_tty_formatting - $stdout.stubs(:tty?).returns false - assert_equal "", Tty.to_s - assert_equal "", Tty.red.to_s - assert_equal "", Tty.green.to_s - assert_equal "", Tty.yellow.to_s - assert_equal "", Tty.blue.to_s - assert_equal "", Tty.magenta.to_s - assert_equal "", Tty.cyan.to_s - assert_equal "", Tty.default.to_s - end - - def test_formatting - $stdout.stubs(:tty?).returns(true) - assert_equal "", Tty.to_s - assert_equal "\033[31m", Tty.red.to_s - assert_equal "\033[32m", Tty.green.to_s - assert_equal "\033[33m", Tty.yellow.to_s - assert_equal "\033[34m", Tty.blue.to_s - assert_equal "\033[35m", Tty.magenta.to_s - assert_equal "\033[36m", Tty.cyan.to_s - assert_equal "\033[39m", Tty.default.to_s - end -end
true
Other
Homebrew
brew
8fee9bf44dad59b422293b6eb37ac83435475b01.json
Convert MPIRequirement test to spec.
Library/Homebrew/test/mpi_requirement_spec.rb
@@ -0,0 +1,14 @@ +require "requirements/mpi_requirement" + +describe MPIRequirement do + describe "::new" do + subject { described_class.new(*(wrappers + tags)) } + let(:wrappers) { [:cc, :cxx, :f77] } + let(:tags) { [:optional, "some-other-tag"] } + + it "untangles wrappers and tags" do + expect(subject.lang_list).to eq(wrappers) + expect(subject.tags).to eq(tags) + end + end +end
true
Other
Homebrew
brew
8fee9bf44dad59b422293b6eb37ac83435475b01.json
Convert MPIRequirement test to spec.
Library/Homebrew/test/mpi_requirement_test.rb
@@ -1,12 +0,0 @@ -require "testing_env" -require "requirements/mpi_requirement" - -class MPIRequirementTests < Homebrew::TestCase - def test_initialize_untangles_tags_and_wrapper_symbols - wrappers = [:cc, :cxx, :f77] - tags = [:optional, "some-other-tag"] - dep = MPIRequirement.new(*wrappers + tags) - assert_equal wrappers, dep.lang_list - assert_equal tags, dep.tags - end -end
true
Other
Homebrew
brew
99da779434bda113f50f4a17880d1dfcacd93d24.json
Convert Gpg test to spec.
Library/Homebrew/test/gpg_spec.rb
@@ -0,0 +1,21 @@ +require "gpg" + +describe Gpg do + subject { described_class } + + describe "::create_test_key" do + it "creates a test key in the home directory" do + skip "GPG Unavailable" unless subject.available? + + Dir.mktmpdir do |dir| + ENV["HOME"] = dir + dir = Pathname.new(dir) + + shutup do + subject.create_test_key(dir) + end + expect(dir/".gnupg/secring.gpg").to exist + end + end + end +end
true
Other
Homebrew
brew
99da779434bda113f50f4a17880d1dfcacd93d24.json
Convert Gpg test to spec.
Library/Homebrew/test/gpg_test.rb
@@ -1,18 +0,0 @@ -require "testing_env" -require "gpg" - -class GpgTest < Homebrew::TestCase - def setup - super - skip "GPG Unavailable" unless Gpg.available? - @dir = Pathname.new(mktmpdir) - end - - def test_create_test_key - Dir.chdir(@dir) do - ENV["HOME"] = @dir - shutup { Gpg.create_test_key(@dir) } - assert_predicate @dir/".gnupg/secring.gpg", :exist? - end - end -end
true
Other
Homebrew
brew
779d9ce60fd931b5ac1819209bf00470703f6a55.json
Convert PkgVersion test to spec.
Library/Homebrew/test/pkg_version_spec.rb
@@ -0,0 +1,81 @@ +require "pkg_version" + +describe PkgVersion do + describe "::parse" do + it "parses versions from a string" do + expect(described_class.parse("1.0_1")).to eq(described_class.new(Version.create("1.0"), 1)) + expect(described_class.parse("1.0_1")).to eq(described_class.new(Version.create("1.0"), 1)) + expect(described_class.parse("1.0")).to eq(described_class.new(Version.create("1.0"), 0)) + expect(described_class.parse("1.0_0")).to eq(described_class.new(Version.create("1.0"), 0)) + expect(described_class.parse("2.1.4_0")).to eq(described_class.new(Version.create("2.1.4"), 0)) + expect(described_class.parse("1.0.1e_1")).to eq(described_class.new(Version.create("1.0.1e"), 1)) + end + end + + specify "#==" do + expect(described_class.parse("1.0_0")).to be == described_class.parse("1.0") + expect(described_class.parse("1.0_1")).to be == described_class.parse("1.0_1") + end + + describe "#>" do + it "returns true if the left version is bigger than the right" do + expect(described_class.parse("1.1")).to be > described_class.parse("1.0_1") + end + + it "returns true if the left version is HEAD" do + expect(described_class.parse("HEAD")).to be > described_class.parse("1.0") + end + + it "raises an error if the other side isn't of the same class" do + expect { + described_class.new(Version.create("1.0"), 0) > Object.new + }.to raise_error(ArgumentError) + end + + it "is not compatible with Version" do + expect { + described_class.new(Version.create("1.0"), 0) > Version.create("1.0") + }.to raise_error(ArgumentError) + end + end + + describe "#<" do + it "returns true if the left version is smaller than the right" do + expect(described_class.parse("1.0_1")).to be < described_class.parse("2.0_1") + end + + it "returns true if the right version is HEAD" do + expect(described_class.parse("1.0")).to be < described_class.parse("HEAD") + end + end + + describe "#<=>" do + it "returns nil if the comparison fails" do + expect(described_class.new(Version.create("1.0"), 0) <=> Object.new).to be nil + end + end + + describe "#to_s" do + it "returns a string of the form 'version_revision'" do + expect(described_class.new(Version.create("1.0"), 0).to_s).to eq("1.0") + expect(described_class.new(Version.create("1.0"), 1).to_s).to eq("1.0_1") + expect(described_class.new(Version.create("1.0"), 0).to_s).to eq("1.0") + expect(described_class.new(Version.create("1.0"), 0).to_s).to eq("1.0") + expect(described_class.new(Version.create("HEAD"), 1).to_s).to eq("HEAD_1") + expect(described_class.new(Version.create("HEAD-ffffff"), 1).to_s).to eq("HEAD-ffffff_1") + end + end + + describe "#hash" do + let(:p1) { described_class.new(Version.create("1.0"), 1) } + let(:p2) { described_class.new(Version.create("1.0"), 1) } + let(:p3) { described_class.new(Version.create("1.1"), 1) } + let(:p4) { described_class.new(Version.create("1.0"), 0) } + + it "returns a hash based on the version and revision" do + expect(p1.hash).to eq(p2.hash) + expect(p1.hash).not_to eq(p3.hash) + expect(p1.hash).not_to eq(p4.hash) + end + end +end
true
Other
Homebrew
brew
779d9ce60fd931b5ac1819209bf00470703f6a55.json
Convert PkgVersion test to spec.
Library/Homebrew/test/pkg_version_test.rb
@@ -1,51 +0,0 @@ -require "testing_env" -require "pkg_version" - -class PkgVersionTests < Homebrew::TestCase - def v(version) - PkgVersion.parse(version) - end - - def test_parse - assert_equal PkgVersion.new(Version.create("1.0"), 1), PkgVersion.parse("1.0_1") - assert_equal PkgVersion.new(Version.create("1.0"), 1), PkgVersion.parse("1.0_1") - assert_equal PkgVersion.new(Version.create("1.0"), 0), PkgVersion.parse("1.0") - assert_equal PkgVersion.new(Version.create("1.0"), 0), PkgVersion.parse("1.0_0") - assert_equal PkgVersion.new(Version.create("2.1.4"), 0), PkgVersion.parse("2.1.4_0") - assert_equal PkgVersion.new(Version.create("1.0.1e"), 1), PkgVersion.parse("1.0.1e_1") - end - - def test_comparison - assert_operator v("1.0_0"), :==, v("1.0") - assert_operator v("1.0_1"), :==, v("1.0_1") - assert_operator v("1.1"), :>, v("1.0_1") - assert_operator v("1.0_0"), :==, v("1.0") - assert_operator v("1.0_1"), :<, v("2.0_1") - assert_operator v("HEAD"), :>, v("1.0") - assert_operator v("1.0"), :<, v("HEAD") - - v = PkgVersion.new(Version.create("1.0"), 0) - assert_nil v <=> Object.new - assert_raises(ArgumentError) { v > Object.new } - assert_raises(ArgumentError) { v > Version.create("1.0") } - end - - def test_to_s - assert_equal "1.0", PkgVersion.new(Version.create("1.0"), 0).to_s - assert_equal "1.0_1", PkgVersion.new(Version.create("1.0"), 1).to_s - assert_equal "1.0", PkgVersion.new(Version.create("1.0"), 0).to_s - assert_equal "1.0", PkgVersion.new(Version.create("1.0"), 0).to_s - assert_equal "HEAD_1", PkgVersion.new(Version.create("HEAD"), 1).to_s - assert_equal "HEAD-ffffff_1", PkgVersion.new(Version.create("HEAD-ffffff"), 1).to_s - end - - def test_hash - p1 = PkgVersion.new(Version.create("1.0"), 1) - p2 = PkgVersion.new(Version.create("1.0"), 1) - p3 = PkgVersion.new(Version.create("1.1"), 1) - p4 = PkgVersion.new(Version.create("1.0"), 0) - assert_equal p1.hash, p2.hash - refute_equal p1.hash, p3.hash - refute_equal p1.hash, p4.hash - end -end
true
Other
Homebrew
brew
f8ea9266410c0c2733b6de3c5a3e690842e7b9a8.json
Convert Language::Go test to spec.
Library/Homebrew/test/language/go_spec.rb
@@ -0,0 +1,15 @@ +require "language/go" + +describe Language::Go do + specify "#stage_deps" do + ENV.delete("HOMEBREW_DEVELOPER") + + expect(described_class).to receive(:opoo).once + + Dir.mktmpdir do |path| + shutup do + described_class.stage_deps [], path + end + end + end +end
true
Other
Homebrew
brew
f8ea9266410c0c2733b6de3c5a3e690842e7b9a8.json
Convert Language::Go test to spec.
Library/Homebrew/test/language_go_test.rb
@@ -1,17 +0,0 @@ -# -*- coding: UTF-8 -*- - -require "testing_env" -require "language/go" - -class LanguageGoTests < Homebrew::TestCase - def test_stage_deps_empty - if ARGV.homebrew_developer? - Language::Go.expects(:odie).once - else - Language::Go.expects(:opoo).once - end - mktmpdir do |path| - shutup { Language::Go.stage_deps [], path } - end - end -end
true
Other
Homebrew
brew
ecb17f4f1d265e1625828565ecbbdac6d5f989c6.json
Add test for `uninstall` before removing artifacts.
Library/Homebrew/cask/spec/cask/cli/uninstall_spec.rb
@@ -41,6 +41,25 @@ expect(Hbc.appdir.join("Caffeine.app")).not_to exist end + it "calls `uninstall` before removing artifacts" do + cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script-app.rb") + + shutup do + Hbc::Installer.new(cask).install + end + + expect(cask).to be_installed + + expect { + shutup do + Hbc::CLI::Uninstall.run("with-uninstall-script-app") + end + }.not_to raise_error + + expect(cask).not_to be_installed + expect(Hbc.appdir.join("MyFancyApp.app")).not_to exist + end + describe "when multiple versions of a cask are installed" do let(:token) { "versioned-cask" } let(:first_installed_version) { "1.2.3" }
true
Other
Homebrew
brew
ecb17f4f1d265e1625828565ecbbdac6d5f989c6.json
Add test for `uninstall` before removing artifacts.
Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-script-app.rb
@@ -0,0 +1,21 @@ +cask 'with-uninstall-script-app' do + version '1.2.3' + sha256 '5633c3a0f2e572cbf021507dec78c50998b398c343232bdfc7e26221d0a5db4d' + + url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyApp.zip" + homepage 'http://example.com/MyFancyApp' + + app 'MyFancyApp/MyFancyApp.app' + + postflight do + IO.write "#{appdir}/MyFancyApp.app/uninstall.sh", <<-EOS.undent + #!/bin/sh + /bin/rm -r "#{appdir}/MyFancyApp.app" + EOS + end + + uninstall script: { + executable: "#{appdir}/MyFancyApp.app/uninstall.sh", + sudo: false + } +end
true
Other
Homebrew
brew
66735b91a316e2d56ad484699178496da5c83656.json
Convert Descriptions test to spec.
Library/Homebrew/test/descriptions_spec.rb
@@ -0,0 +1,42 @@ +require "descriptions" + +describe Descriptions do + subject { described_class.new(descriptions_hash) } + let(:descriptions_hash) { {} } + + it "can print description for a core Formula" do + descriptions_hash["homebrew/core/foo"] = "Core foo" + expect { subject.print }.to output("foo: Core foo\n").to_stdout + end + + it "can print description for an external Formula" do + descriptions_hash["somedev/external/foo"] = "External foo" + expect { subject.print }.to output("foo: External foo\n").to_stdout + end + + it "can print descriptions for duplicate Formulae" do + descriptions_hash["homebrew/core/foo"] = "Core foo" + descriptions_hash["somedev/external/foo"] = "External foo" + + expect { subject.print }.to output( + <<-EOS.undent + homebrew/core/foo: Core foo + somedev/external/foo: External foo + EOS + ).to_stdout + end + + it "can print descriptions for duplicate core and external Formulae" do + descriptions_hash["homebrew/core/foo"] = "Core foo" + descriptions_hash["somedev/external/foo"] = "External foo" + descriptions_hash["otherdev/external/foo"] = "Other external foo" + + expect { subject.print }.to output( + <<-EOS.undent + homebrew/core/foo: Core foo + otherdev/external/foo: Other external foo + somedev/external/foo: External foo + EOS + ).to_stdout + end +end
true
Other
Homebrew
brew
66735b91a316e2d56ad484699178496da5c83656.json
Convert Descriptions test to spec.
Library/Homebrew/test/descriptions_test.rb
@@ -1,48 +0,0 @@ -require "testing_env" -require "descriptions" - -class DescriptionsTest < Homebrew::TestCase - def setup - super - - @descriptions_hash = {} - @descriptions = Descriptions.new(@descriptions_hash) - - @old_stdout = $stdout - $stdout = StringIO.new - end - - def teardown - $stdout = @old_stdout - super - end - - def test_single_core_formula - @descriptions_hash["homebrew/core/foo"] = "Core foo" - @descriptions.print - assert_equal "foo: Core foo", $stdout.string.chomp - end - - def test_single_external_formula - @descriptions_hash["somedev/external/foo"] = "External foo" - @descriptions.print - assert_equal "foo: External foo", $stdout.string.chomp - end - - def test_even_dupes - @descriptions_hash["homebrew/core/foo"] = "Core foo" - @descriptions_hash["somedev/external/foo"] = "External foo" - @descriptions.print - assert_equal "homebrew/core/foo: Core foo\nsomedev/external/foo: External foo", - $stdout.string.chomp - end - - def test_odd_dupes - @descriptions_hash["homebrew/core/foo"] = "Core foo" - @descriptions_hash["somedev/external/foo"] = "External foo" - @descriptions_hash["otherdev/external/foo"] = "Other external foo" - @descriptions.print - assert_equal "homebrew/core/foo: Core foo\notherdev/external/foo: Other external foo\nsomedev/external/foo: External foo", - $stdout.string.chomp - end -end
true
Other
Homebrew
brew
f581ad7f0b73e0a8d38868d2d4fa85bb7fb0c486.json
Convert BuildEnvironment test to spec.
Library/Homebrew/test/build_environment_spec.rb
@@ -0,0 +1,66 @@ +require "build_environment" + +RSpec::Matchers.alias_matcher :use_userpaths, :be_userpaths + +describe BuildEnvironment do + let(:env) { described_class.new } + + describe "#<<" do + it "returns itself" do + expect(env << :foo).to be env + end + end + + describe "#merge" do + it "returns itself" do + expect(env.merge([])).to be env + end + end + + describe "#std?" do + it "returns true if the environment contains :std" do + env << :std + expect(env).to be_std + end + + it "returns false if the environment does not contain :std" do + expect(env).not_to be_std + end + end + + describe "#userpaths?" do + it "returns true if the environment contains :userpaths" do + env << :userpaths + expect(env).to use_userpaths + end + + it "returns false if the environment does not contain :userpaths" do + expect(env).not_to use_userpaths + end + end +end + +describe BuildEnvironmentDSL do + subject { double.extend(described_class) } + + context "single argument" do + before(:each) do + subject.instance_eval do + env :userpaths + end + end + + its(:env) { is_expected.to use_userpaths } + end + + context "multiple arguments" do + before(:each) do + subject.instance_eval do + env :userpaths, :std + end + end + + its(:env) { is_expected.to be_std } + its(:env) { is_expected.to use_userpaths } + end +end
true
Other
Homebrew
brew
f581ad7f0b73e0a8d38868d2d4fa85bb7fb0c486.json
Convert BuildEnvironment test to spec.
Library/Homebrew/test/build_environment_test.rb
@@ -1,46 +0,0 @@ -require "testing_env" -require "build_environment" - -class BuildEnvironmentTests < Homebrew::TestCase - def setup - super - @env = BuildEnvironment.new - end - - def test_shovel_returns_self - assert_same @env, @env << :foo - end - - def test_merge_returns_self - assert_same @env, @env.merge([]) - end - - def test_std? - @env << :std - assert_predicate @env, :std? - end - - def test_userpaths? - @env << :userpaths - assert_predicate @env, :userpaths? - end -end - -class BuildEnvironmentDSLTests < Homebrew::TestCase - def make_instance(&block) - obj = Object.new.extend(BuildEnvironmentDSL) - obj.instance_eval(&block) - obj - end - - def test_env_single_argument - obj = make_instance { env :userpaths } - assert_predicate obj.env, :userpaths? - end - - def test_env_multiple_arguments - obj = make_instance { env :userpaths, :std } - assert_predicate obj.env, :userpaths? - assert_predicate obj.env, :std? - end -end
true
Other
Homebrew
brew
b89c0f16dd5e5d75e6e72187bf2956ce456c8090.json
Convert CxxStdlib test to spec.
Library/Homebrew/test/cxxstdlib_spec.rb
@@ -0,0 +1,68 @@ +require "formula" +require "cxxstdlib" + +describe CxxStdlib do + let(:clang) { CxxStdlib.create(:libstdcxx, :clang) } + let(:gcc) { CxxStdlib.create(:libstdcxx, :gcc) } + let(:gcc40) { CxxStdlib.create(:libstdcxx, :gcc_4_0) } + let(:gcc42) { CxxStdlib.create(:libstdcxx, :gcc_4_2) } + let(:gcc48) { CxxStdlib.create(:libstdcxx, "gcc-4.8") } + let(:gcc49) { CxxStdlib.create(:libstdcxx, "gcc-4.9") } + let(:lcxx) { CxxStdlib.create(:libcxx, :clang) } + let(:purec) { CxxStdlib.create(nil, :clang) } + + describe "#compatible_with?" do + specify "Apple libstdcxx intercompatibility" do + expect(clang).to be_compatible_with(gcc) + expect(clang).to be_compatible_with(gcc42) + end + + specify "compatibility with itself" do + expect(gcc).to be_compatible_with(gcc) + expect(gcc48).to be_compatible_with(gcc48) + expect(clang).to be_compatible_with(clang) + end + + specify "Apple/GNU libstdcxx incompatibility" do + expect(clang).not_to be_compatible_with(gcc48) + expect(gcc48).not_to be_compatible_with(clang) + end + + specify "GNU cross-version incompatibility" do + expect(gcc48).not_to be_compatible_with(gcc49) + expect(gcc49).not_to be_compatible_with(gcc48) + end + + specify "libstdcxx and libcxx incompatibility" do + expect(clang).not_to be_compatible_with(lcxx) + expect(lcxx).not_to be_compatible_with(clang) + end + + specify "compatibility for non-cxx software" do + expect(purec).to be_compatible_with(clang) + expect(clang).to be_compatible_with(purec) + expect(purec).to be_compatible_with(purec) + expect(purec).to be_compatible_with(gcc48) + expect(gcc48).to be_compatible_with(purec) + end + end + + describe "#apple_compiler?" do + it "returns true for Apple compilers" do + expect(clang).to be_an_apple_compiler + expect(gcc).to be_an_apple_compiler + expect(gcc42).to be_an_apple_compiler + end + + it "returns false for non-Apple compilers" do + expect(gcc48).not_to be_an_apple_compiler + end + end + + describe "#type_string" do + specify "formatting" do + expect(clang.type_string).to eq("libstdc++") + expect(lcxx.type_string).to eq("libc++") + end + end +end
true
Other
Homebrew
brew
b89c0f16dd5e5d75e6e72187bf2956ce456c8090.json
Convert CxxStdlib test to spec.
Library/Homebrew/test/stdlib_test.rb
@@ -1,63 +0,0 @@ -require "testing_env" -require "formula" -require "cxxstdlib" - -class CxxStdlibTests < Homebrew::TestCase - def setup - super - @clang = CxxStdlib.create(:libstdcxx, :clang) - @gcc = CxxStdlib.create(:libstdcxx, :gcc) - @gcc40 = CxxStdlib.create(:libstdcxx, :gcc_4_0) - @gcc42 = CxxStdlib.create(:libstdcxx, :gcc_4_2) - @gcc48 = CxxStdlib.create(:libstdcxx, "gcc-4.8") - @gcc49 = CxxStdlib.create(:libstdcxx, "gcc-4.9") - @lcxx = CxxStdlib.create(:libcxx, :clang) - @purec = CxxStdlib.create(nil, :clang) - end - - def test_apple_libstdcxx_intercompatibility - assert @clang.compatible_with?(@gcc) - assert @clang.compatible_with?(@gcc42) - end - - def test_compatibility_same_compilers_and_type - assert @gcc.compatible_with?(@gcc) - assert @gcc48.compatible_with?(@gcc48) - assert @clang.compatible_with?(@clang) - end - - def test_apple_gnu_libstdcxx_incompatibility - assert !@clang.compatible_with?(@gcc48) - assert !@gcc48.compatible_with?(@clang) - end - - def test_gnu_cross_version_incompatibility - assert !@gcc48.compatible_with?(@gcc49) - assert !@gcc49.compatible_with?(@gcc48) - end - - def test_libstdcxx_libcxx_incompatibility - assert !@clang.compatible_with?(@lcxx) - assert !@lcxx.compatible_with?(@clang) - end - - def test_apple_compiler_reporting - assert_predicate @clang, :apple_compiler? - assert_predicate @gcc, :apple_compiler? - assert_predicate @gcc42, :apple_compiler? - refute_predicate @gcc48, :apple_compiler? - end - - def test_type_string_formatting - assert_equal "libstdc++", @clang.type_string - assert_equal "libc++", @lcxx.type_string - end - - def test_compatibility_for_non_cxx_software - assert @purec.compatible_with?(@clang) - assert @clang.compatible_with?(@purec) - assert @purec.compatible_with?(@purec) - assert @purec.compatible_with?(@gcc48) - assert @gcc48.compatible_with?(@purec) - end -end
true
Other
Homebrew
brew
279831fc0e3241eda17b6007aef02299b3c82c9e.json
Convert Exceptions test to spec.
Library/Homebrew/test/exceptions_spec.rb
@@ -0,0 +1,188 @@ +require "exceptions" + +describe MultipleVersionsInstalledError do + subject { described_class.new("foo") } + its(:to_s) { is_expected.to eq("foo has multiple installed versions") } +end + +describe NoSuchKegError do + subject { described_class.new("foo") } + its(:to_s) { is_expected.to eq("No such keg: #{HOMEBREW_CELLAR}/foo") } +end + +describe FormulaValidationError do + subject { described_class.new("foo", "sha257", "magic") } + its(:to_s) { + is_expected.to eq(%q(invalid attribute for formula 'foo': sha257 ("magic"))) + } +end + +describe FormulaUnavailableError do + subject { described_class.new("foo") } + + describe "#dependent_s" do + it "returns nil if there is no dependent" do + expect(subject.dependent_s).to be nil + end + + it "returns nil if it depended on by itself" do + subject.dependent = "foo" + expect(subject.dependent_s).to be nil + end + + it "returns a string if there is a dependent" do + subject.dependent = "foobar" + expect(subject.dependent_s).to eq("(dependency of foobar)") + end + end + + context "without a dependent" do + its(:to_s) { is_expected.to eq('No available formula with the name "foo" ') } + end + + context "with a dependent" do + before(:each) do + subject.dependent = "foobar" + end + + its(:to_s) { + is_expected.to eq('No available formula with the name "foo" (dependency of foobar)') + } + end +end + +describe TapFormulaUnavailableError do + subject { described_class.new(tap, "foo") } + let(:tap) { double(Tap, user: "u", repo: "r", to_s: "u/r", installed?: false) } + its(:to_s) { is_expected.to match(%r{Please tap it and then try again: brew tap u/r}) } +end + +describe FormulaClassUnavailableError do + subject { described_class.new("foo", "foo.rb", "Foo", list) } + let(:mod) do + Module.new do + class Bar < Requirement; end + class Baz < Formula; end + end + end + + context "no classes" do + let(:list) { [] } + its(:to_s) { + is_expected.to match(/Expected to find class Foo, but found no classes\./) + } + end + + context "class not derived from Formula" do + let(:list) { [mod.const_get(:Bar)] } + its(:to_s) { + is_expected.to match(/Expected to find class Foo, but only found: Bar \(not derived from Formula!\)\./) + } + end + + context "class derived from Formula" do + let(:list) { [mod.const_get(:Baz)] } + its(:to_s) { is_expected.to match(/Expected to find class Foo, but only found: Baz\./) } + end +end + +describe FormulaUnreadableError do + subject { described_class.new("foo", formula_error) } + let(:formula_error) { LoadError.new("bar") } + its(:to_s) { is_expected.to eq("foo: bar") } +end + +describe TapUnavailableError do + subject { described_class.new("foo") } + its(:to_s) { is_expected.to eq("No available tap foo.\n") } +end + +describe TapAlreadyTappedError do + subject { described_class.new("foo") } + its(:to_s) { is_expected.to eq("Tap foo already tapped.\n") } +end + +describe TapPinStatusError do + context "pinned" do + subject { described_class.new("foo", true) } + its(:to_s) { is_expected.to eq("foo is already pinned.") } + end + + context "unpinned" do + subject { described_class.new("foo", false) } + its(:to_s) { is_expected.to eq("foo is already unpinned.") } + end +end + +describe BuildError do + subject { described_class.new(formula, "badprg", %w[arg1 arg2], {}) } + let(:formula) { double(Formula, name: "foo") } + its(:to_s) { is_expected.to eq("Failed executing: badprg arg1 arg2") } +end + +describe OperationInProgressError do + subject { described_class.new("foo") } + its(:to_s) { is_expected.to match(/Operation already in progress for foo/) } +end + +describe FormulaInstallationAlreadyAttemptedError do + subject { described_class.new(formula) } + let(:formula) { double(Formula, full_name: "foo/bar") } + its(:to_s) { is_expected.to eq("Formula installation already attempted: foo/bar") } +end + +describe FormulaConflictError do + subject { described_class.new(formula, [conflict]) } + let(:formula) { double(Formula, full_name: "foo/qux") } + let(:conflict) { double(name: "bar", reason: "I decided to") } + its(:to_s) { is_expected.to match(/Please `brew unlink bar` before continuing\./) } +end + +describe CompilerSelectionError do + subject { described_class.new(formula) } + let(:formula) { double(Formula, full_name: "foo") } + its(:to_s) { is_expected.to match(/foo cannot be built with any available compilers\./) } +end + +describe CurlDownloadStrategyError do + context "file does not exist" do + subject { described_class.new("file:///tmp/foo") } + its(:to_s) { is_expected.to eq("File does not exist: /tmp/foo") } + end + + context "download failed" do + subject { described_class.new("http://brew.sh") } + its(:to_s) { is_expected.to eq("Download failed: http://brew.sh") } + end +end + +describe ErrorDuringExecution do + subject { described_class.new("badprg", %w[arg1 arg2]) } + its(:to_s) { is_expected.to eq("Failure while executing: badprg arg1 arg2") } +end + +describe ChecksumMismatchError do + subject { described_class.new("/file.tar.gz", hash1, hash2) } + let(:hash1) { double(hash_type: "sha256", to_s: "deadbeef") } + let(:hash2) { double(hash_type: "sha256", to_s: "deadcafe") } + its(:to_s) { is_expected.to match(/SHA256 mismatch/) } +end + +describe ResourceMissingError do + subject { described_class.new(formula, resource) } + let(:formula) { double(Formula, full_name: "bar") } + let(:resource) { double(inspect: "<resource foo>") } + its(:to_s) { is_expected.to eq("bar does not define resource <resource foo>") } +end + +describe DuplicateResourceError do + subject { described_class.new(resource) } + let(:resource) { double(inspect: "<resource foo>") } + its(:to_s) { is_expected.to eq("Resource <resource foo> is defined more than once") } +end + +describe BottleVersionMismatchError do + subject { described_class.new("/foo.bottle.tar.gz", "1.0", formula, "1.1") } + let(:formula) { double(Formula, full_name: "foo") } + its(:to_s) { is_expected.to match(/Bottle version mismatch/) } +end
true
Other
Homebrew
brew
279831fc0e3241eda17b6007aef02299b3c82c9e.json
Convert Exceptions test to spec.
Library/Homebrew/test/exceptions_test.rb
@@ -1,147 +0,0 @@ -require "testing_env" -require "exceptions" - -class ExceptionsTest < Homebrew::TestCase - def test_multiple_versions_installed_error - assert_equal "foo has multiple installed versions", - MultipleVersionsInstalledError.new("foo").to_s - end - - def test_no_such_keg_error - assert_equal "No such keg: #{HOMEBREW_CELLAR}/foo", - NoSuchKegError.new("foo").to_s - end - - def test_formula_validation_error - assert_equal %q(invalid attribute for formula 'foo': sha257 ("magic")), - FormulaValidationError.new("foo", "sha257", "magic").to_s - end - - def test_formula_unavailable_error - e = FormulaUnavailableError.new "foo" - assert_nil e.dependent_s - - e.dependent = "foo" - assert_nil e.dependent_s - - e.dependent = "foobar" - assert_equal "(dependency of foobar)", e.dependent_s - - assert_equal "No available formula with the name \"foo\" (dependency of foobar)", - e.to_s - end - - def test_tap_formula_unavailable_error - t = stub(user: "u", repo: "r", to_s: "u/r", installed?: false) - assert_match "Please tap it and then try again: brew tap u/r", - TapFormulaUnavailableError.new(t, "foo").to_s - end - - def test_formula_class_unavailable_error - mod = Module.new - mod.module_eval <<-EOS.undent - class Bar < Requirement; end - class Baz < Formula; end - EOS - - assert_match "Expected to find class Foo, but found no classes.", - FormulaClassUnavailableError.new("foo", "foo.rb", "Foo", []).to_s - - list = [mod.const_get(:Bar)] - assert_match "Expected to find class Foo, but only found: Bar (not derived from Formula!).", - FormulaClassUnavailableError.new("foo", "foo.rb", "Foo", list).to_s - - list = [mod.const_get(:Baz)] - assert_match "Expected to find class Foo, but only found: Baz.", - FormulaClassUnavailableError.new("foo", "foo.rb", "Foo", list).to_s - end - - def test_formula_unreadable_error - formula_error = LoadError.new("bar") - assert_equal "foo: bar", FormulaUnreadableError.new("foo", formula_error).to_s - end - - def test_tap_unavailable_error - assert_equal "No available tap foo.\n", TapUnavailableError.new("foo").to_s - end - - def test_tap_already_tapped_error - assert_equal "Tap foo already tapped.\n", - TapAlreadyTappedError.new("foo").to_s - end - - def test_pin_status_error - assert_equal "foo is already pinned.", - TapPinStatusError.new("foo", true).to_s - assert_equal "foo is already unpinned.", - TapPinStatusError.new("foo", false).to_s - end - - def test_build_error - f = stub(name: "foo") - assert_equal "Failed executing: badprg arg1 arg2", - BuildError.new(f, "badprg", %w[arg1 arg2], {}).to_s - end - - def test_operation_in_progress_error - assert_match "Operation already in progress for bar", - OperationInProgressError.new("bar").to_s - end - - def test_formula_installation_already_attempted_error - f = stub(full_name: "foo/bar") - assert_equal "Formula installation already attempted: foo/bar", - FormulaInstallationAlreadyAttemptedError.new(f).to_s - end - - def test_formula_conflict_error - f = stub(full_name: "foo/qux") - c = stub(name: "bar", reason: "I decided to") - assert_match "Please `brew unlink bar` before continuing.", - FormulaConflictError.new(f, [c]).to_s - end - - def test_compiler_selection_error - f = stub(full_name: "foo") - assert_match "foo cannot be built with any available compilers.", - CompilerSelectionError.new(f).to_s - end - - def test_curl_download_strategy_error - assert_equal "File does not exist: /tmp/foo", - CurlDownloadStrategyError.new("file:///tmp/foo").to_s - assert_equal "Download failed: http://brew.sh", - CurlDownloadStrategyError.new("http://brew.sh").to_s - end - - def test_error_during_execution - assert_equal "Failure while executing: badprg arg1 arg2", - ErrorDuringExecution.new("badprg", %w[arg1 arg2]).to_s - end - - def test_checksum_mismatch_error - h1 = stub(hash_type: "sha256", to_s: "deadbeef") - h2 = stub(hash_type: "sha256", to_s: "deadcafe") - assert_match "SHA256 mismatch", - ChecksumMismatchError.new("/file.tar.gz", h1, h2).to_s - end - - def test_resource_missing_error - f = stub(full_name: "bar") - r = stub(inspect: "<resource foo>") - assert_match "bar does not define resource <resource foo>", - ResourceMissingError.new(f, r).to_s - end - - def test_duplicate_resource_error - r = stub(inspect: "<resource foo>") - assert_equal "Resource <resource foo> is defined more than once", - DuplicateResourceError.new(r).to_s - end - - def test_bottle_version_mismatch_error - f = stub(full_name: "foo") - assert_match "Bottle version mismatch", - BottleVersionMismatchError.new("/foo.bottle.tar.gz", "1.0", f, "1.1").to_s - end -end
true
Other
Homebrew
brew
a3e0b188cf3bacdecff4bae188ea123af0848cef.json
Convert Patch test to spec.
Library/Homebrew/test/patch_spec.rb
@@ -0,0 +1,165 @@ +require "patch" + +describe Patch do + describe "#create" do + context "simple patch" do + subject { described_class.create(:p2, nil) } + it { is_expected.to be_kind_of ExternalPatch } + it { is_expected.to be_external } + its(:strip) { is_expected.to eq(:p2) } + end + + context "string patch" do + subject { described_class.create(:p0, "foo") } + it { is_expected.to be_kind_of StringPatch } + its(:strip) { is_expected.to eq(:p0) } + end + + context "string patch without strip" do + subject { described_class.create("foo", nil) } + it { is_expected.to be_kind_of StringPatch } + its(:strip) { is_expected.to eq(:p1) } + end + + context "data patch" do + subject { described_class.create(:p0, :DATA) } + it { is_expected.to be_kind_of DATAPatch } + its(:strip) { is_expected.to eq(:p0) } + end + + context "data patch without strip" do + subject { described_class.create(:DATA, nil) } + it { is_expected.to be_kind_of DATAPatch } + its(:strip) { is_expected.to eq(:p1) } + end + + it "raises an error for unknown values" do + expect { + described_class.create(Object.new) + }.to raise_error(ArgumentError) + + expect { + described_class.create(Object.new, Object.new) + }.to raise_error(ArgumentError) + end + end + + describe "#patch_files" do + subject { described_class.create(:p2, nil) } + + context "empty patch" do + its(:resource) { is_expected.to be_kind_of Resource::Patch } + its(:patch_files) { is_expected.to eq(subject.resource.patch_files) } + its(:patch_files) { is_expected.to eq([]) } + end + + it "returns applied patch files" do + subject.resource.apply("patch1.diff") + expect(subject.patch_files).to eq(["patch1.diff"]) + + subject.resource.apply("patch2.diff", "patch3.diff") + expect(subject.patch_files).to eq(["patch1.diff", "patch2.diff", "patch3.diff"]) + + subject.resource.apply(["patch4.diff", "patch5.diff"]) + expect(subject.patch_files.count).to eq(5) + + subject.resource.apply("patch4.diff", ["patch5.diff", "patch6.diff"], "patch7.diff") + expect(subject.patch_files.count).to eq(7) + end + end + + describe "#normalize_legacy_patches" do + it "can create a patch from a single string" do + patches = described_class.normalize_legacy_patches("http://example.com/patch.diff") + expect(patches.length).to eq(1) + expect(patches.first.strip).to eq(:p1) + end + + it "can create patches from an array" do + patches = described_class.normalize_legacy_patches( + %w[http://example.com/patch1.diff http://example.com/patch2.diff], + ) + + expect(patches.length).to eq(2) + expect(patches[0].strip).to eq(:p1) + expect(patches[1].strip).to eq(:p1) + end + + it "can create patches from a :p0 hash" do + patches = Patch.normalize_legacy_patches( + p0: "http://example.com/patch.diff", + ) + + expect(patches.length).to eq(1) + expect(patches.first.strip).to eq(:p0) + end + + it "can create patches from a :p1 hash" do + patches = Patch.normalize_legacy_patches( + p1: "http://example.com/patch.diff", + ) + + expect(patches.length).to eq(1) + expect(patches.first.strip).to eq(:p1) + end + + it "can create patches from a mixed hash" do + patches = Patch.normalize_legacy_patches( + p1: "http://example.com/patch1.diff", + p0: "http://example.com/patch0.diff", + ) + + expect(patches.length).to eq(2) + expect(patches.count { |p| p.strip == :p0 }).to eq(1) + expect(patches.count { |p| p.strip == :p1 }).to eq(1) + end + + it "can create patches from a mixed hash with array" do + patches = Patch.normalize_legacy_patches( + p1: [ + "http://example.com/patch10.diff", + "http://example.com/patch11.diff", + ], + p0: [ + "http://example.com/patch00.diff", + "http://example.com/patch01.diff", + ], + ) + + expect(patches.length).to eq(4) + expect(patches.count { |p| p.strip == :p0 }).to eq(2) + expect(patches.count { |p| p.strip == :p1 }).to eq(2) + end + + it "returns an empty array if given nil" do + expect(Patch.normalize_legacy_patches(nil)).to be_empty + end + end +end + +describe EmbeddedPatch do + describe "#new" do + subject { described_class.new(:p1) } + its(:inspect) { is_expected.to eq("#<EmbeddedPatch: :p1>") } + end +end + +describe ExternalPatch do + subject { described_class.new(:p1) { url "file:///my.patch" } } + + describe "#url" do + its(:url) { is_expected.to eq("file:///my.patch") } + end + + describe "#inspect" do + its(:inspect) { is_expected.to eq('#<ExternalPatch: :p1 "file:///my.patch">') } + end + + describe "#cached_download" do + before(:each) do + allow(subject.resource).to receive(:cached_download).and_return("/tmp/foo.tar.gz") + end + + its(:cached_download) { is_expected.to eq("/tmp/foo.tar.gz") } + end +end
true
Other
Homebrew
brew
a3e0b188cf3bacdecff4bae188ea123af0848cef.json
Convert Patch test to spec.
Library/Homebrew/test/patch_test.rb
@@ -1,155 +0,0 @@ -require "testing_env" -require "patch" - -class PatchTests < Homebrew::TestCase - def test_create_simple - patch = Patch.create(:p2, nil) - assert_kind_of ExternalPatch, patch - assert_predicate patch, :external? - assert_equal :p2, patch.strip - end - - def test_create_string - patch = Patch.create(:p0, "foo") - assert_kind_of StringPatch, patch - assert_equal :p0, patch.strip - end - - def test_create_string_without_strip - patch = Patch.create("foo", nil) - assert_kind_of StringPatch, patch - assert_equal :p1, patch.strip - end - - def test_create_data - patch = Patch.create(:p0, :DATA) - assert_kind_of DATAPatch, patch - assert_equal :p0, patch.strip - end - - def test_create_data_without_strip - patch = Patch.create(:DATA, nil) - assert_kind_of DATAPatch, patch - assert_equal :p1, patch.strip - end - - def test_raises_for_unknown_values - assert_raises(ArgumentError) { Patch.create(Object.new) } - assert_raises(ArgumentError) { Patch.create(Object.new, Object.new) } - end -end - -class LegacyPatchTests < Homebrew::TestCase - def test_patch_single_string - patches = Patch.normalize_legacy_patches("http://example.com/patch.diff") - assert_equal 1, patches.length - assert_equal :p1, patches.first.strip - end - - def test_patch_array - patches = Patch.normalize_legacy_patches( - %w[http://example.com/patch1.diff http://example.com/patch2.diff], - ) - - assert_equal 2, patches.length - assert_equal :p1, patches[0].strip - assert_equal :p1, patches[1].strip - end - - def test_p0_hash_to_string - patches = Patch.normalize_legacy_patches( - p0: "http://example.com/patch.diff", - ) - - assert_equal 1, patches.length - assert_equal :p0, patches.first.strip - end - - def test_p1_hash_to_string - patches = Patch.normalize_legacy_patches( - p1: "http://example.com/patch.diff", - ) - - assert_equal 1, patches.length - assert_equal :p1, patches.first.strip - end - - def test_mixed_hash_to_strings - patches = Patch.normalize_legacy_patches( - p1: "http://example.com/patch1.diff", - p0: "http://example.com/patch0.diff", - ) - assert_equal 2, patches.length - assert_equal 1, patches.count { |p| p.strip == :p0 } - assert_equal 1, patches.count { |p| p.strip == :p1 } - end - - def test_mixed_hash_to_arrays - patches = Patch.normalize_legacy_patches( - p1: ["http://example.com/patch10.diff", - "http://example.com/patch11.diff"], - p0: ["http://example.com/patch00.diff", - "http://example.com/patch01.diff"], - ) - - assert_equal 4, patches.length - assert_equal 2, patches.count { |p| p.strip == :p0 } - assert_equal 2, patches.count { |p| p.strip == :p1 } - end - - def test_nil - assert_empty Patch.normalize_legacy_patches(nil) - end -end - -class EmbeddedPatchTests < Homebrew::TestCase - def test_inspect - p = EmbeddedPatch.new :p1 - assert_equal "#<EmbeddedPatch: :p1>", p.inspect - end -end - -class ExternalPatchTests < Homebrew::TestCase - def setup - super - @p = ExternalPatch.new(:p1) { url "file:///my.patch" } - end - - def test_url - assert_equal "file:///my.patch", @p.url - end - - def test_inspect - assert_equal '#<ExternalPatch: :p1 "file:///my.patch">', @p.inspect - end - - def test_cached_download - @p.resource.stubs(:cached_download).returns "/tmp/foo.tar.gz" - assert_equal "/tmp/foo.tar.gz", @p.cached_download - end -end - -class ApplyPatchTests < Homebrew::TestCase - def test_empty_patch_files - patch = Patch.create(:p2, nil) - resource = patch.resource - patch_files = patch.patch_files - assert_kind_of Resource::Patch, resource - assert_equal patch_files, resource.patch_files - assert_equal patch_files, [] - end - - def test_resource_patch_apply_method - patch = Patch.create(:p2, nil) - resource = patch.resource - patch_files = patch.patch_files - resource.apply("patch1.diff") - assert_equal patch_files, ["patch1.diff"] - resource.apply("patch2.diff", "patch3.diff") - assert_equal patch_files, ["patch1.diff", "patch2.diff", "patch3.diff"] - resource.apply(["patch4.diff", "patch5.diff"]) - assert_equal patch_files.count, 5 - resource.apply("patch4.diff", ["patch5.diff", "patch6.diff"], "patch7.diff") - assert_equal patch_files.count, 7 - end -end
true
Other
Homebrew
brew
8d7d41dc852e9a6bd51aa36b4142a372681bae39.json
Convert Hardware test to spec.
Library/Homebrew/test/hardware_spec.rb
@@ -0,0 +1,40 @@ +require "hardware" + +module Hardware + describe CPU do + describe "::type" do + it "returns the current CPU's type as a symbol, or :dunno if it cannot be detected" do + expect( + [ + :intel, + :ppc, + :dunno, + ], + ).to include(described_class.type) + end + end + + describe "::family" do + it "returns the current CPU's family name as a symbol, or :dunno if it cannot be detected" do + skip "Needs an Intel CPU." unless described_class.intel? + + expect( + [ + :core, + :core2, + :penryn, + :nehalem, + :arrandale, + :sandybridge, + :ivybridge, + :haswell, + :broadwell, + :skylake, + :kabylake, + :dunno, + ], + ).to include(described_class.family) + end + end + end +end
true
Other
Homebrew
brew
8d7d41dc852e9a6bd51aa36b4142a372681bae39.json
Convert Hardware test to spec.
Library/Homebrew/test/hardware_test.rb
@@ -1,15 +0,0 @@ -require "testing_env" -require "hardware" - -class HardwareTests < Homebrew::TestCase - def test_hardware_cpu_type - assert_includes [:intel, :ppc, :dunno], Hardware::CPU.type - end - - if Hardware::CPU.intel? - def test_hardware_intel_family - families = [:core, :core2, :penryn, :nehalem, :arrandale, :sandybridge, :ivybridge, :haswell, :broadwell, :skylake, :kabylake, :dunno] - assert_includes families, Hardware::CPU.family - end - end -end
true
Other
Homebrew
brew
3bc0c6bd1a74fb5a77fdaca45543eca752eee64f.json
Convert Checksum test to spec.
Library/Homebrew/test/checksum_spec.rb
@@ -0,0 +1,19 @@ +require "checksum" + +describe Checksum do + describe "#empty?" do + subject { described_class.new(:sha256, "") } + it { is_expected.to be_empty } + end + + describe "#==" do + subject { described_class.new(:sha256, TEST_SHA256) } + let(:other) { described_class.new(:sha256, TEST_SHA256) } + let(:other_reversed) { described_class.new(:sha256, TEST_SHA256.reverse) } + let(:other_sha1) { described_class.new(:sha1, TEST_SHA1) } + + it { is_expected.to eq(other) } + it { is_expected.not_to eq(other_reversed) } + it { is_expected.not_to eq(other_sha1) } + end +end
true
Other
Homebrew
brew
3bc0c6bd1a74fb5a77fdaca45543eca752eee64f.json
Convert Checksum test to spec.
Library/Homebrew/test/checksum_test.rb
@@ -1,22 +0,0 @@ -require "testing_env" -require "checksum" - -class ChecksumTests < Homebrew::TestCase - def test_empty? - assert_empty Checksum.new(:sha256, "") - end - - def test_equality - a = Checksum.new(:sha256, TEST_SHA256) - b = Checksum.new(:sha256, TEST_SHA256) - assert_equal a, b - - a = Checksum.new(:sha256, TEST_SHA256) - b = Checksum.new(:sha256, TEST_SHA256.reverse) - refute_equal a, b - - a = Checksum.new(:sha1, TEST_SHA1) - b = Checksum.new(:sha256, TEST_SHA256) - refute_equal a, b - end -end
true
Other
Homebrew
brew
2f919089ef381758f4db236dff4c4e6410259a7e.json
Remove JSON test.
Library/Homebrew/test/json_test.rb
@@ -1,20 +0,0 @@ -require "testing_env" -require "json" - -class JsonSmokeTest < Homebrew::TestCase - def test_encode - hash = { "foo" => ["bar", "baz"] } - json = '{"foo":["bar","baz"]}' - assert_equal json, JSON.generate(hash) - end - - def test_decode - hash = { "foo" => ["bar", "baz"], "qux" => 1 } - json = '{"foo":["bar","baz"],"qux":1}' - assert_equal hash, JSON.parse(json) - end - - def test_decode_failure - assert_raises(JSON::ParserError) { JSON.parse("nope") } - end -end
false
Other
Homebrew
brew
64448834a68ee1e183e5c2bf9504dadfa9431dc1.json
fix existing rule for github.io homepages
Library/Homebrew/dev-cmd/audit.rb
@@ -585,7 +585,7 @@ def audit_homepage # exemptions as they are discovered. Treat mixed content on homepages as a bug. # Justify each exemptions with a code comment so we can keep track here. case homepage - when %r{^http://[^/]*github\.io/}, + when %r{^http://[^/]*\.github\.io/}, %r{^http://[^/]*\.sourceforge\.io/} problem "Please use https:// for #{homepage}" end
false
Other
Homebrew
brew
a09169f248de707bf8121acfb6c5d5c2b92c58de.json
audit: enforce https for *.sourceforge.io urls
Library/Homebrew/dev-cmd/audit.rb
@@ -584,7 +584,9 @@ def audit_homepage # People will run into mixed content sometimes, but we should enforce and then add # exemptions as they are discovered. Treat mixed content on homepages as a bug. # Justify each exemptions with a code comment so we can keep track here. - if homepage =~ %r{^http://[^/]*github\.io/} + case homepage + when %r{^http://[^/]*github\.io/}, + %r{^http://[^/]*\.sourceforge\.io/} problem "Please use https:// for #{homepage}" end
false
Other
Homebrew
brew
f85d3d1f7ff891552c3bd54f8010cd9c401e8cd4.json
Convert Requirement test to spec.
Library/Homebrew/.rubocop.yml
@@ -12,7 +12,7 @@ AllCops: Style/BlockDelimiters: Exclude: - '**/cask/spec/**/*' - - '**/cask/test/**/*' + - '**/*_spec.rb' # so many of these in formulae but none in here Lint/AmbiguousRegexpLiteral:
true
Other
Homebrew
brew
f85d3d1f7ff891552c3bd54f8010cd9c401e8cd4.json
Convert Requirement test to spec.
Library/Homebrew/test/requirement_spec.rb
@@ -0,0 +1,288 @@ +require "extend/ENV" +require "requirement" + +RSpec::Matchers.alias_matcher :have_a_default_formula, :be_a_default_formula +RSpec::Matchers.alias_matcher :be_a_build_requirement, :be_a_build + +describe Requirement do + subject { klass.new } + + let(:klass) { Class.new(described_class) } + + describe "#tags" do + subject { described_class.new(tags) } + + context "single tag" do + let(:tags) { ["bar"] } + + its(:tags) { are_expected.to eq(tags) } + end + + context "multiple tags" do + let(:tags) { ["bar", "baz"] } + + its(:tags) { are_expected.to eq(tags) } + end + + context "symbol tags" do + let(:tags) { [:build] } + + its(:tags) { are_expected.to eq(tags) } + end + + context "symbol and string tags" do + let(:tags) { [:build, "bar"] } + + its(:tags) { are_expected.to eq(tags) } + end + end + + describe "#fatal?" do + context "#fatal true is specified" do + let(:klass) do + Class.new(described_class) do + fatal true + end + end + + it { is_expected.to be_fatal } + end + + context "#fatal is ommitted" do + it { is_expected.not_to be_fatal } + end + end + + describe "#satisfied?" do + context "#satisfy with block and build_env returns true" do + let(:klass) do + Class.new(described_class) do + satisfy(build_env: false) do + true + end + end + end + + it { is_expected.to be_satisfied } + end + + context "#satisfy with block and build_env returns false" do + let(:klass) do + Class.new(described_class) do + satisfy(build_env: false) do + false + end + end + end + + it { is_expected.not_to be_satisfied } + end + + context "#satisfy returns true" do + let(:klass) do + Class.new(described_class) do + satisfy true + end + end + + it { is_expected.to be_satisfied } + end + + context "#satisfy returns false" do + let(:klass) do + Class.new(described_class) do + satisfy false + end + end + + it { is_expected.not_to be_satisfied } + end + + context "#satisfy with block returning true and without :build_env" do + let(:klass) do + Class.new(described_class) do + satisfy do + true + end + end + end + + it "sets up build environment" do + expect(ENV).to receive(:with_build_environment).and_call_original + subject.satisfied? + end + end + + context "#satisfy with block returning true and :build_env set to false" do + let(:klass) do + Class.new(described_class) do + satisfy(build_env: false) do + true + end + end + end + + it "skips setting up build environment" do + expect(ENV).not_to receive(:with_build_environment) + subject.satisfied? + end + end + + context "#satisfy with block returning path and without :build_env" do + let(:klass) do + Class.new(described_class) do + satisfy do + Pathname.new("/foo/bar/baz") + end + end + end + + it "infers path from #satisfy result" do + expect(ENV).to receive(:append_path).with("PATH", Pathname.new("/foo/bar")) + subject.satisfied? + subject.modify_build_environment + end + end + end + + describe "#build?" do + context "#build true is specified" do + let(:klass) do + Class.new(described_class) do + build true + end + end + + it { is_expected.to be_a_build_requirement } + end + + context "#build ommitted" do + it { is_expected.not_to be_a_build_requirement } + end + end + + describe "#name and #option_names" do + let(:const) { :FooRequirement } + let(:klass) { self.class.const_get(const) } + + before(:each) do + self.class.const_set(const, Class.new(described_class)) + end + + after(:each) do + self.class.send(:remove_const, const) + end + + its(:name) { is_expected.to eq("foo") } + its(:option_names) { are_expected.to eq(["foo"]) } + end + + describe "#default_formula?" do + context "#default_formula specified" do + let(:klass) do + Class.new(described_class) do + default_formula "foo" + end + end + + it { is_expected.to have_a_default_formula } + end + + context "#default_formula ommitted" do + it { is_expected.not_to have_a_default_formula } + end + end + + describe "#to_dependency" do + let(:klass) do + Class.new(described_class) do + default_formula "foo" + end + end + + it "returns a Dependency for its default Formula" do + expect(subject.to_dependency).to eq(Dependency.new("foo")) + end + + context "#modify_build_environment" do + context "with error" do + let(:klass) do + Class.new(described_class) do + class ModifyBuildEnvironmentError < StandardError; end + + default_formula "foo" + + satisfy do + true + end + + env do + raise ModifyBuildEnvironmentError + end + end + end + + it "raises an error" do + expect { + subject.to_dependency.modify_build_environment + }.to raise_error(klass.const_get(:ModifyBuildEnvironmentError)) + end + end + end + end + + describe "#modify_build_environment" do + context "without env proc" do + let(:klass) { Class.new(described_class) } + + it "returns nil" do + expect(subject.modify_build_environment).to be nil + end + end + end + + describe "#eql? and #==" do + subject { described_class.new } + + it "returns true if the names and tags are equal" do + other = described_class.new + + expect(subject).to eql(other) + expect(subject).to eq(other) + end + + it "returns false if names differ" do + other = described_class.new + allow(other).to receive(:name).and_return("foo") + expect(subject).not_to eql(other) + expect(subject).not_to eq(other) + end + + it "returns false if tags differ" do + other = described_class.new([:optional]) + + expect(subject).not_to eql(other) + expect(subject).not_to eq(other) + end + end + + describe "#hash" do + subject { described_class.new } + + it "is equal if names and tags are equal" do + other = described_class.new + expect(subject.hash).to eq(other.hash) + end + + it "differs if names differ" do + other = described_class.new + allow(other).to receive(:name).and_return("foo") + expect(subject.hash).not_to eq(other.hash) + end + + it "differs if tags differ" do + other = described_class.new([:optional]) + expect(subject.hash).not_to eq(other.hash) + end + end +end
true
Other
Homebrew
brew
f85d3d1f7ff891552c3bd54f8010cd9c401e8cd4.json
Convert Requirement test to spec.
Library/Homebrew/test/requirement_test.rb
@@ -1,152 +0,0 @@ -require "testing_env" -require "requirement" - -class RequirementTests < Homebrew::TestCase - class TestRequirement < Requirement; end - - def test_accepts_single_tag - dep = Requirement.new(%w[bar]) - assert_equal %w[bar], dep.tags - end - - def test_accepts_multiple_tags - dep = Requirement.new(%w[bar baz]) - assert_equal %w[bar baz].sort, dep.tags.sort - end - - def test_option_names - dep = TestRequirement.new - assert_equal %w[test], dep.option_names - end - - def test_preserves_symbol_tags - dep = Requirement.new([:build]) - assert_equal [:build], dep.tags - end - - def test_accepts_symbol_and_string_tags - dep = Requirement.new([:build, "bar"]) - assert_equal [:build, "bar"], dep.tags - end - - def test_dsl_fatal - req = Class.new(Requirement) { fatal true }.new - assert_predicate req, :fatal? - end - - def test_satisfy_true - req = Class.new(Requirement) do - satisfy(build_env: false) { true } - end.new - assert_predicate req, :satisfied? - end - - def test_satisfy_false - req = Class.new(Requirement) do - satisfy(build_env: false) { false } - end.new - refute_predicate req, :satisfied? - end - - def test_satisfy_with_boolean - req = Class.new(Requirement) do - satisfy true - end.new - assert_predicate req, :satisfied? - end - - def test_satisfy_sets_up_build_env_by_default - req = Class.new(Requirement) do - satisfy { true } - end.new - - ENV.expects(:with_build_environment).yields.returns(true) - - assert_predicate req, :satisfied? - end - - def test_satisfy_build_env_can_be_disabled - req = Class.new(Requirement) do - satisfy(build_env: false) { true } - end.new - - ENV.expects(:with_build_environment).never - - assert_predicate req, :satisfied? - end - - def test_infers_path_from_satisfy_result - which_path = Pathname.new("/foo/bar/baz") - req = Class.new(Requirement) do - satisfy { which_path } - end.new - - ENV.expects(:with_build_environment).yields.returns(which_path) - ENV.expects(:append_path).with("PATH", which_path.parent) - - req.satisfied? - req.modify_build_environment - end - - def test_dsl_build - req = Class.new(Requirement) { build true }.new - assert_predicate req, :build? - end - - def test_infer_name_from_class - const = :FooRequirement - klass = self.class - - klass.const_set(const, Class.new(Requirement)) - - begin - assert_equal "foo", klass.const_get(const).new.name - ensure - klass.send(:remove_const, const) - end - end - - def test_dsl_default_formula - req = Class.new(Requirement) { default_formula "foo" }.new - assert_predicate req, :default_formula? - end - - def test_to_dependency - req = Class.new(Requirement) { default_formula "foo" }.new - assert_equal Dependency.new("foo"), req.to_dependency - end - - def test_to_dependency_calls_requirement_modify_build_environment - error = Class.new(StandardError) - - req = Class.new(Requirement) do - default_formula "foo" - satisfy { true } - env { raise error } - end.new - - assert_raises(error) do - req.to_dependency.modify_build_environment - end - end - - def test_modify_build_environment_without_env_proc - assert_nil Class.new(Requirement).new.modify_build_environment - end - - def test_eql - a = Requirement.new - b = Requirement.new - assert_equal a, b - assert_eql a, b - assert_equal a.hash, b.hash - end - - def test_not_eql - a = Requirement.new([:optional]) - b = Requirement.new - refute_equal a, b - refute_eql a, b - refute_equal a.hash, b.hash - end -end
true
Other
Homebrew
brew
6799081f8a156fbb07246cab936717fc00826857.json
Convert Emoji test to spec.
Library/Homebrew/test/emoji_spec.rb
@@ -0,0 +1,16 @@ +require "emoji" + +describe Emoji do + describe "#install_badge" do + subject { described_class.install_badge } + + it "returns 🍺 by default" do + expect(subject).to eq "🍺" + end + + it "returns the contents of HOMEBREW_INSTALL_BADGE if set" do + ENV["HOMEBREW_INSTALL_BADGE"] = "foo" + expect(subject).to eq "foo" + end + end +end
true
Other
Homebrew
brew
6799081f8a156fbb07246cab936717fc00826857.json
Convert Emoji test to spec.
Library/Homebrew/test/emoji_test.rb
@@ -1,11 +0,0 @@ -require "testing_env" -require "emoji" - -class EmojiTest < Homebrew::TestCase - def test_install_badge - assert_equal "🍺", Emoji.install_badge - - ENV["HOMEBREW_INSTALL_BADGE"] = "foo" - assert_equal "foo", Emoji.install_badge - end -end
true
Other
Homebrew
brew
23767a378bf4c10d2e78e49050ab566d9f8cdaed.json
Convert X11Requirement test to spec.
Library/Homebrew/test/x11_requirement_spec.rb
@@ -0,0 +1,36 @@ +require "requirements/x11_requirement" + +describe X11Requirement do + let(:default_name) { "x11" } + + describe "#name" do + it "defaults to x11" do + expect(subject.name).to eq(default_name) + end + end + + describe "#eql?" do + it "returns true if the names are equal" do + other = described_class.new(default_name) + expect(subject).to eql(other) + end + + it "and returns false if the names differ" do + other = described_class.new("foo") + expect(subject).not_to eql(other) + end + + it "returns false if the minimum version differs" do + other = described_class.new(default_name, ["2.5"]) + expect(subject).not_to eql(other) + end + end + + describe "#modify_build_environment" do + it "calls ENV#x11" do + allow(subject).to receive(:satisfied?).and_return(true) + expect(ENV).to receive(:x11) + subject.modify_build_environment + end + end +end
true
Other
Homebrew
brew
23767a378bf4c10d2e78e49050ab566d9f8cdaed.json
Convert X11Requirement test to spec.
Library/Homebrew/test/x11_requirement_test.rb
@@ -1,31 +0,0 @@ -require "testing_env" -require "requirements/x11_requirement" - -class X11RequirementTests < Homebrew::TestCase - def test_eql_instances_are_eql - x = X11Requirement.new - y = X11Requirement.new - assert_eql x, y - assert_equal x.hash, y.hash - end - - def test_not_eql_when_hashes_differ - x = X11Requirement.new("foo") - y = X11Requirement.new - refute_eql x, y - refute_equal x.hash, y.hash - end - - def test_different_min_version - x = X11Requirement.new - y = X11Requirement.new("x11", %w[2.5]) - refute_eql x, y - end - - def test_x_env - x = X11Requirement.new - x.stubs(:satisfied?).returns(true) - ENV.expects(:x11) - x.modify_build_environment - end -end
true
Other
Homebrew
brew
e07a587f42abcf107866f0937643b1a261adf185.json
--prefix: use opt_prefix when available. Fixes #1952.
Library/Homebrew/cmd/--prefix.rb
@@ -11,7 +11,9 @@ def __prefix if ARGV.named.empty? puts HOMEBREW_PREFIX else - puts ARGV.resolved_formulae.map(&:installed_prefix) + puts ARGV.resolved_formulae.map { |f| + f.opt_prefix.exist? ? f.opt_prefix : f.installed_prefix + } end end end
false
Other
Homebrew
brew
efc1f1c7da50e77e96a4324c9380e19848dcf03d.json
formula_installer: add env to allow unlinked deps. We can enable this locally and/or in `brew test-bot` to see if this code is needed any more. If we can remove it we can start doing much more interesting things with linking keg-only, versioned formulae and system dupe formulae.
Library/Homebrew/formula_installer.rb
@@ -171,12 +171,14 @@ def check_install_sanity end end - unlinked_deps = recursive_formulae.select do |dep| - dep.installed? && !dep.keg_only? && !dep.linked_keg.directory? - end + unless ENV["HOMEBREW_NO_CHECK_UNLINKED_DEPENDENCIES"] + unlinked_deps = recursive_formulae.select do |dep| + dep.installed? && !dep.keg_only? && !dep.linked_keg.directory? + end - unless unlinked_deps.empty? - raise CannotInstallFormulaError, "You must `brew link #{unlinked_deps*" "}` before #{formula.full_name} can be installed" + unless unlinked_deps.empty? + raise CannotInstallFormulaError, "You must `brew link #{unlinked_deps*" "}` before #{formula.full_name} can be installed" + end end pinned_unsatisfied_deps = recursive_deps.select do |dep|
false
Other
Homebrew
brew
93441743794a3d44f90bc53438ca31add960f757.json
Use HTTPS for the homepage.
Library/Homebrew/global.rb
@@ -15,7 +15,7 @@ HOMEBREW_PRODUCT = ENV["HOMEBREW_PRODUCT"] HOMEBREW_VERSION = ENV["HOMEBREW_VERSION"] -HOMEBREW_WWW = "http://brew.sh".freeze +HOMEBREW_WWW = "https://brew.sh".freeze require "config"
true
Other
Homebrew
brew
93441743794a3d44f90bc53438ca31add960f757.json
Use HTTPS for the homepage.
README.md
@@ -1,5 +1,5 @@ # Homebrew -Features, usage and installation instructions are [summarised on the homepage](http://brew.sh). Terminology (e.g. the difference between a Cellar, Tap, Cask and so forth) is [explained here](docs/Formula-Cookbook.md#homebrew-terminology). +Features, usage and installation instructions are [summarised on the homepage](https://brew.sh). Terminology (e.g. the difference between a Cellar, Tap, Cask and so forth) is [explained here](docs/Formula-Cookbook.md#homebrew-terminology). ## Update Bug If Homebrew was updated on Aug 10-11th 2016 and `brew update` always says `Already up-to-date.` you need to run:
true
Other
Homebrew
brew
93441743794a3d44f90bc53438ca31add960f757.json
Use HTTPS for the homepage.
docs/Installation.md
@@ -1,7 +1,7 @@ # Installation The suggested and easiest way to install Homebrew is on the -[homepage](http://brew.sh). +[homepage](https://brew.sh). The standard script installs Homebrew to `/usr/local` so that [you don’t need sudo](FAQ.md) when you @@ -55,5 +55,5 @@ Apple Developer account on older versions of Mac OS X. Sign up for free [here](https://developer.apple.com/register/index.action). <a name="4"><sup>4</sup></a> The one-liner installation method found on -[brew.sh](http://brew.sh) requires a Bourne-compatible shell (e.g. bash or +[brew.sh](https://brew.sh) requires a Bourne-compatible shell (e.g. bash or zsh). Notably, fish, tcsh and csh will not work.
true
Other
Homebrew
brew
fd343a11fbde41420fe13b4acab7bce8eea34d13.json
gcc_version_formula: Use gcc@4.x rather than gcc4x
Library/Homebrew/extend/ENV/shared.rb
@@ -269,7 +269,7 @@ def ld64 # @private def gcc_version_formula(name) version = name[GNU_GCC_REGEXP, 1] - gcc_version_name = "gcc#{version.delete(".")}" + gcc_version_name = "gcc@#{version}" gcc = Formulary.factory("gcc") if gcc.version_suffix == version @@ -286,7 +286,6 @@ def warn_about_non_apple_gcc(name) rescue FormulaUnavailableError => e raise <<-EOS.undent Homebrew GCC requested, but formula #{e.name} not found! - You may need to: brew tap homebrew/versions EOS end
false
Other
Homebrew
brew
ae829ed229395159adf6f1f17fb26518ec27fca6.json
add brew where command
Library/Homebrew/cmd/help.rb
@@ -15,7 +15,7 @@ Developers: brew create [URL [--no-fetch]] - brew edit [FORMULA...] + brew (where|edit) [FORMULA...] http://docs.brew.sh/Formula-Cookbook.html Further help:
true
Other
Homebrew
brew
ae829ed229395159adf6f1f17fb26518ec27fca6.json
add brew where command
Library/Homebrew/dev-cmd/where.rb
@@ -0,0 +1,15 @@ +#: * `where` <formulae>: +#: echo location of the specified <formulae> to stdout + +require "formula" + +module Homebrew + module_function + + def where + raise FormulaUnspecifiedError if ARGV.named.empty? + ARGV.resolved_formulae.each do |f| + puts "#{f.path}\n" + end + end +end
true
Other
Homebrew
brew
ae829ed229395159adf6f1f17fb26518ec27fca6.json
add brew where command
completions/zsh/_brew
@@ -120,6 +120,7 @@ __brew_common_commands() { 'update:fetch latest version of Homebrew and all formulae' 'upgrade:upgrade outdated formulae' 'uses:show formulae which depend on a formula' + 'where:location of formulae' '--cellar:brew cellar' '--env:brew environment' '--repository:brew repository' @@ -793,6 +794,12 @@ _brew_vendor_install() { '--target' } + +# brew where formulae: +_brew_where() { + __brew_formulae +} + # the main completion function _brew() { local curcontext="$curcontext" state state_descr line expl
true
Other
Homebrew
brew
ae829ed229395159adf6f1f17fb26518ec27fca6.json
add brew where command
docs/brew.1.html
@@ -625,6 +625,7 @@ <h2 id="DEVELOPER-COMMANDS">DEVELOPER COMMANDS</h2> <p>If <code>--keep-tmp</code> is passed, retain the temporary directory containing the new repository clone.</p></dd> +<dt><code>where</code> <var>formulae</var></dt><dd><p>echo location of the specified <var>formulae</var> to stdout</p></dd> </dl>
true
Other
Homebrew
brew
ae829ed229395159adf6f1f17fb26518ec27fca6.json
add brew where command
manpages/brew.1
@@ -823,6 +823,10 @@ If \fB\-\-to\-tag\fR is passed, set HOMEBREW_UPDATE_TO_TAG to test updating betw .IP If \fB\-\-keep\-tmp\fR is passed, retain the temporary directory containing the new repository clone\. . +.TP +\fBwhere\fR \fIformulae\fR +echo location of the specified \fIformulae\fR to stdout +. .SH "OFFICIAL EXTERNAL COMMANDS" . .TP
true
Other
Homebrew
brew
7be5a6a3d2cdb68870a37bdaa2d0c5cdec20c70b.json
Convert Blacklist test to spec.
Library/Homebrew/test/blacklist_spec.rb
@@ -0,0 +1,111 @@ +require "blacklist" + +RSpec::Matchers.define :be_blacklisted do + match do |actual| + blacklisted?(actual) + end +end + +describe "Blacklist" do + context "rubygems" do + %w[gem rubygem rubygems].each do |s| + subject { s } + + it { is_expected.to be_blacklisted } + end + end + + context "latex" do + %w[latex tex tex-live texlive TexLive].each do |s| + subject { s } + + it { is_expected.to be_blacklisted } + end + end + + context "pip" do + subject { "pip" } + + it { is_expected.to be_blacklisted } + end + + context "pil" do + subject { "pil" } + + it { is_expected.to be_blacklisted } + end + + context "macruby" do + subject { "MacRuby" } + + it { is_expected.to be_blacklisted } + end + + context "lzma" do + %w[lzma liblzma].each do |s| + subject { s } + + it { is_expected.to be_blacklisted } + end + end + + context "gtest" do + %w[gtest googletest google-test].each do |s| + subject { s } + + it { is_expected.to be_blacklisted } + end + end + + context "gmock" do + %w[gmock googlemock google-mock].each do |s| + subject { s } + + it { is_expected.to be_blacklisted } + end + end + + context "sshpass" do + subject { "sshpass" } + + it { is_expected.to be_blacklisted } + end + + context "gsutil" do + subject { "gsutil" } + + it { is_expected.to be_blacklisted } + end + + context "clojure" do + subject { "clojure" } + + it { is_expected.to be_blacklisted } + end + + context "osmium" do + %w[osmium Osmium].each do |s| + subject { s } + + it { is_expected.to be_blacklisted } + end + end + + context "gfortran" do + subject { "gfortran" } + + it { is_expected.to be_blacklisted } + end + + context "play" do + subject { "play" } + + it { is_expected.to be_blacklisted } + end + + context "haskell_platform" do + subject { "haskell-platform" } + + it { is_expected.to be_blacklisted } + end +end
true
Other
Homebrew
brew
7be5a6a3d2cdb68870a37bdaa2d0c5cdec20c70b.json
Convert Blacklist test to spec.
Library/Homebrew/test/blacklist_test.rb
@@ -1,68 +0,0 @@ -require "testing_env" -require "blacklist" - -class BlacklistTests < Homebrew::TestCase - def assert_blacklisted(s) - assert blacklisted?(s), "'#{s}' should be blacklisted" - end - - def test_rubygems - %w[gem rubygem rubygems].each { |s| assert_blacklisted s } - end - - def test_latex - %w[latex tex tex-live texlive TexLive].each { |s| assert_blacklisted s } - end - - def test_pip - assert_blacklisted "pip" - end - - def test_pil - assert_blacklisted "pil" - end - - def test_macruby - assert_blacklisted "MacRuby" - end - - def test_lzma - %w[lzma liblzma].each { |s| assert_blacklisted s } - end - - def test_gtest - %w[gtest googletest google-test].each { |s| assert_blacklisted s } - end - - def test_gmock - %w[gmock googlemock google-mock].each { |s| assert_blacklisted s } - end - - def test_sshpass - assert_blacklisted "sshpass" - end - - def test_gsutil - assert_blacklisted "gsutil" - end - - def test_clojure - assert_blacklisted "clojure" - end - - def test_osmium - %w[osmium Osmium].each { |s| assert_blacklisted s } - end - - def test_gfortran - assert_blacklisted "gfortran" - end - - def test_play - assert_blacklisted "play" - end - - def test_haskell_platform - assert_blacklisted "haskell-platform" - end -end
true
Other
Homebrew
brew
f531e63949683a7bf33ec96014901e3c6d5eaf61.json
Convert Bash test to spec.
Library/Homebrew/test/bash_spec.rb
@@ -0,0 +1,52 @@ +require "open3" + +RSpec::Matchers.define :have_valid_bash_syntax do + match do |file| + stdout, stderr, status = Open3.capture3("/bin/bash", "-n", file) + + @actual = [file, stderr] + + stdout.empty? && status.success? + end + + failure_message do |(file, stderr)| + "expected that #{file} is a valid Bash file:\n#{stderr}" + end +end + +describe "Bash" do + context "brew" do + subject { HOMEBREW_LIBRARY_PATH.parent.parent/"bin/brew" } + it { is_expected.to have_valid_bash_syntax } + end + + context "every `.sh` file" do + it "has valid bash syntax" do + Pathname.glob("#{HOMEBREW_LIBRARY_PATH}/**/*.sh").each do |path| + relative_path = path.relative_path_from(HOMEBREW_LIBRARY_PATH) + next if relative_path.to_s.start_with?("shims/", "test/", "vendor/") + + expect(path).to have_valid_bash_syntax + end + end + end + + context "Bash completion" do + subject { HOMEBREW_LIBRARY_PATH.parent.parent/"completions/bash/brew" } + it { is_expected.to have_valid_bash_syntax } + end + + context "every shim script" do + it "has valid bash syntax" do + # These have no file extension, but can be identified by their shebang. + (HOMEBREW_LIBRARY_PATH/"shims").find do |path| + next if path.directory? + next if path.symlink? + next unless path.executable? + next unless path.read(12) == "#!/bin/bash\n" + + expect(path).to have_valid_bash_syntax + end + end + end +end
true
Other
Homebrew
brew
f531e63949683a7bf33ec96014901e3c6d5eaf61.json
Convert Bash test to spec.
Library/Homebrew/test/bash_test.rb
@@ -1,35 +0,0 @@ -require "testing_env" - -class BashTests < Homebrew::TestCase - def assert_valid_bash_syntax(file) - return unless file.exist? - output = Utils.popen_read("/bin/bash -n #{file} 2>&1") - assert $?.success?, output - end - - def test_bin_brew - assert_valid_bash_syntax HOMEBREW_LIBRARY_PATH.parent.parent/"bin/brew" - end - - def test_bash_code - Pathname.glob("#{HOMEBREW_LIBRARY_PATH}/**/*.sh").each do |pn| - pn_relative = pn.relative_path_from(HOMEBREW_LIBRARY_PATH) - next if pn_relative.to_s.start_with?("shims/", "test/", "vendor/") - assert_valid_bash_syntax pn - end - end - - def test_bash_completion - script = HOMEBREW_LIBRARY_PATH.parent.parent/"completions/bash/brew" - assert_valid_bash_syntax script - end - - def test_bash_shims - # These have no file extension, but can be identified by their shebang. - (HOMEBREW_LIBRARY_PATH/"shims").find do |pn| - next if pn.directory? || pn.symlink? - next unless pn.executable? && pn.read(12) == "#!/bin/bash\n" - assert_valid_bash_syntax pn - end - end -end
true
Other
Homebrew
brew
46a1e2f22d866275da68d11b871883f34669705f.json
Convert `ARGV` test to spec.
Library/Homebrew/test/ARGV_spec.rb
@@ -0,0 +1,149 @@ +require "extend/ARGV" + +describe HomebrewArgvExtension do + subject { argv.extend(HomebrewArgvExtension) } + let(:argv) { ["mxcl"] } + + describe "#formulae" do + it "raises an error when a Formula is unavailable" do + expect { subject.formulae }.to raise_error FormulaUnavailableError + end + + context "when there are no Formulae" do + let(:argv) { [] } + + it "returns an empty array" do + expect(subject.formulae).to be_empty + end + end + end + + describe "#casks" do + it "returns an empty array if there is no match" do + expect(subject.casks).to eq [] + end + end + + describe "#kegs" do + context "when there are matching Kegs" do + before(:each) do + keg = HOMEBREW_CELLAR + "mxcl/10.0" + keg.mkpath + end + + it "returns an array of Kegs" do + expect(subject.kegs.length).to eq 1 + end + end + + context "when there are no matching Kegs" do + let(:argv) { [] } + + it "returns an empty array" do + expect(subject.kegs).to be_empty + end + end + end + + describe "#named" do + let(:argv) { ["foo", "--debug", "-v"] } + + it "returns an array of non-option arguments" do + expect(subject.named).to eq ["foo"] + end + + context "when there are no named arguments" do + let(:argv) { [] } + + it "returns an empty array" do + expect(subject.named).to be_empty + end + end + end + + describe "#options_only" do + let(:argv) { ["--foo", "-vds", "a", "b", "cdefg"] } + + it "returns an array of option arguments" do + expect(subject.options_only).to eq ["--foo", "-vds"] + end + end + + describe "#flags_only" do + let(:argv) { ["--foo", "-vds", "a", "b", "cdefg"] } + + it "returns an array of flags" do + expect(subject.flags_only).to eq ["--foo"] + end + end + + describe "#empty?" do + let(:argv) { [] } + + it "returns true if it is empty" do + expect(subject).to be_empty + end + end + + describe "#switch?" do + let(:argv) { ["-ns", "-i", "--bar", "-a-bad-arg"] } + + it "returns true if the given string is a switch" do + %w[n s i].each do |s| + expect(subject.switch?(s)).to be true + end + end + + it "returns false if the given string is not a switch" do + %w[b ns bar --bar -n a bad arg].each do |s| + expect(subject.switch?(s)).to be false + end + end + end + + describe "#flag?" do + let(:argv) { ["--foo", "-bq", "--bar"] } + + it "returns true if the given string is a flag" do + expect(subject.flag?("--foo")).to eq true + expect(subject.flag?("--bar")).to eq true + end + + it "returns true if there is a switch with the same initial character" do + expect(subject.flag?("--baz")).to eq true + expect(subject.flag?("--qux")).to eq true + end + + it "returns false if there is no matching flag" do + expect(subject.flag?("--frotz")).to eq false + expect(subject.flag?("--debug")).to eq false + end + end + + describe "#value" do + let(:argv) { ["--foo=", "--bar=ab"] } + + it "returns the value for a given string" do + expect(subject.value("foo")).to eq "" + expect(subject.value("bar")).to eq "ab" + end + + it "returns nil if there is no matching argument" do + expect(subject.value("baz")).to be nil + end + end + + describe "#values" do + let(:argv) { ["--foo=", "--bar=a", "--baz=b,c"] } + + it "returns the value for a given argument" do + expect(subject.values("foo")).to eq [] + expect(subject.values("bar")).to eq ["a"] + expect(subject.values("baz")).to eq ["b", "c"] + end + + it "returns nil if there is no matching argument" do + expect(subject.values("qux")).to be nil + end + end +end
true
Other
Homebrew
brew
46a1e2f22d866275da68d11b871883f34669705f.json
Convert `ARGV` test to spec.
Library/Homebrew/test/ARGV_test.rb
@@ -1,79 +0,0 @@ -require "testing_env" -require "extend/ARGV" - -class ArgvExtensionTests < Homebrew::TestCase - def setup - super - @argv = [].extend(HomebrewArgvExtension) - end - - def test_argv_formulae - @argv.unshift "mxcl" - assert_raises(FormulaUnavailableError) { @argv.formulae } - end - - def test_argv_casks - @argv.unshift "mxcl" - assert_equal [], @argv.casks - end - - def test_argv_kegs - keg = HOMEBREW_CELLAR + "mxcl/10.0" - keg.mkpath - @argv << "mxcl" - assert_equal 1, @argv.kegs.length - end - - def test_argv_named - @argv << "foo" << "--debug" << "-v" - assert_equal %w[foo], @argv.named - end - - def test_options_only - @argv << "--foo" << "-vds" << "a" << "b" << "cdefg" - assert_equal %w[--foo -vds], @argv.options_only - end - - def test_flags_only - @argv << "--foo" << "-vds" << "a" << "b" << "cdefg" - assert_equal %w[--foo], @argv.flags_only - end - - def test_empty_argv - assert_empty @argv.named - assert_empty @argv.kegs - assert_empty @argv.formulae - assert_empty @argv - end - - def test_switch? - @argv << "-ns" << "-i" << "--bar" << "-a-bad-arg" - %w[n s i].each { |s| assert @argv.switch?(s) } - %w[b ns bar --bar -n a bad arg].each { |s| assert !@argv.switch?(s) } - end - - def test_flag? - @argv << "--foo" << "-bq" << "--bar" - assert @argv.flag?("--foo") - assert @argv.flag?("--bar") - assert @argv.flag?("--baz") - assert @argv.flag?("--qux") - assert !@argv.flag?("--frotz") - assert !@argv.flag?("--debug") - end - - def test_value - @argv << "--foo=" << "--bar=ab" - assert_equal "", @argv.value("foo") - assert_equal "ab", @argv.value("bar") - assert_nil @argv.value("baz") - end - - def test_values - @argv << "--foo=" << "--bar=a" << "--baz=b,c" - assert_equal [], @argv.values("foo") - assert_equal ["a"], @argv.values("bar") - assert_equal ["b", "c"], @argv.values("baz") - assert_nil @argv.values("qux") - end -end
true
Other
Homebrew
brew
ab785ca4146eb027e639a43f4efd8925886dfc85.json
Add RSpec to Gemfile.
Library/Homebrew/test/Gemfile
@@ -4,6 +4,9 @@ gem "mocha" gem "minitest" gem "minitest-reporters" gem "parallel_tests" +gem "rspec" +gem "rspec-its", require: false +gem "rspec-wait", require: false group :coverage do gem "simplecov", require: false
true
Other
Homebrew
brew
ab785ca4146eb027e639a43f4efd8925886dfc85.json
Add RSpec to Gemfile.
Library/Homebrew/test/Gemfile.lock
@@ -7,6 +7,7 @@ GEM json simplecov url + diff-lcs (1.3) docile (1.1.5) json (2.0.3) metaclass (0.0.4) @@ -21,6 +22,24 @@ GEM parallel (1.10.0) parallel_tests (2.13.0) parallel + 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) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-its (1.2.0) + rspec-core (>= 3.0.0) + rspec-expectations (>= 3.0.0) + rspec-mocks (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-support (3.5.0) + rspec-wait (0.0.9) + rspec (>= 3, < 4) ruby-progressbar (1.8.1) simplecov (0.13.0) docile (~> 1.1.0) @@ -38,7 +57,10 @@ DEPENDENCIES minitest-reporters mocha parallel_tests + rspec + rspec-its + rspec-wait simplecov BUNDLED WITH - 1.13.7 + 1.14.3
true
Other
Homebrew
brew
f457c6ab327b0520c61021437b87be0cedc5f770.json
diagnostic: Add CircleCI to Env check
Library/Homebrew/extend/os/mac/diagnostic.rb
@@ -53,8 +53,8 @@ def check_xcode_up_to_date return unless MacOS::Xcode.installed? return unless MacOS::Xcode.outdated? - # Travis CI images are going to end up outdated so don't complain. - return if ENV["TRAVIS"] + # CI images are going to end up outdated so don't complain. + return if ENV["TRAVIS"] || ENV["CIRCLECI"] message = <<-EOS.undent Your Xcode (#{MacOS::Xcode.version}) is outdated.
false
Other
Homebrew
brew
b9de5c04908bbbe2e2c30fff57b1301e17082202.json
Simplify spec helper.
Library/Homebrew/cask/spec/spec_helper.rb
@@ -34,16 +34,26 @@ # pretend that the caskroom/cask Tap is installed FileUtils.ln_s Pathname.new(ENV["HOMEBREW_LIBRARY"]).join("Taps", "caskroom", "homebrew-cask"), Tap.fetch("caskroom", "cask").path +HOMEBREW_CASK_DIRS = [ + :appdir, + :caskroom, + :prefpanedir, + :qlplugindir, + :servicedir, + :binarydir, +].freeze + RSpec.configure do |config| config.order = :random config.include(Test::Helper::Shutup) config.around(:each) do |example| begin - @__appdir = Hbc.appdir - @__caskroom = Hbc.caskroom - @__prefpanedir = Hbc.prefpanedir - @__qlplugindir = Hbc.qlplugindir - @__servicedir = Hbc.servicedir + @__dirs = HOMEBREW_CASK_DIRS.map { |dir| + Pathname.new(TEST_TMPDIR).join(dir.to_s).tap { |path| + path.mkpath + Hbc.public_send("#{dir}=", path) + } + } @__argv = ARGV.dup @__env = ENV.to_hash # dup doesn't work on ENV @@ -53,16 +63,7 @@ ARGV.replace(@__argv) ENV.replace(@__env) - Hbc.appdir = @__appdir - Hbc.caskroom = @__caskroom - Hbc.prefpanedir = @__prefpanedir - Hbc.qlplugindir = @__qlplugindir - Hbc.servicedir = @__servicedir - - FileUtils.rm_rf [ - Hbc.appdir.children, - Hbc.caskroom.children, - ] + FileUtils.rm_rf @__dirs.map(&:children) end end end
false
Other
Homebrew
brew
a9e538efbdb0532e9236400434c9970e0cdfd8fc.json
Move NeverSudoSystemCommand to separate file.
Library/Homebrew/cask/spec/spec_helper.rb
@@ -66,11 +66,3 @@ end end end - -module Hbc - class NeverSudoSystemCommand < SystemCommand - def self.run(command, options = {}) - super(command, options.merge(sudo: false)) - end - end -end
true
Other
Homebrew
brew
a9e538efbdb0532e9236400434c9970e0cdfd8fc.json
Move NeverSudoSystemCommand to separate file.
Library/Homebrew/cask/spec/support/never_sudo_system_command.rb
@@ -1,3 +1,5 @@ +require "hbc/system_command" + module Hbc class NeverSudoSystemCommand < SystemCommand def self.run(command, options = {})
true
Other
Homebrew
brew
a616fab5bf84d9e2a07610666cf148444c04b3c4.json
Convert cask test to spec.
Library/Homebrew/cask/spec/cask/cask_spec.rb
@@ -20,4 +20,73 @@ end end end + + describe "load" do + let(:hbc_relative_tap_path) { "../../Taps/caskroom/homebrew-cask" } + + it "returns an instance of the Cask for the given token" do + c = Hbc.load("adium") + expect(c).to be_kind_of(Hbc::Cask) + expect(c.token).to eq("adium") + end + + it "returns an instance of the Cask from a specific file location" do + location = File.expand_path(hbc_relative_tap_path + "/Casks/dia.rb") + c = Hbc.load(location) + expect(c).to be_kind_of(Hbc::Cask) + expect(c.token).to eq("dia") + end + + it "returns an instance of the Cask from a url" do + url = "file://" + File.expand_path(hbc_relative_tap_path + "/Casks/dia.rb") + c = shutup do + Hbc.load(url) + end + expect(c).to be_kind_of(Hbc::Cask) + expect(c.token).to eq("dia") + end + + it "raises an error when failing to download a Cask from a url" do + expect { + url = "file://" + File.expand_path(hbc_relative_tap_path + "/Casks/notacask.rb") + shutup do + Hbc.load(url) + end + }.to raise_error(Hbc::CaskUnavailableError) + end + + it "returns an instance of the Cask from a relative file location" do + c = Hbc.load(hbc_relative_tap_path + "/Casks/bbedit.rb") + expect(c).to be_kind_of(Hbc::Cask) + expect(c.token).to eq("bbedit") + end + + it "uses exact match when loading by token" do + expect(Hbc.load("test-opera").token).to eq("test-opera") + expect(Hbc.load("test-opera-mail").token).to eq("test-opera-mail") + end + + it "raises an error when attempting to load a Cask that doesn't exist" do + expect { + Hbc.load("notacask") + }.to raise_error(Hbc::CaskUnavailableError) + end + end + + describe "all_tokens" do + it "returns a token for every Cask" do + all_cask_tokens = Hbc.all_tokens + expect(all_cask_tokens.count).to be > 20 + all_cask_tokens.each { |token| expect(token).to be_kind_of(String) } + end + end + + describe "metadata" do + it "proposes a versioned metadata directory name for each instance" do + cask_token = "adium" + c = Hbc.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) + end + end end
true
Other
Homebrew
brew
a616fab5bf84d9e2a07610666cf148444c04b3c4.json
Convert cask test to spec.
Library/Homebrew/cask/test/cask_test.rb
@@ -1,71 +0,0 @@ -require "test_helper" - -describe "Cask" do - hbc_relative_tap_path = "../../Taps/caskroom/homebrew-cask" - describe "load" do - it "returns an instance of the Cask for the given token" do - c = Hbc.load("adium") - c.must_be_kind_of(Hbc::Cask) - c.token.must_equal("adium") - end - - it "returns an instance of the Cask from a specific file location" do - location = File.expand_path(hbc_relative_tap_path + "/Casks/dia.rb") - c = Hbc.load(location) - c.must_be_kind_of(Hbc::Cask) - c.token.must_equal("dia") - end - - it "returns an instance of the Cask from a url" do - url = "file://" + File.expand_path(hbc_relative_tap_path + "/Casks/dia.rb") - c = shutup do - Hbc.load(url) - end - c.must_be_kind_of(Hbc::Cask) - c.token.must_equal("dia") - end - - it "raises an error when failing to download a Cask from a url" do - lambda { - url = "file://" + File.expand_path(hbc_relative_tap_path + "/Casks/notacask.rb") - shutup do - Hbc.load(url) - end - }.must_raise(Hbc::CaskUnavailableError) - end - - it "returns an instance of the Cask from a relative file location" do - c = Hbc.load(hbc_relative_tap_path + "/Casks/bbedit.rb") - c.must_be_kind_of(Hbc::Cask) - c.token.must_equal("bbedit") - end - - it "uses exact match when loading by token" do - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/test-opera.rb").token.must_equal("test-opera") - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/test-opera-mail.rb").token.must_equal("test-opera-mail") - end - - it "raises an error when attempting to load a Cask that doesn't exist" do - lambda { - Hbc.load("notacask") - }.must_raise(Hbc::CaskUnavailableError) - end - end - - describe "all_tokens" do - it "returns a token for every Cask" do - all_cask_tokens = Hbc.all_tokens - all_cask_tokens.count.must_be :>, 20 - all_cask_tokens.each { |token| token.must_be_kind_of String } - end - end - - describe "metadata" do - it "proposes a versioned metadata directory name for each instance" do - cask_token = "adium" - c = Hbc.load(cask_token) - metadata_path = Hbc.caskroom.join(cask_token, ".metadata", c.version) - c.metadata_versioned_container_path.to_s.must_equal(metadata_path.to_s) - end - end -end
true
Other
Homebrew
brew
6154182b13642de41125403d3be9959814d0afc3.json
Remove syntax test.
Library/Homebrew/cask/test/syntax_test.rb
@@ -1,17 +0,0 @@ -require "test_helper" - -describe "Syntax check" do - project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../")) - backend_files = Dir[project_root.join("**", "*.rb")].reject { |f| f.match %r{/vendor/|/Casks/} } - interpreter = RUBY_PATH - flags = %w[-c] - flags.unshift "--disable-all" - backend_files.each do |file| - it "#{file} is valid Ruby" do - args = flags + ["--", file] - shutup do - raise SyntaxError, "#{file} failed syntax check" unless system(interpreter, *args) - end - end - end -end
false
Other
Homebrew
brew
0a4bc0e3b4526dacf2045b12741c1359b43607bc.json
Convert uninstall_postflight test to spec.
Library/Homebrew/cask/spec/cask/dsl/uninstall_postflight_spec.rb
@@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" describe Hbc::DSL::UninstallPostflight do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
false
Other
Homebrew
brew
451e7c3aebf77be1d353712d202e2e915b8962f0.json
Convert preflight test to spec.
Library/Homebrew/cask/spec/cask/dsl/preflight_spec.rb
@@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" describe Hbc::DSL::Preflight do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
false
Other
Homebrew
brew
e7c943b561cc9c0bfc1d0923783e5dbf729bc076.json
Convert postflight test to spec.
Library/Homebrew/cask/spec/cask/dsl/postflight_spec.rb
@@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" describe Hbc::DSL::Postflight do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
true
Other
Homebrew
brew
e7c943b561cc9c0bfc1d0923783e5dbf729bc076.json
Convert postflight test to spec.
Library/Homebrew/cask/spec/support/shared_examples/staged.rb
@@ -1,109 +1,143 @@ -require "test_helper" +require "spec_helper" -shared_examples_for Hbc::Staged do +require "hbc/staged" + +shared_examples Hbc::Staged do let(:fake_pathname_exists) { - fake_pathname = Pathname("/path/to/file/that/exists") - fake_pathname.stubs(exist?: true, expand_path: fake_pathname) + fake_pathname = Pathname.new("/path/to/file/that/exists") + allow(fake_pathname).to receive(:exist?).and_return(true) + allow(fake_pathname).to receive(:expand_path).and_return(fake_pathname) fake_pathname } let(:fake_pathname_does_not_exist) { - fake_pathname = Pathname("/path/to/file/that/does/not/exist") - fake_pathname.stubs(exist?: false, expand_path: fake_pathname) + fake_pathname = Pathname.new("/path/to/file/that/does/not/exist") + allow(fake_pathname).to receive(:exist?).and_return(false) + allow(fake_pathname).to receive(:expand_path).and_return(fake_pathname) fake_pathname } it "can run system commands with list-form arguments" do Hbc::FakeSystemCommand.expects_command( ["echo", "homebrew-cask", "rocks!"] ) - staged.system_command("echo", args: ["homebrew-cask", "rocks!"]) + + shutup do + staged.system_command("echo", args: ["homebrew-cask", "rocks!"]) + end end it "can get the Info.plist file for the primary app" do - staged.info_plist_file.to_s.must_include Hbc.appdir.join("TestCask.app/Contents/Info.plist") + expect(staged.info_plist_file.to_s).to include Hbc.appdir.join("TestCask.app/Contents/Info.plist") end it "can execute commands on the Info.plist file" do - staged.stubs(bundle_identifier: "com.example.BasicCask") + allow(staged).to receive(:bundle_identifier).and_return("com.example.BasicCask") Hbc::FakeSystemCommand.expects_command( ["/usr/libexec/PlistBuddy", "-c", "Print CFBundleIdentifier", staged.info_plist_file] ) - staged.plist_exec("Print CFBundleIdentifier") + + shutup do + staged.plist_exec("Print CFBundleIdentifier") + end end it "can set a key in the Info.plist file" do - staged.stubs(bundle_identifier: "com.example.BasicCask") + allow(staged).to receive(:bundle_identifier).and_return("com.example.BasicCask") Hbc::FakeSystemCommand.expects_command( ["/usr/libexec/PlistBuddy", "-c", "Set :JVMOptions:JVMVersion 1.6+", staged.info_plist_file] ) - staged.plist_set(":JVMOptions:JVMVersion", "1.6+") + + shutup do + staged.plist_set(":JVMOptions:JVMVersion", "1.6+") + end end it "can set the permissions of a file" do fake_pathname = fake_pathname_exists - staged.stubs(Pathname: fake_pathname) + allow(staged).to receive(:Pathname).and_return(fake_pathname) Hbc::FakeSystemCommand.expects_command( ["/bin/chmod", "-R", "--", "777", fake_pathname] ) - staged.set_permissions(fake_pathname.to_s, "777") + + shutup do + staged.set_permissions(fake_pathname.to_s, "777") + end end it "can set the permissions of multiple files" do fake_pathname = fake_pathname_exists - staged.stubs(:Pathname).returns(fake_pathname) + allow(staged).to receive(:Pathname).and_return(fake_pathname) Hbc::FakeSystemCommand.expects_command( ["/bin/chmod", "-R", "--", "777", fake_pathname, fake_pathname] ) - staged.set_permissions([fake_pathname.to_s, fake_pathname.to_s], "777") + + shutup do + staged.set_permissions([fake_pathname.to_s, fake_pathname.to_s], "777") + end end it "cannot set the permissions of a file that does not exist" do fake_pathname = fake_pathname_does_not_exist - staged.stubs(Pathname: fake_pathname) + allow(staged).to receive(:Pathname).and_return(fake_pathname) staged.set_permissions(fake_pathname.to_s, "777") end it "can set the ownership of a file" do - staged.stubs(current_user: "fake_user") fake_pathname = fake_pathname_exists - staged.stubs(Pathname: fake_pathname) + + allow(staged).to receive(:current_user).and_return("fake_user") + allow(staged).to receive(:Pathname).and_return(fake_pathname) Hbc::FakeSystemCommand.expects_command( ["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "fake_user:staff", fake_pathname] ) - staged.set_ownership(fake_pathname.to_s) + + shutup do + staged.set_ownership(fake_pathname.to_s) + end end it "can set the ownership of multiple files" do - staged.stubs(current_user: "fake_user") fake_pathname = fake_pathname_exists - staged.stubs(Pathname: fake_pathname) + + allow(staged).to receive(:current_user).and_return("fake_user") + allow(staged).to receive(:Pathname).and_return(fake_pathname) Hbc::FakeSystemCommand.expects_command( ["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "fake_user:staff", fake_pathname, fake_pathname] ) - staged.set_ownership([fake_pathname.to_s, fake_pathname.to_s]) + + shutup do + staged.set_ownership([fake_pathname.to_s, fake_pathname.to_s]) + end end it "can set the ownership of a file with a different user and group" do fake_pathname = fake_pathname_exists - staged.stubs(Pathname: fake_pathname) + + allow(staged).to receive(:Pathname).and_return(fake_pathname) Hbc::FakeSystemCommand.expects_command( ["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "other_user:other_group", fake_pathname] ) - staged.set_ownership(fake_pathname.to_s, user: "other_user", group: "other_group") + + shutup do + staged.set_ownership(fake_pathname.to_s, user: "other_user", group: "other_group") + end end it "cannot set the ownership of a file that does not exist" do - staged.stubs(current_user: "fake_user") + allow(staged).to receive(:current_user).and_return("fake_user") fake_pathname = fake_pathname_does_not_exist - staged.stubs(Pathname: fake_pathname) - staged.set_ownership(fake_pathname.to_s) + allow(staged).to receive(:Pathname).and_return(fake_pathname) + + shutup do + staged.set_ownership(fake_pathname.to_s) + end end end
true
Other
Homebrew
brew
e7c943b561cc9c0bfc1d0923783e5dbf729bc076.json
Convert postflight test to spec.
Library/Homebrew/cask/test/test_helper.rb
@@ -93,7 +93,6 @@ def self.install_without_artifacts_with_caskfile(cask) # Extend MiniTest API with support for RSpec-style shared examples require "support/shared_examples" -require "support/shared_examples/staged.rb" require "support/fake_dirs" require "support/fake_system_command"
true
Other
Homebrew
brew
ba61d3ca6ba6ee4d8553d7f3df1b0de88806a6fe.json
Convert caveats test to spec.
Library/Homebrew/cask/spec/cask/dsl/caveats_spec.rb
@@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" describe Hbc::DSL::Caveats do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
true
Other
Homebrew
brew
ba61d3ca6ba6ee4d8553d7f3df1b0de88806a6fe.json
Convert caveats test to spec.
Library/Homebrew/cask/spec/spec_helper.rb
@@ -17,7 +17,7 @@ require "test/support/helper/shutup" -Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "*.rb")).each(&method(:require)) +Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "**", "*.rb")).each(&method(:require)) require "hbc"
true
Other
Homebrew
brew
ba61d3ca6ba6ee4d8553d7f3df1b0de88806a6fe.json
Convert caveats test to spec.
Library/Homebrew/cask/spec/support/shared_examples/dsl_base.rb
@@ -0,0 +1,23 @@ +require "hbc/dsl/base" + +shared_examples Hbc::DSL::Base do + it "supports the token method" do + expect(dsl.token).to eq(cask.token) + end + + it "supports the version method" do + expect(dsl.version).to eq(cask.version) + end + + it "supports the caskroom_path method" do + expect(dsl.caskroom_path).to eq(cask.caskroom_path) + end + + it "supports the staged_path method" do + expect(dsl.staged_path).to eq(cask.staged_path) + end + + it "supports the appdir method" do + expect(dsl.appdir).to eq(cask.appdir) + end +end
true
Other
Homebrew
brew
ba61d3ca6ba6ee4d8553d7f3df1b0de88806a6fe.json
Convert caveats test to spec.
Library/Homebrew/cask/test/support/shared_examples/dsl_base.rb
@@ -1,23 +0,0 @@ -require "test_helper" - -shared_examples_for Hbc::DSL::Base do - it "supports the token method" do - dsl.token.must_equal cask.token - end - - it "supports the version method" do - dsl.version.must_equal cask.version - end - - it "supports the caskroom_path method" do - dsl.caskroom_path.must_equal cask.caskroom_path - end - - it "supports the staged_path method" do - dsl.staged_path.must_equal cask.staged_path - end - - it "supports the appdir method" do - dsl.appdir.must_equal cask.appdir - end -end
true
Other
Homebrew
brew
ba61d3ca6ba6ee4d8553d7f3df1b0de88806a6fe.json
Convert caveats test to spec.
Library/Homebrew/cask/test/test_helper.rb
@@ -93,7 +93,6 @@ def self.install_without_artifacts_with_caskfile(cask) # Extend MiniTest API with support for RSpec-style shared examples require "support/shared_examples" -require "support/shared_examples/dsl_base.rb" require "support/shared_examples/staged.rb" require "support/fake_dirs"
true
Other
Homebrew
brew
59668d27108c34499ae8d00dd9354dc57a112de0.json
Convert naked test to spec.
Library/Homebrew/cask/spec/cask/container/naked_spec.rb
@@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" describe Hbc::Container::Naked do it "saves files with spaces in them from uris with encoded spaces" do @@ -13,8 +13,13 @@ Hbc::FakeSystemCommand.stubs_command(expected_command) container = Hbc::Container::Naked.new(cask, path, Hbc::FakeSystemCommand) - container.extract - Hbc::FakeSystemCommand.system_calls[expected_command].must_equal 1 + expect { + shutup do + container.extract + end + }.not_to raise_error + + expect(Hbc::FakeSystemCommand.system_calls[expected_command]).to eq(1) end end
false
Other
Homebrew
brew
92e2e7a21665aad705d76b90735aed854b7a09f5.json
Convert DMG test to spec.
Library/Homebrew/cask/spec/cask/container/dmg_spec.rb
@@ -1,7 +1,7 @@ -require "test_helper" +require "spec_helper" describe Hbc::Container::Dmg do - describe "mount!" do + describe "#mount!" do it "does not store nil mounts for dmgs with extra data" do transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") @@ -13,7 +13,7 @@ begin dmg.mount! - dmg.mounts.wont_include nil + expect(dmg.mounts).not_to include nil ensure dmg.eject! end
false
Other
Homebrew
brew
4de74bf744ff3006da32bf592735718fec9798d6.json
Convert uninstall test to spec.
Library/Homebrew/cask/spec/cask/artifact/uninstall_spec.rb
@@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" describe Hbc::Artifact::Uninstall do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") } @@ -7,9 +7,9 @@ Hbc::Artifact::Uninstall.new(cask, command: Hbc::FakeSystemCommand) } - before do + before(:each) do shutup do - TestHelper.install_without_artifacts(cask) + InstallHelper.install_without_artifacts(cask) end end @@ -20,7 +20,7 @@ end } - describe "when using launchctl" do + context "when using launchctl" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-launchctl.rb") } let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] } @@ -40,7 +40,7 @@ EOS } - describe "when launchctl job is owned by user" do + context "when launchctl job is owned by user" do it "can uninstall" do Hbc::FakeSystemCommand.stubs_command( launchctl_list_cmd, @@ -58,7 +58,7 @@ end end - describe "when launchctl job is owned by system" do + context "when launchctl job is owned by system" do it "can uninstall" do Hbc::FakeSystemCommand.stubs_command( launchctl_list_cmd, @@ -77,7 +77,7 @@ end end - describe "when using pkgutil" do + context "when using pkgutil" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-pkgutil.rb") } let(:main_pkg_id) { "my.fancy.package.main" } let(:agent_pkg_id) { "my.fancy.package.agent" } @@ -163,7 +163,7 @@ end end - describe "when using kext" do + context "when using kext" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-kext.rb") } let(:kext_id) { "my.fancy.package.kernelextension" } @@ -188,7 +188,7 @@ end end - describe "when using quit" do + context "when using quit" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-quit.rb") } let(:bundle_id) { "my.fancy.package.app" } let(:quit_application_script) { @@ -208,7 +208,7 @@ end end - describe "when using signal" do + context "when using signal" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-signal.rb") } let(:bundle_id) { "my.fancy.package.app" } let(:signals) { %w[TERM KILL] } @@ -220,14 +220,14 @@ ) signals.each do |signal| - Process.expects(:kill).with(signal, *unix_pids) + expect(Process).to receive(:kill).with(signal, *unix_pids) end subject end end - describe "when using delete" do + context "when using delete" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-delete.rb") } it "can uninstall" do @@ -241,7 +241,7 @@ end end - describe "when using trash" do + context "when using trash" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-trash.rb") } it "can uninstall" do @@ -255,7 +255,7 @@ end end - describe "when using rmdir" do + context "when using rmdir" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-rmdir.rb") } let(:dir_pathname) { Pathname.new("#{TEST_FIXTURE_DIR}/cask/empty_directory") } @@ -272,7 +272,7 @@ end end - describe "when using script" do + context "when using script" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script.rb") } let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } @@ -287,7 +287,7 @@ end end - describe "when using early_script" do + context "when using early_script" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-early-script.rb") } let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } @@ -302,7 +302,7 @@ end end - describe "when using login_item" do + context "when using login_item" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-login-item.rb") } it "can uninstall" do
false
Other
Homebrew
brew
c431758f2dff931b69b16ab412dabacbe77380c0.json
Convert Zap test to spec.
Library/Homebrew/cask/spec/cask/artifact/zap_spec.rb
@@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" # TODO: test that zap removes an alternate version of the same Cask describe Hbc::Artifact::Zap do @@ -8,9 +8,9 @@ Hbc::Artifact::Zap.new(cask, command: Hbc::FakeSystemCommand) } - before do + before(:each) do shutup do - TestHelper.install_without_artifacts(cask) + InstallHelper.install_without_artifacts(cask) end end @@ -21,7 +21,7 @@ end } - describe "when using launchctl" do + context "when using launchctl" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-launchctl.rb") } let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] } @@ -41,7 +41,7 @@ EOS } - describe "when launchctl job is owned by user" do + context "when launchctl job is owned by user" do it "can zap" do Hbc::FakeSystemCommand.stubs_command( launchctl_list_cmd, @@ -78,7 +78,7 @@ end end - describe "when using pkgutil" do + context "when using pkgutil" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-pkgutil.rb") } let(:main_pkg_id) { "my.fancy.package.main" } let(:agent_pkg_id) { "my.fancy.package.agent" } @@ -164,7 +164,7 @@ end end - describe "when using kext" do + context "when using kext" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-kext.rb") } let(:kext_id) { "my.fancy.package.kernelextension" } @@ -189,7 +189,7 @@ end end - describe "when using quit" do + context "when using quit" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-quit.rb") } let(:bundle_id) { "my.fancy.package.app" } let(:quit_application_script) { @@ -209,7 +209,7 @@ end end - describe "when using signal" do + context "when using signal" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-signal.rb") } let(:bundle_id) { "my.fancy.package.app" } let(:signals) { %w[TERM KILL] } @@ -221,14 +221,14 @@ ) signals.each do |signal| - Process.expects(:kill).with(signal, *unix_pids) + expect(Process).to receive(:kill).with(signal, *unix_pids) end subject end end - describe "when using delete" do + context "when using delete" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-delete.rb") } it "can zap" do @@ -242,7 +242,7 @@ end end - describe "when using trash" do + context "when using trash" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-trash.rb") } it "can zap" do @@ -256,7 +256,7 @@ end end - describe "when using rmdir" do + context "when using rmdir" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-rmdir.rb") } let(:dir_pathname) { Pathname.new("#{TEST_FIXTURE_DIR}/cask/empty_directory") } @@ -273,7 +273,7 @@ end end - describe "when using script" do + context "when using script" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-script.rb") } let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } @@ -288,7 +288,7 @@ end end - describe "when using early_script" do + context "when using early_script" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-early-script.rb") } let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } @@ -303,7 +303,7 @@ end end - describe "when using login_item" do + context "when using login_item" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-login-item.rb") } it "can zap" do
true
Other
Homebrew
brew
c431758f2dff931b69b16ab412dabacbe77380c0.json
Convert Zap test to spec.
Library/Homebrew/cask/spec/support/fake_system_command.rb
@@ -0,0 +1,77 @@ +def sudo(*args) + %w[/usr/bin/sudo -E --] + args.flatten +end + +module Hbc + class FakeSystemCommand + def self.responses + @responses ||= {} + end + + def self.expectations + @expectations ||= {} + end + + def self.system_calls + @system_calls ||= Hash.new(0) + end + + def self.clear + @responses = nil + @expectations = nil + @system_calls = nil + end + + def self.stubs_command(command, response = "") + responses[command] = response + end + + def self.expects_command(command, response = "", times = 1) + stubs_command(command, response) + expectations[command] = times + end + + def self.expect_and_pass_through(command, times = 1) + pass_through = ->(cmd, opts) { Hbc::SystemCommand.run(cmd, opts) } + expects_command(command, pass_through, times) + end + + def self.verify_expectations! + expectations.each do |command, times| + unless system_calls[command] == times + raise("expected #{command.inspect} to be run #{times} times, but got #{system_calls[command]}") + end + end + end + + def self.run(command_string, options = {}) + command = Hbc::SystemCommand.new(command_string, options).command + puts command + unless responses.key?(command) + raise("no response faked for #{command.inspect}, faked responses are: #{responses.inspect}") + end + system_calls[command] += 1 + + response = responses[command] + if response.respond_to?(:call) + response.call(command_string, options) + else + Hbc::SystemCommand::Result.new(command, response, "", 0) + end + end + + def self.run!(command, options = {}) + run(command, options.merge(must_succeed: true)) + end + end +end + +RSpec.configure do |config| + config.after(:each) do + begin + Hbc::FakeSystemCommand.verify_expectations! + ensure + Hbc::FakeSystemCommand.clear + end + end +end
true
Other
Homebrew
brew
3db8cdf8613694a26051e0ee291f931a7ca00ae3.json
Convert NestedContainer test to spec.
Library/Homebrew/cask/spec/cask/artifact/nested_container_spec.rb
@@ -1,17 +1,17 @@ -require "test_helper" +require "spec_helper" describe Hbc::Artifact::NestedContainer do describe "install" do it "extracts the specified paths as containers" do cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/nested-app.rb").tap do |c| - TestHelper.install_without_artifacts(c) + InstallHelper.install_without_artifacts(c) end shutup do Hbc::Artifact::NestedContainer.new(cask).install_phase end - cask.staged_path.join("MyNestedApp.app").must_be :directory? + expect(cask.staged_path.join("MyNestedApp.app")).to be_a_directory end end end
false
Other
Homebrew
brew
24d50599410dacbb36decfc957a5933e19d6a205.json
Convert generic artifact test to spec.
Library/Homebrew/cask/spec/cask/artifact/generic_artifact_spec.rb
@@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" describe Hbc::Artifact::Artifact do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact.rb") } @@ -11,14 +11,14 @@ let(:target_path) { Hbc.appdir.join("Caffeine.app") } before do - TestHelper.install_without_artifacts(cask) + InstallHelper.install_without_artifacts(cask) end describe "with no target" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact-no-target.rb") } it "fails to install with no target" do - install_phase.must_raise Hbc::CaskInvalidError + expect(install_phase).to raise_error(Hbc::CaskInvalidError) end end @@ -27,21 +27,21 @@ install_phase.call end - target_path.must_be :directory? - source_path.wont_be :exist? + expect(target_path).to be_a_directory + expect(source_path).not_to exist end it "avoids clobbering an existing artifact" do target_path.mkpath - assert_raises Hbc::CaskError do + expect { shutup do install_phase.call end - end + }.to raise_error(Hbc::CaskError) - source_path.must_be :directory? - target_path.must_be :directory? - File.identical?(source_path, target_path).must_equal false + expect(source_path).to be_a_directory + expect(target_path).to be_a_directory + expect(File.identical?(source_path, target_path)).to be false end end
false
Other
Homebrew
brew
20e85cc96feaa4cb4a9ddac64758297aa2bff728.json
Convert App test to spec.
Library/Homebrew/cask/spec/cask/artifact/app_spec.rb
@@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" describe Hbc::Artifact::App do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } @@ -12,8 +12,8 @@ let(:install_phase) { -> { app.install_phase } } let(:uninstall_phase) { -> { app.uninstall_phase } } - before do - TestHelper.install_without_artifacts(cask) + before(:each) do + InstallHelper.install_without_artifacts(cask) end describe "install_phase" do @@ -22,8 +22,8 @@ install_phase.call end - target_path.must_be :directory? - source_path.wont_be :exist? + expect(target_path).to be_a_directory + expect(source_path).not_to exist end describe "when app is in a subdirectory" do @@ -45,8 +45,8 @@ install_phase.call end - target_path.must_be :directory? - appsubdir.join("Caffeine.app").wont_be :exist? + expect(target_path).to be_a_directory + expect(appsubdir.join("Caffeine.app")).not_to exist end end @@ -58,36 +58,34 @@ install_phase.call end - target_path.must_be :directory? - source_path.wont_be :exist? + expect(target_path).to be_a_directory + expect(source_path).not_to exist - Hbc.appdir.join("Caffeine Deluxe.app").wont_be :exist? - cask.staged_path.join("Caffeine Deluxe.app").must_be :exist? + expect(Hbc.appdir.join("Caffeine Deluxe.app")).not_to exist + expect(cask.staged_path.join("Caffeine Deluxe.app")).to exist end describe "when the target already exists" do - before do + before(:each) do target_path.mkpath end it "avoids clobbering an existing app" do - err = install_phase.must_raise(Hbc::CaskError) + expect(install_phase).to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path}'.") - err.message.must_equal("It seems there is already an App at '#{target_path}'.") - - source_path.must_be :directory? - target_path.must_be :directory? - File.identical?(source_path, target_path).must_equal false + expect(source_path).to be_a_directory + expect(target_path).to be_a_directory + expect(File.identical?(source_path, target_path)).to be false contents_path = target_path.join("Contents/Info.plist") - contents_path.wont_be :exist? + expect(contents_path).not_to exist end describe "given the force option" do let(:force) { true } - before do - Hbc::Utils.stubs(current_user: "fake_user") + before(:each) do + allow(Hbc::Utils).to receive(:current_user).and_return("fake_user") end describe "target is both writable and user-owned" do @@ -101,40 +99,31 @@ Warning: It seems there is already an App at '#{target_path}'; overwriting. EOS - install_phase.must_output(stdout, stderr) + expect { + expect(install_phase).to output(stdout).to_stdout + }.to output(stderr).to_stderr - source_path.wont_be :exist? - target_path.must_be :directory? + expect(source_path).not_to exist + expect(target_path).to be_a_directory contents_path = target_path.join("Contents/Info.plist") - contents_path.must_be :exist? + expect(contents_path).to exist end end describe "target is user-owned but contains read-only files" do - let(:command) { Hbc::FakeSystemCommand } - - let(:chmod_cmd) { - ["/bin/chmod", "-R", "--", "u+rwx", target_path] - } - - let(:chmod_n_cmd) { - ["/bin/chmod", "-R", "-N", target_path] - } - - let(:chflags_cmd) { - ["/usr/bin/chflags", "-R", "--", "000", target_path] - } - - before do + before(:each) do system "/usr/bin/touch", "--", "#{target_path}/foo" system "/bin/chmod", "--", "0555", target_path end it "overwrites the existing app" do - command.expect_and_pass_through(chflags_cmd) - command.expect_and_pass_through(chmod_cmd) - command.expect_and_pass_through(chmod_n_cmd) + expect(command).to receive(:run).with("/bin/chmod", args: ["-R", "--", "u+rwx", target_path], must_succeed: false) + .and_call_original + expect(command).to receive(:run).with("/bin/chmod", args: ["-R", "-N", target_path], must_succeed: false) + .and_call_original + expect(command).to receive(:run).with("/usr/bin/chflags", args: ["-R", "--", "000", target_path], must_succeed: false) + .and_call_original stdout = <<-EOS.undent ==> Removing App: '#{target_path}' @@ -145,16 +134,18 @@ Warning: It seems there is already an App at '#{target_path}'; overwriting. EOS - install_phase.must_output(stdout, stderr) + expect { + expect(install_phase).to output(stdout).to_stdout + }.to output(stderr).to_stderr - source_path.wont_be :exist? - target_path.must_be :directory? + expect(source_path).not_to exist + expect(target_path).to be_a_directory contents_path = target_path.join("Contents/Info.plist") - contents_path.must_be :exist? + expect(contents_path).to exist end - after do + after(:each) do system "/bin/chmod", "--", "0755", target_path end end @@ -164,18 +155,15 @@ describe "when the target is a broken symlink" do let(:deleted_path) { cask.staged_path.join("Deleted.app") } - before do + before(:each) do deleted_path.mkdir File.symlink(deleted_path, target_path) deleted_path.rmdir end it "leaves the target alone" do - err = install_phase.must_raise(Hbc::CaskError) - - err.message.must_equal("It seems there is already an App at '#{target_path}'.") - - File.symlink?(target_path).must_equal true + expect(install_phase).to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path}'.") + expect(target_path).to be_a_symlink end describe "given the force option" do @@ -191,13 +179,15 @@ Warning: It seems there is already an App at '#{target_path}'; overwriting. EOS - install_phase.must_output(stdout, stderr) + expect { + expect(install_phase).to output(stdout).to_stdout + }.to output(stderr).to_stderr - source_path.wont_be :exist? - target_path.must_be :directory? + expect(source_path).not_to exist + expect(target_path).to be_a_directory contents_path = target_path.join("Contents/Info.plist") - contents_path.must_be :exist? + expect(contents_path).to exist end end end @@ -207,26 +197,23 @@ message = "It seems the App source is not there: '#{source_path}'" - error = install_phase.must_raise(Hbc::CaskError) - error.message.must_equal message + expect(install_phase).to raise_error(Hbc::CaskError, message) end end describe "uninstall_phase" do - before do + it "deletes managed apps" do shutup do install_phase.call end - end - it "deletes managed apps" do - target_path.must_be :exist? + expect(target_path).to exist shutup do uninstall_phase.call end - target_path.wont_be :exist? + expect(target_path).not_to exist end end @@ -235,25 +222,23 @@ let(:contents) { app.summary[:contents] } it "returns the correct english_description" do - description.must_equal "Apps" + expect(description).to eq("Apps") end describe "app is correctly installed" do - before do + it "returns the path to the app" do shutup do install_phase.call end - end - it "returns the path to the app" do - contents.must_equal ["#{target_path} (#{target_path.abv})"] + expect(contents).to eq(["#{target_path} (#{target_path.abv})"]) end end describe "app is missing" do it "returns a warning and the supposed path to the app" do - contents.size.must_equal 1 - contents[0].must_match(/.*Missing App.*: #{target_path}/) + expect(contents.size).to eq(1) + expect(contents[0]).to match(/.*Missing App.*: #{target_path}/) end end end
false
Other
Homebrew
brew
75609f7212c9e992eec22554abb3fb5540e62d96.json
Convert alt target test to spec.
Library/Homebrew/cask/spec/cask/artifact/alt_target_spec.rb
@@ -1,4 +1,4 @@ -require "test_helper" +require "spec_helper" describe Hbc::Artifact::App do describe "activate to alternate target" do @@ -12,19 +12,19 @@ let(:target_path) { Hbc.appdir.join("AnotherName.app") } before do - TestHelper.install_without_artifacts(cask) + InstallHelper.install_without_artifacts(cask) end it "installs the given apps using the proper target directory" do - source_path.must_be :directory? - target_path.wont_be :exist? + expect(source_path).to be_a_directory + expect(target_path).not_to exist shutup do install_phase.call end - target_path.must_be :directory? - source_path.wont_be :exist? + expect(target_path).to be_a_directory + expect(source_path).not_to exist end describe "when app is in a subdirectory" do @@ -46,8 +46,8 @@ install_phase.call end - target_path.must_be :directory? - appsubdir.join("Caffeine.app").wont_be :exist? + expect(target_path).to be_a_directory + expect(appsubdir.join("Caffeine.app")).not_to exist end end @@ -59,23 +59,21 @@ install_phase.call end - target_path.must_be :directory? - source_path.wont_be :exist? + expect(target_path).to be_a_directory + expect(source_path).not_to exist - Hbc.appdir.join("Caffeine Deluxe.app").wont_be :exist? - cask.staged_path.join("Caffeine Deluxe.app").must_be :directory? + expect(Hbc.appdir.join("Caffeine Deluxe.app")).not_to exist + expect(cask.staged_path.join("Caffeine Deluxe.app")).to be_a_directory end it "avoids clobbering an existing app by moving over it" do target_path.mkpath - err = install_phase.must_raise(Hbc::CaskError) + expect(install_phase).to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path}'.") - err.message.must_equal("It seems there is already an App at '#{target_path}'.") - - source_path.must_be :directory? - target_path.must_be :directory? - File.identical?(source_path, target_path).must_equal false + expect(source_path).to be_a_directory + expect(target_path).to be_a_directory + expect(File.identical?(source_path, target_path)).to be false end end end
false
Other
Homebrew
brew
787860c1bd228c849ab311e57a5042c1cb5162e2.json
Convert Zap test to spec.
Library/Homebrew/cask/spec/cask/cli/zap_spec.rb
@@ -1,10 +1,10 @@ -require "test_helper" +require "spec_helper" describe Hbc::CLI::Zap do it "shows an error when a bad Cask is provided" do - lambda { + expect { Hbc::CLI::Zap.run("notacask") - }.must_raise Hbc::CaskUnavailableError + }.to raise_error(Hbc::CaskUnavailableError) end it "can zap and unlink multiple Casks at once" do @@ -16,18 +16,18 @@ Hbc::Installer.new(transmission).install end - caffeine.must_be :installed? - transmission.must_be :installed? + expect(caffeine).to be_installed + expect(transmission).to be_installed shutup do Hbc::CLI::Zap.run("--notavalidoption", "local-caffeine", "local-transmission") end - caffeine.wont_be :installed? - Hbc.appdir.join("Transmission.app").wont_be :symlink? - transmission.wont_be :installed? - Hbc.appdir.join("Caffeine.app").wont_be :symlink? + expect(caffeine).not_to be_installed + expect(Hbc.appdir.join("Caffeine.app")).not_to be_a_symlink + expect(transmission).not_to be_installed + expect(Hbc.appdir.join("Transmission.app")).not_to be_a_symlink end # TODO: Explicit test that both zap and uninstall directives get dispatched. @@ -59,17 +59,17 @@ describe "when no Cask is specified" do it "raises an exception" do - lambda { + expect { Hbc::CLI::Zap.run - }.must_raise Hbc::CaskUnspecifiedError + }.to raise_error(Hbc::CaskUnspecifiedError) end end describe "when no Cask is specified, but an invalid option" do it "raises an exception" do - lambda { + expect { Hbc::CLI::Zap.run("--notavalidoption") - }.must_raise Hbc::CaskUnspecifiedError + }.to raise_error(Hbc::CaskUnspecifiedError) end end end
false
Other
Homebrew
brew
32565eb96efcda28f4c255afc4e25467b8560379.json
Convert Version test to spec.
Library/Homebrew/cask/spec/cask/cli/version_spec.rb
@@ -0,0 +1,11 @@ +require "spec_helper" + +describe "brew cask --version" do + it "respects the --version argument" do + expect { + expect { + Hbc::CLI::NullCommand.new("--version").run + }.not_to output.to_stderr + }.to output(Hbc.full_version).to_stdout + end +end
true
Other
Homebrew
brew
32565eb96efcda28f4c255afc4e25467b8560379.json
Convert Version test to spec.
Library/Homebrew/cask/test/cask/cli/version_test.rb
@@ -1,9 +0,0 @@ -require "test_helper" - -describe "brew cask --version" do - it "respects the --version argument" do - lambda { - Hbc::CLI::NullCommand.new("--version").run - }.must_output Hbc.full_version - end -end
true
Other
Homebrew
brew
3d031420404506223d047fc509e53df4cc9185d9.json
Convert Uninstall test to spec.
Library/Homebrew/cask/spec/cask/cli/uninstall_spec.rb
@@ -1,22 +1,22 @@ -require "test_helper" +require "spec_helper" describe Hbc::CLI::Uninstall do it "shows an error when a bad Cask is provided" do - lambda { + expect { Hbc::CLI::Uninstall.run("notacask") - }.must_raise Hbc::CaskUnavailableError + }.to raise_error(Hbc::CaskUnavailableError) end it "shows an error when a Cask is provided that's not installed" do - lambda { + expect { Hbc::CLI::Uninstall.run("anvil") - }.must_raise Hbc::CaskNotInstalledError + }.to raise_error(Hbc::CaskNotInstalledError) end it "tries anyway on a non-present Cask when --force is given" do - lambda do + expect { Hbc::CLI::Uninstall.run("anvil", "--force") - end # wont_raise + }.not_to raise_error end it "can uninstall and unlink multiple Casks at once" do @@ -28,17 +28,17 @@ Hbc::Installer.new(transmission).install end - caffeine.must_be :installed? - transmission.must_be :installed? + expect(caffeine).to be_installed + expect(transmission).to be_installed shutup do Hbc::CLI::Uninstall.run("local-caffeine", "local-transmission") end - caffeine.wont_be :installed? - Hbc.appdir.join("Transmission.app").wont_be :exist? - transmission.wont_be :installed? - Hbc.appdir.join("Caffeine.app").wont_be :exist? + expect(caffeine).not_to be_installed + expect(Hbc.appdir.join("Transmission.app")).not_to exist + expect(transmission).not_to be_installed + expect(Hbc.appdir.join("Caffeine.app")).not_to exist end describe "when multiple versions of a cask are installed" do @@ -67,34 +67,29 @@ end end - after(:each) do - caskroom_path.rmtree if caskroom_path.exist? - end - it "uninstalls one version at a time" do shutup do Hbc::CLI::Uninstall.run("versioned-cask") end - caskroom_path.join(first_installed_version).must_be :exist? - caskroom_path.join(last_installed_version).wont_be :exist? - caskroom_path.must_be :exist? + expect(caskroom_path.join(first_installed_version)).to exist + expect(caskroom_path.join(last_installed_version)).not_to exist + expect(caskroom_path).to exist shutup do Hbc::CLI::Uninstall.run("versioned-cask") end - caskroom_path.join(first_installed_version).wont_be :exist? - caskroom_path.wont_be :exist? + expect(caskroom_path.join(first_installed_version)).not_to exist + expect(caskroom_path).not_to exist end it "displays a message when versions remain installed" do - out, err = capture_io do - Hbc::CLI::Uninstall.run("versioned-cask") - end - - out.must_match(/#{token} #{first_installed_version} is still installed./) - err.must_be :empty? + expect { + expect { + Hbc::CLI::Uninstall.run("versioned-cask") + }.not_to output.to_stderr + }.to output(/#{token} #{first_installed_version} is still installed./).to_stdout end end @@ -121,34 +116,29 @@ EOS end - after do - app.rmtree if app.exist? - caskroom_path.rmtree if caskroom_path.exist? - end - it "can still uninstall those Casks" do shutup do Hbc::CLI::Uninstall.run("ive-been-renamed") end - app.wont_be :exist? - caskroom_path.wont_be :exist? + expect(app).not_to exist + expect(caskroom_path).not_to exist end end describe "when no Cask is specified" do it "raises an exception" do - lambda { + expect { Hbc::CLI::Uninstall.run - }.must_raise Hbc::CaskUnspecifiedError + }.to raise_error(Hbc::CaskUnspecifiedError) end end describe "when no Cask is specified, but an invalid option" do it "raises an exception" do - lambda { + expect { Hbc::CLI::Uninstall.run("--notavalidoption") - }.must_raise Hbc::CaskUnspecifiedError + }.to raise_error(Hbc::CaskUnspecifiedError) end end end
false
Other
Homebrew
brew
82e6070ca045001eab7aec0ba9b85dbca48615f8.json
Convert Search test to spec.
Library/Homebrew/cask/spec/cask/cli/search_spec.rb
@@ -0,0 +1,61 @@ +require "spec_helper" + +describe Hbc::CLI::Search do + it "lists the available Casks that match the search term" do + expect { + Hbc::CLI::Search.run("photoshop") + }.to output(<<-EOS.undent).to_stdout + ==> Partial matches + adobe-photoshop-cc + adobe-photoshop-lightroom + EOS + end + + it "shows that there are no Casks matching a search term that did not result in anything" do + expect { + Hbc::CLI::Search.run("foo-bar-baz") + }.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout + end + + it "lists all available Casks with no search term" do + expect { + Hbc::CLI::Search.run + }.to output(/google-chrome/).to_stdout + end + + it "ignores hyphens in search terms" do + expect { + Hbc::CLI::Search.run("goo-gle-chrome") + }.to output(/google-chrome/).to_stdout + end + + it "ignores hyphens in Cask tokens" do + expect { + Hbc::CLI::Search.run("googlechrome") + }.to output(/google-chrome/).to_stdout + end + + it "accepts multiple arguments" do + expect { + Hbc::CLI::Search.run("google chrome") + }.to output(/google-chrome/).to_stdout + end + + it "accepts a regexp argument" do + expect { + Hbc::CLI::Search.run("/^google-c[a-z]rome$/") + }.to output("==> Regexp matches\ngoogle-chrome\n").to_stdout + end + + it "Returns both exact and partial matches" do + expect { + Hbc::CLI::Search.run("mnemosyne") + }.to output(/^==> Exact match\nmnemosyne\n==> Partial matches\nsubclassed-mnemosyne/).to_stdout + end + + it "does not search the Tap name" do + expect { + Hbc::CLI::Search.run("caskroom") + }.to output(/^No Cask found for "caskroom"\.\n/).to_stdout + end +end
true