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 | 3abfdc9e8012fb7d36010237323a054306a1ea83.json | Convert Dependency test to spec. | Library/Homebrew/test/dependency_test.rb | @@ -1,131 +0,0 @@
-require "testing_env"
-require "dependency"
-
-class DependableTests < Homebrew::TestCase
- def setup
- super
- @tags = ["foo", "bar", :build]
- @dep = Struct.new(:tags).new(@tags).extend(Dependable)
- end
-
- def test_options
- assert_equal %w[--foo --bar].sort, @dep.options.as_flags.sort
- end
-
- def test_interrogation
- assert_predicate @dep, :build?
- refute_predicate @dep, :optional?
- refute_predicate @dep, :recommended?
- end
-end
-
-class DependencyTests < Homebrew::TestCase
- def test_accepts_single_tag
- dep = Dependency.new("foo", %w[bar])
- assert_equal %w[bar], dep.tags
- end
-
- def test_accepts_multiple_tags
- dep = Dependency.new("foo", %w[bar baz])
- assert_equal %w[bar baz].sort, dep.tags.sort
- end
-
- def test_preserves_symbol_tags
- dep = Dependency.new("foo", [:build])
- assert_equal [:build], dep.tags
- end
-
- def test_accepts_symbol_and_string_tags
- dep = Dependency.new("foo", [:build, "bar"])
- assert_equal [:build, "bar"], dep.tags
- end
-
- def test_merge_repeats
- dep = Dependency.new("foo", [:build], nil, "foo")
- dep2 = Dependency.new("foo", ["bar"], nil, "foo2")
- dep3 = Dependency.new("xyz", ["abc"], nil, "foo")
- merged = Dependency.merge_repeats([dep, dep2, dep3])
- assert_equal 2, merged.length
- assert_equal Dependency, merged.first.class
-
- foo_named_dep = merged.find { |d| d.name == "foo" }
- assert_equal ["bar"], foo_named_dep.tags
- assert_includes foo_named_dep.option_names, "foo"
- assert_includes foo_named_dep.option_names, "foo2"
-
- xyz_named_dep = merged.find { |d| d.name == "xyz" }
- assert_equal ["abc"], xyz_named_dep.tags
- assert_includes xyz_named_dep.option_names, "foo"
- refute_includes xyz_named_dep.option_names, "foo2"
- end
-
- def test_merges_necessity_tags
- required_dep = Dependency.new("foo")
- recommended_dep = Dependency.new("foo", [:recommended])
- optional_dep = Dependency.new("foo", [:optional])
-
- deps = Dependency.merge_repeats([required_dep, recommended_dep])
- assert_equal deps.count, 1
- assert_predicate deps.first, :required?
- refute_predicate deps.first, :recommended?
- refute_predicate deps.first, :optional?
-
- deps = Dependency.merge_repeats([required_dep, optional_dep])
- assert_equal deps.count, 1
- assert_predicate deps.first, :required?
- refute_predicate deps.first, :recommended?
- refute_predicate deps.first, :optional?
-
- deps = Dependency.merge_repeats([recommended_dep, optional_dep])
- assert_equal deps.count, 1
- refute_predicate deps.first, :required?
- assert_predicate deps.first, :recommended?
- refute_predicate deps.first, :optional?
- end
-
- def test_merges_temporality_tags
- normal_dep = Dependency.new("foo")
- build_dep = Dependency.new("foo", [:build])
- run_dep = Dependency.new("foo", [:run])
-
- deps = Dependency.merge_repeats([normal_dep, build_dep])
- assert_equal deps.count, 1
- refute_predicate deps.first, :build?
- refute_predicate deps.first, :run?
-
- deps = Dependency.merge_repeats([normal_dep, run_dep])
- assert_equal deps.count, 1
- refute_predicate deps.first, :build?
- refute_predicate deps.first, :run?
-
- deps = Dependency.merge_repeats([build_dep, run_dep])
- assert_equal deps.count, 1
- refute_predicate deps.first, :build?
- refute_predicate deps.first, :run?
- end
-
- def test_equality
- foo1 = Dependency.new("foo")
- foo2 = Dependency.new("foo")
- bar = Dependency.new("bar")
- assert_equal foo1, foo2
- assert_eql foo1, foo2
- refute_equal foo1, bar
- refute_eql foo1, bar
- foo3 = Dependency.new("foo", [:build])
- refute_equal foo1, foo3
- refute_eql foo1, foo3
- end
-end
-
-class TapDependencyTests < Homebrew::TestCase
- def test_tap
- dep = TapDependency.new("foo/bar/dog")
- assert_equal Tap.new("foo", "bar"), dep.tap
- end
-
- def test_option_names
- dep = TapDependency.new("foo/bar/dog")
- assert_equal %w[dog], dep.option_names
- end
-end | true |
Other | Homebrew | brew | 8bea5de173a279cd094b1551760b67f4ba21aa7b.json | Convert Cleaner test to spec. | Library/Homebrew/test/cleaner_spec.rb | @@ -0,0 +1,224 @@
+require "cleaner"
+require "formula"
+
+describe Cleaner do
+ include FileUtils
+
+ subject { described_class.new(f) }
+ let(:f) { formula("cleaner_test") { url "foo-1.0" } }
+
+ before(:each) do
+ f.prefix.mkpath
+ end
+
+ describe "#clean" do
+ it "cleans files" do
+ f.bin.mkpath
+ f.lib.mkpath
+ cp "#{TEST_FIXTURE_DIR}/mach/a.out", f.bin
+ cp Dir["#{TEST_FIXTURE_DIR}/mach/*.dylib"], f.lib
+
+ subject.clean
+
+ expect((f.bin/"a.out").stat.mode).to eq(0100555)
+ expect((f.lib/"fat.dylib").stat.mode).to eq(0100444)
+ expect((f.lib/"x86_64.dylib").stat.mode).to eq(0100444)
+ expect((f.lib/"i386.dylib").stat.mode).to eq(0100444)
+ end
+
+ it "prunes the prefix if it is empty" do
+ subject.clean
+ expect(f.prefix).not_to be_a_directory
+ end
+
+ it "prunes empty directories" do
+ subdir = f.bin/"subdir"
+ subdir.mkpath
+
+ subject.clean
+
+ expect(f.bin).not_to be_a_directory
+ expect(subdir).not_to be_a_directory
+ end
+
+ it "removes a symlink when its target was pruned before" do
+ dir = f.prefix/"b"
+ symlink = f.prefix/"a"
+
+ dir.mkpath
+ ln_s dir.basename, symlink
+
+ subject.clean
+
+ expect(dir).not_to exist
+ expect(symlink).not_to be_a_symlink
+ expect(symlink).not_to exist
+ end
+
+ it "removes symlinks pointing to an empty directory" do
+ dir = f.prefix/"b"
+ symlink = f.prefix/"c"
+
+ dir.mkpath
+ ln_s dir.basename, symlink
+
+ subject.clean
+
+ expect(dir).not_to exist
+ expect(symlink).not_to be_a_symlink
+ expect(symlink).not_to exist
+ end
+
+ it "removes broken symlinks" do
+ symlink = f.prefix/"symlink"
+ ln_s "target", symlink
+
+ subject.clean
+
+ expect(symlink).not_to be_a_symlink
+ end
+
+ it "removes '.la' files" do
+ file = f.lib/"foo.la"
+
+ f.lib.mkpath
+ touch file
+
+ subject.clean
+
+ expect(file).not_to exist
+ end
+
+ it "removes 'perllocal' files" do
+ file = f.lib/"perl5/darwin-thread-multi-2level/perllocal.pod"
+
+ (f.lib/"perl5/darwin-thread-multi-2level").mkpath
+ touch file
+
+ subject.clean
+
+ expect(file).not_to exist
+ end
+
+ it "removes '.packlist' files" do
+ file = f.lib/"perl5/darwin-thread-multi-2level/auto/test/.packlist"
+
+ (f.lib/"perl5/darwin-thread-multi-2level/auto/test").mkpath
+ touch file
+
+ subject.clean
+
+ expect(file).not_to exist
+ end
+
+ it "removes 'charset.alias' files" do
+ file = f.lib/"charset.alias"
+
+ f.lib.mkpath
+ touch file
+
+ subject.clean
+
+ expect(file).not_to exist
+ end
+ end
+
+ describe "::skip_clean" do
+ it "adds paths that should be skipped" do
+ f.class.skip_clean "bin"
+ f.bin.mkpath
+
+ subject.clean
+
+ expect(f.bin).to be_a_directory
+ end
+
+ it "also skips empty sub-directories under the added paths" do
+ f.class.skip_clean "bin"
+ subdir = f.bin/"subdir"
+ subdir.mkpath
+
+ subject.clean
+
+ expect(f.bin).to be_a_directory
+ expect(subdir).to be_a_directory
+ end
+
+ it "allows skipping broken symlinks" do
+ f.class.skip_clean "symlink"
+ symlink = f.prefix/"symlink"
+ ln_s "target", symlink
+
+ subject.clean
+
+ expect(symlink).to be_a_symlink
+ end
+
+ it "allows skipping symlinks pointing to an empty directory" do
+ f.class.skip_clean "c"
+ dir = f.prefix/"b"
+ symlink = f.prefix/"c"
+
+ dir.mkpath
+ ln_s dir.basename, symlink
+
+ subject.clean
+
+ expect(dir).not_to exist
+ expect(symlink).to be_a_symlink
+ expect(symlink).not_to exist
+ end
+
+ it "allows skipping symlinks whose target was pruned before" do
+ f.class.skip_clean "a"
+ dir = f.prefix/"b"
+ symlink = f.prefix/"a"
+
+ dir.mkpath
+ ln_s dir.basename, symlink
+
+ subject.clean
+
+ expect(dir).not_to exist
+ expect(symlink).to be_a_symlink
+ expect(symlink).not_to exist
+ end
+
+ it "allows skipping '.la' files" do
+ file = f.lib/"foo.la"
+
+ f.class.skip_clean :la
+ f.lib.mkpath
+ touch file
+
+ subject.clean
+
+ expect(file).to exist
+ end
+
+ it "allows skipping sub-directories" do
+ dir = f.lib/"subdir"
+ f.class.skip_clean "lib/subdir"
+
+ dir.mkpath
+
+ subject.clean
+
+ expect(dir).to be_a_directory
+ end
+
+ it "allows skipping paths relative to prefix" do
+ dir1 = f.bin/"a"
+ dir2 = f.lib/"bin/a"
+
+ f.class.skip_clean "bin/a"
+ dir1.mkpath
+ dir2.mkpath
+
+ subject.clean
+
+ expect(dir1).to exist
+ expect(dir2).not_to exist
+ end
+ end
+end | true |
Other | Homebrew | brew | 8bea5de173a279cd094b1551760b67f4ba21aa7b.json | Convert Cleaner test to spec. | Library/Homebrew/test/cleaner_test.rb | @@ -1,220 +0,0 @@
-require "testing_env"
-require "cleaner"
-require "formula"
-
-class CleanerTests < Homebrew::TestCase
- include FileUtils
-
- def setup
- super
- @f = formula("cleaner_test") { url "foo-1.0" }
- @f.prefix.mkpath
- end
-
- def test_clean_file
- @f.bin.mkpath
- @f.lib.mkpath
- cp "#{TEST_FIXTURE_DIR}/mach/a.out", @f.bin
- cp Dir["#{TEST_FIXTURE_DIR}/mach/*.dylib"], @f.lib
-
- Cleaner.new(@f).clean
-
- assert_equal 0100555, (@f.bin/"a.out").stat.mode
- assert_equal 0100444, (@f.lib/"fat.dylib").stat.mode
- assert_equal 0100444, (@f.lib/"x86_64.dylib").stat.mode
- assert_equal 0100444, (@f.lib/"i386.dylib").stat.mode
- end
-
- def test_prunes_prefix_if_empty
- Cleaner.new(@f).clean
- refute_predicate @f.prefix, :directory?
- end
-
- def test_prunes_empty_directories
- subdir = @f.bin/"subdir"
- subdir.mkpath
-
- Cleaner.new(@f).clean
-
- refute_predicate @f.bin, :directory?
- refute_predicate subdir, :directory?
- end
-
- def test_skip_clean_empty_directory
- @f.class.skip_clean "bin"
- @f.bin.mkpath
-
- Cleaner.new(@f).clean
-
- assert_predicate @f.bin, :directory?
- end
-
- def test_skip_clean_directory_with_empty_subdir
- @f.class.skip_clean "bin"
- subdir = @f.bin/"subdir"
- subdir.mkpath
-
- Cleaner.new(@f).clean
-
- assert_predicate @f.bin, :directory?
- assert_predicate subdir, :directory?
- end
-
- def test_removes_symlink_when_target_was_pruned_first
- dir = @f.prefix/"b"
- symlink = @f.prefix/"a"
-
- dir.mkpath
- ln_s dir.basename, symlink
-
- Cleaner.new(@f).clean
-
- refute_predicate dir, :exist?
- refute_predicate symlink, :symlink?
- refute_predicate symlink, :exist?
- end
-
- def test_removes_symlink_pointing_to_empty_directory
- dir = @f.prefix/"b"
- symlink = @f.prefix/"c"
-
- dir.mkpath
- ln_s dir.basename, symlink
-
- Cleaner.new(@f).clean
-
- refute_predicate dir, :exist?
- refute_predicate symlink, :symlink?
- refute_predicate symlink, :exist?
- end
-
- def test_removes_broken_symlinks
- symlink = @f.prefix/"symlink"
- ln_s "target", symlink
-
- Cleaner.new(@f).clean
-
- refute_predicate symlink, :symlink?
- end
-
- def test_skip_clean_broken_symlink
- @f.class.skip_clean "symlink"
- symlink = @f.prefix/"symlink"
- ln_s "target", symlink
-
- Cleaner.new(@f).clean
-
- assert_predicate symlink, :symlink?
- end
-
- def test_skip_clean_symlink_pointing_to_empty_directory
- @f.class.skip_clean "c"
- dir = @f.prefix/"b"
- symlink = @f.prefix/"c"
-
- dir.mkpath
- ln_s dir.basename, symlink
-
- Cleaner.new(@f).clean
-
- refute_predicate dir, :exist?
- assert_predicate symlink, :symlink?
- refute_predicate symlink, :exist?
- end
-
- def test_skip_clean_symlink_when_target_pruned
- @f.class.skip_clean "a"
- dir = @f.prefix/"b"
- symlink = @f.prefix/"a"
-
- dir.mkpath
- ln_s dir.basename, symlink
-
- Cleaner.new(@f).clean
-
- refute_predicate dir, :exist?
- assert_predicate symlink, :symlink?
- refute_predicate symlink, :exist?
- end
-
- def test_removes_la_files
- file = @f.lib/"foo.la"
-
- @f.lib.mkpath
- touch file
-
- Cleaner.new(@f).clean
-
- refute_predicate file, :exist?
- end
-
- def test_removes_perllocal_files
- file = @f.lib/"perl5/darwin-thread-multi-2level/perllocal.pod"
-
- (@f.lib/"perl5/darwin-thread-multi-2level").mkpath
- touch file
-
- Cleaner.new(@f).clean
-
- refute_predicate file, :exist?
- end
-
- def test_removes_packlist_files
- file = @f.lib/"perl5/darwin-thread-multi-2level/auto/test/.packlist"
-
- (@f.lib/"perl5/darwin-thread-multi-2level/auto/test").mkpath
- touch file
-
- Cleaner.new(@f).clean
-
- refute_predicate file, :exist?
- end
-
- def test_skip_clean_la
- file = @f.lib/"foo.la"
-
- @f.class.skip_clean :la
- @f.lib.mkpath
- touch file
-
- Cleaner.new(@f).clean
-
- assert_predicate file, :exist?
- end
-
- def test_remove_charset_alias
- file = @f.lib/"charset.alias"
-
- @f.lib.mkpath
- touch file
-
- Cleaner.new(@f).clean
-
- refute_predicate file, :exist?
- end
-
- def test_skip_clean_subdir
- dir = @f.lib/"subdir"
- @f.class.skip_clean "lib/subdir"
-
- dir.mkpath
-
- Cleaner.new(@f).clean
-
- assert_predicate dir, :directory?
- end
-
- def test_skip_clean_paths_are_anchored_to_prefix
- dir1 = @f.bin/"a"
- dir2 = @f.lib/"bin/a"
-
- @f.class.skip_clean "bin/a"
- dir1.mkpath
- dir2.mkpath
-
- Cleaner.new(@f).clean
-
- assert_predicate dir1, :exist?
- refute_predicate dir2, :exist?
- end
-end | true |
Other | Homebrew | brew | 25396d9c4d7a7a111eebf02f0ebdbb0e69aad3b0.json | Install tap command completions and manpages
Taps can include completion scripts for external commands under
`completions/bash`, `completions/fish`, or `completions/zsh`. `brew tap`
will automatically install these into the correct directories during
install. | Library/Homebrew/cmd/list.rb | @@ -77,6 +77,7 @@ def list
lib/ruby/site_ruby/[12].*
lib/ruby/vendor_ruby/[12].*
manpages/brew.1
+ manpages/brew-cask.1
share/pypy/*
share/pypy3/*
share/info/dir | true |
Other | Homebrew | brew | 25396d9c4d7a7a111eebf02f0ebdbb0e69aad3b0.json | Install tap command completions and manpages
Taps can include completion scripts for external commands under
`completions/bash`, `completions/fish`, or `completions/zsh`. `brew tap`
will automatically install these into the correct directories during
install. | Library/Homebrew/cmd/tap.rb | @@ -38,7 +38,7 @@ module Homebrew
def tap
if ARGV.include? "--repair"
- Tap.each(&:link_manpages)
+ Tap.each(&:link_completions_and_manpages)
elsif ARGV.include? "--list-official"
require "official_taps"
puts OFFICIAL_TAPS.map { |t| "homebrew/#{t}" } | true |
Other | Homebrew | brew | 25396d9c4d7a7a111eebf02f0ebdbb0e69aad3b0.json | Install tap command completions and manpages
Taps can include completion scripts for external commands under
`completions/bash`, `completions/fish`, or `completions/zsh`. `brew tap`
will automatically install these into the correct directories during
install. | Library/Homebrew/cmd/update-report.rb | @@ -104,8 +104,8 @@ def update_report
puts if ARGV.include?("--preinstall")
end
- link_completions_and_docs
- Tap.each(&:link_manpages)
+ link_completions_manpages_and_docs
+ Tap.each(&:link_completions_and_manpages)
Homebrew.failed = true if ENV["HOMEBREW_UPDATE_FAILED"]
@@ -281,7 +281,7 @@ def migrate_legacy_repository_if_necessary
EOS
end
- link_completions_and_docs(new_homebrew_repository)
+ link_completions_manpages_and_docs(new_homebrew_repository)
ohai "Migrated HOMEBREW_REPOSITORY to #{new_homebrew_repository}!"
puts <<-EOS.undent
@@ -302,16 +302,11 @@ def migrate_legacy_repository_if_necessary
$stderr.puts e.backtrace
end
- def link_completions_and_docs(repository = HOMEBREW_REPOSITORY)
+ def link_completions_manpages_and_docs(repository = HOMEBREW_REPOSITORY)
command = "brew update"
- link_src_dst_dirs(repository/"completions/bash",
- HOMEBREW_PREFIX/"etc/bash_completion.d", command)
- link_src_dst_dirs(repository/"docs",
- HOMEBREW_PREFIX/"share/doc/homebrew", command, link_dir: true)
- link_src_dst_dirs(repository/"completions/zsh",
- HOMEBREW_PREFIX/"share/zsh/site-functions", command)
- link_src_dst_dirs(repository/"manpages",
- HOMEBREW_PREFIX/"share/man/man1", command)
+ Utils::Link.link_completions(repository, command)
+ Utils::Link.link_manpages(repository, command)
+ Utils::Link.link_docs(repository, command)
rescue => e
ofail <<-EOS.undent
Failed to link all completions, docs and manpages: | true |
Other | Homebrew | brew | 25396d9c4d7a7a111eebf02f0ebdbb0e69aad3b0.json | Install tap command completions and manpages
Taps can include completion scripts for external commands under
`completions/bash`, `completions/fish`, or `completions/zsh`. `brew tap`
will automatically install these into the correct directories during
install. | Library/Homebrew/tap.rb | @@ -236,7 +236,7 @@ def install(options = {})
raise
end
- link_manpages
+ link_completions_and_manpages
formula_count = formula_files.size
puts "Tapped #{formula_count} formula#{plural(formula_count, "e")} (#{path.abv})" unless quiet
@@ -254,8 +254,10 @@ def install(options = {})
EOS
end
- def link_manpages
- link_path_manpages(path, "brew tap --repair")
+ def link_completions_and_manpages
+ command = "brew tap --repair"
+ Utils::Link.link_manpages(path, command)
+ Utils::Link.link_completions(path, command)
end
# uninstall this {Tap}.
@@ -267,23 +269,14 @@ def uninstall
unpin if pinned?
formula_count = formula_files.size
Descriptions.uncache_formulae(formula_names)
- unlink_manpages
+ Utils::Link.unlink_manpages(path)
+ Utils::Link.unlink_completions(path)
path.rmtree
path.parent.rmdir_if_possible
puts "Untapped #{formula_count} formula#{plural(formula_count, "e")}"
clear_cache
end
- def unlink_manpages
- return unless (path/"man").exist?
- (path/"man").find do |src|
- next if src.directory?
- dst = HOMEBREW_PREFIX/"share"/src.relative_path_from(path)
- dst.delete if dst.symlink? && src == dst.resolved_path
- dst.parent.rmdir_if_possible
- end
- end
-
# True if the {#remote} of {Tap} is customized.
def custom_remote?
return true unless remote | true |
Other | Homebrew | brew | 25396d9c4d7a7a111eebf02f0ebdbb0e69aad3b0.json | Install tap command completions and manpages
Taps can include completion scripts for external commands under
`completions/bash`, `completions/fish`, or `completions/zsh`. `brew tap`
will automatically install these into the correct directories during
install. | Library/Homebrew/test/tap_test.rb | @@ -60,9 +60,18 @@ class Foo < Formula
@cmd_file.parent.mkpath
touch @cmd_file
chmod 0755, @cmd_file
- @manpage_file = @path/"man/man1/brew-tap-cmd.1"
+ @manpage_file = @path/"manpages/brew-tap-cmd.1"
@manpage_file.parent.mkpath
touch @manpage_file
+ @bash_completion_file = @path/"completions/bash/brew-tap-cmd"
+ @bash_completion_file.parent.mkpath
+ touch @bash_completion_file
+ @zsh_completion_file = @path/"completions/zsh/_brew-tap-cmd"
+ @zsh_completion_file.parent.mkpath
+ touch @zsh_completion_file
+ @fish_completion_file = @path/"completions/fish/brew-tap-cmd.fish"
+ @fish_completion_file.parent.mkpath
+ touch @fish_completion_file
end
def setup_git_repo
@@ -238,10 +247,39 @@ def test_install_and_uninstall
shutup { tap.install clone_target: @tap.path/".git" }
assert_predicate tap, :installed?
assert_predicate HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1", :file?
+ assert_predicate HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd", :file?
+ assert_predicate HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd", :file?
+ assert_predicate HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish", :file?
shutup { tap.uninstall }
refute_predicate tap, :installed?
refute_predicate HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1", :exist?
refute_predicate HOMEBREW_PREFIX/"share/man/man1", :exist?
+ refute_predicate HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd", :exist?
+ refute_predicate HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd", :exist?
+ refute_predicate HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish", :exist?
+ ensure
+ (HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist?
+ (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist?
+ end
+
+ def test_link_completions_and_manpages
+ setup_tap_files
+ setup_git_repo
+ tap = Tap.new("Homebrew", "baz")
+ shutup { tap.install clone_target: @tap.path/".git" }
+ (HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").delete
+ (HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").delete
+ (HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").delete
+ (HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").delete
+ shutup { tap.link_completions_and_manpages }
+ assert_predicate HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1", :file?
+ assert_predicate HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd", :file?
+ assert_predicate HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd", :file?
+ assert_predicate HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish", :file?
+ shutup { tap.uninstall }
+ ensure
+ (HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist?
+ (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist?
end
def test_pin_and_unpin | true |
Other | Homebrew | brew | 25396d9c4d7a7a111eebf02f0ebdbb0e69aad3b0.json | Install tap command completions and manpages
Taps can include completion scripts for external commands under
`completions/bash`, `completions/fish`, or `completions/zsh`. `brew tap`
will automatically install these into the correct directories during
install. | Library/Homebrew/utils.rb | @@ -9,6 +9,7 @@
require "utils/github"
require "utils/hash"
require "utils/inreplace"
+require "utils/link"
require "utils/popen"
require "utils/tty"
require "time"
@@ -481,38 +482,6 @@ def truncate_text_to_approximate_size(s, max_bytes, options = {})
out
end
-def link_src_dst_dirs(src_dir, dst_dir, command, link_dir: false)
- return unless src_dir.exist?
- conflicts = []
- src_paths = link_dir ? [src_dir] : src_dir.find
- src_paths.each do |src|
- next if src.directory? && !link_dir
- dst = dst_dir/src.relative_path_from(src_dir)
- if dst.symlink?
- next if src == dst.resolved_path
- dst.unlink
- end
- if dst.exist?
- conflicts << dst
- next
- end
- dst_dir.parent.mkpath
- dst.make_relative_symlink(src)
- end
-
- return if conflicts.empty?
- onoe <<-EOS.undent
- Could not link:
- #{conflicts.join("\n")}
-
- Please delete these paths and run `#{command}`.
- EOS
-end
-
-def link_path_manpages(path, command)
- link_src_dst_dirs(path/"man", HOMEBREW_PREFIX/"share/man", command)
-end
-
def migrate_legacy_keg_symlinks_if_necessary
legacy_linked_kegs = HOMEBREW_LIBRARY/"LinkedKegs"
return unless legacy_linked_kegs.directory? | true |
Other | Homebrew | brew | 25396d9c4d7a7a111eebf02f0ebdbb0e69aad3b0.json | Install tap command completions and manpages
Taps can include completion scripts for external commands under
`completions/bash`, `completions/fish`, or `completions/zsh`. `brew tap`
will automatically install these into the correct directories during
install. | Library/Homebrew/utils/link.rb | @@ -0,0 +1,70 @@
+module Utils
+ module Link
+ module_function
+
+ def link_src_dst_dirs(src_dir, dst_dir, command, link_dir: false)
+ return unless src_dir.exist?
+ conflicts = []
+ src_paths = link_dir ? [src_dir] : src_dir.find
+ src_paths.each do |src|
+ next if src.directory? && !link_dir
+ dst = dst_dir/src.relative_path_from(src_dir)
+ if dst.symlink?
+ next if src == dst.resolved_path
+ dst.unlink
+ end
+ if dst.exist?
+ conflicts << dst
+ next
+ end
+ dst_dir.parent.mkpath
+ dst.make_relative_symlink(src)
+ end
+
+ return if conflicts.empty?
+ onoe <<-EOS.undent
+ Could not link:
+ #{conflicts.join("\n")}
+
+ Please delete these paths and run `#{command}`.
+ EOS
+ end
+ private_class_method :link_src_dst_dirs
+
+ def unlink_src_dst_dirs(src_dir, dst_dir, unlink_dir: false)
+ return unless src_dir.exist?
+ src_paths = unlink_dir ? [src_dir] : src_dir.find
+ src_paths.each do |src|
+ next if src.directory? && !unlink_dir
+ dst = dst_dir/src.relative_path_from(src_dir)
+ dst.delete if dst.symlink? && src == dst.resolved_path
+ dst.parent.rmdir_if_possible
+ end
+ end
+ private_class_method :unlink_src_dst_dirs
+
+ def link_manpages(path, command)
+ link_src_dst_dirs(path/"manpages", HOMEBREW_PREFIX/"share/man/man1", command)
+ end
+
+ def unlink_manpages(path)
+ unlink_src_dst_dirs(path/"manpages", HOMEBREW_PREFIX/"share/man/man1")
+ end
+
+ def link_completions(path, command)
+ link_src_dst_dirs(path/"completions/bash", HOMEBREW_PREFIX/"etc/bash_completion.d", command)
+ link_src_dst_dirs(path/"completions/zsh", HOMEBREW_PREFIX/"share/zsh/site-functions", command)
+ link_src_dst_dirs(path/"completions/fish", HOMEBREW_PREFIX/"share/fish/vendor_completions.d", command)
+ end
+
+ def unlink_completions(path)
+ unlink_src_dst_dirs(path/"completions/bash", HOMEBREW_PREFIX/"etc/bash_completion.d")
+ unlink_src_dst_dirs(path/"completions/zsh", HOMEBREW_PREFIX/"share/zsh/site-functions")
+ unlink_src_dst_dirs(path/"completions/fish", HOMEBREW_PREFIX/"share/fish/vendor_completions.d")
+ end
+
+ def link_docs(path, command)
+ link_src_dst_dirs(path/"docs", HOMEBREW_PREFIX/"share/doc/homebrew", command, link_dir: true)
+ end
+ end
+end | true |
Other | Homebrew | brew | e3f4701f385c286a2cc72c5d07870cc9a6ce0bf4.json | audit: fix audit on formulae without homepages | Library/Homebrew/dev-cmd/audit.rb | @@ -605,6 +605,11 @@ def audit_desc
def audit_homepage
homepage = formula.homepage
+ if homepage.nil? || homepage.empty?
+ problem "Formula should have a homepage."
+ return
+ end
+
unless homepage =~ %r{^https?://}
problem "The homepage should start with http or https (URL is #{homepage})."
end | true |
Other | Homebrew | brew | e3f4701f385c286a2cc72c5d07870cc9a6ce0bf4.json | audit: fix audit on formulae without homepages | Library/Homebrew/test/audit_test.rb | @@ -466,6 +466,17 @@ class #{Formulary.class_s(name)} < Formula
end
end
+ def test_audit_without_homepage
+ fa = formula_auditor "foo", <<-EOS.undent, online: true
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ end
+ EOS
+
+ fa.audit_homepage
+ assert_match "Formula should have a homepage.", fa.problems.first
+ end
+
def test_audit_xcodebuild_suggests_symroot
fa = formula_auditor "foo", <<-EOS.undent
class Foo < Formula | true |
Other | Homebrew | brew | 9ce757b339d0fbda95c6dcc07d07dc33b08dad8a.json | Remove unused utils/homebrew_vars. | Library/Homebrew/utils/homebrew_vars.rb | @@ -1,11 +0,0 @@
-#!/usr/bin/env ruby
-
-ENV.keys.each do |key|
- if key =~ /^HOMEBREW.*/
- # Remove any HOMEBREW.* vars containing white-space which causes a problem for "env -i" command via string.
- #
- # (Any user supplied HOMEBREW.* vars with valid white-space need to be hard-coded in 'bin/brew')
- #
- puts "#{key}=#{ENV[key]}" unless ENV[key].split(' ').length > 1
- end
-end | false |
Other | Homebrew | brew | 177aefdf555488653572f1f98bf4d6d8c7a03671.json | xcodebuild audit: match xcodebuild with no args
Closes #2199.
Signed-off-by: Misty De Meo <mistydemeo@gmail.com> | Library/Homebrew/dev-cmd/audit.rb | @@ -924,7 +924,7 @@ def audit_text
end
end
- if text =~ /xcodebuild[ (]["'*]/ && !text.include?("SYMROOT=")
+ if text =~ /xcodebuild[ (]*["'*]*/ && !text.include?("SYMROOT=")
problem 'xcodebuild should be passed an explicit "SYMROOT"'
end
| true |
Other | Homebrew | brew | 177aefdf555488653572f1f98bf4d6d8c7a03671.json | xcodebuild audit: match xcodebuild with no args
Closes #2199.
Signed-off-by: Misty De Meo <mistydemeo@gmail.com> | Library/Homebrew/test/audit_test.rb | @@ -465,4 +465,38 @@ class #{Formulary.class_s(name)} < Formula
end
end
end
+
+ def test_audit_xcodebuild_suggests_symroot
+ fa = formula_auditor "foo", <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ homepage "http://example.com"
+
+ def install
+ xcodebuild "-project", "meow.xcodeproject"
+ end
+ end
+ EOS
+
+ fa.audit_text
+
+ assert_match 'xcodebuild should be passed an explicit "SYMROOT"', fa.problems.first
+ end
+
+ def test_audit_bare_xcodebuild_suggests_symroot_also
+ fa = formula_auditor "foo", <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ homepage "http://example.com"
+
+ def install
+ xcodebuild
+ end
+ end
+ EOS
+
+ fa.audit_text
+
+ assert_match 'xcodebuild should be passed an explicit "SYMROOT"', fa.problems.first
+ end
end | true |
Other | Homebrew | brew | 2826aa4c7f9b6d8c9ebac30c084160e10365ef55.json | Convert BuildOptions test to spec. | Library/Homebrew/test/build_options_spec.rb | @@ -0,0 +1,52 @@
+require "build_options"
+require "options"
+
+RSpec::Matchers.alias_matcher :be_built_with, :be_with
+RSpec::Matchers.alias_matcher :be_built_without, :be_without
+
+describe BuildOptions do
+ subject { described_class.new(args, opts) }
+ let(:bad_build) { described_class.new(bad_args, opts) }
+ let(:args) { Options.create(%w[--with-foo --with-bar --without-qux]) }
+ let(:opts) { Options.create(%w[--with-foo --with-bar --without-baz --without-qux]) }
+ let(:bad_args) { Options.create(%w[--with-foo --with-bar --without-bas --without-qux --without-abc]) }
+
+ specify "#include?" do
+ expect(subject).to include("with-foo")
+ expect(subject).not_to include("with-qux")
+ expect(subject).not_to include("--with-foo")
+ end
+
+ specify "#with?" do
+ expect(subject).to be_built_with("foo")
+ expect(subject).to be_built_with("bar")
+ expect(subject).to be_built_with("baz")
+ end
+
+ specify "#without?" do
+ expect(subject).to be_built_without("qux")
+ expect(subject).to be_built_without("xyz")
+ end
+
+ specify "#used_options" do
+ expect(subject.used_options).to include("--with-foo")
+ expect(subject.used_options).to include("--with-bar")
+ end
+
+ specify "#unused_options" do
+ expect(subject.unused_options).to include("--without-baz")
+ end
+
+ specify "#invalid_options" do
+ expect(subject.invalid_options).to be_empty
+ expect(bad_build.invalid_options).to include("--without-bas")
+ expect(bad_build.invalid_options).to include("--without-abc")
+ expect(bad_build.invalid_options).not_to include("--with-foo")
+ expect(bad_build.invalid_options).not_to include("--with-baz")
+ end
+
+ specify "#invalid_option_names" do
+ expect(subject.invalid_option_names).to be_empty
+ expect(bad_build.invalid_option_names).to eq(%w[--without-abc --without-bas])
+ end
+end | true |
Other | Homebrew | brew | 2826aa4c7f9b6d8c9ebac30c084160e10365ef55.json | Convert BuildOptions test to spec. | Library/Homebrew/test/build_options_test.rb | @@ -1,50 +0,0 @@
-require "testing_env"
-require "build_options"
-require "options"
-
-class BuildOptionsTests < Homebrew::TestCase
- def setup
- super
- args = Options.create(%w[--with-foo --with-bar --without-qux])
- opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux])
- @build = BuildOptions.new(args, opts)
- bad_args = Options.create(%w[--with-foo --with-bar --without-bas --without-qux --without-abc])
- @bad_build = BuildOptions.new(bad_args, opts)
- end
-
- def test_include
- assert_includes @build, "with-foo"
- refute_includes @build, "with-qux"
- refute_includes @build, "--with-foo"
- end
-
- def test_with_without
- assert @build.with?("foo")
- assert @build.with?("bar")
- assert @build.with?("baz")
- assert @build.without?("qux")
- assert @build.without?("xyz")
- end
-
- def test_used_options
- assert_includes @build.used_options, "--with-foo"
- assert_includes @build.used_options, "--with-bar"
- end
-
- def test_unused_options
- assert_includes @build.unused_options, "--without-baz"
- end
-
- def test_invalid_options
- assert_empty @build.invalid_options
- assert_includes @bad_build.invalid_options, "--without-bas"
- assert_includes @bad_build.invalid_options, "--without-abc"
- refute_includes @bad_build.invalid_options, "--with-foo"
- refute_includes @bad_build.invalid_options, "--with-baz"
- end
-
- def test_invalid_option_names
- assert_empty @build.invalid_option_names
- assert_equal @bad_build.invalid_option_names, %w[--without-abc --without-bas]
- end
-end | true |
Other | Homebrew | brew | 2826aa4c7f9b6d8c9ebac30c084160e10365ef55.json | Convert BuildOptions test to spec. | Library/Homebrew/test/tab_spec.rb | @@ -1,7 +1,7 @@
require "tab"
require "formula"
-RSpec::Matchers.alias_matcher :have_option_with, :be_with
+RSpec::Matchers.alias_matcher :be_built_with, :be_with
describe Tab do
matcher :be_poured_from_bottle do
@@ -80,10 +80,10 @@
end
specify "#with?" do
- expect(subject).to have_option_with("foo")
- expect(subject).to have_option_with("qux")
- expect(subject).not_to have_option_with("bar")
- expect(subject).not_to have_option_with("baz")
+ expect(subject).to be_built_with("foo")
+ expect(subject).to be_built_with("qux")
+ expect(subject).not_to be_built_with("bar")
+ expect(subject).not_to be_built_with("baz")
end
specify "#universal?" do | true |
Other | Homebrew | brew | ac2cafe13914881d6db72c57e007ccaa7a6a0e04.json | Convert Caveats test to spec. | Library/Homebrew/test/caveats_spec.rb | @@ -0,0 +1,29 @@
+require "formula"
+require "caveats"
+
+describe Caveats do
+ subject { described_class.new(f) }
+ let(:f) { formula { url "foo-1.0" } }
+
+ specify "#f" do
+ expect(subject.f).to eq(f)
+ end
+
+ describe "#empty?" do
+ it "returns true if the Formula has no caveats" do
+ expect(subject).to be_empty
+ end
+
+ it "returns false if the Formula has caveats" do
+ f = formula do
+ url "foo-1.0"
+
+ def caveats
+ "something"
+ end
+ end
+
+ expect(described_class.new(f)).not_to be_empty
+ end
+ end
+end | true |
Other | Homebrew | brew | ac2cafe13914881d6db72c57e007ccaa7a6a0e04.json | Convert Caveats test to spec. | Library/Homebrew/test/caveats_test.rb | @@ -1,30 +0,0 @@
-require "testing_env"
-require "formula"
-require "caveats"
-
-class CaveatsTests < Homebrew::TestCase
- def setup
- super
- @f = formula { url "foo-1.0" }
- @c = Caveats.new @f
- end
-
- def test_f
- assert_equal @f, @c.f
- end
-
- def test_empty?
- assert @c.empty?
-
- f = formula do
- url "foo-1.0"
-
- def caveats
- "something"
- end
- end
- c = Caveats.new f
-
- refute c.empty?
- end
-end | true |
Other | Homebrew | brew | 37f7e84e04051af769f13dda3b0d400802446a7f.json | Convert Options test to spec. | Library/Homebrew/test/options_spec.rb | @@ -0,0 +1,148 @@
+require "options"
+
+describe Option do
+ subject { described_class.new("foo") }
+
+ specify "#to_s" do
+ expect(subject.to_s).to eq("--foo")
+ end
+
+ specify "equality" do
+ foo = Option.new("foo")
+ bar = Option.new("bar")
+ expect(subject).to eq(foo)
+ expect(subject).not_to eq(bar)
+ expect(subject).to eql(foo)
+ expect(subject).not_to eql(bar)
+ end
+
+ specify "#description" do
+ expect(subject.description).to be_empty
+ expect(Option.new("foo", "foo").description).to eq("foo")
+ end
+
+ specify "#inspect" do
+ expect(subject.inspect).to eq("#<Option: \"--foo\">")
+ end
+end
+
+describe DeprecatedOption do
+ subject { described_class.new("foo", "bar") }
+
+ specify "#old" do
+ expect(subject.old).to eq("foo")
+ end
+
+ specify "#old_flag" do
+ expect(subject.old_flag).to eq("--foo")
+ end
+
+ specify "#current" do
+ expect(subject.current).to eq("bar")
+ end
+
+ specify "#current_flag" do
+ expect(subject.current_flag).to eq("--bar")
+ end
+
+ specify "equality" do
+ foobar = DeprecatedOption.new("foo", "bar")
+ boofar = DeprecatedOption.new("boo", "far")
+ expect(foobar).to eq(subject)
+ expect(subject).to eq(foobar)
+ expect(boofar).not_to eq(subject)
+ expect(subject).not_to eq(boofar)
+ end
+end
+
+describe Options do
+ it "removes duplicate options" do
+ subject << Option.new("foo")
+ subject << Option.new("foo")
+ expect(subject).to include("--foo")
+ expect(subject.count).to eq(1)
+ end
+
+ it "preserves existing member when adding a duplicate" do
+ a = Option.new("foo", "bar")
+ b = Option.new("foo", "qux")
+ subject << a << b
+ expect(subject.count).to eq(1)
+ expect(subject.first).to be(a)
+ expect(subject.first.description).to eq(a.description)
+ end
+
+ specify "#include?" do
+ subject << Option.new("foo")
+ expect(subject).to include("--foo")
+ expect(subject).to include("foo")
+ expect(subject).to include(Option.new("foo"))
+ end
+
+ describe "#+" do
+ it "returns options" do
+ expect(subject + Options.new).to be_an_instance_of(Options)
+ end
+ end
+
+ describe "#-" do
+ it "returns options" do
+ expect(subject - Options.new).to be_an_instance_of(Options)
+ end
+ end
+
+ specify "#&" do
+ foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) }
+ options = Options.new << foo << bar
+ subject << foo << baz
+ expect((subject & options).to_a).to eq([foo])
+ end
+
+ specify "#|" do
+ foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) }
+ options = Options.new << foo << bar
+ subject << foo << baz
+ expect((subject | options).sort).to eq([foo, bar, baz].sort)
+ end
+
+ specify "#*" do
+ subject << Option.new("aa") << Option.new("bb") << Option.new("cc")
+ expect((subject * "XX").split("XX").sort).to eq(%w[--aa --bb --cc])
+ end
+
+ describe "<<" do
+ it "returns itself" do
+ expect(subject << Option.new("foo")).to be subject
+ end
+ end
+
+ specify "#as_flags" do
+ subject << Option.new("foo")
+ expect(subject.as_flags).to eq(%w[--foo])
+ end
+
+ specify "#to_a" do
+ option = Option.new("foo")
+ subject << option
+ expect(subject.to_a).to eq([option])
+ end
+
+ specify "#to_ary" do
+ option = Option.new("foo")
+ subject << option
+ expect(subject.to_ary).to eq([option])
+ end
+
+ specify "::create_with_array" do
+ array = %w[--foo --bar]
+ option1 = Option.new("foo")
+ option2 = Option.new("bar")
+ expect(Options.create(array).sort).to eq([option1, option2].sort)
+ end
+
+ specify "#inspect" do
+ expect(subject.inspect).to eq("#<Options: []>")
+ subject << Option.new("foo")
+ expect(subject.inspect).to eq("#<Options: [#<Option: \"--foo\">]>")
+ end
+end | true |
Other | Homebrew | brew | 37f7e84e04051af769f13dda3b0d400802446a7f.json | Convert Options test to spec. | Library/Homebrew/test/options_test.rb | @@ -1,148 +0,0 @@
-require "testing_env"
-require "options"
-
-class OptionTests < Homebrew::TestCase
- def setup
- super
- @option = Option.new("foo")
- end
-
- def test_to_s
- assert_equal "--foo", @option.to_s
- end
-
- def test_equality
- foo = Option.new("foo")
- bar = Option.new("bar")
- assert_equal foo, @option
- refute_equal bar, @option
- assert_eql @option, foo
- refute_eql @option, bar
- end
-
- def test_description
- assert_empty @option.description
- assert_equal "foo", Option.new("foo", "foo").description
- end
-
- def test_inspect
- assert_equal "#<Option: \"--foo\">", @option.inspect
- end
-end
-
-class DeprecatedOptionTests < Homebrew::TestCase
- def setup
- super
- @deprecated_option = DeprecatedOption.new("foo", "bar")
- end
-
- def test_old
- assert_equal "foo", @deprecated_option.old
- assert_equal "--foo", @deprecated_option.old_flag
- end
-
- def test_current
- assert_equal "bar", @deprecated_option.current
- assert_equal "--bar", @deprecated_option.current_flag
- end
-
- def test_equality
- foobar = DeprecatedOption.new("foo", "bar")
- boofar = DeprecatedOption.new("boo", "far")
- assert_equal foobar, @deprecated_option
- refute_equal boofar, @deprecated_option
- assert_eql @deprecated_option, foobar
- refute_eql @deprecated_option, boofar
- end
-end
-
-class OptionsTests < Homebrew::TestCase
- def setup
- super
- @options = Options.new
- end
-
- def test_no_duplicate_options
- @options << Option.new("foo")
- @options << Option.new("foo")
- assert_includes @options, "--foo"
- assert_equal 1, @options.count
- end
-
- def test_preserves_existing_member_when_pushing_duplicate
- a = Option.new("foo", "bar")
- b = Option.new("foo", "qux")
- @options << a << b
- assert_equal 1, @options.count
- assert_same a, @options.first
- assert_equal a.description, @options.first.description
- end
-
- def test_include
- @options << Option.new("foo")
- assert_includes @options, "--foo"
- assert_includes @options, "foo"
- assert_includes @options, Option.new("foo")
- end
-
- def test_union_returns_options
- assert_instance_of Options, @options + Options.new
- end
-
- def test_difference_returns_options
- assert_instance_of Options, @options - Options.new
- end
-
- def test_shovel_returns_self
- assert_same @options, @options << Option.new("foo")
- end
-
- def test_as_flags
- @options << Option.new("foo")
- assert_equal %w[--foo], @options.as_flags
- end
-
- def test_to_a
- option = Option.new("foo")
- @options << option
- assert_equal [option], @options.to_a
- end
-
- def test_to_ary
- option = Option.new("foo")
- @options << option
- assert_equal [option], @options.to_ary
- end
-
- def test_intersection
- foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) }
- options = Options.new << foo << bar
- @options << foo << baz
- assert_equal [foo], (@options & options).to_a
- end
-
- def test_set_union
- foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) }
- options = Options.new << foo << bar
- @options << foo << baz
- assert_equal [foo, bar, baz].sort, (@options | options).sort
- end
-
- def test_times
- @options << Option.new("aa") << Option.new("bb") << Option.new("cc")
- assert_equal %w[--aa --bb --cc], (@options * "XX").split("XX").sort
- end
-
- def test_create_with_array
- array = %w[--foo --bar]
- option1 = Option.new("foo")
- option2 = Option.new("bar")
- assert_equal [option1, option2].sort, Options.create(array).sort
- end
-
- def test_inspect
- assert_equal "#<Options: []>", @options.inspect
- @options << Option.new("foo")
- assert_equal "#<Options: [#<Option: \"--foo\">]>", @options.inspect
- end
-end | true |
Other | Homebrew | brew | 8ef45eb896d5f440019bd34dfcf4d0ed0ff4f253.json | README: add FX Coudert. | README.md | @@ -40,7 +40,8 @@ This is our PGP key which is valid until May 24, 2017.
## Who Are You?
Homebrew's lead maintainer is [Mike McQuaid](https://github.com/mikemcquaid).
-Homebrew's current maintainers are [Alyssa Ross](https://github.com/alyssais), [Andrew Janke](https://github.com/apjanke), [Baptiste Fontaine](https://github.com/bfontaine), [Alex Dunn](https://github.com/dunn), [ilovezfs](https://github.com/ilovezfs), [Josh Hagins](https://github.com/jawshooah), [JCount](https://github.com/jcount), [Misty De Meo](https://github.com/mistydemeo), [Tomasz Pajor](https://github.com/nijikon), [Markus Reiter](https://github.com/reitermarkus), [Tim Smith](https://github.com/tdsmith), [Tom Schoonjans](https://github.com/tschoonj), [Uladzislau Shablinski](https://github.com/vladshablinsky) and [William Woodruff](https://github.com/woodruffw).
+Homebrew's current maintainers are [Alyssa Ross](https://github.com/alyssais), [Andrew Janke](https://github.com/apjanke), [Baptiste Fontaine](https://github.com/bfontaine), [Alex Dunn](https://github.com/dunn),
+[FX Coudert](https://github.com/fxcoudert), [ilovezfs](https://github.com/ilovezfs), [Josh Hagins](https://github.com/jawshooah), [JCount](https://github.com/jcount), [Misty De Meo](https://github.com/mistydemeo), [Tomasz Pajor](https://github.com/nijikon), [Markus Reiter](https://github.com/reitermarkus), [Tim Smith](https://github.com/tdsmith), [Tom Schoonjans](https://github.com/tschoonj), [Uladzislau Shablinski](https://github.com/vladshablinsky) and [William Woodruff](https://github.com/woodruffw).
Former maintainers with significant contributions include [Xu Cheng](https://github.com/xu-cheng), [Martin Afanasjew](https://github.com/UniqMartin), [Dominyk Tiller](https://github.com/DomT4), [Brett Koonce](https://github.com/asparagui), [Jack Nagel](https://github.com/jacknagel), [Adam Vandenberg](https://github.com/adamv) and Homebrew's creator: [Max Howell](https://github.com/mxcl).
| true |
Other | Homebrew | brew | 8ef45eb896d5f440019bd34dfcf4d0ed0ff4f253.json | README: add FX Coudert. | docs/brew.1.html | @@ -791,7 +791,7 @@ <h2 id="AUTHORS">AUTHORS</h2>
<p>Homebrew's lead maintainer is Mike McQuaid.</p>
-<p>Homebrew's current maintainers are Alyssa Ross, Andrew Janke, Baptiste Fontaine, Alex Dunn, ilovezfs, Josh Hagins, JCount, Misty De Meo, Tomasz Pajor, Markus Reiter, Tim Smith, Tom Schoonjans, Uladzislau Shablinski and William Woodruff.</p>
+<p>Homebrew's current maintainers are Alyssa Ross, Andrew Janke, Baptiste Fontaine, [Alex Dunn](https://github.</p>
<p>Former maintainers with significant contributions include Xu Cheng, Martin Afanasjew, Dominyk Tiller, Brett Koonce, Jack Nagel, Adam Vandenberg and Homebrew's creator: Max Howell.</p>
| true |
Other | Homebrew | brew | 8ef45eb896d5f440019bd34dfcf4d0ed0ff4f253.json | README: add FX Coudert. | manpages/brew.1 | @@ -1056,7 +1056,7 @@ Homebrew Documentation: \fIhttps://github\.com/Homebrew/brew/blob/master/docs/\f
Homebrew\'s lead maintainer is Mike McQuaid\.
.
.P
-Homebrew\'s current maintainers are Alyssa Ross, Andrew Janke, Baptiste Fontaine, Alex Dunn, ilovezfs, Josh Hagins, JCount, Misty De Meo, Tomasz Pajor, Markus Reiter, Tim Smith, Tom Schoonjans, Uladzislau Shablinski and William Woodruff\.
+Homebrew\'s current maintainers are Alyssa Ross, Andrew Janke, Baptiste Fontaine, [Alex Dunn](https://github\.
.
.P
Former maintainers with significant contributions include Xu Cheng, Martin Afanasjew, Dominyk Tiller, Brett Koonce, Jack Nagel, Adam Vandenberg and Homebrew\'s creator: Max Howell\. | true |
Other | Homebrew | brew | b0cd1c732d25b112e75facf48325f7841c8b6ac3.json | Convert Formula test to spec. | Library/Homebrew/test/formula_spec.rb | @@ -0,0 +1,1295 @@
+require "test/support/fixtures/testball"
+require "formula"
+
+RSpec::Matchers.alias_matcher :follow_installed_alias, :be_follow_installed_alias
+RSpec::Matchers.alias_matcher :have_any_version_installed, :be_any_version_installed
+RSpec::Matchers.alias_matcher :need_migration, :be_migration_needed
+
+RSpec::Matchers.alias_matcher :have_changed_installed_alias_target, :be_installed_alias_target_changed
+RSpec::Matchers.alias_matcher :supersede_an_installed_formula, :be_supersedes_an_installed_formula
+RSpec::Matchers.alias_matcher :have_changed_alias, :be_alias_changed
+
+RSpec::Matchers.alias_matcher :have_option_defined, :be_option_defined
+RSpec::Matchers.alias_matcher :have_post_install_defined, :be_post_install_defined
+RSpec::Matchers.alias_matcher :have_test_defined, :be_test_defined
+RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle
+
+describe Formula do
+ describe "::new" do
+ let(:klass) do
+ Class.new(described_class) do
+ url "http://example.com/foo-1.0.tar.gz"
+ end
+ end
+
+ let(:name) { "formula_name" }
+ let(:path) { Formulary.core_path(name) }
+ let(:spec) { :stable }
+ let(:alias_name) { "baz@1" }
+ let(:alias_path) { CoreTap.instance.alias_dir/alias_name }
+ let(:f) { klass.new(name, path, spec) }
+ let(:f_alias) { klass.new(name, path, spec, alias_path: alias_path) }
+
+ specify "formula instantiation" do
+ expect(f.name).to eq(name)
+ expect(f.specified_name).to eq(name)
+ expect(f.full_name).to eq(name)
+ expect(f.full_specified_name).to eq(name)
+ expect(f.path).to eq(path)
+ expect(f.alias_path).to be nil
+ expect(f.alias_name).to be nil
+ expect(f.full_alias_name).to be nil
+ expect { klass.new }.to raise_error(ArgumentError)
+ end
+
+ specify "formula instantiation with alias" do
+ expect(f_alias.name).to eq(name)
+ expect(f_alias.full_name).to eq(name)
+ expect(f_alias.path).to eq(path)
+ expect(f_alias.alias_path).to eq(alias_path)
+ expect(f_alias.alias_name).to eq(alias_name)
+ expect(f_alias.specified_name).to eq(alias_name)
+ expect(f_alias.full_alias_name).to eq(alias_name)
+ expect(f_alias.full_specified_name).to eq(alias_name)
+ expect { klass.new }.to raise_error(ArgumentError)
+ end
+
+ context "in a Tap" do
+ let(:tap) { Tap.new("foo", "bar") }
+ let(:path) { (tap.path/"Formula/#{name}.rb") }
+ let(:full_name) { "#{tap.user}/#{tap.repo}/#{name}" }
+ let(:full_alias_name) { "#{tap.user}/#{tap.repo}/#{alias_name}" }
+
+ specify "formula instantiation" do
+ expect(f.name).to eq(name)
+ expect(f.specified_name).to eq(name)
+ expect(f.full_name).to eq(full_name)
+ expect(f.full_specified_name).to eq(full_name)
+ expect(f.path).to eq(path)
+ expect(f.alias_path).to be nil
+ expect(f.alias_name).to be nil
+ expect(f.full_alias_name).to be nil
+ expect { klass.new }.to raise_error(ArgumentError)
+ end
+
+ specify "formula instantiation with alias" do
+ expect(f_alias.name).to eq(name)
+ expect(f_alias.full_name).to eq(full_name)
+ expect(f_alias.path).to eq(path)
+ expect(f_alias.alias_path).to eq(alias_path)
+ expect(f_alias.alias_name).to eq(alias_name)
+ expect(f_alias.specified_name).to eq(alias_name)
+ expect(f_alias.full_alias_name).to eq(full_alias_name)
+ expect(f_alias.full_specified_name).to eq(full_alias_name)
+ expect { klass.new }.to raise_error(ArgumentError)
+ end
+ end
+ end
+
+ describe "#follow_installed_alias?" do
+ let(:f) do
+ formula do
+ url "foo-1.0"
+ end
+ end
+
+ it "returns true by default" do
+ expect(f).to follow_installed_alias
+ end
+
+ it "can be set to true" do
+ f.follow_installed_alias = true
+ expect(f).to follow_installed_alias
+ end
+
+ it "can be set to false" do
+ f.follow_installed_alias = false
+ expect(f).not_to follow_installed_alias
+ end
+ end
+
+ example "installed alias with core" do
+ f = formula do
+ url "foo-1.0"
+ end
+
+ build_values_with_no_installed_alias = [
+ nil,
+ BuildOptions.new({}, {}),
+ Tab.new(source: { "path" => f.path.to_s }),
+ ]
+ build_values_with_no_installed_alias.each do |build|
+ f.build = build
+ expect(f.installed_alias_path).to be nil
+ expect(f.installed_alias_name).to be nil
+ expect(f.full_installed_alias_name).to be nil
+ expect(f.installed_specified_name).to eq(f.name)
+ expect(f.full_installed_specified_name).to eq(f.name)
+ end
+
+ alias_name = "bar"
+ alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}"
+
+ f.build = Tab.new(source: { "path" => alias_path })
+
+ expect(f.installed_alias_path).to eq(alias_path)
+ expect(f.installed_alias_name).to eq(alias_name)
+ expect(f.full_installed_alias_name).to eq(alias_name)
+ expect(f.installed_specified_name).to eq(alias_name)
+ expect(f.full_installed_specified_name).to eq(alias_name)
+ end
+
+ example "installed alias with tap" do
+ tap = Tap.new("user", "repo")
+ name = "foo"
+ path = "#{tap.path}/Formula/#{name}.rb"
+ f = formula name, path: path do
+ url "foo-1.0"
+ end
+
+ build_values_with_no_installed_alias = [nil, BuildOptions.new({}, {}), Tab.new(source: { "path" => f.path })]
+ build_values_with_no_installed_alias.each do |build|
+ f.build = build
+ expect(f.installed_alias_path).to be nil
+ expect(f.installed_alias_name).to be nil
+ expect(f.full_installed_alias_name).to be nil
+ expect(f.installed_specified_name).to eq(f.name)
+ expect(f.full_installed_specified_name).to eq(f.full_name)
+ end
+
+ alias_name = "bar"
+ full_alias_name = "#{tap.user}/#{tap.repo}/#{alias_name}"
+ alias_path = "#{tap.alias_dir}/#{alias_name}"
+
+ f.build = Tab.new(source: { "path" => alias_path })
+
+ expect(f.installed_alias_path).to eq(alias_path)
+ expect(f.installed_alias_name).to eq(alias_name)
+ expect(f.full_installed_alias_name).to eq(full_alias_name)
+ expect(f.installed_specified_name).to eq(alias_name)
+ expect(f.full_installed_specified_name).to eq(full_alias_name)
+ end
+
+ specify "#prefix" do
+ f = Testball.new
+ expect(f.prefix).to eq(HOMEBREW_CELLAR/f.name/"0.1")
+ expect(f.prefix).to be_kind_of(Pathname)
+ end
+
+ example "revised prefix" do
+ f = Class.new(Testball) { revision(1) }.new
+ expect(f.prefix).to eq(HOMEBREW_CELLAR/f.name/"0.1_1")
+ end
+
+ specify "#any_version_installed?" do
+ f = formula do
+ url "foo"
+ version "1.0"
+ end
+
+ expect(f).not_to have_any_version_installed
+
+ prefix = HOMEBREW_CELLAR/f.name/"0.1"
+ prefix.mkpath
+ FileUtils.touch prefix/Tab::FILENAME
+
+ expect(f).to have_any_version_installed
+ end
+
+ specify "#migration_needed" do
+ f = Testball.new("newname")
+ f.instance_variable_set(:@oldname, "oldname")
+ f.instance_variable_set(:@tap, CoreTap.instance)
+
+ oldname_prefix = (HOMEBREW_CELLAR/"oldname/2.20")
+ newname_prefix = (HOMEBREW_CELLAR/"newname/2.10")
+
+ oldname_prefix.mkpath
+ oldname_tab = Tab.empty
+ oldname_tab.tabfile = oldname_prefix/Tab::FILENAME
+ oldname_tab.write
+
+ expect(f).not_to need_migration
+
+ oldname_tab.tabfile.unlink
+ oldname_tab.source["tap"] = "homebrew/core"
+ oldname_tab.write
+
+ expect(f).to need_migration
+
+ newname_prefix.mkpath
+
+ expect(f).not_to need_migration
+ end
+
+ describe "#installed?" do
+ let(:f) { Testball.new }
+
+ it "returns false if the #installed_prefix is not a directory" do
+ allow(f).to receive(:installed_prefix).and_return(double(directory?: false))
+ expect(f).not_to be_installed
+ end
+
+ it "returns false if the #installed_prefix does not have children" do
+ allow(f).to receive(:installed_prefix).and_return(double(directory?: true, children: []))
+ expect(f).not_to be_installed
+ end
+
+ it "returns true if the #installed_prefix has children" do
+ allow(f).to receive(:installed_prefix).and_return(double(directory?: true, children: [double]))
+ expect(f).to be_installed
+ end
+ end
+
+ describe "#installed prefix" do
+ let(:f) do
+ formula do
+ url "foo"
+ version "1.9"
+
+ head "foo"
+
+ devel do
+ url "foo"
+ version "2.1-devel"
+ end
+ end
+ end
+
+ let(:stable_prefix) { HOMEBREW_CELLAR/f.name/f.version }
+ let(:devel_prefix) { HOMEBREW_CELLAR/f.name/f.devel.version }
+ let(:head_prefix) { HOMEBREW_CELLAR/f.name/f.head.version }
+
+ it "is the same as #prefix by default" do
+ expect(f.installed_prefix).to eq(f.prefix)
+ end
+
+ it "returns the stable prefix if it is installed" do
+ stable_prefix.mkpath
+ expect(f.installed_prefix).to eq(stable_prefix)
+ end
+
+ it "returns the devel prefix if it is installed" do
+ devel_prefix.mkpath
+ expect(f.installed_prefix).to eq(devel_prefix)
+ end
+
+ it "returns the head prefix if it is installed" do
+ head_prefix.mkpath
+ expect(f.installed_prefix).to eq(head_prefix)
+ end
+
+ it "returns the stable prefix if head is outdated" do
+ head_prefix.mkpath
+
+ tab = Tab.empty
+ tab.tabfile = head_prefix/Tab::FILENAME
+ tab.source["versions"] = { "stable" => "1.0" }
+ tab.write
+
+ expect(f.installed_prefix).to eq(stable_prefix)
+ end
+
+ it "returns the stable prefix if head and devel are outdated" do
+ head_prefix.mkpath
+
+ tab = Tab.empty
+ tab.tabfile = head_prefix/Tab::FILENAME
+ tab.source["versions"] = { "stable" => "1.9", "devel" => "2.0" }
+ tab.write
+
+ expect(f.installed_prefix).to eq(stable_prefix)
+ end
+
+ it "returns the devel prefix if the active specification is :devel" do
+ f.active_spec = :devel
+ expect(f.installed_prefix).to eq(devel_prefix)
+ end
+
+ it "returns the head prefix if the active specification is :head" do
+ f.active_spec = :head
+ expect(f.installed_prefix).to eq(head_prefix)
+ end
+ end
+
+ describe "#latest_head_prefix" do
+ let(:f) { Testball.new }
+
+ it "returns the latest head prefix" do
+ stamps_with_revisions = [
+ [111111, 1],
+ [222222, 0],
+ [222222, 1],
+ [222222, 2],
+ ]
+
+ stamps_with_revisions.each do |stamp, revision|
+ version = "HEAD-#{stamp}"
+ version << "_#{revision}" unless revision.zero?
+
+ prefix = f.rack/version
+ prefix.mkpath
+
+ tab = Tab.empty
+ tab.tabfile = prefix/Tab::FILENAME
+ tab.source_modified_time = stamp
+ tab.write
+ end
+
+ prefix = HOMEBREW_CELLAR/f.name/"HEAD-222222_2"
+
+ expect(f.latest_head_prefix).to eq(prefix)
+ end
+ end
+
+ specify "equality" do
+ x = Testball.new
+ y = Testball.new
+
+ expect(x).to eq(y)
+ expect(x).to eql(y)
+ expect(x.hash).to eq(y.hash)
+ end
+
+ specify "inequality" do
+ x = Testball.new("foo")
+ y = Testball.new("bar")
+
+ expect(x).not_to eq(y)
+ expect(x).not_to eql(y)
+ expect(x.hash).not_to eq(y.hash)
+ end
+
+ specify "comparison with non formula objects does not raise" do
+ expect(Object.new).not_to eq(Testball.new)
+ end
+
+ specify "#<=>" do
+ expect(Testball.new <=> Object.new).to be nil
+ end
+
+ describe "#installed_alias_path" do
+ example "alias paths with build options" do
+ alias_path = (CoreTap.instance.alias_dir/"another_name")
+
+ f = formula alias_path: alias_path do
+ url "foo-1.0"
+ end
+ f.build = BuildOptions.new({}, {})
+
+ expect(f.alias_path).to eq(alias_path)
+ expect(f.installed_alias_path).to be nil
+ end
+
+ example "alias paths with tab with non alias source path" do
+ alias_path = (CoreTap.instance.alias_dir/"another_name")
+ source_path = (CoreTap.instance.formula_dir/"another_other_name")
+
+ f = formula alias_path: alias_path do
+ url "foo-1.0"
+ end
+ f.build = Tab.new(source: { "path" => source_path.to_s })
+
+ expect(f.alias_path).to eq(alias_path)
+ expect(f.installed_alias_path).to be nil
+ end
+
+ example "alias paths with tab with alias source path" do
+ alias_path = (CoreTap.instance.alias_dir/"another_name")
+ source_path = (CoreTap.instance.alias_dir/"another_other_name")
+
+ f = formula alias_path: alias_path do
+ url "foo-1.0"
+ end
+ f.build = Tab.new(source: { "path" => source_path.to_s })
+
+ expect(f.alias_path).to eq(alias_path)
+ expect(f.installed_alias_path).to eq(source_path.to_s)
+ end
+ end
+
+ describe "::installed_with_alias_path" do
+ specify "with alias path with nil" do
+ expect(described_class.installed_with_alias_path(nil)).to be_empty
+ end
+
+ specify "with alias path with a path" do
+ alias_path = "#{CoreTap.instance.alias_dir}/alias"
+ different_alias_path = "#{CoreTap.instance.alias_dir}/another_alias"
+
+ formula_with_alias = formula "foo" do
+ url "foo-1.0"
+ end
+ formula_with_alias.build = Tab.empty
+ formula_with_alias.build.source["path"] = alias_path
+
+ formula_without_alias = formula "bar" do
+ url "bar-1.0"
+ end
+ formula_without_alias.build = Tab.empty
+ formula_without_alias.build.source["path"] = formula_without_alias.path.to_s
+
+ formula_with_different_alias = formula "baz" do
+ url "baz-1.0"
+ end
+ formula_with_different_alias.build = Tab.empty
+ formula_with_different_alias.build.source["path"] = different_alias_path
+
+ formulae = [
+ formula_with_alias,
+ formula_without_alias,
+ formula_with_different_alias,
+ ]
+
+ allow(described_class).to receive(:installed).and_return(formulae)
+
+ expect(described_class.installed_with_alias_path(alias_path))
+ .to eq([formula_with_alias])
+ end
+ end
+
+ specify "spec integration" do
+ f = formula do
+ homepage "http://example.com"
+
+ url "http://example.com/test-0.1.tbz"
+ mirror "http://example.org/test-0.1.tbz"
+ sha256 TEST_SHA256
+
+ head "http://example.com/test.git", tag: "foo"
+
+ devel do
+ url "http://example.com/test-0.2.tbz"
+ mirror "http://example.org/test-0.2.tbz"
+ sha256 TEST_SHA256
+ end
+ end
+
+ expect(f.homepage).to eq("http://example.com")
+ expect(f.version).to eq(Version.create("0.1"))
+ expect(f).to be_stable
+ expect(f.stable.version).to eq(Version.create("0.1"))
+ expect(f.devel.version).to eq(Version.create("0.2"))
+ expect(f.head.version).to eq(Version.create("HEAD"))
+ end
+
+ specify "#active_spec=" do
+ f = formula do
+ url "foo"
+ version "1.0"
+ revision 1
+
+ devel do
+ url "foo"
+ version "1.0beta"
+ end
+ end
+
+ expect(f.active_spec_sym).to eq(:stable)
+ expect(f.send(:active_spec)).to eq(f.stable)
+ expect(f.pkg_version.to_s).to eq("1.0_1")
+
+ f.active_spec = :devel
+
+ expect(f.active_spec_sym).to eq(:devel)
+ expect(f.send(:active_spec)).to eq(f.devel)
+ expect(f.pkg_version.to_s).to eq("1.0beta_1")
+ expect { f.active_spec = :head }.to raise_error(FormulaSpecificationError)
+ end
+
+ specify "class specs are always initialized" do
+ f = formula do
+ url "foo-1.0"
+ end
+
+ expect(f.class.stable).to be_kind_of(SoftwareSpec)
+ expect(f.class.devel).to be_kind_of(SoftwareSpec)
+ expect(f.class.head).to be_kind_of(SoftwareSpec)
+ end
+
+ specify "incomplete instance specs are not accessible" do
+ f = formula do
+ url "foo-1.0"
+ end
+
+ expect(f.devel).to be nil
+ expect(f.head).to be nil
+ end
+
+ it "honors attributes declared before specs" do
+ f = formula do
+ url "foo-1.0"
+
+ depends_on "foo"
+
+ devel do
+ url "foo-1.1"
+ end
+ end
+
+ expect(f.class.stable.deps.first.name).to eq("foo")
+ expect(f.class.devel.deps.first.name).to eq("foo")
+ expect(f.class.head.deps.first.name).to eq("foo")
+ end
+
+ describe "#pkg_version" do
+ specify "simple version" do
+ f = formula do
+ url "foo-1.0.bar"
+ end
+
+ expect(f.pkg_version).to eq(PkgVersion.parse("1.0"))
+ end
+
+ specify "version with revision" do
+ f = formula do
+ url "foo-1.0.bar"
+ revision 1
+ end
+
+ expect(f.pkg_version).to eq(PkgVersion.parse("1.0_1"))
+ end
+
+ specify "head uses revisions" do
+ f = formula "test", spec: :head do
+ url "foo-1.0.bar"
+ revision 1
+
+ head "foo"
+ end
+
+ expect(f.pkg_version).to eq(PkgVersion.parse("HEAD_1"))
+ end
+ end
+
+ specify "#update_head_version" do
+ f = formula do
+ head "foo", using: :git
+ end
+
+ cached_location = f.head.downloader.cached_location
+ cached_location.mkpath
+ cached_location.cd do
+ FileUtils.touch "LICENSE"
+
+ shutup do
+ system("git", "init")
+ system("git", "add", "--all")
+ system("git", "commit", "-m", "Initial commit")
+ end
+ end
+
+ f.update_head_version
+
+ expect(f.head.version).to eq(Version.create("HEAD-5658946"))
+ end
+
+ specify "legacy options" do
+ f = formula do
+ url "foo-1.0"
+
+ def options
+ [
+ ["--foo", "desc"],
+ ["--bar", "desc"],
+ ]
+ end
+
+ option("baz")
+ end
+
+ expect(f).to have_option_defined("foo")
+ expect(f).to have_option_defined("bar")
+ expect(f).to have_option_defined("baz")
+ end
+
+ specify "#desc" do
+ f = formula do
+ desc "a formula"
+
+ url "foo-1.0"
+ end
+
+ expect(f.desc).to eq("a formula")
+ end
+
+ specify "#post_install_defined?" do
+ f1 = formula do
+ url "foo-1.0"
+
+ def post_install
+ # do nothing
+ end
+ end
+
+ f2 = formula do
+ url "foo-1.0"
+ end
+
+ expect(f1).to have_post_install_defined
+ expect(f2).not_to have_post_install_defined
+ end
+
+ specify "#test_defined?" do
+ f1 = formula do
+ url "foo-1.0"
+
+ def test
+ # do nothing
+ end
+ end
+
+ f2 = formula do
+ url "foo-1.0"
+ end
+
+ expect(f1).to have_test_defined
+ expect(f2).not_to have_test_defined
+ end
+
+ specify "test fixtures" do
+ f1 = formula do
+ url "foo-1.0"
+ end
+
+ expect(f1.test_fixtures("foo")).to eq(Pathname.new("#{HOMEBREW_LIBRARY_PATH}/test/support/fixtures/foo"))
+ end
+
+ specify "dependencies" do
+ f1 = formula "f1" do
+ url "f1-1.0"
+ end
+
+ f2 = formula "f2" do
+ url "f2-1.0"
+ end
+
+ f3 = formula "f3" do
+ url "f3-1.0"
+
+ depends_on "f1" => :build
+ depends_on "f2"
+ end
+
+ f4 = formula "f4" do
+ url "f4-1.0"
+
+ depends_on "f1"
+ end
+
+ stub_formula_loader(f1)
+ stub_formula_loader(f2)
+ stub_formula_loader(f3)
+ stub_formula_loader(f4)
+
+ f5 = formula "f5" do
+ url "f5-1.0"
+
+ depends_on "f3" => :build
+ depends_on "f4"
+ end
+
+ expect(f5.deps.map(&:name)).to eq(["f3", "f4"])
+ expect(f5.recursive_dependencies.map(&:name)).to eq(["f1", "f2", "f3", "f4"])
+ expect(f5.runtime_dependencies.map(&:name)).to eq(["f1", "f4"])
+ end
+
+ specify "runtime dependencies with optional deps from tap" do
+ tap_loader = double
+
+ allow(tap_loader).to receive(:get_formula).and_raise(RuntimeError, "tried resolving tap formula")
+ allow(Formulary).to receive(:loader_for).with("foo/bar/f1", from: nil).and_return(tap_loader)
+ stub_formula_loader(formula("f2") { url("f2-1.0") }, "baz/qux/f2")
+
+ f3 = formula "f3" do
+ url "f3-1.0"
+
+ depends_on "foo/bar/f1" => :optional
+ depends_on "baz/qux/f2"
+ end
+
+ expect(f3.runtime_dependencies.map(&:name)).to eq(["baz/qux/f2"])
+
+ stub_formula_loader(formula("f1") { url("f1-1.0") }, "foo/bar/f1")
+ f3.build = BuildOptions.new(Options.create(["--with-f1"]), f3.options)
+
+ expect(f3.runtime_dependencies.map(&:name)).to eq(["foo/bar/f1", "baz/qux/f2"])
+ end
+
+ specify "requirements" do
+ f1 = formula "f1" do
+ url "f1-1"
+
+ depends_on :python
+ depends_on x11: :recommended
+ depends_on xcode: ["1.0", :optional]
+ end
+ stub_formula_loader(f1)
+
+ python = PythonRequirement.new
+ x11 = X11Requirement.new("x11", [:recommended])
+ xcode = XcodeRequirement.new(["1.0", :optional])
+
+ expect(Set.new(f1.recursive_requirements)).to eq(Set[python, x11])
+
+ f1.build = BuildOptions.new(["--with-xcode", "--without-x11"], f1.options)
+
+ expect(Set.new(f1.recursive_requirements)).to eq(Set[python, xcode])
+
+ f1.build = f1.stable.build
+ f2 = formula "f2" do
+ url "f2-1"
+
+ depends_on "f1"
+ end
+
+ expect(Set.new(f2.recursive_requirements)).to eq(Set[python, x11])
+ expect(Set.new(f2.recursive_requirements {})).to eq(Set[python, x11, xcode])
+
+ requirements = f2.recursive_requirements do |_dependent, requirement|
+ Requirement.prune if requirement.is_a?(PythonRequirement)
+ end
+
+ expect(Set.new(requirements)).to eq(Set[x11, xcode])
+ end
+
+ specify "#to_hash" do
+ f1 = formula "foo" do
+ url "foo-1.0"
+
+ bottle do
+ cellar(:any)
+ sha256(TEST_SHA256 => Utils::Bottles.tag)
+ end
+ end
+
+ h = f1.to_hash
+
+ expect(h).to be_a(Hash)
+ expect(h["name"]).to eq("foo")
+ expect(h["full_name"]).to eq("foo")
+ expect(h["versions"]["stable"]).to eq("1.0")
+ expect(h["versions"]["bottle"]).to be_truthy
+ end
+
+ describe "#eligible_kegs_for_cleanup" do
+ it "returns Kegs eligible for cleanup" do
+ f1 = Class.new(Testball) do
+ version("1.0")
+ end.new
+
+ f2 = Class.new(Testball) do
+ version("0.2")
+ version_scheme(1)
+ end.new
+
+ f3 = Class.new(Testball) do
+ version("0.3")
+ version_scheme(1)
+ end.new
+
+ f4 = Class.new(Testball) do
+ version("0.1")
+ version_scheme(2)
+ end.new
+
+ shutup do
+ [f1, f2, f3, f4].each do |f|
+ f.brew { f.install }
+ Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
+ end
+ end
+
+ expect(f1).to be_installed
+ expect(f2).to be_installed
+ expect(f3).to be_installed
+ expect(f4).to be_installed
+ expect(f3.eligible_kegs_for_cleanup.sort_by(&:version))
+ .to eq([f2, f1].map { |f| Keg.new(f.prefix) })
+ end
+
+ specify "with pinned Keg" do
+ f1 = Class.new(Testball) { version("0.1") }.new
+ f2 = Class.new(Testball) { version("0.2") }.new
+ f3 = Class.new(Testball) { version("0.3") }.new
+
+ shutup do
+ f1.brew { f1.install }
+ f1.pin
+ f2.brew { f2.install }
+ f3.brew { f3.install }
+ end
+
+ expect(f1.prefix).to eq((HOMEBREW_PINNED_KEGS/f1.name).resolved_path)
+ expect(f1).to be_installed
+ expect(f2).to be_installed
+ expect(f3).to be_installed
+ expect(shutup { f3.eligible_kegs_for_cleanup }).to eq([Keg.new(f2.prefix)])
+ end
+
+ specify "with HEAD installed" do
+ f = formula do
+ version("0.1")
+ head("foo")
+ end
+
+ stable_prefix = f.installed_prefix
+ stable_prefix.mkpath
+
+ [["000000_1", 1], ["111111", 2], ["111111_1", 2]].each do |pkg_version_suffix, stamp|
+ prefix = f.prefix("HEAD-#{pkg_version_suffix}")
+ prefix.mkpath
+ tab = Tab.empty
+ tab.tabfile = prefix/Tab::FILENAME
+ tab.source_modified_time = stamp
+ tab.write
+ end
+
+ eligible_kegs = f.installed_kegs - [Keg.new(f.prefix("HEAD-111111_1"))]
+ expect(f.eligible_kegs_for_cleanup).to eq(eligible_kegs)
+ end
+ end
+
+ describe "#pour_bottle?" do
+ it "returns false if set to false" do
+ f = formula "foo" do
+ url "foo-1.0"
+
+ def pour_bottle?
+ false
+ end
+ end
+
+ expect(f).not_to pour_bottle
+ end
+
+ it "returns true if set to true" do
+ f = formula "foo" do
+ url "foo-1.0"
+
+ def pour_bottle?
+ true
+ end
+ end
+
+ expect(f).to pour_bottle
+ end
+
+ it "returns false if set to false via DSL" do
+ f = formula "foo" do
+ url "foo-1.0"
+
+ pour_bottle? do
+ reason "false reason"
+ satisfy { (var == etc) }
+ end
+ end
+
+ expect(f).not_to pour_bottle
+ end
+
+ it "returns true if set to true via DSL" do
+ f = formula "foo" do
+ url "foo-1.0"
+
+ pour_bottle? do
+ reason "true reason"
+ satisfy { true }
+ end
+ end
+
+ expect(f).to pour_bottle
+ end
+ end
+
+ describe "alias changes" do
+ let(:f) do
+ formula "formula_name", alias_path: alias_path do
+ url "foo-1.0"
+ end
+ end
+
+ let(:new_formula) do
+ formula "new_formula_name", alias_path: alias_path do
+ url "foo-1.1"
+ end
+ end
+
+ let(:tab) { Tab.empty }
+ let(:alias_path) { "#{CoreTap.instance.alias_dir}/bar" }
+
+ before(:each) do
+ allow(described_class).to receive(:installed).and_return([f])
+
+ f.build = tab
+ new_formula.build = tab
+ end
+
+ specify "alias changes when not installed with alias" do
+ tab.source["path"] = Formulary.core_path(f.name).to_s
+
+ expect(f.current_installed_alias_target).to be nil
+ expect(f.latest_formula).to eq(f)
+ expect(f).not_to have_changed_installed_alias_target
+ expect(f).not_to supersede_an_installed_formula
+ expect(f).not_to have_changed_alias
+ expect(f.old_installed_formulae).to be_empty
+ end
+
+ specify "alias changes when not changed" do
+ tab.source["path"] = alias_path
+ stub_formula_loader(f, alias_path)
+
+ expect(f.current_installed_alias_target).to eq(f)
+ expect(f.latest_formula).to eq(f)
+ expect(f).not_to have_changed_installed_alias_target
+ expect(f).not_to supersede_an_installed_formula
+ expect(f).not_to have_changed_alias
+ expect(f.old_installed_formulae).to be_empty
+ end
+
+ specify "alias changes when new alias target" do
+ tab.source["path"] = alias_path
+ stub_formula_loader(new_formula, alias_path)
+
+ expect(f.current_installed_alias_target).to eq(new_formula)
+ expect(f.latest_formula).to eq(new_formula)
+ expect(f).to have_changed_installed_alias_target
+ expect(f).not_to supersede_an_installed_formula
+ expect(f).to have_changed_alias
+ expect(f.old_installed_formulae).to be_empty
+ end
+
+ specify "alias changes when old formulae installed" do
+ tab.source["path"] = alias_path
+ stub_formula_loader(new_formula, alias_path)
+
+ expect(new_formula.current_installed_alias_target).to eq(new_formula)
+ expect(new_formula.latest_formula).to eq(new_formula)
+ expect(new_formula).not_to have_changed_installed_alias_target
+ expect(new_formula).to supersede_an_installed_formula
+ expect(new_formula).to have_changed_alias
+ expect(new_formula.old_installed_formulae).to eq([f])
+ end
+ end
+
+ describe "#outdated_kegs" do
+ let(:outdated_prefix) { (HOMEBREW_CELLAR/"#{f.name}/1.11") }
+ let(:same_prefix) { (HOMEBREW_CELLAR/"#{f.name}/1.20") }
+ let(:greater_prefix) { (HOMEBREW_CELLAR/"#{f.name}/1.21") }
+ let(:head_prefix) { (HOMEBREW_CELLAR/"#{f.name}/HEAD") }
+ let(:old_alias_target_prefix) { (HOMEBREW_CELLAR/"#{old_formula.name}/1.0") }
+
+ let(:f) do
+ formula do
+ url "foo"
+ version "1.20"
+ end
+ end
+
+ let(:old_formula) do
+ formula "foo@1" do
+ url "foo-1.0"
+ end
+ end
+
+ let(:new_formula) do
+ formula "foo@2" do
+ url "foo-2.0"
+ end
+ end
+
+ let(:alias_path) { "#{f.tap.alias_dir}/bar" }
+
+ def setup_tab_for_prefix(prefix, options = {})
+ prefix.mkpath
+ tab = Tab.empty
+ tab.tabfile = prefix/Tab::FILENAME
+ tab.source["path"] = options[:path].to_s if options[:path]
+ tab.source["tap"] = options[:tap] if options[:tap]
+ tab.source["versions"] = options[:versions] if options[:versions]
+ tab.source_modified_time = options[:source_modified_time].to_i
+ tab.write unless options[:no_write]
+ tab
+ end
+
+ def reset_outdated_kegs
+ f.instance_variable_set(:@outdated_kegs, nil)
+ end
+
+ example "greater different tap installed" do
+ setup_tab_for_prefix(greater_prefix, tap: "user/repo")
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "greater same tap installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(greater_prefix, tap: "homebrew/core")
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated different tap installed" do
+ setup_tab_for_prefix(outdated_prefix, tap: "user/repo")
+ expect(f.outdated_kegs).not_to be_empty
+ end
+
+ example "outdated same tap installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(outdated_prefix, tap: "homebrew/core")
+ expect(f.outdated_kegs).not_to be_empty
+ end
+
+ example "outdated follow alias and alias unchanged" do
+ f.follow_installed_alias = true
+ f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
+ stub_formula_loader(f, alias_path)
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated follow alias and alias changed and new target not installed" do
+ f.follow_installed_alias = true
+ f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
+ stub_formula_loader(new_formula, alias_path)
+ expect(f.outdated_kegs).not_to be_empty
+ end
+
+ example "outdated follow alias and alias changed and new target installed" do
+ f.follow_installed_alias = true
+ f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
+ stub_formula_loader(new_formula, alias_path)
+ setup_tab_for_prefix(new_formula.prefix)
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated no follow alias and alias unchanged" do
+ f.follow_installed_alias = false
+ f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
+ stub_formula_loader(f, alias_path)
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated no follow alias and alias changed" do
+ f.follow_installed_alias = false
+ f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
+
+ f2 = formula "foo@2" do
+ url "foo-2.0"
+ end
+
+ stub_formula_loader(f2, alias_path)
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated old alias targets installed" do
+ f = formula alias_path: alias_path do
+ url "foo-1.0"
+ end
+
+ tab = setup_tab_for_prefix(old_alias_target_prefix, path: alias_path)
+ old_formula.build = tab
+ allow(described_class).to receive(:installed).and_return([old_formula])
+ expect(f.outdated_kegs).not_to be_empty
+ end
+
+ example "outdated old alias targets not installed" do
+ f = formula alias_path: alias_path do
+ url "foo-1.0"
+ end
+
+ tab = setup_tab_for_prefix(old_alias_target_prefix, path: old_formula.path)
+ old_formula.build = tab
+ allow(described_class).to receive(:installed).and_return([old_formula])
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated same head installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(head_prefix, tap: "homebrew/core")
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated different head installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(head_prefix, tap: "user/repo")
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated mixed taps greater version installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(outdated_prefix, tap: "homebrew/core")
+ setup_tab_for_prefix(greater_prefix, tap: "user/repo")
+
+ expect(f.outdated_kegs).to be_empty
+
+ setup_tab_for_prefix(greater_prefix, tap: "homebrew/core")
+ reset_outdated_kegs
+
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated mixed taps outdated version installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+
+ extra_outdated_prefix = HOMEBREW_CELLAR/f.name/"1.0"
+
+ setup_tab_for_prefix(outdated_prefix)
+ setup_tab_for_prefix(extra_outdated_prefix, tap: "homebrew/core")
+ reset_outdated_kegs
+
+ expect(f.outdated_kegs).not_to be_empty
+
+ setup_tab_for_prefix(outdated_prefix, tap: "user/repo")
+ reset_outdated_kegs
+
+ expect(f.outdated_kegs).not_to be_empty
+ end
+
+ example "outdated same version tap installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(same_prefix, tap: "homebrew/core")
+
+ expect(f.outdated_kegs).to be_empty
+
+ setup_tab_for_prefix(same_prefix, tap: "user/repo")
+ reset_outdated_kegs
+
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated installed head less than stable" do
+ tab = setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0" })
+
+ expect(f.outdated_kegs).not_to be_empty
+
+ tab.source["versions"] = { "stable" => f.version.to_s }
+ tab.write
+ reset_outdated_kegs
+
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ describe ":fetch_head" do
+ let(:f) do
+ repo = testball_repo
+ formula "testball" do
+ url "foo"
+ version "2.10"
+ head "file://#{repo}", using: :git
+ end
+ end
+ let(:testball_repo) { HOMEBREW_PREFIX/"testball_repo" }
+
+ example do
+ begin
+ outdated_stable_prefix = HOMEBREW_CELLAR/"testball/1.0"
+ head_prefix_a = HOMEBREW_CELLAR/"testball/HEAD"
+ head_prefix_b = HOMEBREW_CELLAR/"testball/HEAD-aaaaaaa_1"
+ head_prefix_c = HOMEBREW_CELLAR/"testball/HEAD-18a7103"
+
+ setup_tab_for_prefix(outdated_stable_prefix)
+ tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" })
+ setup_tab_for_prefix(head_prefix_b)
+
+ testball_repo.mkdir
+ testball_repo.cd do
+ FileUtils.touch "LICENSE"
+
+ shutup do
+ system("git", "init")
+ system("git", "add", "--all")
+ system("git", "commit", "-m", "Initial commit")
+ end
+ end
+
+ expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
+
+ tab_a.source["versions"] = { "stable" => f.version.to_s }
+ tab_a.write
+ reset_outdated_kegs
+ expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
+
+ head_prefix_a.rmtree
+ reset_outdated_kegs
+ expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
+
+ setup_tab_for_prefix(head_prefix_c, source_modified_time: 1)
+ reset_outdated_kegs
+ expect(f.outdated_kegs(fetch_head: true)).to be_empty
+ ensure
+ testball_repo.rmtree if testball_repo.exist?
+ end
+ end
+ end
+
+ describe "with changed version scheme" do
+ let(:f) do
+ formula "testball" do
+ url "foo"
+ version "20141010"
+ version_scheme 1
+ end
+ end
+
+ example do
+ prefix = HOMEBREW_CELLAR/"testball/0.1"
+ setup_tab_for_prefix(prefix, versions: { "stable" => "0.1" })
+
+ expect(f.outdated_kegs).not_to be_empty
+ end
+ end
+
+ describe "with mixed version schemes" do
+ let(:f) do
+ formula "testball" do
+ url "foo"
+ version "20141010"
+ version_scheme 3
+ end
+ end
+
+ example do
+ prefix_a = HOMEBREW_CELLAR/"testball/20141009"
+ setup_tab_for_prefix(prefix_a, versions: { "stable" => "20141009", "version_scheme" => 1 })
+
+ prefix_b = HOMEBREW_CELLAR/"testball/2.14"
+ setup_tab_for_prefix(prefix_b, versions: { "stable" => "2.14", "version_scheme" => 2 })
+
+ expect(f.outdated_kegs).not_to be_empty
+ reset_outdated_kegs
+
+ prefix_c = HOMEBREW_CELLAR/"testball/20141009"
+ setup_tab_for_prefix(prefix_c, versions: { "stable" => "20141009", "version_scheme" => 3 })
+
+ expect(f.outdated_kegs).not_to be_empty
+ reset_outdated_kegs
+
+ prefix_d = HOMEBREW_CELLAR/"testball/20141011"
+ setup_tab_for_prefix(prefix_d, versions: { "stable" => "20141009", "version_scheme" => 3 })
+ expect(f.outdated_kegs).to be_empty
+ end
+ end
+
+ describe "with version scheme" do
+ let(:f) do
+ formula "testball" do
+ url "foo"
+ version "1.0"
+ version_scheme 2
+ end
+ end
+
+ example do
+ head_prefix = HOMEBREW_CELLAR/"testball/HEAD"
+
+ setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 1 })
+ expect(f.outdated_kegs).not_to be_empty
+
+ reset_outdated_kegs
+ head_prefix.rmtree
+
+ setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 2 })
+ expect(f.outdated_kegs).to be_empty
+ end
+ end
+ end
+end | true |
Other | Homebrew | brew | b0cd1c732d25b112e75facf48325f7841c8b6ac3.json | Convert Formula test to spec. | Library/Homebrew/test/formula_test.rb | @@ -1,1205 +0,0 @@
-require "testing_env"
-require "test/support/fixtures/testball"
-require "formula"
-
-class FormulaTests < Homebrew::TestCase
- def test_formula_instantiation
- klass = Class.new(Formula) { url "http://example.com/foo-1.0.tar.gz" }
- name = "formula_name"
- path = Formulary.core_path(name)
- spec = :stable
-
- f = klass.new(name, path, spec)
- assert_equal name, f.name
- assert_equal name, f.specified_name
- assert_equal name, f.full_name
- assert_equal name, f.full_specified_name
- assert_equal path, f.path
- assert_nil f.alias_path
- assert_nil f.alias_name
- assert_nil f.full_alias_name
- assert_raises(ArgumentError) { klass.new }
- end
-
- def test_formula_instantiation_with_alias
- klass = Class.new(Formula) { url "http://example.com/foo-1.0.tar.gz" }
- name = "formula_name"
- path = Formulary.core_path(name)
- spec = :stable
- alias_name = "baz@1"
- alias_path = CoreTap.instance.alias_dir/alias_name
-
- f = klass.new(name, path, spec, alias_path: alias_path)
- assert_equal name, f.name
- assert_equal name, f.full_name
- assert_equal path, f.path
- assert_equal alias_path, f.alias_path
- assert_equal alias_name, f.alias_name
- assert_equal alias_name, f.specified_name
- assert_equal alias_name, f.full_alias_name
- assert_equal alias_name, f.full_specified_name
- assert_raises(ArgumentError) { klass.new }
- end
-
- def test_tap_formula_instantiation
- tap = Tap.new("foo", "bar")
- klass = Class.new(Formula) { url "baz-1.0" }
- name = "baz"
- full_name = "#{tap.user}/#{tap.repo}/#{name}"
- path = tap.path/"Formula/#{name}.rb"
- spec = :stable
-
- f = klass.new(name, path, spec)
- assert_equal name, f.name
- assert_equal name, f.specified_name
- assert_equal full_name, f.full_name
- assert_equal full_name, f.full_specified_name
- assert_equal path, f.path
- assert_nil f.alias_path
- assert_nil f.alias_name
- assert_nil f.full_alias_name
- assert_raises(ArgumentError) { klass.new }
- end
-
- def test_tap_formula_instantiation_with_alias
- tap = Tap.new("foo", "bar")
- klass = Class.new(Formula) { url "baz-1.0" }
- name = "baz"
- full_name = "#{tap.user}/#{tap.repo}/#{name}"
- path = tap.path/"Formula/#{name}.rb"
- spec = :stable
- alias_name = "baz@1"
- full_alias_name = "#{tap.user}/#{tap.repo}/#{alias_name}"
- alias_path = CoreTap.instance.alias_dir/alias_name
-
- f = klass.new(name, path, spec, alias_path: alias_path)
- assert_equal name, f.name
- assert_equal full_name, f.full_name
- assert_equal path, f.path
- assert_equal alias_path, f.alias_path
- assert_equal alias_name, f.alias_name
- assert_equal alias_name, f.specified_name
- assert_equal full_alias_name, f.full_alias_name
- assert_equal full_alias_name, f.full_specified_name
- assert_raises(ArgumentError) { klass.new }
- end
-
- def test_follow_installed_alias
- f = formula { url "foo-1.0" }
- assert_predicate f, :follow_installed_alias?
-
- f.follow_installed_alias = true
- assert_predicate f, :follow_installed_alias?
-
- f.follow_installed_alias = false
- refute_predicate f, :follow_installed_alias?
- end
-
- def test_installed_alias_with_core
- f = formula { url "foo-1.0" }
-
- build_values_with_no_installed_alias = [
- nil,
- BuildOptions.new({}, {}),
- Tab.new(source: { "path" => f.path.to_s }),
- ]
-
- build_values_with_no_installed_alias.each do |build|
- f.build = build
- assert_nil f.installed_alias_path
- assert_nil f.installed_alias_name
- assert_nil f.full_installed_alias_name
- assert_equal f.name, f.installed_specified_name
- assert_equal f.name, f.full_installed_specified_name
- end
-
- alias_name = "bar"
- alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}"
- f.build = Tab.new(source: { "path" => alias_path })
- assert_equal alias_path, f.installed_alias_path
- assert_equal alias_name, f.installed_alias_name
- assert_equal alias_name, f.full_installed_alias_name
- assert_equal alias_name, f.installed_specified_name
- assert_equal alias_name, f.full_installed_specified_name
- end
-
- def test_installed_alias_with_tap
- tap = Tap.new("user", "repo")
- name = "foo"
- path = "#{tap.path}/Formula/#{name}.rb"
- f = formula(name, path) { url "foo-1.0" }
-
- build_values_with_no_installed_alias = [
- nil,
- BuildOptions.new({}, {}),
- Tab.new(source: { "path" => f.path }),
- ]
-
- build_values_with_no_installed_alias.each do |build|
- f.build = build
- assert_nil f.installed_alias_path
- assert_nil f.installed_alias_name
- assert_nil f.full_installed_alias_name
- assert_equal f.name, f.installed_specified_name
- assert_equal f.full_name, f.full_installed_specified_name
- end
-
- alias_name = "bar"
- full_alias_name = "#{tap.user}/#{tap.repo}/#{alias_name}"
- alias_path = "#{tap.alias_dir}/#{alias_name}"
- f.build = Tab.new(source: { "path" => alias_path })
- assert_equal alias_path, f.installed_alias_path
- assert_equal alias_name, f.installed_alias_name
- assert_equal full_alias_name, f.full_installed_alias_name
- assert_equal alias_name, f.installed_specified_name
- assert_equal full_alias_name, f.full_installed_specified_name
- end
-
- def test_prefix
- f = Testball.new
- assert_equal HOMEBREW_CELLAR/f.name/"0.1", f.prefix
- assert_kind_of Pathname, f.prefix
- end
-
- def test_revised_prefix
- f = Class.new(Testball) { revision 1 }.new
- assert_equal HOMEBREW_CELLAR/f.name/"0.1_1", f.prefix
- end
-
- def test_any_version_installed?
- f = formula do
- url "foo"
- version "1.0"
- end
- refute_predicate f, :any_version_installed?
- prefix = HOMEBREW_CELLAR+f.name+"0.1"
- prefix.mkpath
- FileUtils.touch prefix+Tab::FILENAME
- assert_predicate f, :any_version_installed?
- end
-
- def test_migration_needed
- f = Testball.new("newname")
- f.instance_variable_set(:@oldname, "oldname")
- f.instance_variable_set(:@tap, CoreTap.instance)
-
- oldname_prefix = HOMEBREW_CELLAR/"oldname/2.20"
- newname_prefix = HOMEBREW_CELLAR/"newname/2.10"
- oldname_prefix.mkpath
- oldname_tab = Tab.empty
- oldname_tab.tabfile = oldname_prefix.join("INSTALL_RECEIPT.json")
- oldname_tab.write
-
- refute_predicate f, :migration_needed?
-
- oldname_tab.tabfile.unlink
- oldname_tab.source["tap"] = "homebrew/core"
- oldname_tab.write
-
- assert_predicate f, :migration_needed?
-
- newname_prefix.mkpath
-
- refute_predicate f, :migration_needed?
- end
-
- def test_installed?
- f = Testball.new
- f.stubs(:installed_prefix).returns(stub(directory?: false))
- refute_predicate f, :installed?
-
- f.stubs(:installed_prefix).returns(
- stub(directory?: true, children: []),
- )
- refute_predicate f, :installed?
-
- f.stubs(:installed_prefix).returns(
- stub(directory?: true, children: [stub]),
- )
- assert_predicate f, :installed?
- end
-
- def test_installed_prefix
- f = Testball.new
- assert_equal f.prefix, f.installed_prefix
- end
-
- def test_installed_prefix_head_installed
- f = formula do
- head "foo"
- devel do
- url "foo"
- version "1.0"
- end
- end
- prefix = HOMEBREW_CELLAR+f.name+f.head.version
- prefix.mkpath
- assert_equal prefix, f.installed_prefix
- end
-
- def test_installed_prefix_devel_installed
- f = formula do
- head "foo"
- devel do
- url "foo"
- version "1.0"
- end
- end
- prefix = HOMEBREW_CELLAR+f.name+f.devel.version
- prefix.mkpath
- assert_equal prefix, f.installed_prefix
- end
-
- def test_installed_prefix_stable_installed
- f = formula do
- head "foo"
- devel do
- url "foo"
- version "1.0-devel"
- end
- end
- prefix = HOMEBREW_CELLAR+f.name+f.version
- prefix.mkpath
- assert_equal prefix, f.installed_prefix
- end
-
- def test_installed_prefix_outdated_stable_head_installed
- f = formula do
- url "foo"
- version "1.9"
- head "foo"
- end
-
- head_prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD"
- head_prefix.mkpath
- tab = Tab.empty
- tab.tabfile = head_prefix.join("INSTALL_RECEIPT.json")
- tab.source["versions"] = { "stable" => "1.0" }
- tab.write
-
- assert_equal HOMEBREW_CELLAR/"#{f.name}/#{f.version}", f.installed_prefix
- end
-
- def test_installed_prefix_outdated_devel_head_installed
- f = formula do
- url "foo"
- version "1.9"
- devel do
- url "foo"
- version "2.1"
- end
- end
-
- head_prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD"
- head_prefix.mkpath
- tab = Tab.empty
- tab.tabfile = head_prefix.join("INSTALL_RECEIPT.json")
- tab.source["versions"] = { "stable" => "1.9", "devel" => "2.0" }
- tab.write
-
- assert_equal HOMEBREW_CELLAR/"#{f.name}/#{f.version}", f.installed_prefix
- end
-
- def test_installed_prefix_head
- f = formula("test", Pathname.new(__FILE__).expand_path, :head) do
- head "foo"
- devel do
- url "foo"
- version "1.0-devel"
- end
- end
- prefix = HOMEBREW_CELLAR+f.name+f.head.version
- assert_equal prefix, f.installed_prefix
- end
-
- def test_installed_prefix_devel
- f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do
- head "foo"
- devel do
- url "foo"
- version "1.0-devel"
- end
- end
- prefix = HOMEBREW_CELLAR+f.name+f.devel.version
- assert_equal prefix, f.installed_prefix
- end
-
- def test_latest_head_prefix
- f = Testball.new
-
- stamps_with_revisions = [[111111, 1], [222222, 1], [222222, 2], [222222, 0]]
-
- stamps_with_revisions.each do |stamp, revision|
- version = "HEAD-#{stamp}"
- version += "_#{revision}" if revision > 0
- prefix = f.rack.join(version)
- prefix.mkpath
-
- tab = Tab.empty
- tab.tabfile = prefix.join("INSTALL_RECEIPT.json")
- tab.source_modified_time = stamp
- tab.write
- end
-
- prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD-222222_2"
- assert_equal prefix, f.latest_head_prefix
- end
-
- def test_equality
- x = Testball.new
- y = Testball.new
- assert_equal x, y
- assert_eql x, y
- assert_equal x.hash, y.hash
- end
-
- def test_inequality
- x = Testball.new("foo")
- y = Testball.new("bar")
- refute_equal x, y
- refute_eql x, y
- refute_equal x.hash, y.hash
- end
-
- def test_comparison_with_non_formula_objects_does_not_raise
- refute_equal Testball.new, Object.new
- end
-
- def test_sort_operator
- assert_nil Testball.new <=> Object.new
- end
-
- def test_alias_paths_with_build_options
- alias_path = CoreTap.instance.alias_dir/"another_name"
- f = formula(alias_path: alias_path) { url "foo-1.0" }
- f.build = BuildOptions.new({}, {})
- assert_equal alias_path, f.alias_path
- assert_nil f.installed_alias_path
- end
-
- def test_alias_paths_with_tab_with_non_alias_source_path
- alias_path = CoreTap.instance.alias_dir/"another_name"
- source_path = CoreTap.instance.formula_dir/"another_other_name"
- f = formula(alias_path: alias_path) { url "foo-1.0" }
- f.build = Tab.new(source: { "path" => source_path.to_s })
- assert_equal alias_path, f.alias_path
- assert_nil f.installed_alias_path
- end
-
- def test_alias_paths_with_tab_with_alias_source_path
- alias_path = CoreTap.instance.alias_dir/"another_name"
- source_path = CoreTap.instance.alias_dir/"another_other_name"
- f = formula(alias_path: alias_path) { url "foo-1.0" }
- f.build = Tab.new(source: { "path" => source_path.to_s })
- assert_equal alias_path, f.alias_path
- assert_equal source_path.to_s, f.installed_alias_path
- end
-
- def test_installed_with_alias_path_with_nil
- assert_predicate Formula.installed_with_alias_path(nil), :empty?
- end
-
- def test_installed_with_alias_path_with_a_path
- alias_path = "#{CoreTap.instance.alias_dir}/alias"
- different_alias_path = "#{CoreTap.instance.alias_dir}/another_alias"
-
- formula_with_alias = formula("foo") { url "foo-1.0" }
- formula_with_alias.build = Tab.empty
- formula_with_alias.build.source["path"] = alias_path
-
- formula_without_alias = formula("bar") { url "bar-1.0" }
- formula_without_alias.build = Tab.empty
- formula_without_alias.build.source["path"] = formula_without_alias.path.to_s
-
- formula_with_different_alias = formula("baz") { url "baz-1.0" }
- formula_with_different_alias.build = Tab.empty
- formula_with_different_alias.build.source["path"] = different_alias_path
-
- formulae = [
- formula_with_alias,
- formula_without_alias,
- formula_with_different_alias,
- ]
-
- Formula.stubs(:installed).returns(formulae)
- assert_equal [formula_with_alias], Formula.installed_with_alias_path(alias_path)
- end
-
- def test_formula_spec_integration
- f = formula do
- homepage "http://example.com"
- url "http://example.com/test-0.1.tbz"
- mirror "http://example.org/test-0.1.tbz"
- sha256 TEST_SHA256
-
- head "http://example.com/test.git", tag: "foo"
-
- devel do
- url "http://example.com/test-0.2.tbz"
- mirror "http://example.org/test-0.2.tbz"
- sha256 TEST_SHA256
- end
- end
-
- assert_equal "http://example.com", f.homepage
- assert_version_equal "0.1", f.version
- assert_predicate f, :stable?
-
- assert_version_equal "0.1", f.stable.version
- assert_version_equal "0.2", f.devel.version
- assert_version_equal "HEAD", f.head.version
- end
-
- def test_formula_active_spec=
- f = formula do
- url "foo"
- version "1.0"
- revision 1
-
- devel do
- url "foo"
- version "1.0beta"
- end
- end
- assert_equal :stable, f.active_spec_sym
- assert_equal f.stable, f.send(:active_spec)
- assert_equal "1.0_1", f.pkg_version.to_s
- f.active_spec = :devel
- assert_equal :devel, f.active_spec_sym
- assert_equal f.devel, f.send(:active_spec)
- assert_equal "1.0beta_1", f.pkg_version.to_s
- assert_raises(FormulaSpecificationError) { f.active_spec = :head }
- end
-
- def test_path
- name = "foo-bar"
- assert_equal Pathname.new("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/Formula/#{name}.rb"), Formulary.core_path(name)
- end
-
- def test_class_specs_are_always_initialized
- f = formula { url "foo-1.0" }
-
- %w[stable devel head].each do |spec|
- assert_kind_of SoftwareSpec, f.class.send(spec)
- end
- end
-
- def test_incomplete_instance_specs_are_not_accessible
- f = formula { url "foo-1.0" }
-
- %w[devel head].each { |spec| assert_nil f.send(spec) }
- end
-
- def test_honors_attributes_declared_before_specs
- f = formula do
- url "foo-1.0"
- depends_on "foo"
- devel { url "foo-1.1" }
- end
-
- %w[stable devel head].each do |spec|
- assert_equal "foo", f.class.send(spec).deps.first.name
- end
- end
-
- def test_simple_version
- assert_equal PkgVersion.parse("1.0"), formula { url "foo-1.0.bar" }.pkg_version
- end
-
- def test_version_with_revision
- f = formula do
- url "foo-1.0.bar"
- revision 1
- end
-
- assert_equal PkgVersion.parse("1.0_1"), f.pkg_version
- end
-
- def test_head_uses_revisions
- f = formula("test", Pathname.new(__FILE__).expand_path, :head) do
- url "foo-1.0.bar"
- revision 1
- head "foo"
- end
-
- assert_equal PkgVersion.parse("HEAD_1"), f.pkg_version
- end
-
- def test_update_head_version
- f = formula do
- head "foo", using: :git
- end
-
- cached_location = f.head.downloader.cached_location
- cached_location.mkpath
-
- cached_location.cd do
- FileUtils.touch "LICENSE"
- shutup do
- system "git", "init"
- system "git", "add", "--all"
- system "git", "commit", "-m", "Initial commit"
- end
- end
-
- f.update_head_version
- assert_equal Version.create("HEAD-5658946"), f.head.version
- end
-
- def test_legacy_options
- f = formula do
- url "foo-1.0"
-
- def options
- [["--foo", "desc"], ["--bar", "desc"]]
- end
-
- option "baz"
- end
-
- assert f.option_defined?("foo")
- assert f.option_defined?("bar")
- assert f.option_defined?("baz")
- end
-
- def test_desc
- f = formula do
- desc "a formula"
- url "foo-1.0"
- end
-
- assert_equal "a formula", f.desc
- end
-
- def test_post_install_defined
- f1 = formula do
- url "foo-1.0"
-
- def post_install; end
- end
-
- f2 = formula do
- url "foo-1.0"
- end
-
- assert f1.post_install_defined?
- refute f2.post_install_defined?
- end
-
- def test_test_defined
- f1 = formula do
- url "foo-1.0"
-
- def test; end
- end
-
- f2 = formula do
- url "foo-1.0"
- end
-
- assert f1.test_defined?
- refute f2.test_defined?
- end
-
- def test_test_fixtures
- f1 = formula do
- url "foo-1.0"
- end
-
- assert_equal Pathname.new("#{HOMEBREW_LIBRARY_PATH}/test/support/fixtures/foo"),
- f1.test_fixtures("foo")
- end
-
- def test_dependencies
- stub_formula_loader formula("f1") { url "f1-1.0" }
- stub_formula_loader formula("f2") { url "f2-1.0" }
-
- f3 = formula("f3") do
- url "f3-1.0"
- depends_on "f1" => :build
- depends_on "f2"
- end
- stub_formula_loader f3
-
- f4 = formula("f4") do
- url "f4-1.0"
- depends_on "f1"
- end
- stub_formula_loader f4
-
- f5 = formula("f5") do
- url "f5-1.0"
- depends_on "f3" => :build
- depends_on "f4"
- end
-
- assert_equal %w[f3 f4], f5.deps.map(&:name)
- assert_equal %w[f1 f2 f3 f4], f5.recursive_dependencies.map(&:name)
- assert_equal %w[f1 f4], f5.runtime_dependencies.map(&:name)
- end
-
- def test_runtime_dependencies_with_optional_deps_from_tap
- tap_loader = mock
- tap_loader.stubs(:get_formula).raises(RuntimeError, "tried resolving tap formula")
- Formulary.stubs(:loader_for).with("foo/bar/f1", from: nil).returns(tap_loader)
-
- stub_formula_loader formula("f2") { url "f2-1.0" }, "baz/qux/f2"
-
- f3 = formula("f3") do
- url "f3-1.0"
- depends_on "foo/bar/f1" => :optional
- depends_on "baz/qux/f2"
- end
-
- # f1 shouldn't be loaded by default.
- # If it is, an exception will be raised.
- assert_equal %w[baz/qux/f2], f3.runtime_dependencies.map(&:name)
-
- # If --with-f1, f1 should be loaded.
- stub_formula_loader formula("f1") { url "f1-1.0" }, "foo/bar/f1"
- f3.build = BuildOptions.new(Options.create(%w[--with-f1]), f3.options)
- assert_equal %w[foo/bar/f1 baz/qux/f2], f3.runtime_dependencies.map(&:name)
- end
-
- def test_requirements
- f1 = formula("f1") do
- url "f1-1"
-
- depends_on :python
- depends_on x11: :recommended
- depends_on xcode: ["1.0", :optional]
- end
- stub_formula_loader f1
-
- python = PythonRequirement.new
- x11 = X11Requirement.new("x11", [:recommended])
- xcode = XcodeRequirement.new(["1.0", :optional])
-
- # Default block should filter out deps that aren't being used
- assert_equal Set[python, x11], Set.new(f1.recursive_requirements)
-
- f1.build = BuildOptions.new(["--with-xcode", "--without-x11"], f1.options)
- assert_equal Set[python, xcode], Set.new(f1.recursive_requirements)
- f1.build = f1.stable.build
-
- f2 = formula("f2") do
- url "f2-1"
- depends_on "f1"
- end
-
- assert_equal Set[python, x11], Set.new(f2.recursive_requirements)
-
- # Empty block should allow all requirements
- assert_equal Set[python, x11, xcode], Set.new(f2.recursive_requirements {})
-
- # Requirements can be pruned
- requirements = f2.recursive_requirements do |_dependent, requirement|
- Requirement.prune if requirement.is_a?(PythonRequirement)
- end
- assert_equal Set[x11, xcode], Set.new(requirements)
- end
-
- def test_to_hash
- f1 = formula("foo") do
- url "foo-1.0"
- end
-
- h = f1.to_hash
- assert h.is_a?(Hash), "Formula#to_hash should return a Hash"
- assert_equal "foo", h["name"]
- assert_equal "foo", h["full_name"]
- assert_equal "1.0", h["versions"]["stable"]
- end
-
- def test_to_hash_bottle
- f1 = formula("foo") do
- url "foo-1.0"
-
- bottle do
- cellar :any
- sha256 TEST_SHA256 => Utils::Bottles.tag
- end
- end
-
- h = f1.to_hash
- assert h.is_a?(Hash), "Formula#to_hash should return a Hash"
- assert h["versions"]["bottle"], "The hash should say the formula is bottled"
- end
-
- def test_eligible_kegs_for_cleanup
- f1 = Class.new(Testball) do
- version "1.0"
- end.new
- f2 = Class.new(Testball) do
- version "0.2"
- version_scheme 1
- end.new
- f3 = Class.new(Testball) do
- version "0.3"
- version_scheme 1
- end.new
- f4 = Class.new(Testball) do
- version "0.1"
- version_scheme 2
- end.new
-
- shutup do
- [f1, f2, f3, f4].each do |f|
- f.brew { f.install }
- Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
- end
- end
-
- assert_predicate f1, :installed?
- assert_predicate f2, :installed?
- assert_predicate f3, :installed?
- assert_predicate f4, :installed?
-
- assert_equal [f2, f1].map { |f| Keg.new(f.prefix) },
- f3.eligible_kegs_for_cleanup.sort_by(&:version)
- end
-
- def test_eligible_kegs_for_cleanup_keg_pinned
- f1 = Class.new(Testball) { version "0.1" }.new
- f2 = Class.new(Testball) { version "0.2" }.new
- f3 = Class.new(Testball) { version "0.3" }.new
-
- shutup do
- f1.brew { f1.install }
- f1.pin
- f2.brew { f2.install }
- f3.brew { f3.install }
- end
-
- assert_equal (HOMEBREW_PINNED_KEGS/f1.name).resolved_path, f1.prefix
-
- assert_predicate f1, :installed?
- assert_predicate f2, :installed?
- assert_predicate f3, :installed?
-
- assert_equal [Keg.new(f2.prefix)], shutup { f3.eligible_kegs_for_cleanup }
- end
-
- def test_eligible_kegs_for_cleanup_head_installed
- f = formula do
- version "0.1"
- head "foo"
- end
-
- stable_prefix = f.installed_prefix
- stable_prefix.mkpath
-
- [["000000_1", 1], ["111111", 2], ["111111_1", 2]].each do |pkg_version_suffix, stamp|
- prefix = f.prefix("HEAD-#{pkg_version_suffix}")
- prefix.mkpath
- tab = Tab.empty
- tab.tabfile = prefix.join("INSTALL_RECEIPT.json")
- tab.source_modified_time = stamp
- tab.write
- end
-
- eligible_kegs = f.installed_kegs - [Keg.new(f.prefix("HEAD-111111_1"))]
- assert_equal eligible_kegs, f.eligible_kegs_for_cleanup
- end
-
- def test_pour_bottle
- f_false = formula("foo") do
- url "foo-1.0"
- def pour_bottle?
- false
- end
- end
- refute f_false.pour_bottle?
-
- f_true = formula("foo") do
- url "foo-1.0"
- def pour_bottle?
- true
- end
- end
- assert f_true.pour_bottle?
- end
-
- def test_pour_bottle_dsl
- f_false = formula("foo") do
- url "foo-1.0"
- pour_bottle? do
- reason "false reason"
- satisfy { var == etc }
- end
- end
- refute f_false.pour_bottle?
-
- f_true = formula("foo") do
- url "foo-1.0"
- pour_bottle? do
- reason "true reason"
- satisfy { true }
- end
- end
- assert f_true.pour_bottle?
- end
-end
-
-class AliasChangeTests < Homebrew::TestCase
- attr_reader :f, :new_formula, :tab, :alias_path
-
- def make_formula(name, version)
- f = formula(name, alias_path: alias_path) { url "foo-#{version}" }
- f.build = tab
- f
- end
-
- def setup
- super
-
- alias_name = "bar"
- @alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}"
-
- @tab = Tab.empty
-
- @f = make_formula("formula_name", "1.0")
- @new_formula = make_formula("new_formula_name", "1.1")
-
- Formula.stubs(:installed).returns([f])
- end
-
- def test_alias_changes_when_not_installed_with_alias
- tab.source["path"] = Formulary.core_path(f.name).to_s
-
- assert_nil f.current_installed_alias_target
- assert_equal f, f.latest_formula
- refute_predicate f, :installed_alias_target_changed?
- refute_predicate f, :supersedes_an_installed_formula?
- refute_predicate f, :alias_changed?
- assert_predicate f.old_installed_formulae, :empty?
- end
-
- def test_alias_changes_when_not_changed
- tab.source["path"] = alias_path
- stub_formula_loader(f, alias_path)
-
- assert_equal f, f.current_installed_alias_target
- assert_equal f, f.latest_formula
- refute_predicate f, :installed_alias_target_changed?
- refute_predicate f, :supersedes_an_installed_formula?
- refute_predicate f, :alias_changed?
- assert_predicate f.old_installed_formulae, :empty?
- end
-
- def test_alias_changes_when_new_alias_target
- tab.source["path"] = alias_path
- stub_formula_loader(new_formula, alias_path)
-
- assert_equal new_formula, f.current_installed_alias_target
- assert_equal new_formula, f.latest_formula
- assert_predicate f, :installed_alias_target_changed?
- refute_predicate f, :supersedes_an_installed_formula?
- assert_predicate f, :alias_changed?
- assert_predicate f.old_installed_formulae, :empty?
- end
-
- def test_alias_changes_when_old_formulae_installed
- tab.source["path"] = alias_path
- stub_formula_loader(new_formula, alias_path)
-
- assert_equal new_formula, new_formula.current_installed_alias_target
- assert_equal new_formula, new_formula.latest_formula
- refute_predicate new_formula, :installed_alias_target_changed?
- assert_predicate new_formula, :supersedes_an_installed_formula?
- assert_predicate new_formula, :alias_changed?
- assert_equal [f], new_formula.old_installed_formulae
- end
-end
-
-class OutdatedVersionsTests < Homebrew::TestCase
- attr_reader :outdated_prefix,
- :same_prefix,
- :greater_prefix,
- :head_prefix,
- :old_alias_target_prefix
- attr_reader :f, :old_formula, :new_formula
-
- def setup
- super
-
- @f = formula do
- url "foo"
- version "1.20"
- end
-
- @old_formula = formula("foo@1") { url "foo-1.0" }
- @new_formula = formula("foo@2") { url "foo-2.0" }
-
- @outdated_prefix = HOMEBREW_CELLAR/"#{f.name}/1.11"
- @same_prefix = HOMEBREW_CELLAR/"#{f.name}/1.20"
- @greater_prefix = HOMEBREW_CELLAR/"#{f.name}/1.21"
- @head_prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD"
- @old_alias_target_prefix = HOMEBREW_CELLAR/"#{old_formula.name}/1.0"
- end
-
- def alias_path
- "#{@f.tap.alias_dir}/bar"
- end
-
- def setup_tab_for_prefix(prefix, options = {})
- prefix.mkpath
- tab = Tab.empty
- tab.tabfile = prefix.join("INSTALL_RECEIPT.json")
- tab.source["path"] = options[:path].to_s if options[:path]
- tab.source["tap"] = options[:tap] if options[:tap]
- tab.source["versions"] = options[:versions] if options[:versions]
- tab.source_modified_time = options[:source_modified_time].to_i
- tab.write unless options[:no_write]
- tab
- end
-
- def reset_outdated_kegs
- f.instance_variable_set(:@outdated_kegs, nil)
- end
-
- def test_greater_different_tap_installed
- setup_tab_for_prefix(greater_prefix, tap: "user/repo")
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_greater_same_tap_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(greater_prefix, tap: "homebrew/core")
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_different_tap_installed
- setup_tab_for_prefix(outdated_prefix, tap: "user/repo")
- refute_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_same_tap_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(outdated_prefix, tap: "homebrew/core")
- refute_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_follow_alias_and_alias_unchanged
- f.follow_installed_alias = true
- f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
- stub_formula_loader(f, alias_path)
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_follow_alias_and_alias_changed_and_new_target_not_installed
- f.follow_installed_alias = true
- f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
- stub_formula_loader(new_formula, alias_path)
- refute_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_follow_alias_and_alias_changed_and_new_target_installed
- f.follow_installed_alias = true
- f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
- stub_formula_loader(new_formula, alias_path)
- setup_tab_for_prefix(new_formula.prefix) # install new_formula
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_no_follow_alias_and_alias_unchanged
- f.follow_installed_alias = false
- f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
- stub_formula_loader(f, alias_path)
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_no_follow_alias_and_alias_changed
- f.follow_installed_alias = false
- f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
- stub_formula_loader(formula("foo@2") { url "foo-2.0" }, alias_path)
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_old_alias_targets_installed
- @f = formula(alias_path: alias_path) { url "foo-1.0" }
- tab = setup_tab_for_prefix(old_alias_target_prefix, path: alias_path)
- old_formula.build = tab
- Formula.stubs(:installed).returns([old_formula])
- refute_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_old_alias_targets_not_installed
- @f = formula(alias_path: alias_path) { url "foo-1.0" }
- tab = setup_tab_for_prefix(old_alias_target_prefix, path: old_formula.path)
- old_formula.build = tab
- Formula.stubs(:installed).returns([old_formula])
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_same_head_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(head_prefix, tap: "homebrew/core")
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_different_head_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(head_prefix, tap: "user/repo")
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_mixed_taps_greater_version_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(outdated_prefix, tap: "homebrew/core")
- setup_tab_for_prefix(greater_prefix, tap: "user/repo")
-
- assert_predicate f.outdated_kegs, :empty?
-
- setup_tab_for_prefix(greater_prefix, tap: "homebrew/core")
- reset_outdated_kegs
-
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_mixed_taps_outdated_version_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
-
- extra_outdated_prefix = HOMEBREW_CELLAR/"#{f.name}/1.0"
-
- setup_tab_for_prefix(outdated_prefix)
- setup_tab_for_prefix(extra_outdated_prefix, tap: "homebrew/core")
- reset_outdated_kegs
-
- refute_predicate f.outdated_kegs, :empty?
-
- setup_tab_for_prefix(outdated_prefix, tap: "user/repo")
- reset_outdated_kegs
-
- refute_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_same_version_tap_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(same_prefix, tap: "homebrew/core")
-
- assert_predicate f.outdated_kegs, :empty?
-
- setup_tab_for_prefix(same_prefix, tap: "user/repo")
- reset_outdated_kegs
-
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_installed_head_less_than_stable
- tab = setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0" })
- refute_predicate f.outdated_kegs, :empty?
-
- # Tab.for_keg(head_prefix) will be fetched from CACHE but we write it anyway
- tab.source["versions"] = { "stable" => f.version.to_s }
- tab.write
- reset_outdated_kegs
-
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_fetch_head
- outdated_stable_prefix = HOMEBREW_CELLAR.join("testball/1.0")
- head_prefix_a = HOMEBREW_CELLAR.join("testball/HEAD")
- head_prefix_b = HOMEBREW_CELLAR.join("testball/HEAD-aaaaaaa_1")
- head_prefix_c = HOMEBREW_CELLAR.join("testball/HEAD-18a7103")
-
- setup_tab_for_prefix(outdated_stable_prefix)
- tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" })
- setup_tab_for_prefix(head_prefix_b)
-
- testball_repo = HOMEBREW_PREFIX.join("testball_repo")
- testball_repo.mkdir
-
- @f = formula("testball") do
- url "foo"
- version "2.10"
- head "file://#{testball_repo}", using: :git
- end
-
- testball_repo.cd do
- FileUtils.touch "LICENSE"
- shutup do
- system "git", "init"
- system "git", "add", "--all"
- system "git", "commit", "-m", "Initial commit"
- end
- end
-
- refute_predicate f.outdated_kegs(fetch_head: true), :empty?
-
- tab_a.source["versions"] = { "stable" => f.version.to_s }
- tab_a.write
- reset_outdated_kegs
- refute_predicate f.outdated_kegs(fetch_head: true), :empty?
-
- head_prefix_a.rmtree
- reset_outdated_kegs
- refute_predicate f.outdated_kegs(fetch_head: true), :empty?
-
- setup_tab_for_prefix(head_prefix_c, source_modified_time: 1)
- reset_outdated_kegs
- assert_predicate f.outdated_kegs(fetch_head: true), :empty?
- ensure
- testball_repo.rmtree if testball_repo.exist?
- end
-
- def test_outdated_kegs_version_scheme_changed
- @f = formula("testball") do
- url "foo"
- version "20141010"
- version_scheme 1
- end
-
- prefix = HOMEBREW_CELLAR.join("testball/0.1")
- setup_tab_for_prefix(prefix, versions: { "stable" => "0.1" })
-
- refute_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_kegs_mixed_version_schemes
- @f = formula("testball") do
- url "foo"
- version "20141010"
- version_scheme 3
- end
-
- prefix_a = HOMEBREW_CELLAR.join("testball/20141009")
- setup_tab_for_prefix(prefix_a, versions: { "stable" => "20141009", "version_scheme" => 1 })
-
- prefix_b = HOMEBREW_CELLAR.join("testball/2.14")
- setup_tab_for_prefix(prefix_b, versions: { "stable" => "2.14", "version_scheme" => 2 })
-
- refute_predicate f.outdated_kegs, :empty?
- reset_outdated_kegs
-
- prefix_c = HOMEBREW_CELLAR.join("testball/20141009")
- setup_tab_for_prefix(prefix_c, versions: { "stable" => "20141009", "version_scheme" => 3 })
-
- refute_predicate f.outdated_kegs, :empty?
- reset_outdated_kegs
-
- prefix_d = HOMEBREW_CELLAR.join("testball/20141011")
- setup_tab_for_prefix(prefix_d, versions: { "stable" => "20141009", "version_scheme" => 3 })
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_kegs_head_with_version_scheme
- @f = formula("testball") do
- url "foo"
- version "1.0"
- version_scheme 2
- end
-
- head_prefix = HOMEBREW_CELLAR.join("testball/HEAD")
-
- setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 1 })
- refute_predicate f.outdated_kegs, :empty?
-
- reset_outdated_kegs
- head_prefix.rmtree
-
- setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 2 })
- assert_predicate f.outdated_kegs, :empty?
- end
-end | true |
Other | Homebrew | brew | b0cd1c732d25b112e75facf48325f7841c8b6ac3.json | Convert Formula test to spec. | Library/Homebrew/test/formulary_spec.rb | @@ -216,4 +216,12 @@ class Wrong#{subject.class_s(formula_name)} < Formula
end
end
end
+
+ describe "::core_path" do
+ it "returns the path to a Formula in the core tap" do
+ name = "foo-bar"
+ expect(subject.core_path(name))
+ .to eq(Pathname.new("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/Formula/#{name}.rb"))
+ end
+ end
end | true |
Other | Homebrew | brew | e03caebaedf579d5330c5c908b2d3ffa927ea5c3.json | Convert Tab test to spec. | Library/Homebrew/test/tab_spec.rb | @@ -0,0 +1,341 @@
+require "tab"
+require "formula"
+
+RSpec::Matchers.alias_matcher :have_option_with, :be_with
+
+describe Tab do
+ matcher :be_poured_from_bottle do
+ match do |actual|
+ actual.poured_from_bottle == true
+ end
+ end
+
+ matcher :be_built_as_bottle do
+ match do |actual|
+ actual.built_as_bottle == true
+ end
+ end
+
+ subject {
+ described_class.new(
+ "homebrew_version" => HOMEBREW_VERSION,
+ "used_options" => used_options.as_flags,
+ "unused_options" => unused_options.as_flags,
+ "built_as_bottle" => false,
+ "poured_from_bottle" => true,
+ "changed_files" => [],
+ "time" => time,
+ "source_modified_time" => 0,
+ "HEAD" => TEST_SHA1,
+ "compiler" => "clang",
+ "stdlib" => "libcxx",
+ "runtime_dependencies" => [],
+ "source" => {
+ "tap" => CoreTap.instance.to_s,
+ "path" => CoreTap.instance.path.to_s,
+ "spec" => "stable",
+ "versions" => {
+ "stable" => "0.10",
+ "devel" => "0.14",
+ "head" => "HEAD-1111111",
+ },
+ },
+ )
+ }
+ let(:time) { Time.now.to_i }
+ let(:unused_options) { Options.create(%w[--with-baz --without-qux]) }
+ let(:used_options) { Options.create(%w[--with-foo --without-bar]) }
+
+ let(:f) { formula { url "foo-1.0" } }
+ let(:f_tab_path) { f.prefix/"INSTALL_RECEIPT.json" }
+ let(:f_tab_content) { (TEST_FIXTURE_DIR/"receipt.json").read }
+
+ specify "defaults" do
+ tab = described_class.empty
+
+ expect(tab.homebrew_version).to eq(HOMEBREW_VERSION)
+ expect(tab.unused_options).to be_empty
+ expect(tab.used_options).to be_empty
+ expect(tab.changed_files).to be nil
+ expect(tab).not_to be_built_as_bottle
+ expect(tab).not_to be_poured_from_bottle
+ expect(tab).to be_stable
+ expect(tab).not_to be_devel
+ expect(tab).not_to be_head
+ expect(tab.tap).to be nil
+ expect(tab.time).to be nil
+ expect(tab.HEAD).to be nil
+ expect(tab.runtime_dependencies).to be_empty
+ expect(tab.stable_version).to be nil
+ expect(tab.devel_version).to be nil
+ expect(tab.head_version).to be nil
+ expect(tab.cxxstdlib.compiler).to eq(DevelopmentTools.default_compiler)
+ expect(tab.cxxstdlib.type).to be nil
+ expect(tab.source["path"]).to be nil
+ end
+
+ specify "#include?" do
+ expect(subject).to include("with-foo")
+ expect(subject).to include("without-bar")
+ end
+
+ specify "#with?" do
+ expect(subject).to have_option_with("foo")
+ expect(subject).to have_option_with("qux")
+ expect(subject).not_to have_option_with("bar")
+ expect(subject).not_to have_option_with("baz")
+ end
+
+ specify "#universal?" do
+ tab = described_class.new(used_options: %w[--universal])
+ expect(tab).to be_universal
+ end
+
+ specify "#parsed_homebrew_version" do
+ tab = described_class.new
+ expect(tab.parsed_homebrew_version).to be Version::NULL
+
+ tab = described_class.new(homebrew_version: "1.2.3")
+ expect(tab.parsed_homebrew_version).to eq("1.2.3")
+ expect(tab.parsed_homebrew_version).to be < "1.2.3-1-g12789abdf"
+ expect(tab.parsed_homebrew_version).to be_kind_of(Version)
+
+ tab.homebrew_version = "1.2.4-567-g12789abdf"
+ expect(tab.parsed_homebrew_version).to be > "1.2.4"
+ expect(tab.parsed_homebrew_version).to be > "1.2.4-566-g21789abdf"
+ expect(tab.parsed_homebrew_version).to be < "1.2.4-568-g01789abdf"
+
+ tab = described_class.new(homebrew_version: "2.0.0-134-gabcdefabc-dirty")
+ expect(tab.parsed_homebrew_version).to be > "2.0.0"
+ expect(tab.parsed_homebrew_version).to be > "2.0.0-133-g21789abdf"
+ expect(tab.parsed_homebrew_version).to be < "2.0.0-135-g01789abdf"
+ end
+
+ specify "#runtime_dependencies" do
+ tab = described_class.new
+ expect(tab.runtime_dependencies).to be nil
+
+ tab.homebrew_version = "1.1.6"
+ expect(tab.runtime_dependencies).to be nil
+
+ tab.runtime_dependencies = []
+ expect(tab.runtime_dependencies).not_to be nil
+
+ tab.homebrew_version = "1.1.5"
+ expect(tab.runtime_dependencies).to be nil
+
+ tab.homebrew_version = "1.1.7"
+ expect(tab.runtime_dependencies).not_to be nil
+
+ tab.homebrew_version = "1.1.10"
+ expect(tab.runtime_dependencies).not_to be nil
+
+ tab.runtime_dependencies = [{ "full_name" => "foo", "version" => "1.0" }]
+ expect(tab.runtime_dependencies).not_to be nil
+ end
+
+ specify "#cxxstdlib" do
+ expect(subject.cxxstdlib.compiler).to eq(:clang)
+ expect(subject.cxxstdlib.type).to eq(:libcxx)
+ end
+
+ specify "other attributes" do
+ expect(subject.HEAD).to eq(TEST_SHA1)
+ expect(subject.tap.name).to eq("homebrew/core")
+ expect(subject.time).to eq(time)
+ expect(subject).not_to be_built_as_bottle
+ expect(subject).to be_poured_from_bottle
+ end
+
+ describe "::from_file" do
+ it "parses a Tab from a file" do
+ path = Pathname.new("#{TEST_FIXTURE_DIR}/receipt.json")
+ tab = described_class.from_file(path)
+ source_path = "/usr/local/Library/Taps/homebrew/homebrew-core/Formula/foo.rb"
+ runtime_dependencies = [{ "full_name" => "foo", "version" => "1.0" }]
+ changed_files = %w[INSTALL_RECEIPT.json bin/foo]
+
+ expect(tab.used_options.sort).to eq(used_options.sort)
+ expect(tab.unused_options.sort).to eq(unused_options.sort)
+ expect(tab.changed_files).to eq(changed_files)
+ expect(tab).not_to be_built_as_bottle
+ expect(tab).to be_poured_from_bottle
+ expect(tab).to be_stable
+ expect(tab).not_to be_devel
+ expect(tab).not_to be_head
+ expect(tab.tap.name).to eq("homebrew/core")
+ expect(tab.spec).to eq(:stable)
+ expect(tab.time).to eq(Time.at(1_403_827_774).to_i)
+ expect(tab.HEAD).to eq(TEST_SHA1)
+ expect(tab.cxxstdlib.compiler).to eq(:clang)
+ expect(tab.cxxstdlib.type).to eq(:libcxx)
+ expect(tab.runtime_dependencies).to eq(runtime_dependencies)
+ expect(tab.stable_version.to_s).to eq("2.14")
+ expect(tab.devel_version.to_s).to eq("2.15")
+ expect(tab.head_version.to_s).to eq("HEAD-0000000")
+ expect(tab.source["path"]).to eq(source_path)
+ end
+
+ it "can parse an old Tab file" do
+ path = Pathname.new("#{TEST_FIXTURE_DIR}/receipt_old.json")
+ tab = described_class.from_file(path)
+
+ expect(tab.used_options.sort).to eq(used_options.sort)
+ expect(tab.unused_options.sort).to eq(unused_options.sort)
+ expect(tab).not_to be_built_as_bottle
+ expect(tab).to be_poured_from_bottle
+ expect(tab).to be_stable
+ expect(tab).not_to be_devel
+ expect(tab).not_to be_head
+ expect(tab.tap.name).to eq("homebrew/core")
+ expect(tab.spec).to eq(:stable)
+ expect(tab.time).to eq(Time.at(1_403_827_774).to_i)
+ expect(tab.HEAD).to eq(TEST_SHA1)
+ expect(tab.cxxstdlib.compiler).to eq(:clang)
+ expect(tab.cxxstdlib.type).to eq(:libcxx)
+ expect(tab.runtime_dependencies).to be nil
+ end
+ end
+
+ describe "::create" do
+ it "creates a Tab" do
+ f = formula do
+ url "foo-1.0"
+ depends_on "bar"
+ depends_on "user/repo/from_tap"
+ depends_on "baz" => :build
+ end
+
+ tap = Tap.new("user", "repo")
+ from_tap = formula("from_tap", path: tap.path/"Formula/from_tap.rb") do
+ url "from_tap-1.0"
+ end
+ stub_formula_loader from_tap
+
+ stub_formula_loader formula("bar") { url "bar-2.0" }
+ stub_formula_loader formula("baz") { url "baz-3.0" }
+
+ compiler = DevelopmentTools.default_compiler
+ stdlib = :libcxx
+ tab = described_class.create(f, compiler, stdlib)
+
+ runtime_dependencies = [
+ { "full_name" => "bar", "version" => "2.0" },
+ { "full_name" => "user/repo/from_tap", "version" => "1.0" },
+ ]
+
+ expect(tab.runtime_dependencies).to eq(runtime_dependencies)
+ expect(tab.source["path"]).to eq(f.path.to_s)
+ end
+
+ it "can create a Tab from an alias" do
+ alias_path = CoreTap.instance.alias_dir/"bar"
+ f = formula(alias_path: alias_path) { url "foo-1.0" }
+ compiler = DevelopmentTools.default_compiler
+ stdlib = :libcxx
+ tab = described_class.create(f, compiler, stdlib)
+
+ expect(tab.source["path"]).to eq(f.alias_path.to_s)
+ end
+ end
+
+ describe "::for_keg" do
+ subject { described_class.for_keg(f.prefix) }
+
+ it "creates a Tab for a given Keg" do
+ f.prefix.mkpath
+ f_tab_path.write f_tab_content
+
+ expect(subject.tabfile).to eq(f_tab_path)
+ end
+
+ it "can create a Tab for a non-existant Keg" do
+ f.prefix.mkpath
+
+ expect(subject.tabfile).to be nil
+ end
+ end
+
+ describe "::for_formula" do
+ it "creates a Tab for a given Formula" do
+ tab = described_class.for_formula(f)
+ expect(tab.source["path"]).to eq(f.path.to_s)
+ end
+
+ it "can create a Tab for for a Formula from an alias" do
+ alias_path = CoreTap.instance.alias_dir/"bar"
+ f = formula(alias_path: alias_path) { url "foo-1.0" }
+
+ tab = described_class.for_formula(f)
+ expect(tab.source["path"]).to eq(alias_path.to_s)
+ end
+
+ it "creates a Tab for a given Formula" do
+ f.prefix.mkpath
+ f_tab_path.write f_tab_content
+
+ tab = described_class.for_formula(f)
+ expect(tab.tabfile).to eq(f_tab_path)
+ end
+
+ it "can create a Tab for a non-existant Formula" do
+ f.prefix.mkpath
+
+ tab = described_class.for_formula(f)
+ expect(tab.tabfile).to be nil
+ end
+
+ it "can create a Tab for a Formula with multiple Kegs" do
+ f.prefix.mkpath
+ f_tab_path.write f_tab_content
+
+ f2 = formula { url "foo-2.0" }
+ f2.prefix.mkpath
+
+ expect(f2.rack).to eq(f.rack)
+ expect(f.installed_prefixes.length).to eq(2)
+
+ tab = described_class.for_formula(f)
+ expect(tab.tabfile).to eq(f_tab_path)
+ end
+
+ it "can create a Tab for a Formula with an outdated Kegs" do
+ f_tab_path.write f_tab_content
+
+ f2 = formula { url "foo-2.0" }
+
+ expect(f2.rack).to eq(f.rack)
+ expect(f.installed_prefixes.length).to eq(1)
+
+ tab = described_class.for_formula(f)
+ expect(tab.tabfile).to eq(f_tab_path)
+ end
+ end
+
+ specify "#to_json" do
+ tab = described_class.new(JSON.parse(subject.to_json))
+ expect(tab.used_options.sort).to eq(subject.used_options.sort)
+ expect(tab.unused_options.sort).to eq(subject.unused_options.sort)
+ expect(tab.built_as_bottle).to eq(subject.built_as_bottle)
+ expect(tab.poured_from_bottle).to eq(subject.poured_from_bottle)
+ expect(tab.changed_files).to eq(subject.changed_files)
+ expect(tab.tap).to eq(subject.tap)
+ expect(tab.spec).to eq(subject.spec)
+ expect(tab.time).to eq(subject.time)
+ expect(tab.HEAD).to eq(subject.HEAD)
+ expect(tab.compiler).to eq(subject.compiler)
+ expect(tab.stdlib).to eq(subject.stdlib)
+ expect(tab.runtime_dependencies).to eq(subject.runtime_dependencies)
+ expect(tab.stable_version).to eq(subject.stable_version)
+ expect(tab.devel_version).to eq(subject.devel_version)
+ expect(tab.head_version).to eq(subject.head_version)
+ expect(tab.source["path"]).to eq(subject.source["path"])
+ end
+
+ specify "::remap_deprecated_options" do
+ deprecated_options = [DeprecatedOption.new("with-foo", "with-foo-new")]
+ remapped_options = described_class.remap_deprecated_options(deprecated_options, subject.used_options)
+ expect(remapped_options).to include(Option.new("without-bar"))
+ expect(remapped_options).to include(Option.new("with-foo-new"))
+ end
+end | true |
Other | Homebrew | brew | e03caebaedf579d5330c5c908b2d3ffa927ea5c3.json | Convert Tab test to spec. | Library/Homebrew/test/tab_test.rb | @@ -1,318 +0,0 @@
-require "testing_env"
-require "tab"
-require "formula"
-
-class TabTests < Homebrew::TestCase
- def setup
- super
-
- @time = Time.now.to_i
- @used = Options.create(%w[--with-foo --without-bar])
- @unused = Options.create(%w[--with-baz --without-qux])
-
- @tab = Tab.new(
- "homebrew_version" => HOMEBREW_VERSION,
- "used_options" => @used.as_flags,
- "unused_options" => @unused.as_flags,
- "built_as_bottle" => false,
- "poured_from_bottle" => true,
- "changed_files" => [],
- "time" => @time,
- "source_modified_time" => 0,
- "HEAD" => TEST_SHA1,
- "compiler" => "clang",
- "stdlib" => "libcxx",
- "runtime_dependencies" => [],
- "source" => {
- "tap" => CoreTap.instance.to_s,
- "path" => CoreTap.instance.path.to_s,
- "spec" => "stable",
- "versions" => {
- "stable" => "0.10",
- "devel" => "0.14",
- "head" => "HEAD-1111111",
- },
- },
- )
- end
-
- def test_defaults
- tab = Tab.empty
-
- assert_equal HOMEBREW_VERSION, tab.homebrew_version
- assert_empty tab.unused_options
- assert_empty tab.used_options
- assert_nil tab.changed_files
- refute_predicate tab, :built_as_bottle
- refute_predicate tab, :poured_from_bottle
- assert_predicate tab, :stable?
- refute_predicate tab, :devel?
- refute_predicate tab, :head?
- assert_nil tab.tap
- assert_nil tab.time
- assert_nil tab.HEAD
- assert_empty tab.runtime_dependencies
- assert_nil tab.stable_version
- assert_nil tab.devel_version
- assert_nil tab.head_version
- assert_equal DevelopmentTools.default_compiler, tab.cxxstdlib.compiler
- assert_nil tab.cxxstdlib.type
- assert_nil tab.source["path"]
- end
-
- def test_include?
- assert_includes @tab, "with-foo"
- assert_includes @tab, "without-bar"
- end
-
- def test_with?
- assert @tab.with?("foo")
- assert @tab.with?("qux")
- refute @tab.with?("bar")
- refute @tab.with?("baz")
- end
-
- def test_universal?
- tab = Tab.new(used_options: %w[--universal])
- assert_predicate tab, :universal?
- end
-
- def test_parsed_homebrew_version
- tab = Tab.new
- assert_same Version::NULL, tab.parsed_homebrew_version
-
- tab = Tab.new(homebrew_version: "1.2.3")
- assert_equal "1.2.3", tab.parsed_homebrew_version
- assert tab.parsed_homebrew_version < "1.2.3-1-g12789abdf"
- assert_kind_of Version, tab.parsed_homebrew_version
-
- tab.homebrew_version = "1.2.4-567-g12789abdf"
- assert tab.parsed_homebrew_version > "1.2.4"
- assert tab.parsed_homebrew_version > "1.2.4-566-g21789abdf"
- assert tab.parsed_homebrew_version < "1.2.4-568-g01789abdf"
-
- tab = Tab.new(homebrew_version: "2.0.0-134-gabcdefabc-dirty")
- assert tab.parsed_homebrew_version > "2.0.0"
- assert tab.parsed_homebrew_version > "2.0.0-133-g21789abdf"
- assert tab.parsed_homebrew_version < "2.0.0-135-g01789abdf"
- end
-
- def test_runtime_dependencies
- tab = Tab.new
- assert_nil tab.runtime_dependencies
-
- tab.homebrew_version = "1.1.6"
- assert_nil tab.runtime_dependencies
-
- tab.runtime_dependencies = []
- refute_nil tab.runtime_dependencies
-
- tab.homebrew_version = "1.1.5"
- assert_nil tab.runtime_dependencies
-
- tab.homebrew_version = "1.1.7"
- refute_nil tab.runtime_dependencies
-
- tab.homebrew_version = "1.1.10"
- refute_nil tab.runtime_dependencies
-
- tab.runtime_dependencies = [{ "full_name" => "foo", "version" => "1.0" }]
- refute_nil tab.runtime_dependencies
- end
-
- def test_cxxstdlib
- assert_equal :clang, @tab.cxxstdlib.compiler
- assert_equal :libcxx, @tab.cxxstdlib.type
- end
-
- def test_other_attributes
- assert_equal TEST_SHA1, @tab.HEAD
- assert_equal "homebrew/core", @tab.tap.name
- assert_equal @time, @tab.time
- refute_predicate @tab, :built_as_bottle
- assert_predicate @tab, :poured_from_bottle
- end
-
- def test_from_old_version_file
- path = Pathname.new("#{TEST_FIXTURE_DIR}/receipt_old.json")
- tab = Tab.from_file(path)
-
- assert_equal @used.sort, tab.used_options.sort
- assert_equal @unused.sort, tab.unused_options.sort
- refute_predicate tab, :built_as_bottle
- assert_predicate tab, :poured_from_bottle
- assert_predicate tab, :stable?
- refute_predicate tab, :devel?
- refute_predicate tab, :head?
- assert_equal "homebrew/core", tab.tap.name
- assert_equal :stable, tab.spec
- refute_nil tab.time
- assert_equal TEST_SHA1, tab.HEAD
- assert_equal :clang, tab.cxxstdlib.compiler
- assert_equal :libcxx, tab.cxxstdlib.type
- assert_nil tab.runtime_dependencies
- end
-
- def test_from_file
- path = Pathname.new("#{TEST_FIXTURE_DIR}/receipt.json")
- tab = Tab.from_file(path)
- source_path = "/usr/local/Library/Taps/homebrew/homebrew-core/Formula/foo.rb"
- runtime_dependencies = [{ "full_name" => "foo", "version" => "1.0" }]
- changed_files = %w[INSTALL_RECEIPT.json bin/foo]
-
- assert_equal @used.sort, tab.used_options.sort
- assert_equal @unused.sort, tab.unused_options.sort
- assert_equal changed_files, tab.changed_files
- refute_predicate tab, :built_as_bottle
- assert_predicate tab, :poured_from_bottle
- assert_predicate tab, :stable?
- refute_predicate tab, :devel?
- refute_predicate tab, :head?
- assert_equal "homebrew/core", tab.tap.name
- assert_equal :stable, tab.spec
- refute_nil tab.time
- assert_equal TEST_SHA1, tab.HEAD
- assert_equal :clang, tab.cxxstdlib.compiler
- assert_equal :libcxx, tab.cxxstdlib.type
- assert_equal runtime_dependencies, tab.runtime_dependencies
- assert_equal "2.14", tab.stable_version.to_s
- assert_equal "2.15", tab.devel_version.to_s
- assert_equal "HEAD-0000000", tab.head_version.to_s
- assert_equal source_path, tab.source["path"]
- end
-
- def test_create
- f = formula do
- url "foo-1.0"
- depends_on "bar"
- depends_on "user/repo/from_tap"
- depends_on "baz" => :build
- end
-
- tap = Tap.new("user", "repo")
- from_tap = formula("from_tap", tap.path/"Formula/from_tap.rb") do
- url "from_tap-1.0"
- end
- stub_formula_loader from_tap
-
- stub_formula_loader formula("bar") { url "bar-2.0" }
- stub_formula_loader formula("baz") { url "baz-3.0" }
-
- compiler = DevelopmentTools.default_compiler
- stdlib = :libcxx
- tab = Tab.create(f, compiler, stdlib)
-
- runtime_dependencies = [
- { "full_name" => "bar", "version" => "2.0" },
- { "full_name" => "user/repo/from_tap", "version" => "1.0" },
- ]
-
- assert_equal runtime_dependencies, tab.runtime_dependencies
- assert_equal f.path.to_s, tab.source["path"]
- end
-
- def test_create_from_alias
- alias_path = CoreTap.instance.alias_dir/"bar"
- f = formula(alias_path: alias_path) { url "foo-1.0" }
- compiler = DevelopmentTools.default_compiler
- stdlib = :libcxx
- tab = Tab.create(f, compiler, stdlib)
-
- assert_equal f.alias_path.to_s, tab.source["path"]
- end
-
- def test_for_formula
- f = formula { url "foo-1.0" }
- tab = Tab.for_formula(f)
-
- assert_equal f.path.to_s, tab.source["path"]
- end
-
- def test_for_formula_from_alias
- alias_path = CoreTap.instance.alias_dir/"bar"
- f = formula(alias_path: alias_path) { url "foo-1.0" }
- tab = Tab.for_formula(f)
-
- assert_equal alias_path.to_s, tab.source["path"]
- end
-
- def test_to_json
- tab = Tab.new(JSON.parse(@tab.to_json))
- assert_equal @tab.used_options.sort, tab.used_options.sort
- assert_equal @tab.unused_options.sort, tab.unused_options.sort
- assert_equal @tab.built_as_bottle, tab.built_as_bottle
- assert_equal @tab.poured_from_bottle, tab.poured_from_bottle
- assert_equal @tab.changed_files, tab.changed_files
- assert_equal @tab.tap, tab.tap
- assert_equal @tab.spec, tab.spec
- assert_equal @tab.time, tab.time
- assert_equal @tab.HEAD, tab.HEAD
- assert_equal @tab.compiler, tab.compiler
- assert_equal @tab.stdlib, tab.stdlib
- assert_equal @tab.runtime_dependencies, tab.runtime_dependencies
- assert_equal @tab.stable_version, tab.stable_version
- assert_equal @tab.devel_version, tab.devel_version
- assert_equal @tab.head_version, tab.head_version
- assert_equal @tab.source["path"], tab.source["path"]
- end
-
- def test_remap_deprecated_options
- deprecated_options = [DeprecatedOption.new("with-foo", "with-foo-new")]
- remapped_options = Tab.remap_deprecated_options(deprecated_options, @tab.used_options)
- assert_includes remapped_options, Option.new("without-bar")
- assert_includes remapped_options, Option.new("with-foo-new")
- end
-end
-
-class TabLoadingTests < Homebrew::TestCase
- def setup
- super
- @f = formula { url "foo-1.0" }
- @f.prefix.mkpath
- @path = @f.prefix.join(Tab::FILENAME)
- @path.write TEST_FIXTURE_DIR.join("receipt.json").read
- end
-
- def test_for_keg
- tab = Tab.for_keg(@f.prefix)
- assert_equal @path, tab.tabfile
- end
-
- def test_for_keg_nonexistent_path
- @path.unlink
- tab = Tab.for_keg(@f.prefix)
- assert_nil tab.tabfile
- end
-
- def test_for_formula
- tab = Tab.for_formula(@f)
- assert_equal @path, tab.tabfile
- end
-
- def test_for_formula_nonexistent_path
- @path.unlink
- tab = Tab.for_formula(@f)
- assert_nil tab.tabfile
- end
-
- def test_for_formula_multiple_kegs
- f2 = formula { url "foo-2.0" }
- f2.prefix.mkpath
-
- assert_equal @f.rack, f2.rack
- assert_equal 2, @f.installed_prefixes.length
-
- tab = Tab.for_formula(@f)
- assert_equal @path, tab.tabfile
- end
-
- def test_for_formula_outdated_keg
- f2 = formula { url "foo-2.0" }
-
- assert_equal @f.rack, f2.rack
- assert_equal 1, @f.installed_prefixes.length
-
- tab = Tab.for_formula(f2)
- assert_equal @path, tab.tabfile
- end
-end | true |
Other | Homebrew | brew | 890631dc29cbf0035566d5c5d1e74ddf43684bc2.json | Convert ENV test to spec. | Library/Homebrew/test/ARGV_spec.rb | @@ -1,7 +1,7 @@
require "extend/ARGV"
describe HomebrewArgvExtension do
- subject { argv.extend(HomebrewArgvExtension) }
+ subject { argv.extend(described_class) }
let(:argv) { ["mxcl"] }
describe "#formulae" do | true |
Other | Homebrew | brew | 890631dc29cbf0035566d5c5d1e74ddf43684bc2.json | Convert ENV test to spec. | Library/Homebrew/test/ENV_spec.rb | @@ -0,0 +1,189 @@
+require "extend/ENV"
+
+shared_examples EnvActivation do
+ subject { env.extend(described_class) }
+ let(:env) { {}.extend(EnvActivation) }
+
+ it "supports switching compilers" do
+ subject.clang
+ expect(subject["LD"]).to be nil
+ expect(subject["CC"]).to eq(subject["OBJC"])
+ end
+
+ describe "#with_build_environment" do
+ it "restores the environment" do
+ before = subject.dup
+
+ subject.with_build_environment do
+ subject["foo"] = "bar"
+ end
+
+ expect(subject["foo"]).to be nil
+ expect(subject).to eq(before)
+ end
+
+ it "ensures the environment is restored" do
+ before = subject.dup
+
+ expect {
+ subject.with_build_environment do
+ subject["foo"] = "bar"
+ raise StandardError
+ end
+ }.to raise_error(StandardError)
+
+ expect(subject["foo"]).to be nil
+ expect(subject).to eq(before)
+ end
+
+ it "returns the value of the block" do
+ expect(subject.with_build_environment { 1 }).to eq(1)
+ end
+
+ it "does not mutate the interface" do
+ expected = subject.methods
+
+ subject.with_build_environment do
+ expect(subject.methods).to eq(expected)
+ end
+
+ expect(subject.methods).to eq(expected)
+ end
+ end
+
+ describe "#append" do
+ it "appends to an existing key" do
+ subject["foo"] = "bar"
+ subject.append "foo", "1"
+ expect(subject["foo"]).to eq("bar 1")
+ end
+
+ it "appends to an existing empty key" do
+ subject["foo"] = ""
+ subject.append "foo", "1"
+ expect(subject["foo"]).to eq("1")
+ end
+
+ it "appends to a non-existant key" do
+ subject.append "foo", "1"
+ expect(subject["foo"]).to eq("1")
+ end
+
+ # NOTE: this may be a wrong behavior; we should probably reject objects that
+ # do not respond to #to_str. For now this documents existing behavior.
+ it "coerces a value to a string" do
+ subject.append "foo", 42
+ expect(subject["foo"]).to eq("42")
+ end
+ end
+
+ describe "#prepend" do
+ it "prepends to an existing key" do
+ subject["foo"] = "bar"
+ subject.prepend "foo", "1"
+ expect(subject["foo"]).to eq("1 bar")
+ end
+
+ it "prepends to an existing empty key" do
+ subject["foo"] = ""
+ subject.prepend "foo", "1"
+ expect(subject["foo"]).to eq("1")
+ end
+
+ it "prepends to a non-existant key" do
+ subject.prepend "foo", "1"
+ expect(subject["foo"]).to eq("1")
+ end
+
+ # NOTE: this may be a wrong behavior; we should probably reject objects that
+ # do not respond to #to_str. For now this documents existing behavior.
+ it "coerces a value to a string" do
+ subject.prepend "foo", 42
+ expect(subject["foo"]).to eq("42")
+ end
+ end
+
+ describe "#append_path" do
+ it "appends to a path" do
+ subject.append_path "FOO", "/usr/bin"
+ expect(subject["FOO"]).to eq("/usr/bin")
+
+ subject.append_path "FOO", "/bin"
+ expect(subject["FOO"]).to eq("/usr/bin#{File::PATH_SEPARATOR}/bin")
+ end
+ end
+
+ describe "#prepend_path" do
+ it "prepends to a path" do
+ subject.prepend_path "FOO", "/usr/bin"
+ expect(subject["FOO"]).to eq("/usr/bin")
+
+ subject.prepend_path "FOO", "/bin"
+ expect(subject["FOO"]).to eq("/bin#{File::PATH_SEPARATOR}/usr/bin")
+ end
+ end
+
+ describe "#compiler" do
+ it "allows switching compilers" do
+ [:clang, :gcc_4_2, :gcc_4_0].each do |compiler|
+ subject.public_send(compiler)
+ expect(subject.compiler).to eq(compiler)
+ end
+ end
+ end
+
+ example "deparallelize_block_form_restores_makeflags" do
+ subject["MAKEFLAGS"] = "-j4"
+
+ subject.deparallelize do
+ expect(subject["MAKEFLAGS"]).to be nil
+ end
+
+ expect(subject["MAKEFLAGS"]).to eq("-j4")
+ end
+end
+
+describe Stdenv do
+ include_examples EnvActivation
+end
+
+describe Superenv do
+ include_examples EnvActivation
+
+ it "initializes deps" do
+ expect(subject.deps).to eq([])
+ expect(subject.keg_only_deps).to eq([])
+ end
+
+ describe "#cxx11" do
+ it "raises an error when the compiler isn't supported" do
+ %w[gcc gcc-4.7].each do |compiler|
+ subject["HOMEBREW_CC"] = compiler
+
+ expect { subject.cxx11 }
+ .to raise_error(/The selected compiler doesn't support C\+\+11:/)
+
+ expect(subject["HOMEBREW_CCCFG"]).to be nil
+ end
+ end
+
+ it "supports gcc-5" do
+ subject["HOMEBREW_CC"] = "gcc-5"
+ subject.cxx11
+ expect(subject["HOMEBREW_CCCFG"]).to include("x")
+ end
+
+ example "supports gcc-6" do
+ subject["HOMEBREW_CC"] = "gcc-6"
+ subject.cxx11
+ expect(subject["HOMEBREW_CCCFG"]).to include("x")
+ end
+
+ it "supports clang" do
+ subject["HOMEBREW_CC"] = "clang"
+ subject.cxx11
+ expect(subject["HOMEBREW_CCCFG"]).to include("x")
+ expect(subject["HOMEBREW_CCCFG"]).to include("g")
+ end
+ end
+end | true |
Other | Homebrew | brew | 890631dc29cbf0035566d5c5d1e74ddf43684bc2.json | Convert ENV test to spec. | Library/Homebrew/test/ENV_test.rb | @@ -1,175 +0,0 @@
-require "testing_env"
-require "extend/ENV"
-require "testing_env"
-
-module SharedEnvTests
- def setup
- super
- @env = {}.extend(EnvActivation)
- end
-
- def test_switching_compilers
- @env.clang
- assert_nil @env["LD"]
- assert_equal @env["OBJC"], @env["CC"]
- end
-
- def test_with_build_environment_restores_env
- before = @env.dup
- @env.with_build_environment do
- @env["foo"] = "bar"
- end
- assert_nil @env["foo"]
- assert_equal before, @env
- end
-
- def test_with_build_environment_ensures_env_restored
- before = @env.dup
- begin
- @env.with_build_environment do
- @env["foo"] = "bar"
- raise Exception
- end
- rescue Exception
- end
- assert_nil @env["foo"]
- assert_equal before, @env
- end
-
- def test_with_build_environment_returns_block_value
- assert_equal 1, @env.with_build_environment { 1 }
- end
-
- def test_with_build_environment_does_not_mutate_interface
- expected = @env.methods
- @env.with_build_environment { assert_equal expected, @env.methods }
- assert_equal expected, @env.methods
- end
-
- def test_append_existing_key
- @env["foo"] = "bar"
- @env.append "foo", "1"
- assert_equal "bar 1", @env["foo"]
- end
-
- def test_append_existing_key_empty
- @env["foo"] = ""
- @env.append "foo", "1"
- assert_equal "1", @env["foo"]
- end
-
- def test_append_missing_key
- @env.append "foo", "1"
- assert_equal "1", @env["foo"]
- end
-
- def test_prepend_existing_key
- @env["foo"] = "bar"
- @env.prepend "foo", "1"
- assert_equal "1 bar", @env["foo"]
- end
-
- def test_prepend_existing_key_empty
- @env["foo"] = ""
- @env.prepend "foo", "1"
- assert_equal "1", @env["foo"]
- end
-
- def test_prepend_missing_key
- @env.prepend "foo", "1"
- assert_equal "1", @env["foo"]
- end
-
- # NOTE: this may be a wrong behavior; we should probably reject objects that
- # do not respond to #to_str. For now this documents existing behavior.
- def test_append_coerces_value_to_string
- @env.append "foo", 42
- assert_equal "42", @env["foo"]
- end
-
- def test_prepend_coerces_value_to_string
- @env.prepend "foo", 42
- assert_equal "42", @env["foo"]
- end
-
- def test_append_path
- @env.append_path "FOO", "/usr/bin"
- assert_equal "/usr/bin", @env["FOO"]
- @env.append_path "FOO", "/bin"
- assert_equal "/usr/bin#{File::PATH_SEPARATOR}/bin", @env["FOO"]
- end
-
- def test_prepend_path
- @env.prepend_path "FOO", "/usr/bin"
- assert_equal "/usr/bin", @env["FOO"]
- @env.prepend_path "FOO", "/bin"
- assert_equal "/bin#{File::PATH_SEPARATOR}/usr/bin", @env["FOO"]
- end
-
- def test_switching_compilers_updates_compiler
- [:clang, :gcc_4_2, :gcc_4_0].each do |compiler|
- @env.send(compiler)
- assert_equal compiler, @env.compiler
- end
- end
-
- def test_deparallelize_block_form_restores_makeflags
- @env["MAKEFLAGS"] = "-j4"
- @env.deparallelize do
- assert_nil @env["MAKEFLAGS"]
- end
- assert_equal "-j4", @env["MAKEFLAGS"]
- end
-end
-
-class StdenvTests < Homebrew::TestCase
- include SharedEnvTests
-
- def setup
- super
- @env.extend(Stdenv)
- end
-end
-
-class SuperenvTests < Homebrew::TestCase
- include SharedEnvTests
-
- def setup
- super
- @env.extend(Superenv)
- end
-
- def test_initializes_deps
- assert_equal [], @env.deps
- assert_equal [], @env.keg_only_deps
- end
-
- def test_unsupported_cxx11
- %w[gcc gcc-4.7].each do |compiler|
- @env["HOMEBREW_CC"] = compiler
- assert_raises do
- @env.cxx11
- end
- refute_match "x", @env["HOMEBREW_CCCFG"]
- end
- end
-
- def test_supported_cxx11_gcc_5
- @env["HOMEBREW_CC"] = "gcc-5"
- @env.cxx11
- assert_match "x", @env["HOMEBREW_CCCFG"]
- end
-
- def test_supported_cxx11_gcc_6
- @env["HOMEBREW_CC"] = "gcc-6"
- @env.cxx11
- assert_match "x", @env["HOMEBREW_CCCFG"]
- end
-
- def test_supported_cxx11_clang
- @env["HOMEBREW_CC"] = "clang"
- @env.cxx11
- assert_match "x", @env["HOMEBREW_CCCFG"]
- assert_match "g", @env["HOMEBREW_CCCFG"]
- end
-end | true |
Other | Homebrew | brew | 004e8175c6ceb58f026e79e6bbd0ddac9e8380f6.json | Add `formula` spec helper. | Library/Homebrew/test/spec_helper.rb | @@ -16,6 +16,7 @@
require "test/support/helper/shutup"
require "test/support/helper/fixtures"
+require "test/support/helper/formula"
require "test/support/helper/spec/shared_context/integration_test"
TEST_DIRECTORIES = [
@@ -32,6 +33,7 @@
config.order = :random
config.include(Test::Helper::Shutup)
config.include(Test::Helper::Fixtures)
+ config.include(Test::Helper::Formula)
config.before(:each) do |example|
if example.metadata[:needs_macos]
skip "Not on macOS." unless OS.mac? | true |
Other | Homebrew | brew | 004e8175c6ceb58f026e79e6bbd0ddac9e8380f6.json | Add `formula` spec helper. | Library/Homebrew/test/support/helper/formula.rb | @@ -0,0 +1,19 @@
+require "formulary"
+
+module Test
+ module Helper
+ module Formula
+ def formula(name = "formula_name", path: Formulary.core_path(name), spec: :stable, alias_path: nil, &block)
+ Class.new(::Formula, &block).new(name, path, spec, alias_path: alias_path)
+ end
+
+ # Use a stubbed {Formulary::FormulaLoader} to make a given formula be found
+ # when loading from {Formulary} with `ref`.
+ def stub_formula_loader(formula, ref = formula.full_name)
+ loader = double(get_formula: formula)
+ allow(Formulary).to receive(:loader_for).with(ref, from: :keg).and_return(loader)
+ allow(Formulary).to receive(:loader_for).with(ref, from: nil).and_return(loader)
+ end
+ end
+ end
+end | true |
Other | Homebrew | brew | af65b07ac944082f5c9a84803690189e403b854a.json | Convert `patching` test to spec. | Library/Homebrew/test/patching_spec.rb | @@ -0,0 +1,289 @@
+require "formula"
+
+describe "patching" do
+ TESTBALL_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz".freeze
+ TESTBALL_PATCHES_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1-patches.tgz".freeze
+ PATCH_URL_A = "file://#{TEST_FIXTURE_DIR}/patches/noop-a.diff".freeze
+ PATCH_URL_B = "file://#{TEST_FIXTURE_DIR}/patches/noop-b.diff".freeze
+ PATCH_A_CONTENTS = File.read "#{TEST_FIXTURE_DIR}/patches/noop-a.diff"
+ PATCH_B_CONTENTS = File.read "#{TEST_FIXTURE_DIR}/patches/noop-b.diff"
+ APPLY_A = "noop-a.diff".freeze
+ APPLY_B = "noop-b.diff".freeze
+ APPLY_C = "noop-c.diff".freeze
+
+ def formula(name = "formula_name", path: Formulary.core_path(name), spec: :stable, alias_path: nil, &block)
+ Class.new(Formula) {
+ url TESTBALL_URL
+ sha256 TESTBALL_SHA256
+ class_eval(&block)
+ }.new(name, path, spec, alias_path: alias_path)
+ end
+
+ matcher :be_patched do
+ match do |formula|
+ shutup do
+ formula.brew do
+ formula.patch
+ s = File.read("libexec/NOOP")
+ expect(s).not_to include("NOOP"), "libexec/NOOP was not patched as expected"
+ expect(s).to include("ABCD"), "libexec/NOOP was not patched as expected"
+ end
+ end
+ end
+ end
+
+ matcher :be_sequentially_patched do
+ match do |formula|
+ shutup do
+ formula.brew do
+ formula.patch
+ s = File.read("libexec/NOOP")
+ expect(s).not_to include("NOOP"), "libexec/NOOP was not patched as expected"
+ expect(s).not_to include("ABCD"), "libexec/NOOP was not patched as expected"
+ expect(s).to include("1234"), "libexec/NOOP was not patched as expected"
+ end
+ end
+ end
+ end
+
+ matcher :miss_apply do
+ match do |formula|
+ expect {
+ shutup do
+ formula.brew do
+ formula.patch
+ end
+ end
+ }.to raise_error(MissingApplyError)
+ end
+ end
+
+ specify "single_patch" do
+ expect(
+ formula do
+ def patches
+ PATCH_URL_A
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_dsl" do
+ expect(
+ formula do
+ patch do
+ url PATCH_URL_A
+ sha256 PATCH_A_SHA256
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_dsl_with_apply" do
+ expect(
+ formula do
+ patch do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply APPLY_A
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_dsl_with_sequential_apply" do
+ expect(
+ formula do
+ patch do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply APPLY_A, APPLY_C
+ end
+ end,
+ ).to be_sequentially_patched
+ end
+
+ specify "single_patch_dsl_with_strip" do
+ expect(
+ formula do
+ patch :p1 do
+ url PATCH_URL_A
+ sha256 PATCH_A_SHA256
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_dsl_with_strip_with_apply" do
+ expect(
+ formula do
+ patch :p1 do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply APPLY_A
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_dsl_with_incorrect_strip" do
+ expect {
+ shutup do
+ f = formula do
+ patch :p0 do
+ url PATCH_URL_A
+ sha256 PATCH_A_SHA256
+ end
+ end
+
+ f.brew { |formula, _staging| formula.patch }
+ end
+ }.to raise_error(ErrorDuringExecution)
+ end
+
+ specify "single_patch_dsl_with_incorrect_strip_with_apply" do
+ expect {
+ shutup do
+ f = formula do
+ patch :p0 do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply APPLY_A
+ end
+ end
+
+ f.brew { |formula, _staging| formula.patch }
+ end
+ }.to raise_error(ErrorDuringExecution)
+ end
+
+ specify "patch_p0_dsl" do
+ expect(
+ formula do
+ patch :p0 do
+ url PATCH_URL_B
+ sha256 PATCH_B_SHA256
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_p0_dsl_with_apply" do
+ expect(
+ formula do
+ patch :p0 do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply APPLY_B
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_p0" do
+ expect(
+ formula do
+ def patches
+ { p0: PATCH_URL_B }
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_array" do
+ expect(
+ formula do
+ def patches
+ [PATCH_URL_A]
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_hash" do
+ expect(
+ formula do
+ def patches
+ { p1: PATCH_URL_A }
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_hash_array" do
+ expect(
+ formula do
+ def patches
+ { p1: [PATCH_URL_A] }
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_string" do
+ expect(formula { patch PATCH_A_CONTENTS }).to be_patched
+ end
+
+ specify "patch_string_with_strip" do
+ expect(formula { patch :p0, PATCH_B_CONTENTS }).to be_patched
+ end
+
+ specify "patch_data_constant" do
+ expect(
+ formula("test", path: Pathname.new(__FILE__).expand_path) do
+ def patches
+ :DATA
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_missing_apply_fail" do
+ expect(
+ formula do
+ def patches
+ TESTBALL_PATCHES_URL
+ end
+ end,
+ ).to miss_apply
+ end
+
+ specify "single_patch_dsl_missing_apply_fail" do
+ expect(
+ formula do
+ patch do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ end
+ end,
+ ).to miss_apply
+ end
+
+ specify "single_patch_dsl_with_apply_enoent_fail" do
+ expect {
+ shutup do
+ f = formula do
+ patch do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply "patches/#{APPLY_A}"
+ end
+ end
+
+ f.brew { |formula, _staging| formula.patch }
+ end
+ }.to raise_error(ErrorDuringExecution)
+ end
+end
+
+__END__
+diff --git a/libexec/NOOP b/libexec/NOOP
+index bfdda4c..e08d8f4 100755
+--- a/libexec/NOOP
++++ b/libexec/NOOP
+@@ -1,2 +1,2 @@
+ #!/bin/bash
+-echo NOOP
+\ No newline at end of file
++echo ABCD
+\ No newline at end of file | true |
Other | Homebrew | brew | af65b07ac944082f5c9a84803690189e403b854a.json | Convert `patching` test to spec. | Library/Homebrew/test/patching_test.rb | @@ -1,248 +0,0 @@
-require "testing_env"
-require "formula"
-
-class PatchingTests < Homebrew::TestCase
- TESTBALL_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz".freeze
- TESTBALL_PATCHES_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1-patches.tgz".freeze
- PATCH_URL_A = "file://#{TEST_FIXTURE_DIR}/patches/noop-a.diff".freeze
- PATCH_URL_B = "file://#{TEST_FIXTURE_DIR}/patches/noop-b.diff".freeze
- PATCH_A_CONTENTS = File.read "#{TEST_FIXTURE_DIR}/patches/noop-a.diff"
- PATCH_B_CONTENTS = File.read "#{TEST_FIXTURE_DIR}/patches/noop-b.diff"
- APPLY_A = "noop-a.diff".freeze
- APPLY_B = "noop-b.diff".freeze
- APPLY_C = "noop-c.diff".freeze
-
- def formula(*args, &block)
- super do
- url TESTBALL_URL
- sha256 TESTBALL_SHA256
- class_eval(&block)
- end
- end
-
- def assert_patched(formula)
- shutup do
- formula.brew do
- formula.patch
- s = File.read("libexec/NOOP")
- refute_includes s, "NOOP", "libexec/NOOP was not patched as expected"
- assert_includes s, "ABCD", "libexec/NOOP was not patched as expected"
- end
- end
- end
-
- def assert_sequentially_patched(formula)
- shutup do
- formula.brew do
- formula.patch
- s = File.read("libexec/NOOP")
- refute_includes s, "NOOP", "libexec/NOOP was not patched as expected"
- refute_includes s, "ABCD", "libexec/NOOP was not patched as expected"
- assert_includes s, "1234", "libexec/NOOP was not patched as expected"
- end
- end
- end
-
- def assert_missing_apply_fail(formula)
- assert_raises(MissingApplyError) do
- shutup do
- formula.brew do
- formula.patch
- end
- end
- end
- end
-
- def test_single_patch
- assert_patched formula {
- def patches
- PATCH_URL_A
- end
- }
- end
-
- def test_single_patch_dsl
- assert_patched formula {
- patch do
- url PATCH_URL_A
- sha256 PATCH_A_SHA256
- end
- }
- end
-
- def test_single_patch_dsl_with_apply
- assert_patched formula {
- patch do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply APPLY_A
- end
- }
- end
-
- def test_single_patch_dsl_with_sequential_apply
- assert_sequentially_patched formula {
- patch do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply APPLY_A, APPLY_C
- end
- }
- end
-
- def test_single_patch_dsl_with_strip
- assert_patched formula {
- patch :p1 do
- url PATCH_URL_A
- sha256 PATCH_A_SHA256
- end
- }
- end
-
- def test_single_patch_dsl_with_strip_with_apply
- assert_patched formula {
- patch :p1 do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply APPLY_A
- end
- }
- end
-
- def test_single_patch_dsl_with_incorrect_strip
- assert_raises(ErrorDuringExecution) do
- shutup do
- formula do
- patch :p0 do
- url PATCH_URL_A
- sha256 PATCH_A_SHA256
- end
- end.brew { |f, _staging| f.patch }
- end
- end
- end
-
- def test_single_patch_dsl_with_incorrect_strip_with_apply
- assert_raises(ErrorDuringExecution) do
- shutup do
- formula do
- patch :p0 do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply APPLY_A
- end
- end.brew { |f, _staging| f.patch }
- end
- end
- end
-
- def test_patch_p0_dsl
- assert_patched formula {
- patch :p0 do
- url PATCH_URL_B
- sha256 PATCH_B_SHA256
- end
- }
- end
-
- def test_patch_p0_dsl_with_apply
- assert_patched formula {
- patch :p0 do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply APPLY_B
- end
- }
- end
-
- def test_patch_p0
- assert_patched formula {
- def patches
- { p0: PATCH_URL_B }
- end
- }
- end
-
- def test_patch_array
- assert_patched formula {
- def patches
- [PATCH_URL_A]
- end
- }
- end
-
- def test_patch_hash
- assert_patched formula {
- def patches
- { p1: PATCH_URL_A }
- end
- }
- end
-
- def test_patch_hash_array
- assert_patched formula {
- def patches
- { p1: [PATCH_URL_A] }
- end
- }
- end
-
- def test_patch_string
- assert_patched formula { patch PATCH_A_CONTENTS }
- end
-
- def test_patch_string_with_strip
- assert_patched formula { patch :p0, PATCH_B_CONTENTS }
- end
-
- def test_patch_data_constant
- assert_patched formula("test", Pathname.new(__FILE__).expand_path) {
- def patches
- :DATA
- end
- }
- end
-
- def test_single_patch_missing_apply_fail
- assert_missing_apply_fail formula {
- def patches
- TESTBALL_PATCHES_URL
- end
- }
- end
-
- def test_single_patch_dsl_missing_apply_fail
- assert_missing_apply_fail formula {
- patch do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- end
- }
- end
-
- def test_single_patch_dsl_with_apply_enoent_fail
- assert_raises(ErrorDuringExecution) do
- shutup do
- formula do
- patch do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply "patches/#{APPLY_A}"
- end
- end.brew { |f, _staging| f.patch }
- end
- end
- end
-end
-
-__END__
-diff --git a/libexec/NOOP b/libexec/NOOP
-index bfdda4c..e08d8f4 100755
---- a/libexec/NOOP
-+++ b/libexec/NOOP
-@@ -1,2 +1,2 @@
- #!/bin/bash
--echo NOOP
-\ No newline at end of file
-+echo ABCD
-\ No newline at end of file | true |
Other | Homebrew | brew | 95aa8869a957ea81b1b8ab7485adb0229b12c3e9.json | Add William Woodruff, JCount to maintainers lists | README.md | @@ -40,7 +40,7 @@ This is our PGP key which is valid until May 24, 2017.
## Who Are You?
Homebrew's lead maintainer is [Mike McQuaid](https://github.com/mikemcquaid).
-Homebrew's current maintainers are [Misty De Meo](https://github.com/mistydemeo), [Andrew Janke](https://github.com/apjanke), [Tomasz Pajor](https://github.com/nijikon), [Josh Hagins](https://github.com/jawshooah), [Baptiste Fontaine](https://github.com/bfontaine), [Markus Reiter](https://github.com/reitermarkus), [ilovezfs](https://github.com/ilovezfs), [Tom Schoonjans](https://github.com/tschoonj), [Uladzislau Shablinski](https://github.com/vladshablinsky), [Tim Smith](https://github.com/tdsmith) and [Alex Dunn](https://github.com/dunn).
+Homebrew's current maintainers are [Misty De Meo](https://github.com/mistydemeo), [Andrew Janke](https://github.com/apjanke), [Tomasz Pajor](https://github.com/nijikon), [Josh Hagins](https://github.com/jawshooah), [Baptiste Fontaine](https://github.com/bfontaine), [Markus Reiter](https://github.com/reitermarkus), [ilovezfs](https://github.com/ilovezfs), [Tom Schoonjans](https://github.com/tschoonj), [Uladzislau Shablinski](https://github.com/vladshablinsky), [Tim Smith](https://github.com/tdsmith), [Alex Dunn](https://github.com/dunn), [William Woodruff](https://github.com/woodruffw), and [JCount](https://github.com/jcount).
Former maintainers with significant contributions include [Xu Cheng](https://github.com/xu-cheng), [Martin Afanasjew](https://github.com/UniqMartin), [Dominyk Tiller](https://github.com/DomT4), [Brett Koonce](https://github.com/asparagui), [Jack Nagel](https://github.com/jacknagel), [Adam Vandenberg](https://github.com/adamv) and Homebrew's creator: [Max Howell](https://github.com/mxcl).
| true |
Other | Homebrew | brew | 95aa8869a957ea81b1b8ab7485adb0229b12c3e9.json | Add William Woodruff, JCount to maintainers lists | docs/brew.1.html | @@ -791,7 +791,7 @@ <h2 id="AUTHORS">AUTHORS</h2>
<p>Homebrew's lead maintainer is Mike McQuaid.</p>
-<p>Homebrew's current maintainers are Misty De Meo, Andrew Janke, Tomasz Pajor, Josh Hagins, Baptiste Fontaine, Markus Reiter, ilovezfs, Tom Schoonjans, Uladzislau Shablinski, Tim Smith and Alex Dunn.</p>
+<p>Homebrew's current maintainers are Misty De Meo, Andrew Janke, Tomasz Pajor, Josh Hagins, Baptiste Fontaine, Markus Reiter, ilovezfs, Tom Schoonjans, Uladzislau Shablinski, Tim Smith, Alex Dunn, William Woodruff, and JCount.</p>
<p>Former maintainers with significant contributions include Xu Cheng, Martin Afanasjew, Dominyk Tiller, Brett Koonce, Jack Nagel, Adam Vandenberg and Homebrew's creator: Max Howell.</p>
| true |
Other | Homebrew | brew | 95aa8869a957ea81b1b8ab7485adb0229b12c3e9.json | Add William Woodruff, JCount to maintainers lists | manpages/brew.1 | @@ -1056,7 +1056,7 @@ Homebrew Documentation: \fIhttps://github\.com/Homebrew/brew/blob/master/docs/\f
Homebrew\'s lead maintainer is Mike McQuaid\.
.
.P
-Homebrew\'s current maintainers are Misty De Meo, Andrew Janke, Tomasz Pajor, Josh Hagins, Baptiste Fontaine, Markus Reiter, ilovezfs, Tom Schoonjans, Uladzislau Shablinski, Tim Smith and Alex Dunn\.
+Homebrew\'s current maintainers are Misty De Meo, Andrew Janke, Tomasz Pajor, Josh Hagins, Baptiste Fontaine, Markus Reiter, ilovezfs, Tom Schoonjans, Uladzislau Shablinski, Tim Smith, Alex Dunn, William Woodruff, and JCount\.
.
.P
Former maintainers with significant contributions include Xu Cheng, Martin Afanasjew, Dominyk Tiller, Brett Koonce, Jack Nagel, Adam Vandenberg and Homebrew\'s creator: Max Howell\. | true |
Other | Homebrew | brew | 9a47205b0eb7b016989259de9238223854eed2ed.json | README: add Netlify link. | README.md | @@ -73,6 +73,10 @@ Our bottles (binary packages) are hosted by [Bintray](https://bintray.com/homebr
[](https://bintray.com/homebrew)
+[Our website](https://brew.sh) is hosted by [Netlify](https://www.netlify.com).
+
+[](https://www.netlify.com)
+
Secure password storage and syncing provided by [1Password for Teams](https://1password.com/teams/) by [AgileBits](https://agilebits.com)
[](https://agilebits.com) | false |
Other | Homebrew | brew | 56a0afe5792d398d1682426bbebb1e53346b34d5.json | Extend #ds_file? in Pathname | Library/Homebrew/extend/pathname.rb | @@ -457,6 +457,10 @@ def install_metafiles(from = Pathname.pwd)
end
end
+ def ds_store?
+ basename.to_s == ".DS_Store"
+ end
+
# https://bugs.ruby-lang.org/issues/9915
if RUBY_VERSION == "2.0.0"
prepend Module.new { | true |
Other | Homebrew | brew | 56a0afe5792d398d1682426bbebb1e53346b34d5.json | Extend #ds_file? in Pathname | Library/Homebrew/test/pathname_test.rb | @@ -166,6 +166,11 @@ def test_cp_path_sub_directory
@dir.cp_path_sub @src, @dst
assert_predicate @dst/@dir.basename, :directory?
end
+
+ def test_ds_store
+ refute_predicate @file, :ds_store?
+ assert_predicate @src/".DS_Store", :ds_store?
+ end
end
class PathnameInstallTests < Homebrew::TestCase | true |
Other | Homebrew | brew | 7f8cd184936e3419a5bf960121f76098505d6811.json | Convert `brew create` test to spec. | Library/Homebrew/test/create_test.rb | @@ -1,12 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestCreate < IntegrationCommandTestCase
- def test_create
- url = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
- cmd("create", url, "HOMEBREW_EDITOR" => "/bin/cat")
-
- formula_file = CoreTap.new.formula_dir/"testball.rb"
- assert formula_file.exist?, "The formula source should have been created"
- assert_match %Q(sha256 "#{TESTBALL_SHA256}"), formula_file.read
- end
-end | true |
Other | Homebrew | brew | 7f8cd184936e3419a5bf960121f76098505d6811.json | Convert `brew create` test to spec. | Library/Homebrew/test/dev-cmd/create_spec.rb | @@ -0,0 +1,13 @@
+describe "brew create", :integration_test do
+ let(:url) { "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" }
+ let(:formula_file) { CoreTap.new.formula_dir/"testball.rb" }
+
+ it "creates a new Formula file for a given URL" do
+ shutup do
+ brew "create", url, "HOMEBREW_EDITOR" => "/bin/cat"
+ end
+
+ expect(formula_file).to exist
+ expect(formula_file.read).to match(%Q(sha256 "#{TESTBALL_SHA256}"))
+ end
+end | true |
Other | Homebrew | brew | 0248b5e357de99654b6a2f4ee5fd20829c8481e6.json | Convert `brew test` test to spec. | Library/Homebrew/test/dev-cmd/test_spec.rb | @@ -0,0 +1,56 @@
+describe "brew test", :integration_test do
+ it "fails when no argument is given" do
+ expect { brew "test" }
+ .to output(/This command requires a formula argument/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "fails when a Formula is not installed" do
+ expect { brew "test", testball }
+ .to output(/Testing requires the latest version of testball/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "fails when a Formula has no test" do
+ shutup do
+ expect { brew "install", testball }.to be_a_success
+ end
+
+ expect { brew "test", testball }
+ .to output(/testball defines no test/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "tests a given Formula" do
+ setup_test_formula "testball", <<-EOS.undent
+ head "https://github.com/example/testball2.git"
+
+ devel do
+ url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
+ sha256 "#{TESTBALL_SHA256}"
+ end
+
+ keg_only "just because"
+
+ test do
+ end
+ EOS
+
+ shutup do
+ expect { brew "install", "testball" }.to be_a_success
+ end
+
+ expect { brew "test", "--HEAD", "testball" }
+ .to output(/Testing testball/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "test", "--devel", "testball" }
+ .to output(/Testing testball/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end | true |
Other | Homebrew | brew | 0248b5e357de99654b6a2f4ee5fd20829c8481e6.json | Convert `brew test` test to spec. | Library/Homebrew/test/test_formula_test.rb | @@ -1,30 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestTestFormula < IntegrationCommandTestCase
- def test_test_formula
- assert_match "This command requires a formula argument", cmd_fail("test")
- assert_match "Testing requires the latest version of testball",
- cmd_fail("test", testball)
-
- cmd("install", testball)
- assert_match "testball defines no test", cmd_fail("test", testball)
-
- setup_test_formula "testball_copy", <<-EOS.undent
- head "https://github.com/example/testball2.git"
-
- devel do
- url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
- sha256 "#{TESTBALL_SHA256}"
- end
-
- keg_only "just because"
-
- test do
- end
- EOS
-
- cmd("install", "testball_copy")
- assert_match "Testing testball_copy", cmd("test", "--HEAD", "testball_copy")
- assert_match "Testing testball_copy", cmd("test", "--devel", "testball_copy")
- end
-end | true |
Other | Homebrew | brew | be2645b04f3b001069daf353289a19155afaf00c.json | Convert `brew options` test to spec. | Library/Homebrew/test/cmd/options_spec.rb | @@ -0,0 +1,12 @@
+describe "brew options", :integration_test do
+ it "prints a given Formula's options" do
+ setup_test_formula "testball", <<-EOS.undent
+ depends_on "bar" => :recommended
+ EOS
+
+ expect { brew "options", "testball" }
+ .to output("--with-foo\n\tBuild with foo\n--without-bar\n\tBuild without bar support\n\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end | true |
Other | Homebrew | brew | be2645b04f3b001069daf353289a19155afaf00c.json | Convert `brew options` test to spec. | Library/Homebrew/test/options_test.rb | @@ -1,17 +1,5 @@
require "testing_env"
require "options"
-require "testing_env"
-
-class IntegrationCommandTestOptions < IntegrationCommandTestCase
- def test_options
- setup_test_formula "testball", <<-EOS.undent
- depends_on "bar" => :recommended
- EOS
-
- assert_equal "--with-foo\n\tBuild with foo\n--without-bar\n\tBuild without bar support",
- cmd("options", "testball").chomp
- end
-end
class OptionTests < Homebrew::TestCase
def setup | true |
Other | Homebrew | brew | c37dbb79b669fc0c4088415d7269a6618f1ccb3c.json | Convert `brew help` test to spec. | Library/Homebrew/test/cmd/help_spec.rb | @@ -0,0 +1,47 @@
+describe "brew", :integration_test do
+ it "prints help when no argument is given" do
+ expect { brew }
+ .to output(/Example usage:\n/).to_stderr
+ .and be_a_failure
+ end
+
+ describe "help" do
+ it "prints help" do
+ expect { brew "help" }
+ .to output(/Example usage:\n/).to_stdout
+ .and be_a_success
+ end
+
+ it "prints help for a documented Ruby command" do
+ expect { brew "help", "cat" }
+ .to output(/^brew cat/).to_stdout
+ .and be_a_success
+ end
+
+ it "prints help for a documented shell command" do
+ expect { brew "help", "update" }
+ .to output(/^brew update/).to_stdout
+ .and be_a_success
+ end
+
+ it "prints help for a documented Ruby developer command" do
+ expect { brew "help", "update-test" }
+ .to output(/^brew update-test/).to_stdout
+ .and be_a_success
+ end
+
+ it "fails when given an unknown command" do
+ expect { brew "help", "command-that-does-not-exist" }
+ .to output(/Unknown command: command-that-does-not-exist/).to_stderr
+ .and be_a_failure
+ end
+ end
+
+ describe "cat" do
+ it "prints help when no argument is given" do
+ expect { brew "cat" }
+ .to output(/^brew cat/).to_stderr
+ .and be_a_failure
+ end
+ end
+end | true |
Other | Homebrew | brew | c37dbb79b669fc0c4088415d7269a6618f1ccb3c.json | Convert `brew help` test to spec. | Library/Homebrew/test/help_test.rb | @@ -1,21 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestHelp < IntegrationCommandTestCase
- def test_help
- assert_match "Example usage:\n",
- cmd_fail # Generic help (empty argument list).
- assert_match "Unknown command: command-that-does-not-exist",
- cmd_fail("help", "command-that-does-not-exist")
- assert_match(/^brew cat /,
- cmd_fail("cat")) # Missing formula argument triggers help.
-
- assert_match "Example usage:\n",
- cmd("help") # Generic help.
- assert_match(/^brew cat /,
- cmd("help", "cat")) # Internal command (documented, Ruby).
- assert_match(/^brew update /,
- cmd("help", "update")) # Internal command (documented, Shell).
- assert_match(/^brew update-test /,
- cmd("help", "update-test")) # Internal developer command (documented, Ruby).
- end
-end | true |
Other | Homebrew | brew | be498acf4fee38912a497b26e2beed97ee1f8b9a.json | Convert `brew unpack` test to spec. | Library/Homebrew/test/cmd/unpack_spec.rb | @@ -0,0 +1,16 @@
+describe "brew unpack", :integration_test do
+ it "unpacks a given Formula's archive" do
+ setup_test_formula "testball"
+
+ Dir.mktmpdir do |path|
+ path = Pathname.new(path)
+
+ shutup do
+ expect { brew "unpack", "testball", "--destdir=#{path}" }
+ .to be_a_success
+ end
+
+ expect(path/"testball-0.1").to be_a_directory
+ end
+ end
+end | true |
Other | Homebrew | brew | be498acf4fee38912a497b26e2beed97ee1f8b9a.json | Convert `brew unpack` test to spec. | Library/Homebrew/test/unpack_test.rb | @@ -1,13 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestUnpack < IntegrationCommandTestCase
- def test_unpack
- setup_test_formula "testball"
-
- mktmpdir do |path|
- cmd "unpack", "testball", "--destdir=#{path}"
- assert File.directory?("#{path}/testball-0.1"),
- "The tarball should be unpacked"
- end
- end
-end | true |
Other | Homebrew | brew | 5bf70805d8c134174dfb55791c25066239d9bc0e.json | Convert `brew linkapps` test to spec. | Library/Homebrew/test/cmd/linkapps_spec.rb | @@ -0,0 +1,24 @@
+describe "brew linkapps", :integration_test do
+ let(:home_dir) { @home_dir = Pathname.new(Dir.mktmpdir) }
+ let(:apps_dir) { home_dir/"Applications" }
+
+ after(:each) do
+ home_dir.rmtree unless @home_dir.nil?
+ end
+
+ it "symlinks applications" do
+ apps_dir.mkpath
+
+ setup_test_formula "testball"
+
+ source_app = HOMEBREW_CELLAR/"testball/0.1/TestBall.app"
+ source_app.mkpath
+
+ expect { brew "linkapps", "--local", "HOME" => home_dir }
+ .to output(/Linking: #{Regexp.escape(source_app)}/).to_stdout
+ .and output(/`brew linkapps` has been deprecated/).to_stderr
+ .and be_a_success
+
+ expect(apps_dir/"TestBall.app").to be_a_symlink
+ end
+end | true |
Other | Homebrew | brew | 5bf70805d8c134174dfb55791c25066239d9bc0e.json | Convert `brew linkapps` test to spec. | Library/Homebrew/test/linkapps_test.rb | @@ -1,15 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestLinkapps < IntegrationCommandTestCase
- def test_linkapps
- home_dir = Pathname.new(mktmpdir)
- (home_dir/"Applications").mkpath
-
- setup_test_formula "testball"
-
- source_dir = HOMEBREW_CELLAR/"testball/0.1/TestBall.app"
- source_dir.mkpath
- assert_match "Linking: #{source_dir}",
- cmd("linkapps", "--local", "HOME" => home_dir)
- end
-end | true |
Other | Homebrew | brew | 1d7fde515b9cce2e3fc4dddce1c34f5e410bca87.json | Update deps_spec descriptions | Library/Homebrew/test/deps_spec.rb | @@ -8,19 +8,19 @@
EOS
end
- it "outputs nothing for formula foo" do
+ it "outputs no dependencies for a Formula that has no dependencies" do
expect { brew "deps", "foo" }.to output("").to_stdout
.and not_to_output.to_stderr
.and be_a_success
end
- it "outputs foo for formula bar" do
+ it "outputs a dependency for a Formula that has one dependency" do
expect { brew "deps", "bar" }.to output("foo\n").to_stdout
.and not_to_output.to_stderr
.and be_a_success
end
- it "outputs formulae bar and foo for formula baz" do
+ it "outputs dependencies on separate lines for a Formula that has multiple dependencies" do
expect { brew "deps", "baz" }.to output("bar\nfoo\n").to_stdout
.and not_to_output.to_stderr
.and be_a_success | false |
Other | Homebrew | brew | 5e9057500419d1a2b41efe784e9f12ae232e7f6e.json | audit: handle redirects in get_content_details. | Library/Homebrew/dev-cmd/audit.rb | @@ -1542,12 +1542,16 @@ def problem(text)
def get_content_details(url)
out = {}
output, = curl_output "--connect-timeout", "15", "--include", url
- split = output.partition("\r\n\r\n")
- headers = split.first
- out[:status] = headers[%r{HTTP\/.* (\d+)}, 1]
+ status_code = :unknown
+ while status_code == :unknown || status_code.to_s.start_with?("3")
+ headers, _, output = output.partition("\r\n\r\n")
+ status_code = headers[%r{HTTP\/.* (\d+)}, 1]
+ end
+
+ out[:status] = status_code
out[:etag] = headers[%r{ETag: ([wW]\/)?"(([^"]|\\")*)"}, 2]
out[:content_length] = headers[/Content-Length: (\d+)/, 1]
- out[:file_hash] = Digest::SHA256.digest split.last
+ out[:file_hash] = Digest::SHA256.digest output
out
end
end | false |
Other | Homebrew | brew | d4df9d44e09df6197275113b266df2b7d51a0339.json | Exclude executables from metafiles
Exclude executables in #empty_installation? to avoid 'Empty
Installation' error when only executable which name is the
same as one of metafiles is installed. | Library/Homebrew/keg.rb | @@ -208,6 +208,7 @@ def ==(other)
def empty_installation?
Pathname.glob("#{path}/**/*") do |file|
+ return false if file.executable?
next if file.directory?
basename = file.basename.to_s
next if Metafiles.copy?(basename) | false |
Other | Homebrew | brew | ca4fba99c417437aca2efb36cc3c89e871d5f5a0.json | Convert CompilerSelector test to spec. | Library/Homebrew/test/compiler_selector_spec.rb | @@ -0,0 +1,122 @@
+require "compilers"
+require "software_spec"
+
+describe CompilerSelector do
+ subject { described_class.new(software_spec, versions, compilers) }
+ let(:compilers) { [:clang, :gcc, :llvm, :gnu] }
+ let(:software_spec) { SoftwareSpec.new }
+ let(:cc) { :clang }
+ let(:versions) do
+ double(
+ gcc_4_0_build_version: Version::NULL,
+ gcc_build_version: Version.create("5666"),
+ llvm_build_version: Version::NULL,
+ clang_build_version: Version.create("425"),
+ )
+ end
+
+ before(:each) do
+ allow(versions).to receive(:non_apple_gcc_version) do |name|
+ case name
+ when "gcc-4.8" then Version.create("4.8.1")
+ when "gcc-4.7" then Version.create("4.7.1")
+ else Version::NULL
+ end
+ end
+ end
+
+ describe "#compiler" do
+ it "raises an error if no matching compiler can be found" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:llvm)
+ software_spec.fails_with(:gcc)
+ software_spec.fails_with(gcc: "4.8")
+ software_spec.fails_with(gcc: "4.7")
+
+ expect { subject.compiler }.to raise_error(CompilerSelectionError)
+ end
+
+ it "defaults to cc" do
+ expect(subject.compiler).to eq(cc)
+ end
+
+ it "returns gcc if it fails with clang" do
+ software_spec.fails_with(:clang)
+ expect(subject.compiler).to eq(:gcc)
+ end
+
+ it "returns clang if it fails with llvm" do
+ software_spec.fails_with(:llvm)
+ expect(subject.compiler).to eq(:clang)
+ end
+
+ it "returns clang if it fails with gcc" do
+ software_spec.fails_with(:gcc)
+ expect(subject.compiler).to eq(:clang)
+ end
+
+ it "returns clang if it fails with non-Apple gcc" do
+ software_spec.fails_with(gcc: "4.8")
+ expect(subject.compiler).to eq(:clang)
+ end
+
+ it "still returns gcc-4.8 if it fails with gcc without a specific version" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:gcc)
+ expect(subject.compiler).to eq("gcc-4.8")
+ end
+
+ it "returns gcc if it fails with clang and llvm" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:llvm)
+ expect(subject.compiler).to eq(:gcc)
+ end
+
+ it "returns clang if it fails with gcc and llvm" do
+ software_spec.fails_with(:gcc)
+ software_spec.fails_with(:llvm)
+ expect(subject.compiler).to eq(:clang)
+ end
+
+ example "returns gcc if it fails with a specific gcc version" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(gcc: "4.8")
+ expect(subject.compiler).to eq(:gcc)
+ end
+
+ example "returns a lower version of gcc if it fails with the highest version" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:gcc)
+ software_spec.fails_with(:llvm)
+ software_spec.fails_with(gcc: "4.8")
+ expect(subject.compiler).to eq("gcc-4.7")
+ end
+
+ it "prefers gcc" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:gcc)
+ expect(subject.compiler).to eq("gcc-4.8")
+ end
+
+ it "raises an error when gcc is missing" do
+ allow(versions).to receive(:gcc_build_version).and_return(Version::NULL)
+
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:llvm)
+ software_spec.fails_with(gcc: "4.8")
+ software_spec.fails_with(gcc: "4.7")
+
+ expect { subject.compiler }.to raise_error(CompilerSelectionError)
+ end
+
+ it "raises an error when llvm and gcc are missing" do
+ allow(versions).to receive(:gcc_build_version).and_return(Version::NULL)
+
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(gcc: "4.8")
+ software_spec.fails_with(gcc: "4.7")
+
+ expect { subject.compiler }.to raise_error(CompilerSelectionError)
+ end
+ end
+end | true |
Other | Homebrew | brew | ca4fba99c417437aca2efb36cc3c89e871d5f5a0.json | Convert CompilerSelector test to spec. | Library/Homebrew/test/compiler_selector_test.rb | @@ -1,117 +0,0 @@
-require "testing_env"
-require "compilers"
-require "software_spec"
-
-class CompilerSelectorTests < Homebrew::TestCase
- class Double < SoftwareSpec
- def <<(cc)
- fails_with(cc)
- self
- end
- end
-
- class CompilerVersions
- attr_accessor :gcc_4_0_build_version, :gcc_build_version,
- :clang_build_version
-
- def initialize
- @gcc_4_0_build_version = Version::NULL
- @gcc_build_version = Version.create("5666")
- @llvm_build_version = Version::NULL
- @clang_build_version = Version.create("425")
- end
-
- def non_apple_gcc_version(name)
- case name
- when "gcc-4.8" then Version.create("4.8.1")
- when "gcc-4.7" then Version.create("4.7.1")
- else Version::NULL
- end
- end
- end
-
- def setup
- super
- @f = Double.new
- @cc = :clang
- @versions = CompilerVersions.new
- @selector = CompilerSelector.new(
- @f, @versions, [:clang, :gcc, :llvm, :gnu]
- )
- end
-
- def actual_cc
- @selector.compiler
- end
-
- def test_all_compiler_failures
- @f << :clang << :llvm << :gcc << { gcc: "4.8" } << { gcc: "4.7" }
- assert_raises(CompilerSelectionError) { actual_cc }
- end
-
- def test_no_compiler_failures
- assert_equal @cc, actual_cc
- end
-
- def test_fails_with_clang
- @f << :clang
- assert_equal :gcc, actual_cc
- end
-
- def test_fails_with_llvm
- @f << :llvm
- assert_equal :clang, actual_cc
- end
-
- def test_fails_with_gcc
- @f << :gcc
- assert_equal :clang, actual_cc
- end
-
- def test_fails_with_non_apple_gcc
- @f << { gcc: "4.8" }
- assert_equal :clang, actual_cc
- end
-
- def test_mixed_failures_1
- @f << :clang << :gcc
- assert_equal "gcc-4.8", actual_cc
- end
-
- def test_mixed_failures_2
- @f << :clang << :llvm
- assert_equal :gcc, actual_cc
- end
-
- def test_mixed_failures_3
- @f << :gcc << :llvm
- assert_equal :clang, actual_cc
- end
-
- def test_mixed_failures_4
- @f << :clang << { gcc: "4.8" }
- assert_equal :gcc, actual_cc
- end
-
- def test_mixed_failures_5
- @f << :clang << :gcc << :llvm << { gcc: "4.8" }
- assert_equal "gcc-4.7", actual_cc
- end
-
- def test_gcc_precedence
- @f << :clang << :gcc
- assert_equal "gcc-4.8", actual_cc
- end
-
- def test_missing_gcc
- @versions.gcc_build_version = Version::NULL
- @f << :clang << :llvm << { gcc: "4.8" } << { gcc: "4.7" }
- assert_raises(CompilerSelectionError) { actual_cc }
- end
-
- def test_missing_llvm_and_gcc
- @versions.gcc_build_version = Version::NULL
- @f << :clang << { gcc: "4.8" } << { gcc: "4.7" }
- assert_raises(CompilerSelectionError) { actual_cc }
- end
-end | true |
Other | Homebrew | brew | 85ff9add185fc24d99b296cf9cca3071b6d865c0.json | Convert Pathname test to spec. | Library/Homebrew/test/pathname_spec.rb | @@ -0,0 +1,300 @@
+require "tmpdir"
+require "extend/pathname"
+require "install_renamed"
+
+describe Pathname do
+ include FileUtils
+
+ let(:src) { Pathname.new(Dir.mktmpdir) }
+ let(:dst) { Pathname.new(Dir.mktmpdir) }
+ let(:file) { src/"foo" }
+ let(:dir) { src/"bar" }
+
+ after(:each) { rm_rf [src, dst] }
+
+ describe DiskUsageExtension do
+ before(:each) do
+ mkdir_p dir/"a-directory"
+ touch [dir/".DS_Store", dir/"a-file"]
+ File.truncate(dir/"a-file", 1_048_576)
+ ln_s dir/"a-file", dir/"a-symlink"
+ ln dir/"a-file", dir/"a-hardlink"
+ end
+
+ describe "#file_count" do
+ it "returns the number of files in a directory" do
+ expect(dir.file_count).to eq(3)
+ end
+ end
+
+ describe "#abv" do
+ context "when called on a directory" do
+ it "returns a string with the file count and disk usage" do
+ expect(dir.abv).to eq("3 files, 1M")
+ end
+ end
+
+ context "when called on a file" do
+ it "returns the disk usage" do
+ expect((dir/"a-file").abv).to eq("1M")
+ end
+ end
+ end
+ end
+
+ describe "#rmdir_if_possible" do
+ before(:each) { mkdir_p dir }
+
+ it "returns true and removes a directory if it doesn't contain files" do
+ expect(dir.rmdir_if_possible).to be true
+ expect(dir).not_to exist
+ end
+
+ it "returns false and doesn't delete a directory if it contains files" do
+ touch dir/"foo"
+ expect(dir.rmdir_if_possible).to be false
+ expect(dir).to be_a_directory
+ end
+
+ it "ignores .DS_Store files" do
+ touch dir/".DS_Store"
+ expect(dir.rmdir_if_possible).to be true
+ expect(dir).not_to exist
+ end
+ end
+
+ describe "#write" do
+ it "creates a file and writes to it" do
+ expect(file).not_to exist
+ file.write("CONTENT")
+ expect(File.read(file)).to eq("CONTENT")
+ end
+
+ it "raises an error if the file already exists" do
+ touch file
+ expect { file.write("CONTENT") }.to raise_error(RuntimeError)
+ end
+ end
+
+ describe "#append_lines" do
+ it "appends lines to a file" do
+ touch file
+
+ file.append_lines("CONTENT")
+ expect(File.read(file)).to eq <<-EOS.undent
+ CONTENT
+ EOS
+
+ file.append_lines("CONTENTS")
+ expect(File.read(file)).to eq <<-EOS.undent
+ CONTENT
+ CONTENTS
+ EOS
+ end
+
+ it "raises an error if the file does not exist" do
+ expect(file).not_to exist
+ expect { file.append_lines("CONTENT") }.to raise_error(RuntimeError)
+ end
+ end
+
+ describe "#atomic_write" do
+ it "atomically replaces a file" do
+ touch file
+ file.atomic_write("CONTENT")
+ expect(File.read(file)).to eq("CONTENT")
+ end
+
+ it "preserves permissions" do
+ File.open(file, "w", 0100777).close
+ file.atomic_write("CONTENT")
+ expect(file.stat.mode).to eq(0100777 & ~File.umask)
+ end
+
+ it "preserves default permissions" do
+ file.atomic_write("CONTENT")
+ sentinel = file.parent.join("sentinel")
+ touch sentinel
+ expect(file.stat.mode).to eq(sentinel.stat.mode)
+ end
+ end
+
+ describe "#ensure_writable" do
+ it "makes a file writable and restores permissions afterwards" do
+ touch file
+ chmod 0555, file
+ expect(file).not_to be_writable
+ file.ensure_writable do
+ expect(file).to be_writable
+ end
+ expect(file).not_to be_writable
+ end
+ end
+
+ describe "#extname" do
+ it "supports common multi-level archives" do
+ expect(Pathname.new("foo-0.1.tar.gz").extname).to eq(".tar.gz")
+ expect(Pathname.new("foo-0.1.cpio.gz").extname).to eq(".cpio.gz")
+ end
+ end
+
+ describe "#stem" do
+ it "returns the basename without double extensions" do
+ expect(Pathname("foo-0.1.tar.gz").stem).to eq("foo-0.1")
+ expect(Pathname("foo-0.1.cpio.gz").stem).to eq("foo-0.1")
+ end
+ end
+
+ describe "#install" do
+ before(:each) do
+ (src/"a.txt").write "This is sample file a."
+ (src/"b.txt").write "This is sample file b."
+ end
+
+ it "raises an error if the file doesn't exist" do
+ expect { dst.install "non_existent_file" }.to raise_error(Errno::ENOENT)
+ end
+
+ it "installs a file to a directory with its basename" do
+ touch file
+ dst.install(file)
+ expect(dst/file.basename).to exist
+ expect(file).not_to exist
+ end
+
+ it "creates intermediate directories" do
+ touch file
+ expect(dir).not_to be_a_directory
+ dir.install(file)
+ expect(dir).to be_a_directory
+ end
+
+ it "can install a file" do
+ dst.install src/"a.txt"
+ expect(dst/"a.txt").to exist, "a.txt was not installed"
+ expect(dst/"b.txt").not_to exist, "b.txt was installed."
+ end
+
+ it "can install an array of files" do
+ dst.install [src/"a.txt", src/"b.txt"]
+
+ expect(dst/"a.txt").to exist, "a.txt was not installed"
+ expect(dst/"b.txt").to exist, "b.txt was not installed"
+ end
+
+ it "can install a directory" do
+ bin = src/"bin"
+ bin.mkpath
+ mv Dir[src/"*.txt"], bin
+ dst.install bin
+
+ expect(dst/"bin/a.txt").to exist, "a.txt was not installed"
+ expect(dst/"bin/b.txt").to exist, "b.txt was not installed"
+ end
+
+ it "supports renaming files" do
+ dst.install src/"a.txt" => "c.txt"
+
+ expect(dst/"c.txt").to exist, "c.txt was not installed"
+ expect(dst/"a.txt").not_to exist, "a.txt was installed but not renamed"
+ expect(dst/"b.txt").not_to exist, "b.txt was installed"
+ end
+
+ it "supports renaming multiple files" do
+ dst.install(src/"a.txt" => "c.txt", src/"b.txt" => "d.txt")
+
+ expect(dst/"c.txt").to exist, "c.txt was not installed"
+ expect(dst/"d.txt").to exist, "d.txt was not installed"
+ expect(dst/"a.txt").not_to exist, "a.txt was installed but not renamed"
+ expect(dst/"b.txt").not_to exist, "b.txt was installed but not renamed"
+ end
+
+ it "supports renaming directories" do
+ bin = src/"bin"
+ bin.mkpath
+ mv Dir[src/"*.txt"], bin
+ dst.install bin => "libexec"
+
+ expect(dst/"bin").not_to exist, "bin was installed but not renamed"
+ expect(dst/"libexec/a.txt").to exist, "a.txt was not installed"
+ expect(dst/"libexec/b.txt").to exist, "b.txt was not installed"
+ end
+
+ it "can install directories as relative symlinks" do
+ bin = src/"bin"
+ bin.mkpath
+ mv Dir[src/"*.txt"], bin
+ dst.install_symlink bin
+
+ expect(dst/"bin").to be_a_symlink
+ expect(dst/"bin").to be_a_directory
+ expect(dst/"bin/a.txt").to exist
+ expect(dst/"bin/b.txt").to exist
+ expect((dst/"bin").readlink).to be_relative
+ end
+
+ it "can install relative paths as symlinks" do
+ dst.install_symlink "foo" => "bar"
+ expect((dst/"bar").readlink).to eq(Pathname.new("foo"))
+ end
+ end
+
+ describe InstallRenamed do
+ before(:each) do
+ dst.extend(InstallRenamed)
+ end
+
+ it "renames the installed file if it already exists" do
+ file.write "a"
+ dst.install file
+
+ file.write "b"
+ dst.install file
+
+ expect(File.read(dst/file.basename)).to eq("a")
+ expect(File.read(dst/"#{file.basename}.default")).to eq("b")
+ end
+
+ it "renames the installed directory" do
+ file.write "a"
+ dst.install src
+ expect(File.read(dst/src.basename/file.basename)).to eq("a")
+ end
+
+ it "recursively renames directories" do
+ (dst/dir.basename).mkpath
+ (dst/dir.basename/"another_file").write "a"
+ dir.mkpath
+ (dir/"another_file").write "b"
+ dst.install dir
+ expect(File.read(dst/dir.basename/"another_file.default")).to eq("b")
+ end
+ end
+
+ describe "#cp_path_sub" do
+ it "copies a file and replaces the given pattern" do
+ file.write "a"
+ file.cp_path_sub src, dst
+ expect(File.read(dst/file.basename)).to eq("a")
+ end
+
+ it "copies a directory and replaces the given pattern" do
+ dir.mkpath
+ dir.cp_path_sub src, dst
+ expect(dst/dir.basename).to be_a_directory
+ end
+ end
+end
+
+describe FileUtils do
+ let(:dst) { Pathname.new(Dir.mktmpdir) }
+
+ describe "#mkdir" do
+ it "creates indermediate directories" do
+ described_class.mkdir dst/"foo/bar/baz" do
+ expect(dst/"foo/bar/baz").to exist, "foo/bar/baz was not created"
+ expect(dst/"foo/bar/baz").to be_a_directory, "foo/bar/baz was not a directory structure"
+ end
+ end
+ end
+end | true |
Other | Homebrew | brew | 85ff9add185fc24d99b296cf9cca3071b6d865c0.json | Convert Pathname test to spec. | Library/Homebrew/test/pathname_test.rb | @@ -1,263 +0,0 @@
-require "testing_env"
-require "tmpdir"
-require "extend/pathname"
-require "install_renamed"
-
-module PathnameTestExtension
- include FileUtils
-
- def setup
- super
- @src = Pathname.new(mktmpdir)
- @dst = Pathname.new(mktmpdir)
- @file = @src/"foo"
- @dir = @src/"bar"
- end
-end
-
-class PathnameTests < Homebrew::TestCase
- include PathnameTestExtension
-
- def test_disk_usage_extension
- mkdir_p @dir/"a-directory"
- touch @dir/".DS_Store"
- touch @dir/"a-file"
- File.truncate(@dir/"a-file", 1_048_576)
- ln_s @dir/"a-file", @dir/"a-symlink"
- ln @dir/"a-file", @dir/"a-hardlink"
- assert_equal 3, @dir.file_count
- assert_equal "3 files, 1M", @dir.abv
- assert_equal "1M", (@dir/"a-file").abv
- end
-
- def test_rmdir_if_possible
- mkdir_p @dir
- touch @dir/"foo"
-
- assert !@dir.rmdir_if_possible
- assert_predicate @dir, :directory?
-
- rm_f @dir/"foo"
- assert @dir.rmdir_if_possible
- refute_predicate @dir, :exist?
- end
-
- def test_rmdir_if_possible_ignore_ds_store
- mkdir_p @dir
- touch @dir/".DS_Store"
- assert @dir.rmdir_if_possible
- refute_predicate @dir, :exist?
- end
-
- def test_write
- @file.write("CONTENT")
- assert_equal "CONTENT", File.read(@file)
- end
-
- def test_write_does_not_overwrite
- touch @file
- assert_raises(RuntimeError) { @file.write("CONTENT") }
- end
-
- def test_append_lines
- touch @file
- @file.append_lines("CONTENT")
- assert_equal "CONTENT\n", File.read(@file)
- @file.append_lines("CONTENTS")
- assert_equal "CONTENT\nCONTENTS\n", File.read(@file)
- end
-
- def test_append_lines_does_not_create
- assert_raises(RuntimeError) { @file.append_lines("CONTENT") }
- end
-
- def test_atomic_write
- touch @file
- @file.atomic_write("CONTENT")
- assert_equal "CONTENT", File.read(@file)
- end
-
- def test_atomic_write_preserves_permissions
- File.open(@file, "w", 0100777) {}
- @file.atomic_write("CONTENT")
- assert_equal 0100777 & ~File.umask, @file.stat.mode
- end
-
- def test_atomic_write_preserves_default_permissions
- @file.atomic_write("CONTENT")
- sentinel = @file.parent.join("sentinel")
- touch sentinel
- assert_equal sentinel.stat.mode, @file.stat.mode
- end
-
- def test_ensure_writable
- touch @file
- chmod 0555, @file
- @file.ensure_writable { assert_predicate @file, :writable? }
- refute_predicate @file, :writable?
- end
-
- def test_extname
- assert_equal ".tar.gz", Pathname("foo-0.1.tar.gz").extname
- assert_equal ".cpio.gz", Pathname("foo-0.1.cpio.gz").extname
- end
-
- def test_stem
- assert_equal "foo-0.1", Pathname("foo-0.1.tar.gz").stem
- assert_equal "foo-0.1", Pathname("foo-0.1.cpio.gz").stem
- end
-
- def test_install_missing_file
- assert_raises(Errno::ENOENT) { @dst.install "non_existent_file" }
- end
-
- def test_install_removes_original
- touch @file
- @dst.install(@file)
-
- assert_predicate @dst/@file.basename, :exist?
- refute_predicate @file, :exist?
- end
-
- def test_install_creates_intermediate_directories
- touch @file
- refute_predicate @dir, :directory?
- @dir.install(@file)
- assert_predicate @dir, :directory?
- end
-
- def test_install_renamed
- @dst.extend(InstallRenamed)
-
- @file.write "a"
- @dst.install @file
- @file.write "b"
- @dst.install @file
-
- assert_equal "a", File.read(@dst/@file.basename)
- assert_equal "b", File.read(@dst/"#{@file.basename}.default")
- end
-
- def test_install_renamed_directory
- @dst.extend(InstallRenamed)
- @file.write "a"
- @dst.install @src
- assert_equal "a", File.read(@dst/@src.basename/@file.basename)
- end
-
- def test_install_renamed_directory_recursive
- @dst.extend(InstallRenamed)
- (@dst/@dir.basename).mkpath
- (@dst/@dir.basename/"another_file").write "a"
- @dir.mkpath
- (@dir/"another_file").write "b"
- @dst.install @dir
- assert_equal "b", File.read(@dst/@dir.basename/"another_file.default")
- end
-
- def test_cp_path_sub_file
- @file.write "a"
- @file.cp_path_sub @src, @dst
- assert_equal "a", File.read(@dst/"foo")
- end
-
- def test_cp_path_sub_directory
- @dir.mkpath
- @dir.cp_path_sub @src, @dst
- assert_predicate @dst/@dir.basename, :directory?
- end
-end
-
-class PathnameInstallTests < Homebrew::TestCase
- include PathnameTestExtension
-
- def setup
- super
- (@src/"a.txt").write "This is sample file a."
- (@src/"b.txt").write "This is sample file b."
- end
-
- def test_install
- @dst.install @src/"a.txt"
-
- assert_predicate @dst/"a.txt", :exist?, "a.txt was not installed"
- refute_predicate @dst/"b.txt", :exist?, "b.txt was installed."
- end
-
- def test_install_list
- @dst.install [@src/"a.txt", @src/"b.txt"]
-
- assert_predicate @dst/"a.txt", :exist?, "a.txt was not installed"
- assert_predicate @dst/"b.txt", :exist?, "b.txt was not installed"
- end
-
- def test_install_glob
- @dst.install Dir[@src/"*.txt"]
-
- assert_predicate @dst/"a.txt", :exist?, "a.txt was not installed"
- assert_predicate @dst/"b.txt", :exist?, "b.txt was not installed"
- end
-
- def test_install_directory
- bin = @src/"bin"
- bin.mkpath
- mv Dir[@src/"*.txt"], bin
- @dst.install bin
-
- assert_predicate @dst/"bin/a.txt", :exist?, "a.txt was not installed"
- assert_predicate @dst/"bin/b.txt", :exist?, "b.txt was not installed"
- end
-
- def test_install_rename
- @dst.install @src/"a.txt" => "c.txt"
-
- assert_predicate @dst/"c.txt", :exist?, "c.txt was not installed"
- refute_predicate @dst/"a.txt", :exist?, "a.txt was installed but not renamed"
- refute_predicate @dst/"b.txt", :exist?, "b.txt was installed"
- end
-
- def test_install_rename_more
- @dst.install(@src/"a.txt" => "c.txt", @src/"b.txt" => "d.txt")
-
- assert_predicate @dst/"c.txt", :exist?, "c.txt was not installed"
- assert_predicate @dst/"d.txt", :exist?, "d.txt was not installed"
- refute_predicate @dst/"a.txt", :exist?, "a.txt was installed but not renamed"
- refute_predicate @dst/"b.txt", :exist?, "b.txt was installed but not renamed"
- end
-
- def test_install_rename_directory
- bin = @src/"bin"
- bin.mkpath
- mv Dir[@src/"*.txt"], bin
- @dst.install bin => "libexec"
-
- refute_predicate @dst/"bin", :exist?, "bin was installed but not renamed"
- assert_predicate @dst/"libexec/a.txt", :exist?, "a.txt was not installed"
- assert_predicate @dst/"libexec/b.txt", :exist?, "b.txt was not installed"
- end
-
- def test_install_symlink
- bin = @src/"bin"
- bin.mkpath
- mv Dir[@src/"*.txt"], bin
- @dst.install_symlink bin
-
- assert_predicate @dst/"bin", :symlink?
- assert_predicate @dst/"bin", :directory?
- assert_predicate @dst/"bin/a.txt", :exist?
- assert_predicate @dst/"bin/b.txt", :exist?
- assert_predicate((@dst/"bin").readlink, :relative?)
- end
-
- def test_install_relative_symlink
- @dst.install_symlink "foo" => "bar"
- assert_equal Pathname.new("foo"), (@dst/"bar").readlink
- end
-
- def test_mkdir_creates_intermediate_directories
- mkdir @dst/"foo/bar/baz" do
- assert_predicate @dst/"foo/bar/baz", :exist?, "foo/bar/baz was not created"
- assert_predicate @dst/"foo/bar/baz", :directory?, "foo/bar/baz was not a directory structure"
- end
- end
-end | true |
Other | Homebrew | brew | e793e526611ca4cbc6d0155af8c596c4e826fc41.json | Revert "formula_versions: handle uncommitted formulae." | Library/Homebrew/formula_versions.rb | @@ -15,7 +15,6 @@ def initialize(formula, options = {})
@repository = formula.tap.path
@entry_name = @path.relative_path_from(repository).to_s
@max_depth = options[:max_depth]
- @current_formula = formula
end
def rev_list(branch)
@@ -65,33 +64,25 @@ def version_attributes_map(attributes, branch)
attributes.each do |attribute|
attributes_map[attribute] ||= {}
- # Set the attributes for the current formula in case it's not been
- # committed yet.
- set_attribute_map(attributes_map[attribute], @current_formula, attribute)
end
rev_list(branch) do |rev|
formula_at_revision(rev) do |f|
attributes.each do |attribute|
- set_attribute_map(attributes_map[attribute], f, attribute)
+ map = attributes_map[attribute]
+ if f.stable
+ map[:stable] ||= {}
+ map[:stable][f.stable.version] ||= []
+ map[:stable][f.stable.version] << f.send(attribute)
+ end
+ next unless f.devel
+ map[:devel] ||= {}
+ map[:devel][f.devel.version] ||= []
+ map[:devel][f.devel.version] << f.send(attribute)
end
end
end
attributes_map
end
-
- private
-
- def set_attribute_map(map, f, attribute)
- if f.stable
- map[:stable] ||= {}
- map[:stable][f.stable.version] ||= []
- map[:stable][f.stable.version] << f.send(attribute)
- end
- return unless f.devel
- map[:devel] ||= {}
- map[:devel][f.devel.version] ||= []
- map[:devel][f.devel.version] << f.send(attribute)
- end
end | false |
Other | Homebrew | brew | 7393485b7b2f15b84506d1c7f7d157db545aa18f.json | Convert `dependency_expansion` test to spec. | Library/Homebrew/test/dependency_expansion_spec.rb | @@ -0,0 +1,136 @@
+require "dependency"
+
+describe Dependency do
+ def build_dep(name, tags = [], deps = [])
+ dep = described_class.new(name.to_s, tags)
+ allow(dep).to receive(:to_formula).and_return(double(deps: deps, name: name))
+ dep
+ end
+
+ let(:foo) { build_dep(:foo) }
+ let(:bar) { build_dep(:bar) }
+ let(:baz) { build_dep(:baz) }
+ let(:qux) { build_dep(:qux) }
+ let(:deps) { [foo, bar, baz, qux] }
+ let(:formula) { double(deps: deps, name: "f") }
+
+ describe "::expand" do
+ it "yields dependent and dependency pairs" do
+ i = 0
+ described_class.expand(formula) do |dependent, dep|
+ expect(dependent).to eq(formula)
+ expect(deps[i]).to eq(dep)
+ i += 1
+ end
+ end
+
+ it "returns the dependencies" do
+ expect(described_class.expand(formula)).to eq(deps)
+ end
+
+ it "prunes all when given a block with ::prune" do
+ expect(described_class.expand(formula) { described_class.prune }).to be_empty
+ end
+
+ it "can prune selectively" do
+ deps = described_class.expand(formula) do |_, dep|
+ described_class.prune if dep.name == "foo"
+ end
+
+ expect(deps).to eq([bar, baz, qux])
+ end
+
+ it "preserves dependency order" do
+ allow(foo).to receive(:to_formula).and_return(double(name: "f", deps: [qux, baz]))
+ expect(described_class.expand(formula)).to eq([qux, baz, foo, bar])
+ end
+ end
+
+ it "skips optionals by default" do
+ deps = [build_dep(:foo, [:optional]), bar, baz, qux]
+ f = double(deps: deps, build: double(with?: false), name: "f")
+ expect(described_class.expand(f)).to eq([bar, baz, qux])
+ end
+
+ it "keeps recommended dependencies by default" do
+ deps = [build_dep(:foo, [:recommended]), bar, baz, qux]
+ f = double(deps: deps, build: double(with?: true), name: "f")
+ expect(described_class.expand(f)).to eq(deps)
+ end
+
+ it "merges repeated dependencies with differing options" do
+ foo2 = build_dep(:foo, ["option"])
+ baz2 = build_dep(:baz, ["option"])
+ deps << foo2 << baz2
+ deps = [foo2, bar, baz2, qux]
+ deps.zip(described_class.expand(formula)) do |expected, actual|
+ expect(expected.tags).to eq(actual.tags)
+ expect(expected).to eq(actual)
+ end
+ end
+
+ it "merges dependencies and perserves env_proc" do
+ env_proc = double
+ dep = described_class.new("foo", [], env_proc)
+ allow(dep).to receive(:to_formula).and_return(double(deps: [], name: "foo"))
+ deps.replace([dep])
+ expect(described_class.expand(formula).first.env_proc).to eq(env_proc)
+ end
+
+ it "merges tags without duplicating them" do
+ foo2 = build_dep(:foo, ["option"])
+ foo3 = build_dep(:foo, ["option"])
+ deps << foo2 << foo3
+
+ expect(described_class.expand(formula).first.tags).to eq(%w[option])
+ end
+
+ it "skips parent but yields children with ::skip" do
+ f = double(
+ name: "f",
+ deps: [
+ build_dep(:foo, [], [bar, baz]),
+ build_dep(:foo, [], [baz]),
+ ],
+ )
+
+ deps = described_class.expand(f) do |_dependent, dep|
+ described_class.skip if %w[foo qux].include? dep.name
+ end
+
+ expect(deps).to eq([bar, baz])
+ end
+
+ it "keeps dependency but prunes recursive dependencies with ::keep_but_prune_recursive_deps" do
+ foo = build_dep(:foo, [:build], bar)
+ baz = build_dep(:baz, [:build])
+ f = double(name: "f", deps: [foo, baz])
+
+ deps = described_class.expand(f) do |_dependent, dep|
+ described_class.keep_but_prune_recursive_deps if dep.build?
+ end
+
+ expect(deps).to eq([foo, baz])
+ end
+
+ it "returns only the dependencies given as a collection as second argument" do
+ expect(formula.deps).to eq([foo, bar, baz, qux])
+ expect(described_class.expand(formula, [bar, baz])).to eq([bar, baz])
+ end
+
+ it "doesn't raise an error when a dependency is cyclic" do
+ foo = build_dep(:foo)
+ bar = build_dep(:bar, [], [foo])
+ allow(foo).to receive(:to_formula).and_return(double(deps: [bar], name: foo.name))
+ f = double(name: "f", deps: [foo, bar])
+ expect { described_class.expand(f) }.not_to raise_error
+ end
+
+ it "cleans the expand stack" do
+ foo = build_dep(:foo)
+ allow(foo).to receive(:to_formula).and_raise(FormulaUnavailableError, foo.name)
+ f = double(name: "f", deps: [foo])
+ expect { described_class.expand(f) }.to raise_error(FormulaUnavailableError)
+ expect(described_class.instance_variable_get(:@expand_stack)).to be_empty
+ end
+end | true |
Other | Homebrew | brew | 7393485b7b2f15b84506d1c7f7d157db545aa18f.json | Convert `dependency_expansion` test to spec. | Library/Homebrew/test/dependency_expansion_test.rb | @@ -1,138 +0,0 @@
-require "testing_env"
-require "dependency"
-
-class DependencyExpansionTests < Homebrew::TestCase
- def build_dep(name, tags = [], deps = [])
- dep = Dependency.new(name.to_s, tags)
- dep.stubs(:to_formula).returns(stub(deps: deps, name: name))
- dep
- end
-
- def setup
- super
- @foo = build_dep(:foo)
- @bar = build_dep(:bar)
- @baz = build_dep(:baz)
- @qux = build_dep(:qux)
- @deps = [@foo, @bar, @baz, @qux]
- @f = stub(deps: @deps, name: "f")
- end
-
- def test_expand_yields_dependent_and_dep_pairs
- i = 0
- Dependency.expand(@f) do |dependent, dep|
- assert_equal @f, dependent
- assert_equal dep, @deps[i]
- i += 1
- end
- end
-
- def test_expand_no_block
- assert_equal @deps, Dependency.expand(@f)
- end
-
- def test_expand_prune_all
- assert_empty Dependency.expand(@f) { Dependency.prune }
- end
-
- def test_expand_selective_pruning
- deps = Dependency.expand(@f) do |_, dep|
- Dependency.prune if dep.name == "foo"
- end
-
- assert_equal [@bar, @baz, @qux], deps
- end
-
- def test_expand_preserves_dependency_order
- @foo.stubs(:to_formula).returns(stub(name: "f", deps: [@qux, @baz]))
- assert_equal [@qux, @baz, @foo, @bar], Dependency.expand(@f)
- end
-
- def test_expand_skips_optionals_by_default
- deps = [build_dep(:foo, [:optional]), @bar, @baz, @qux]
- f = stub(deps: deps, build: stub(with?: false), name: "f")
- assert_equal [@bar, @baz, @qux], Dependency.expand(f)
- end
-
- def test_expand_keeps_recommendeds_by_default
- deps = [build_dep(:foo, [:recommended]), @bar, @baz, @qux]
- f = stub(deps: deps, build: stub(with?: true), name: "f")
- assert_equal deps, Dependency.expand(f)
- end
-
- def test_merges_repeated_deps_with_differing_options
- @foo2 = build_dep(:foo, ["option"])
- @baz2 = build_dep(:baz, ["option"])
- @deps << @foo2 << @baz2
- deps = [@foo2, @bar, @baz2, @qux]
- deps.zip(Dependency.expand(@f)) do |expected, actual|
- assert_equal expected.tags, actual.tags
- assert_equal expected, actual
- end
- end
-
- def test_merger_preserves_env_proc
- env_proc = stub
- dep = Dependency.new("foo", [], env_proc)
- dep.stubs(:to_formula).returns(stub(deps: [], name: "foo"))
- @deps.replace [dep]
- assert_equal env_proc, Dependency.expand(@f).first.env_proc
- end
-
- def test_merged_tags_no_dupes
- @foo2 = build_dep(:foo, ["option"])
- @foo3 = build_dep(:foo, ["option"])
- @deps << @foo2 << @foo3
-
- assert_equal %w[option], Dependency.expand(@f).first.tags
- end
-
- def test_skip_skips_parent_but_yields_children
- f = stub(
- name: "f",
- deps: [
- build_dep(:foo, [], [@bar, @baz]),
- build_dep(:foo, [], [@baz]),
- ],
- )
-
- deps = Dependency.expand(f) do |_dependent, dep|
- Dependency.skip if %w[foo qux].include? dep.name
- end
-
- assert_equal [@bar, @baz], deps
- end
-
- def test_keep_dep_but_prune_recursive_deps
- foo = build_dep(:foo, [:build], @bar)
- baz = build_dep(:baz, [:build])
- f = stub(name: "f", deps: [foo, baz])
-
- deps = Dependency.expand(f) do |_dependent, dep|
- Dependency.keep_but_prune_recursive_deps if dep.build?
- end
-
- assert_equal [foo, baz], deps
- end
-
- def test_deps_with_collection_argument
- assert_equal [@foo, @bar, @baz, @qux], @f.deps
- assert_equal [@bar, @baz], Dependency.expand(@f, [@bar, @baz])
- end
-
- def test_cyclic_dependency
- foo = build_dep(:foo)
- bar = build_dep(:bar, [], [foo])
- foo.stubs(:to_formula).returns(stub(deps: [bar], name: "foo"))
- f = stub(name: "f", deps: [foo, bar])
- assert_nothing_raised { Dependency.expand(f) }
- end
-
- def test_clean_expand_stack
- foo = build_dep(:foo)
- foo.stubs(:to_formula).raises(FormulaUnavailableError, "foo")
- f = stub(name: "f", deps: [foo])
- assert_raises(FormulaUnavailableError) { Dependency.expand(f) }
- assert_empty Dependency.instance_variable_get(:@expand_stack)
- end
-end | true |
Other | Homebrew | brew | babc375372df635c023977de9f1279a7689e2453.json | Convert Resource test to spec. | Library/Homebrew/test/resource_spec.rb | @@ -0,0 +1,147 @@
+require "resource"
+
+describe Resource do
+ subject { described_class.new("test") }
+
+ describe "#url" do
+ it "sets the URL" do
+ subject.url("foo")
+ expect(subject.url).to eq("foo")
+ end
+
+ it "can set the URL with specifications" do
+ subject.url("foo", branch: "master")
+ expect(subject.url).to eq("foo")
+ expect(subject.specs).to eq(branch: "master")
+ end
+
+ it "can set the URL with a custom download strategy class" do
+ strategy = Class.new(AbstractDownloadStrategy)
+ subject.url("foo", using: strategy)
+ expect(subject.url).to eq("foo")
+ expect(subject.download_strategy).to eq(strategy)
+ end
+
+ it "can set the URL with specifications and a custom download strategy class" do
+ strategy = Class.new(AbstractDownloadStrategy)
+ subject.url("foo", using: strategy, branch: "master")
+ expect(subject.url).to eq("foo")
+ expect(subject.specs).to eq(branch: "master")
+ expect(subject.download_strategy).to eq(strategy)
+ end
+
+ it "can set the URL with a custom download strategy symbol" do
+ subject.url("foo", using: :git)
+ expect(subject.url).to eq("foo")
+ expect(subject.download_strategy).to eq(GitDownloadStrategy)
+ end
+
+ it "raises an error if the download strategy class is unkown" do
+ expect { subject.url("foo", using: Class.new) }.to raise_error(TypeError)
+ end
+
+ it "does not mutate the specifications hash" do
+ specs = { using: :git, branch: "master" }
+ subject.url("foo", specs)
+ expect(subject.specs).to eq(branch: "master")
+ expect(subject.using).to eq(:git)
+ expect(specs).to eq(using: :git, branch: "master")
+ end
+ end
+
+ describe "#version" do
+ it "sets the version" do
+ subject.version("1.0")
+ expect(subject.version).to eq(Version.parse("1.0"))
+ expect(subject.version).not_to be_detected_from_url
+ end
+
+ it "can detect the version from a URL" do
+ subject.url("http://example.com/foo-1.0.tar.gz")
+ expect(subject.version).to eq(Version.parse("1.0"))
+ expect(subject.version).to be_detected_from_url
+ end
+
+ it "can set the version with a scheme" do
+ klass = Class.new(Version)
+ subject.version klass.new("1.0")
+ expect(subject.version).to eq(Version.parse("1.0"))
+ expect(subject.version).to be_a(klass)
+ end
+
+ it "can set the version from a tag" do
+ subject.url("http://example.com/foo-1.0.tar.gz", tag: "v1.0.2")
+ expect(subject.version).to eq(Version.parse("1.0.2"))
+ expect(subject.version).to be_detected_from_url
+ end
+
+ it "rejects non-string versions" do
+ expect { subject.version(1) }.to raise_error(TypeError)
+ expect { subject.version(2.0) }.to raise_error(TypeError)
+ expect { subject.version(Object.new) }.to raise_error(TypeError)
+ end
+
+ it "returns nil if unset" do
+ expect(subject.version).to be nil
+ end
+ end
+
+ describe "#mirrors" do
+ it "is empty by defaults" do
+ expect(subject.mirrors).to be_empty
+ end
+
+ it "returns an array of mirrors added with #mirror" do
+ subject.mirror("foo")
+ subject.mirror("bar")
+ expect(subject.mirrors).to eq(%w[foo bar])
+ end
+ end
+
+ describe "#checksum" do
+ it "returns nil if unset" do
+ expect(subject.checksum).to be nil
+ end
+
+ it "returns the checksum set with #sha256" do
+ subject.sha256(TEST_SHA256)
+ expect(subject.checksum).to eq(Checksum.new(:sha256, TEST_SHA256))
+ end
+ end
+
+ describe "#download_strategy" do
+ it "returns the download strategy" do
+ strategy = Object.new
+ expect(DownloadStrategyDetector)
+ .to receive(:detect).with("foo", nil).and_return(strategy)
+ subject.url("foo")
+ expect(subject.download_strategy).to eq(strategy)
+ end
+ end
+
+ specify "#verify_download_integrity_missing" do
+ fn = Pathname.new("test")
+
+ allow(fn).to receive(:file?).and_return(true)
+ expect(fn).to receive(:verify_checksum).and_raise(ChecksumMissingError)
+ expect(fn).to receive(:sha256)
+
+ shutup do
+ subject.verify_download_integrity(fn)
+ end
+ end
+
+ specify "#verify_download_integrity_mismatch" do
+ fn = double(file?: true)
+ checksum = subject.sha256(TEST_SHA256)
+
+ expect(fn).to receive(:verify_checksum).with(checksum)
+ .and_raise(ChecksumMismatchError.new(fn, checksum, Object.new))
+
+ shutup do
+ expect {
+ subject.verify_download_integrity(fn)
+ }.to raise_error(ChecksumMismatchError)
+ end
+ end
+end | true |
Other | Homebrew | brew | babc375372df635c023977de9f1279a7689e2453.json | Convert Resource test to spec. | Library/Homebrew/test/resource_test.rb | @@ -1,133 +0,0 @@
-require "testing_env"
-require "resource"
-
-class ResourceTests < Homebrew::TestCase
- def setup
- super
- @resource = Resource.new("test")
- end
-
- def test_url
- @resource.url("foo")
- assert_equal "foo", @resource.url
- end
-
- def test_url_with_specs
- @resource.url("foo", branch: "master")
- assert_equal "foo", @resource.url
- assert_equal({ branch: "master" }, @resource.specs)
- end
-
- def test_url_with_custom_download_strategy_class
- strategy = Class.new(AbstractDownloadStrategy)
- @resource.url("foo", using: strategy)
- assert_equal "foo", @resource.url
- assert_equal strategy, @resource.download_strategy
- end
-
- def test_url_with_specs_and_download_strategy
- strategy = Class.new(AbstractDownloadStrategy)
- @resource.url("foo", using: strategy, branch: "master")
- assert_equal "foo", @resource.url
- assert_equal({ branch: "master" }, @resource.specs)
- assert_equal strategy, @resource.download_strategy
- end
-
- def test_url_with_custom_download_strategy_symbol
- @resource.url("foo", using: :git)
- assert_equal "foo", @resource.url
- assert_equal GitDownloadStrategy, @resource.download_strategy
- end
-
- def test_raises_for_unknown_download_strategy_class
- assert_raises(TypeError) { @resource.url("foo", using: Class.new) }
- end
-
- def test_does_not_mutate_specs_hash
- specs = { using: :git, branch: "master" }
- @resource.url("foo", specs)
- assert_equal({ branch: "master" }, @resource.specs)
- assert_equal(:git, @resource.using)
- assert_equal({ using: :git, branch: "master" }, specs)
- end
-
- def test_version
- @resource.version("1.0")
- assert_version_equal "1.0", @resource.version
- refute_predicate @resource.version, :detected_from_url?
- end
-
- def test_version_from_url
- @resource.url("http://example.com/foo-1.0.tar.gz")
- assert_version_equal "1.0", @resource.version
- assert_predicate @resource.version, :detected_from_url?
- end
-
- def test_version_with_scheme
- klass = Class.new(Version)
- @resource.version klass.new("1.0")
- assert_version_equal "1.0", @resource.version
- assert_instance_of klass, @resource.version
- end
-
- def test_version_from_tag
- @resource.url("http://example.com/foo-1.0.tar.gz", tag: "v1.0.2")
- assert_version_equal "1.0.2", @resource.version
- assert_predicate @resource.version, :detected_from_url?
- end
-
- def test_rejects_non_string_versions
- assert_raises(TypeError) { @resource.version(1) }
- assert_raises(TypeError) { @resource.version(2.0) }
- assert_raises(TypeError) { @resource.version(Object.new) }
- end
-
- def test_version_when_url_is_not_set
- assert_nil @resource.version
- end
-
- def test_mirrors
- assert_empty @resource.mirrors
- @resource.mirror("foo")
- @resource.mirror("bar")
- assert_equal %w[foo bar], @resource.mirrors
- end
-
- def test_checksum_setters
- assert_nil @resource.checksum
- @resource.sha256(TEST_SHA256)
- assert_equal Checksum.new(:sha256, TEST_SHA256), @resource.checksum
- end
-
- def test_download_strategy
- strategy = Object.new
- DownloadStrategyDetector
- .expects(:detect).with("foo", nil).returns(strategy)
- @resource.url("foo")
- assert_equal strategy, @resource.download_strategy
- end
-
- def test_verify_download_integrity_missing
- fn = Pathname.new("test")
-
- fn.stubs(file?: true)
- fn.expects(:verify_checksum).raises(ChecksumMissingError)
- fn.expects(:sha256)
-
- shutup { @resource.verify_download_integrity(fn) }
- end
-
- def test_verify_download_integrity_mismatch
- fn = stub(file?: true)
- checksum = @resource.sha256(TEST_SHA256)
-
- fn.expects(:verify_checksum).with(checksum)
- .raises(ChecksumMismatchError.new(fn, checksum, Object.new))
-
- shutup do
- assert_raises(ChecksumMismatchError) do
- @resource.verify_download_integrity(fn)
- end
- end
- end
-end | true |
Other | Homebrew | brew | f7151e589fec5cd8caef00798c02e0c54eff5419.json | Convert JavaRequirement test to spec. | Library/Homebrew/test/java_requirement_spec.rb | @@ -0,0 +1,107 @@
+require "requirements/java_requirement"
+
+describe JavaRequirement do
+ subject { described_class.new([]) }
+
+ before(:each) do
+ ENV["JAVA_HOME"] = nil
+ end
+
+ describe "#message" do
+ its(:message) { is_expected.to match(/Java is required to install this formula./) }
+ end
+
+ describe "#inspect" do
+ subject { described_class.new(%w[1.7+]) }
+ its(:inspect) { is_expected.to eq('#<JavaRequirement: "java" [] version="1.7+">') }
+ end
+
+ describe "#display_s" do
+ context "without specific version" do
+ its(:display_s) { is_expected.to eq("java") }
+ end
+
+ context "with version 1.8" do
+ subject { described_class.new(%w[1.8]) }
+ its(:display_s) { is_expected.to eq("java = 1.8") }
+ end
+
+ context "with version 1.8+" do
+ subject { described_class.new(%w[1.8+]) }
+ its(:display_s) { is_expected.to eq("java >= 1.8") }
+ end
+ end
+
+ describe "#satisfied?" do
+ subject { described_class.new(%w[1.8]) }
+
+ it "returns false if no `java` executable can be found" do
+ allow(File).to receive(:executable?).and_return(false)
+ expect(subject).not_to be_satisfied
+ end
+
+ it "returns true if #preferred_java returns a path" do
+ allow(subject).to receive(:preferred_java).and_return(Pathname.new("/usr/bin/java"))
+ expect(subject).to be_satisfied
+ end
+
+ context "when #possible_javas contains paths" do
+ let(:path) { Pathname.new(Dir.mktmpdir) }
+ let(:java) { path/"java" }
+
+ def setup_java_with_version(version)
+ IO.write java, <<-EOS.undent
+ #!/bin/sh
+ echo 'java version "#{version}"'
+ EOS
+ FileUtils.chmod "+x", java
+ end
+
+ before(:each) do
+ allow(subject).to receive(:possible_javas).and_return([java])
+ end
+
+ after(:each) do
+ path.rmtree
+ end
+
+ context "and 1.7 is required" do
+ subject { described_class.new(%w[1.7]) }
+
+ it "returns false if all are lower" do
+ setup_java_with_version "1.6.0_5"
+ expect(subject).not_to be_satisfied
+ end
+
+ it "returns true if one is equal" do
+ setup_java_with_version "1.7.0_5"
+ expect(subject).to be_satisfied
+ end
+
+ it "returns false if all are higher" do
+ setup_java_with_version "1.8.0_5"
+ expect(subject).not_to be_satisfied
+ end
+ end
+
+ context "and 1.7+ is required" do
+ subject { described_class.new(%w[1.7+]) }
+
+ it "returns false if all are lower" do
+ setup_java_with_version "1.6.0_5"
+ expect(subject).not_to be_satisfied
+ end
+
+ it "returns true if one is equal" do
+ setup_java_with_version "1.7.0_5"
+ expect(subject).to be_satisfied
+ end
+
+ it "returns true if one is higher" do
+ setup_java_with_version "1.8.0_5"
+ expect(subject).to be_satisfied
+ end
+ end
+ end
+ end
+end | true |
Other | Homebrew | brew | f7151e589fec5cd8caef00798c02e0c54eff5419.json | Convert JavaRequirement test to spec. | Library/Homebrew/test/java_requirement_test.rb | @@ -1,50 +0,0 @@
-require "testing_env"
-require "requirements/java_requirement"
-
-class JavaRequirementTests < Homebrew::TestCase
- def setup
- super
- ENV["JAVA_HOME"] = nil
- end
-
- def test_message
- a = JavaRequirement.new([])
- assert_match(/Java is required to install this formula./, a.message)
- end
-
- def test_inspect
- a = JavaRequirement.new(%w[1.7+])
- assert_equal a.inspect, '#<JavaRequirement: "java" [] version="1.7+">'
- end
-
- def test_display_s
- x = JavaRequirement.new([])
- assert_equal x.display_s, "java"
- y = JavaRequirement.new(%w[1.8])
- assert_equal y.display_s, "java = 1.8"
- z = JavaRequirement.new(%w[1.8+])
- assert_equal z.display_s, "java >= 1.8"
- end
-
- def test_satisfied?
- a = JavaRequirement.new(%w[1.8])
- File.stubs(:executable?).returns(false)
- refute_predicate a, :satisfied?
-
- b = JavaRequirement.new([])
- b.stubs(:preferred_java).returns(Pathname.new("/usr/bin/java"))
- assert_predicate b, :satisfied?
-
- c = JavaRequirement.new(%w[1.7+])
- c.stubs(:possible_javas).returns([Pathname.new("/usr/bin/java")])
- Utils.stubs(:popen_read).returns('java version "1.6.0_5"')
- refute_predicate c, :satisfied?
- Utils.stubs(:popen_read).returns('java version "1.8.0_5"')
- assert_predicate c, :satisfied?
-
- d = JavaRequirement.new(%w[1.7])
- d.stubs(:possible_javas).returns([Pathname.new("/usr/bin/java")])
- Utils.stubs(:popen_read).returns('java version "1.8.0_5"')
- refute_predicate d, :satisfied?
- end
-end | true |
Other | Homebrew | brew | 69f361089c8c4793b9aad532c13331a1f09ff92a.json | Convert Migrator test to spec. | Library/Homebrew/test/migrator_spec.rb | @@ -0,0 +1,264 @@
+require "migrator"
+require "test/support/fixtures/testball"
+require "tab"
+require "keg"
+
+describe Migrator do
+ subject { described_class.new(new_formula) }
+
+ let(:new_formula) { Testball.new("newname") }
+ let(:old_formula) { Testball.new("oldname") }
+
+ let(:new_keg_record) { HOMEBREW_CELLAR/"newname/0.1" }
+ let(:old_keg_record) { HOMEBREW_CELLAR/"oldname/0.1" }
+
+ let(:old_tab) { Tab.empty }
+
+ let(:keg) { Keg.new(old_keg_record) }
+ let(:old_pin) { HOMEBREW_PINNED_KEGS/"oldname" }
+
+ before(:each) do |example|
+ allow(new_formula).to receive(:oldname).and_return("oldname")
+
+ # do not create directories for error tests
+ next if example.metadata[:description].start_with?("raises an error")
+
+ (old_keg_record/"bin").mkpath
+
+ %w[inside bindir].each do |file|
+ FileUtils.touch old_keg_record/"bin/#{file}"
+ end
+
+ old_tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
+ old_tab.source["path"] = "/oldname"
+ old_tab.write
+
+ keg.link
+ keg.optlink
+
+ old_pin.make_relative_symlink old_keg_record
+
+ subject # needs to be evaluated eagerly
+
+ (HOMEBREW_PREFIX/"bin").mkpath
+ end
+
+ after(:each) do
+ if !old_keg_record.parent.symlink? && old_keg_record.directory?
+ keg.unlink
+ end
+
+ if new_keg_record.directory?
+ new_keg = Keg.new(new_keg_record)
+ new_keg.unlink
+ end
+ end
+
+ describe "::new" do
+ it "raises an error if there is no old name" do
+ expect {
+ described_class.new(old_formula)
+ }.to raise_error(Migrator::MigratorNoOldnameError)
+ end
+
+ it "raises an error if there is no old path" do
+ expect {
+ described_class.new(new_formula)
+ }.to raise_error(Migrator::MigratorNoOldpathError)
+ end
+
+ it "raises an error if the Taps differ" do
+ keg = HOMEBREW_CELLAR/"oldname/0.1"
+ keg.mkpath
+ tab = Tab.empty
+ tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
+ tab.source["tap"] = "homebrew/core"
+ tab.write
+
+ expect {
+ described_class.new(new_formula)
+ }.to raise_error(Migrator::MigratorDifferentTapsError)
+ end
+ end
+
+ specify "#move_to_new_directory" do
+ keg.unlink
+ shutup do
+ subject.move_to_new_directory
+ end
+
+ expect(new_keg_record).to be_a_directory
+ expect(new_keg_record/"bin").to be_a_directory
+ expect(new_keg_record/"bin/inside").to be_a_file
+ expect(new_keg_record/"bin/bindir").to be_a_file
+ expect(old_keg_record).not_to be_a_directory
+ end
+
+ specify "#backup_oldname_cellar" do
+ old_keg_record.parent.rmtree
+ (new_keg_record/"bin").mkpath
+
+ subject.backup_oldname_cellar
+
+ expect(old_keg_record/"bin").to be_a_directory
+ expect(old_keg_record/"bin").to be_a_directory
+ end
+
+ specify "#repin" do
+ (new_keg_record/"bin").mkpath
+ expected_relative = new_keg_record.relative_path_from HOMEBREW_PINNED_KEGS
+
+ subject.repin
+
+ expect(subject.new_pin_record).to be_a_symlink
+ expect(subject.new_pin_record.readlink).to eq(expected_relative)
+ expect(subject.old_pin_record).not_to exist
+ end
+
+ specify "#unlink_oldname" do
+ expect(HOMEBREW_LINKED_KEGS.children.count).to eq(1)
+ expect((HOMEBREW_PREFIX/"opt").children.count).to eq(1)
+
+ shutup do
+ subject.unlink_oldname
+ end
+
+ expect(HOMEBREW_LINKED_KEGS).not_to exist
+ expect(HOMEBREW_LIBRARY/"bin").not_to exist
+ end
+
+ specify "#link_newname" do
+ keg.unlink
+ keg.uninstall
+
+ (new_keg_record/"bin").mkpath
+ %w[inside bindir].each do |file|
+ FileUtils.touch new_keg_record/"bin"/file
+ end
+
+ shutup do
+ subject.link_newname
+ end
+
+ expect(HOMEBREW_LINKED_KEGS.children.count).to eq(1)
+ expect((HOMEBREW_PREFIX/"opt").children.count).to eq(1)
+ end
+
+ specify "#link_oldname_opt" do
+ new_keg_record.mkpath
+ subject.link_oldname_opt
+ expect((HOMEBREW_PREFIX/"opt/oldname").realpath).to eq(new_keg_record.realpath)
+ end
+
+ specify "#link_oldname_cellar" do
+ (new_keg_record/"bin").mkpath
+ keg.unlink
+ keg.uninstall
+ subject.link_oldname_cellar
+ expect((HOMEBREW_CELLAR/"oldname").realpath).to eq(new_keg_record.parent.realpath)
+ end
+
+ specify "#update_tabs" do
+ (new_keg_record/"bin").mkpath
+ tab = Tab.empty
+ tab.tabfile = HOMEBREW_CELLAR/"newname/0.1/INSTALL_RECEIPT.json"
+ tab.source["path"] = "/path/that/must/be/changed/by/update_tabs"
+ tab.write
+ subject.update_tabs
+ expect(Tab.for_keg(new_keg_record).source["path"]).to eq(new_formula.path.to_s)
+ end
+
+ specify "#migrate" do
+ tab = Tab.empty
+ tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
+ tab.source["path"] = old_formula.path.to_s
+ tab.write
+
+ shutup do
+ subject.migrate
+ end
+
+ expect(new_keg_record).to exist
+ expect(old_keg_record.parent).to be_a_symlink
+ expect(HOMEBREW_LINKED_KEGS/"oldname").not_to exist
+ expect((HOMEBREW_LINKED_KEGS/"newname").realpath).to eq(new_keg_record.realpath)
+ expect(old_keg_record.realpath).to eq(new_keg_record.realpath)
+ expect((HOMEBREW_PREFIX/"opt/oldname").realpath).to eq(new_keg_record.realpath)
+ expect((HOMEBREW_CELLAR/"oldname").realpath).to eq(new_keg_record.parent.realpath)
+ expect((HOMEBREW_PINNED_KEGS/"newname").realpath).to eq(new_keg_record.realpath)
+ expect(Tab.for_keg(new_keg_record).source["path"]).to eq(new_formula.path.to_s)
+ end
+
+ specify "#unlinik_oldname_opt" do
+ new_keg_record.mkpath
+ old_opt_record = HOMEBREW_PREFIX/"opt/oldname"
+ old_opt_record.unlink if old_opt_record.symlink?
+ old_opt_record.make_relative_symlink(new_keg_record)
+ subject.unlink_oldname_opt
+ expect(old_opt_record).not_to be_a_symlink
+ end
+
+ specify "#unlink_oldname_cellar" do
+ new_keg_record.mkpath
+ keg.unlink
+ keg.uninstall
+ old_keg_record.parent.make_relative_symlink(new_keg_record.parent)
+ subject.unlink_oldname_cellar
+ expect(old_keg_record.parent).not_to be_a_symlink
+ end
+
+ specify "#backup_oldname_cellar" do
+ (new_keg_record/"bin").mkpath
+ keg.unlink
+ keg.uninstall
+ subject.backup_oldname_cellar
+ expect(old_keg_record.subdirs).not_to be_empty
+ end
+
+ specify "#backup_old_tabs" do
+ tab = Tab.empty
+ tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
+ tab.source["path"] = "/should/be/the/same"
+ tab.write
+ migrator = Migrator.new(new_formula)
+ tab.tabfile.delete
+ migrator.backup_old_tabs
+ expect(Tab.for_keg(old_keg_record).source["path"]).to eq("/should/be/the/same")
+ end
+
+ describe "#backup_oldname" do
+ after(:each) do
+ expect(old_keg_record.parent).to be_a_directory
+ expect(old_keg_record.parent.subdirs).not_to be_empty
+ expect(HOMEBREW_LINKED_KEGS/"oldname").to exist
+ expect(HOMEBREW_PREFIX/"opt/oldname").to exist
+ expect(HOMEBREW_PINNED_KEGS/"oldname").to be_a_symlink
+ expect(keg).to be_linked
+ end
+
+ context "when cellar exists" do
+ it "backs up the old name" do
+ subject.backup_oldname
+ end
+ end
+
+ context "when cellar is removed" do
+ it "backs up the old name" do
+ (new_keg_record/"bin").mkpath
+ keg.unlink
+ keg.uninstall
+ subject.backup_oldname
+ end
+ end
+
+ context "when cellar is linked" do
+ it "backs up the old name" do
+ (new_keg_record/"bin").mkpath
+ keg.unlink
+ keg.uninstall
+ old_keg_record.parent.make_relative_symlink(new_keg_record.parent)
+ subject.backup_oldname
+ end
+ end
+ end
+end | true |
Other | Homebrew | brew | 69f361089c8c4793b9aad532c13331a1f09ff92a.json | Convert Migrator test to spec. | Library/Homebrew/test/migrator_test.rb | @@ -1,251 +0,0 @@
-require "testing_env"
-require "migrator"
-require "test/support/fixtures/testball"
-require "tab"
-require "keg"
-
-class Formula
- attr_writer :oldname
-end
-
-class MigratorErrorsTests < Homebrew::TestCase
- def setup
- super
- @new_f = Testball.new("newname")
- @new_f.oldname = "oldname"
- @old_f = Testball.new("oldname")
- end
-
- def test_no_oldname
- assert_raises(Migrator::MigratorNoOldnameError) { Migrator.new(@old_f) }
- end
-
- def test_no_oldpath
- assert_raises(Migrator::MigratorNoOldpathError) { Migrator.new(@new_f) }
- end
-
- def test_different_taps
- keg = HOMEBREW_CELLAR/"oldname/0.1"
- keg.mkpath
- tab = Tab.empty
- tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
- tab.source["tap"] = "homebrew/core"
- tab.write
- assert_raises(Migrator::MigratorDifferentTapsError) { Migrator.new(@new_f) }
- end
-end
-
-class MigratorTests < Homebrew::TestCase
- include FileUtils
-
- def setup
- super
-
- @new_f = Testball.new("newname")
- @new_f.oldname = "oldname"
-
- @old_f = Testball.new("oldname")
-
- @old_keg_record = HOMEBREW_CELLAR/"oldname/0.1"
- @old_keg_record.join("bin").mkpath
- @new_keg_record = HOMEBREW_CELLAR/"newname/0.1"
-
- %w[inside bindir].each { |file| touch @old_keg_record.join("bin", file) }
-
- @old_tab = Tab.empty
- @old_tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
- @old_tab.source["path"] = "/oldname"
- @old_tab.write
-
- @keg = Keg.new(@old_keg_record)
- @keg.link
- @keg.optlink
-
- @old_pin = HOMEBREW_PINNED_KEGS/"oldname"
- @old_pin.make_relative_symlink @old_keg_record
-
- @migrator = Migrator.new(@new_f)
-
- mkpath HOMEBREW_PREFIX/"bin"
- end
-
- def teardown
- if !@old_keg_record.parent.symlink? && @old_keg_record.directory?
- @keg.unlink
- end
-
- if @new_keg_record.directory?
- new_keg = Keg.new(@new_keg_record)
- new_keg.unlink
- end
-
- super
- end
-
- def test_move_cellar
- @keg.unlink
- shutup { @migrator.move_to_new_directory }
- assert_predicate @new_keg_record, :directory?
- assert_predicate @new_keg_record/"bin", :directory?
- assert_predicate @new_keg_record/"bin/inside", :file?
- assert_predicate @new_keg_record/"bin/bindir", :file?
- refute_predicate @old_keg_record, :directory?
- end
-
- def test_backup_cellar
- @old_keg_record.parent.rmtree
- @new_keg_record.join("bin").mkpath
-
- @migrator.backup_oldname_cellar
-
- assert_predicate @old_keg_record, :directory?
- assert_predicate @old_keg_record/"bin", :directory?
- end
-
- def test_repin
- @new_keg_record.join("bin").mkpath
- expected_relative = @new_keg_record.relative_path_from HOMEBREW_PINNED_KEGS
-
- @migrator.repin
-
- assert_predicate @migrator.new_pin_record, :symlink?
- assert_equal expected_relative, @migrator.new_pin_record.readlink
- refute_predicate @migrator.old_pin_record, :exist?
- end
-
- def test_unlink_oldname
- assert_equal 1, HOMEBREW_LINKED_KEGS.children.size
- assert_equal 1, (HOMEBREW_PREFIX/"opt").children.size
-
- shutup { @migrator.unlink_oldname }
-
- refute_predicate HOMEBREW_LINKED_KEGS, :exist?
- refute_predicate HOMEBREW_LIBRARY/"bin", :exist?
- end
-
- def test_link_newname
- @keg.unlink
- @keg.uninstall
- @new_keg_record.join("bin").mkpath
- %w[inside bindir].each { |file| touch @new_keg_record.join("bin", file) }
-
- shutup { @migrator.link_newname }
-
- assert_equal 1, HOMEBREW_LINKED_KEGS.children.size
- assert_equal 1, (HOMEBREW_PREFIX/"opt").children.size
- end
-
- def test_link_oldname_opt
- @new_keg_record.mkpath
- @migrator.link_oldname_opt
- assert_equal @new_keg_record.realpath, (HOMEBREW_PREFIX/"opt/oldname").realpath
- end
-
- def test_link_oldname_cellar
- @new_keg_record.join("bin").mkpath
- @keg.unlink
- @keg.uninstall
- @migrator.link_oldname_cellar
- assert_equal @new_keg_record.parent.realpath, (HOMEBREW_CELLAR/"oldname").realpath
- end
-
- def test_update_tabs
- @new_keg_record.join("bin").mkpath
- tab = Tab.empty
- tab.tabfile = HOMEBREW_CELLAR/"newname/0.1/INSTALL_RECEIPT.json"
- tab.source["path"] = "/path/that/must/be/changed/by/update_tabs"
- tab.write
- @migrator.update_tabs
- assert_equal @new_f.path.to_s, Tab.for_keg(@new_keg_record).source["path"]
- end
-
- def test_migrate
- tab = Tab.empty
- tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
- tab.source["path"] = @old_f.path.to_s
- tab.write
-
- shutup { @migrator.migrate }
-
- assert_predicate @new_keg_record, :exist?
- assert_predicate @old_keg_record.parent, :symlink?
- refute_predicate HOMEBREW_LINKED_KEGS/"oldname", :exist?
- assert_equal @new_keg_record.realpath, (HOMEBREW_LINKED_KEGS/"newname").realpath
- assert_equal @new_keg_record.realpath, @old_keg_record.realpath
- assert_equal @new_keg_record.realpath, (HOMEBREW_PREFIX/"opt/oldname").realpath
- assert_equal @new_keg_record.parent.realpath, (HOMEBREW_CELLAR/"oldname").realpath
- assert_equal @new_keg_record.realpath, (HOMEBREW_PINNED_KEGS/"newname").realpath
- assert_equal @new_f.path.to_s, Tab.for_keg(@new_keg_record).source["path"]
- end
-
- def test_unlinik_oldname_opt
- @new_keg_record.mkpath
- old_opt_record = HOMEBREW_PREFIX/"opt/oldname"
- old_opt_record.unlink if old_opt_record.symlink?
- old_opt_record.make_relative_symlink(@new_keg_record)
- @migrator.unlink_oldname_opt
- refute_predicate old_opt_record, :symlink?
- end
-
- def test_unlink_oldname_cellar
- @new_keg_record.mkpath
- @keg.unlink
- @keg.uninstall
- @old_keg_record.parent.make_relative_symlink(@new_keg_record.parent)
- @migrator.unlink_oldname_cellar
- refute_predicate @old_keg_record.parent, :symlink?
- end
-
- def test_backup_oldname_cellar
- @new_keg_record.join("bin").mkpath
- @keg.unlink
- @keg.uninstall
- @migrator.backup_oldname_cellar
- refute_predicate @old_keg_record.subdirs, :empty?
- end
-
- def test_backup_old_tabs
- tab = Tab.empty
- tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
- tab.source["path"] = "/should/be/the/same"
- tab.write
- migrator = Migrator.new(@new_f)
- tab.tabfile.delete
- migrator.backup_old_tabs
- assert_equal "/should/be/the/same", Tab.for_keg(@old_keg_record).source["path"]
- end
-
- # Backup tests are divided into three groups: when oldname Cellar is deleted
- # and when it still exists and when it's a symlink
-
- def check_after_backup
- assert_predicate @old_keg_record.parent, :directory?
- refute_predicate @old_keg_record.parent.subdirs, :empty?
- assert_predicate HOMEBREW_LINKED_KEGS/"oldname", :exist?
- assert_predicate HOMEBREW_PREFIX/"opt/oldname", :exist?
- assert_predicate HOMEBREW_PINNED_KEGS/"oldname", :symlink?
- assert_predicate @keg, :linked?
- end
-
- def test_backup_cellar_exist
- @migrator.backup_oldname
- check_after_backup
- end
-
- def test_backup_cellar_removed
- @new_keg_record.join("bin").mkpath
- @keg.unlink
- @keg.uninstall
- @migrator.backup_oldname
- check_after_backup
- end
-
- def test_backup_cellar_linked
- @new_keg_record.join("bin").mkpath
- @keg.unlink
- @keg.uninstall
- @old_keg_record.parent.make_relative_symlink(@new_keg_record.parent)
- @migrator.backup_oldname
- check_after_backup
- end
-end | true |
Other | Homebrew | brew | 42bb19a6317172804cd149024115f6973fa2fd4f.json | formula_installer: detect recursive dependencies.
Detect recursive dependencies and refuse to install them providing
instruction on exactly what is depending on what.
Fixes #1933. | Library/Homebrew/formula_installer.rb | @@ -151,6 +151,28 @@ def check_install_sanity
recursive_deps = formula.recursive_dependencies
recursive_formulae = recursive_deps.map(&:to_formula)
+ recursive_dependencies = []
+ recursive_formulae.each do |dep|
+ dep_recursive_dependencies = dep.recursive_dependencies.map(&:to_s)
+ if dep_recursive_dependencies.include?(formula.name)
+ recursive_dependencies << "#{formula.full_name} depends on #{dep.full_name}"
+ recursive_dependencies << "#{dep.full_name} depends on #{formula.full_name}"
+ end
+ end
+
+ unless recursive_dependencies.empty?
+ raise CannotInstallFormulaError, <<-EOS.undent
+ #{formula.full_name} contains a recursive dependency on itself:
+ #{recursive_dependencies.join("\n ")}
+ EOS
+ end
+
+ if recursive_formulae.flat_map(&:recursive_dependencies).map(&:to_s).include?(formula.name)
+ raise CannotInstallFormulaError, <<-EOS.undent
+ #{formula.full_name} contains a recursive dependency on itself!
+ EOS
+ end
+
if ENV["HOMEBREW_CHECK_RECURSIVE_VERSION_DEPENDENCIES"]
version_hash = {}
version_conflicts = Set.new | false |
Other | Homebrew | brew | 8bb46baebbc0694130b86483705bfef2c159704e.json | Add RSpec support for integration commands. | Library/Homebrew/test/spec_helper.rb | @@ -16,6 +16,7 @@
require "test/support/helper/shutup"
require "test/support/helper/fixtures"
+require "test/support/helper/spec/shared_context/integration_test"
TEST_DIRECTORIES = [
CoreTap.instance.path/"Formula", | true |
Other | Homebrew | brew | 8bb46baebbc0694130b86483705bfef2c159704e.json | Add RSpec support for integration commands. | Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb | @@ -0,0 +1,94 @@
+require "rspec"
+require "open3"
+
+RSpec::Matchers.define_negated_matcher :not_to_output, :output
+RSpec::Matchers.define_negated_matcher :be_a_failure, :be_a_success
+
+RSpec.shared_context "integration test" do
+ extend RSpec::Matchers::DSL
+
+ matcher :be_a_success do
+ match do |actual|
+ status = actual.is_a?(Proc) ? actual.call : actual
+ status.respond_to?(:success?) && status.success?
+ end
+
+ def supports_block_expectations?
+ true
+ end
+
+ # It needs to be nested like this:
+ #
+ # expect {
+ # expect {
+ # # command
+ # }.to be_a_success
+ # }.to output(something).to_stdout
+ #
+ # rather than this:
+ #
+ # expect {
+ # expect {
+ # # command
+ # }.to output(something).to_stdout
+ # }.to be_a_success
+ #
+ def expects_call_stack_jump?
+ true
+ end
+ end
+
+ before(:each) do
+ (HOMEBREW_PREFIX/"bin").mkpath
+ FileUtils.touch HOMEBREW_PREFIX/"bin/brew"
+ end
+
+ after(:each) do
+ FileUtils.rm HOMEBREW_PREFIX/"bin/brew"
+ FileUtils.rmdir HOMEBREW_PREFIX/"bin"
+ end
+
+ # Generate unique ID to be able to
+ # properly merge coverage results.
+ def command_id_from_args(args)
+ @command_count ||= 0
+ pretty_args = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@")
+ file_and_line = caller[1].sub(/(.*\d+):.*/, '\1')
+ .sub("#{HOMEBREW_LIBRARY_PATH}/test/", "")
+ "#{file_and_line}:brew #{pretty_args}:#{@command_count += 1}"
+ end
+
+ # Runs a `brew` command with the test configuration
+ # and with coverage reporting enabled.
+ def brew(*args)
+ env = args.last.is_a?(Hash) ? args.pop : {}
+
+ env.merge!(
+ "HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew",
+ "HOMEBREW_INTEGRATION_TEST" => command_id_from_args(args),
+ "HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR,
+ "HOMEBREW_DEVELOPER" => ENV["HOMEBREW_DEVELOPER"],
+ )
+
+ ruby_args = [
+ "-W0",
+ "-I", "#{HOMEBREW_LIBRARY_PATH}/test/support/lib",
+ "-I", HOMEBREW_LIBRARY_PATH.to_s,
+ "-rconfig"
+ ]
+ ruby_args << "-rsimplecov" if ENV["HOMEBREW_TESTS_COVERAGE"]
+ ruby_args << "-rtest/support/helper/integration_mocks"
+ ruby_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s
+
+ Bundler.with_original_env do
+ stdout, stderr, status = Open3.capture3(env, RUBY_PATH, *ruby_args, *args)
+ $stdout.print stdout
+ $stderr.print stderr
+ status
+ end
+ end
+end
+
+RSpec.configure do |config|
+ config.include_context "integration test", :integration_test
+end | true |
Other | Homebrew | brew | 22042797d3111316e977eeee6f70439ae41448f6.json | Convert FormulaLock test to spec. | Library/Homebrew/test/formula_lock_spec.rb | @@ -0,0 +1,34 @@
+require "formula_lock"
+
+describe FormulaLock do
+ subject { described_class.new("foo") }
+
+ describe "#lock" do
+ it "does not raise an error when already locked" do
+ subject.lock
+
+ expect { subject.lock }.not_to raise_error
+ end
+
+ it "raises an error if a lock already exists" do
+ subject.lock
+
+ expect {
+ described_class.new("foo").lock
+ }.to raise_error(OperationInProgressError)
+ end
+ end
+
+ describe "#unlock" do
+ it "does not raise an error when already unlocked" do
+ expect { subject.unlock }.not_to raise_error
+ end
+
+ it "unlocks a locked Formula" do
+ subject.lock
+ subject.unlock
+
+ expect { described_class.new("foo").lock }.not_to raise_error
+ end
+ end
+end | true |
Other | Homebrew | brew | 22042797d3111316e977eeee6f70439ae41448f6.json | Convert FormulaLock test to spec. | Library/Homebrew/test/formula_lock_test.rb | @@ -1,23 +0,0 @@
-require "testing_env"
-require "formula_lock"
-
-class FormulaLockTests < Homebrew::TestCase
- def setup
- super
- @lock = FormulaLock.new("foo")
- @lock.lock
- end
-
- def teardown
- @lock.unlock
- super
- end
-
- def test_locking_file_with_existing_lock_raises_error
- assert_raises(OperationInProgressError) { FormulaLock.new("foo").lock }
- end
-
- def test_locking_existing_lock_suceeds
- assert_nothing_raised { @lock.lock }
- end
-end | true |
Other | Homebrew | brew | df7ae5eb26a9552ff61c66ed5680c701bf0be7df.json | Use the env block | Library/Homebrew/requirements/ruby_requirement.rb | @@ -8,11 +8,10 @@ def initialize(tags)
super
end
- satisfy build_env: false do
- found_ruby = rubies.detect { |ruby| suitable?(ruby) }
- return unless found_ruby
- ENV.prepend_path "PATH", found_ruby.dirname
- found_ruby
+ satisfy build_env: false { suitable_ruby }
+
+ env do
+ ENV.prepend_path "PATH", suitable_ruby
end
def message
@@ -35,6 +34,10 @@ def display_s
private
+ def suitable_ruby
+ rubies.detect { |ruby| suitable?(ruby) }
+ end
+
def rubies
rubies = which_all("ruby")
if ruby_formula.installed? | false |
Other | Homebrew | brew | 423f22df0033f83a04a9452d2e755a96e830b039.json | Convert `search_remote_tap` test to spec. | Library/Homebrew/test/cmd/search_remote_tap_spec.rb | @@ -0,0 +1,19 @@
+require "cmd/search"
+
+describe Homebrew do
+ specify "#search_tap" do
+ json_response = {
+ "tree" => [
+ {
+ "path" => "Formula/not-a-formula.rb",
+ "type" => "blob",
+ },
+ ],
+ }
+
+ allow(GitHub).to receive(:open).and_yield(json_response)
+
+ expect(described_class.search_tap("homebrew", "not-a-tap", "not-a-formula"))
+ .to eq(["homebrew/not-a-tap/not-a-formula"])
+ end
+end | true |
Other | Homebrew | brew | 423f22df0033f83a04a9452d2e755a96e830b039.json | Convert `search_remote_tap` test to spec. | Library/Homebrew/test/search_remote_tap_test.rb | @@ -1,19 +0,0 @@
-require "testing_env"
-require "cmd/search"
-
-class SearchRemoteTapTests < Homebrew::TestCase
- def test_search_remote_tap
- json_response = {
- "tree" => [
- {
- "path" => "Formula/not-a-formula.rb",
- "type" => "blob",
- },
- ],
- }
-
- GitHub.stubs(:open).yields(json_response)
-
- assert_equal ["homebrew/not-a-tap/not-a-formula"], Homebrew.search_tap("homebrew", "not-a-tap", "not-a-formula")
- end
-end | true |
Other | Homebrew | brew | 9fc14e663bc52b5e32a4c2d07ed6114b99fcbf54.json | Convert GPG2Requirement test to spec. | Library/Homebrew/test/gpg2_requirement_spec.rb | @@ -0,0 +1,23 @@
+require "requirements/gpg2_requirement"
+require "fileutils"
+
+describe GPG2Requirement do
+ let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
+
+ after(:each) do
+ FileUtils.rm_rf dir unless @dir.nil?
+ end
+
+ describe "#satisfied?" do
+ it "returns true if GPG2 is installed" do
+ ENV["PATH"] = dir/"bin"
+ (dir/"bin/gpg").write <<-EOS.undent
+ #!/bin/bash
+ echo 2.0.30
+ EOS
+ FileUtils.chmod 0755, dir/"bin/gpg"
+
+ expect(subject).to be_satisfied
+ end
+ end
+end | true |
Other | Homebrew | brew | 9fc14e663bc52b5e32a4c2d07ed6114b99fcbf54.json | Convert GPG2Requirement test to spec. | Library/Homebrew/test/gpg2_requirement_test.rb | @@ -1,25 +0,0 @@
-require "testing_env"
-require "requirements/gpg2_requirement"
-require "fileutils"
-
-class GPG2RequirementTests < Homebrew::TestCase
- def setup
- super
- @dir = Pathname.new(mktmpdir)
- (@dir/"bin/gpg").write <<-EOS.undent
- #!/bin/bash
- echo 2.0.30
- EOS
- FileUtils.chmod 0755, @dir/"bin/gpg"
- end
-
- def teardown
- FileUtils.rm_rf @dir
- super
- end
-
- def test_satisfied
- ENV["PATH"] = @dir/"bin"
- assert_predicate GPG2Requirement.new, :satisfied?
- end
-end | true |
Other | Homebrew | brew | 1be7852493cee7f7af9b31cef4547aca23bebb0b.json | Convert SoftwareSpec test to spec. | Library/Homebrew/test/software_spec_spec.rb | @@ -0,0 +1,184 @@
+require "software_spec"
+
+RSpec::Matchers.alias_matcher :have_defined_resource, :be_resource_defined
+RSpec::Matchers.alias_matcher :have_defined_option, :be_option_defined
+
+describe SoftwareSpec do
+ let(:owner) { double(name: "some_name", full_name: "some_name", tap: "homebrew/core") }
+
+ describe "#resource" do
+ it "defines a resource" do
+ subject.resource("foo") { url "foo-1.0" }
+ expect(subject).to have_defined_resource("foo")
+ end
+
+ it "sets itself to be the resource's owner" do
+ subject.resource("foo") { url "foo-1.0" }
+ subject.owner = owner
+ subject.resources.each_value do |r|
+ expect(r.owner).to eq(subject)
+ end
+ end
+
+ it "receives the owner's version if it has no own version" do
+ subject.url("foo-42")
+ subject.resource("bar") { url "bar" }
+ subject.owner = owner
+
+ expect(subject.resource("bar").version).to eq("42")
+ end
+
+ it "raises an error when duplicate resources are defined" do
+ subject.resource("foo") { url "foo-1.0" }
+ expect {
+ subject.resource("foo") { url "foo-1.0" }
+ }.to raise_error(DuplicateResourceError)
+ end
+
+ it "raises an error when accessing missing resources" do
+ subject.owner = owner
+ expect {
+ subject.resource("foo")
+ }.to raise_error(ResourceMissingError)
+ end
+ end
+
+ describe "#owner" do
+ it "sets the owner" do
+ subject.owner = owner
+ expect(subject.owner).to eq(owner)
+ end
+
+ it "sets the name" do
+ subject.owner = owner
+ expect(subject.name).to eq(owner.name)
+ end
+ end
+
+ describe "#option" do
+ it "defines an option" do
+ subject.option("foo")
+ expect(subject).to have_defined_option("foo")
+ end
+
+ it "raises an error when it begins with dashes" do
+ expect {
+ subject.option("--foo")
+ }.to raise_error(ArgumentError)
+ end
+
+ it "raises an error when name is empty" do
+ expect {
+ subject.option("")
+ }.to raise_error(ArgumentError)
+ end
+
+ it "special cases the cxx11 option" do
+ subject.option(:cxx11)
+ expect(subject).to have_defined_option("c++11")
+ expect(subject).not_to have_defined_option("cxx11")
+ end
+
+ it "supports options with descriptions" do
+ subject.option("bar", "description")
+ expect(subject.options.first.description).to eq("description")
+ end
+
+ it "defaults to an empty string when no description is given" do
+ subject.option("foo")
+ expect(subject.options.first.description).to eq("")
+ end
+ end
+
+ describe "#deprecated_option" do
+ it "allows specifying deprecated options" do
+ subject.deprecated_option("foo" => "bar")
+ expect(subject.deprecated_options).not_to be_empty
+ expect(subject.deprecated_options.first.old).to eq("foo")
+ expect(subject.deprecated_options.first.current).to eq("bar")
+ end
+
+ it "allows specifying deprecated options as a Hash from an Array/String to an Array/String" do
+ subject.deprecated_option(["foo1", "foo2"] => "bar1", "foo3" => ["bar2", "bar3"])
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo1", "bar1"))
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo2", "bar1"))
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo3", "bar2"))
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo3", "bar3"))
+ end
+
+ it "raises an error when empty" do
+ expect {
+ subject.deprecated_option({})
+ }.to raise_error(ArgumentError)
+ end
+ end
+
+ describe "#depends_on" do
+ it "allows specifying dependencies" do
+ subject.depends_on("foo")
+ expect(subject.deps.first.name).to eq("foo")
+ end
+
+ it "allows specifying optional dependencies" do
+ subject.depends_on "foo" => :optional
+ expect(subject).to have_defined_option("with-foo")
+ end
+
+ it "allows specifying recommended dependencies" do
+ subject.depends_on "bar" => :recommended
+ expect(subject).to have_defined_option("without-bar")
+ end
+ end
+
+ specify "explicit options override defaupt depends_on option description" do
+ subject.option("with-foo", "blah")
+ subject.depends_on("foo" => :optional)
+ expect(subject.options.first.description).to eq("blah")
+ end
+
+ describe "#patch" do
+ it "adds a patch" do
+ subject.patch(:p1, :DATA)
+ expect(subject.patches.count).to eq(1)
+ expect(subject.patches.first.strip).to eq(:p1)
+ end
+ end
+end
+
+describe HeadSoftwareSpec do
+ specify "#version" do
+ expect(subject.version).to eq(Version.create("HEAD"))
+ end
+
+ specify "#verify_download_integrity" do
+ expect(subject.verify_download_integrity(Object.new)).to be nil
+ end
+end
+
+describe BottleSpecification do
+ specify "#sha256" do
+ checksums = {
+ snow_leopard_32: "deadbeef" * 8,
+ snow_leopard: "faceb00c" * 8,
+ lion: "baadf00d" * 8,
+ mountain_lion: "8badf00d" * 8,
+ }
+
+ checksums.each_pair do |cat, digest|
+ subject.sha256(digest => cat)
+ end
+
+ checksums.each_pair do |cat, digest|
+ checksum, = subject.checksum_for(cat)
+ expect(Checksum.new(:sha256, digest)).to eq(checksum)
+ end
+ end
+
+ %w[root_url prefix cellar rebuild].each do |method|
+ specify "##{method}" do
+ object = Object.new
+ subject.public_send(method, object)
+ expect(subject.public_send(method)).to eq(object)
+ end
+ end
+end | true |
Other | Homebrew | brew | 1be7852493cee7f7af9b31cef4547aca23bebb0b.json | Convert SoftwareSpec test to spec. | Library/Homebrew/test/software_spec_test.rb | @@ -1,184 +0,0 @@
-require "testing_env"
-require "software_spec"
-
-class SoftwareSpecTests < Homebrew::TestCase
- def setup
- super
- @spec = SoftwareSpec.new
- end
-
- def test_resource
- @spec.resource("foo") { url "foo-1.0" }
- assert @spec.resource_defined?("foo")
- end
-
- def test_raises_when_duplicate_resources_are_defined
- @spec.resource("foo") { url "foo-1.0" }
- assert_raises(DuplicateResourceError) do
- @spec.resource("foo") { url "foo-1.0" }
- end
- end
-
- def test_raises_when_accessing_missing_resources
- @spec.owner = Class.new do
- def name
- "test"
- end
-
- def full_name
- "test"
- end
-
- def tap
- "homebrew/core"
- end
- end.new
- assert_raises(ResourceMissingError) { @spec.resource("foo") }
- end
-
- def test_set_owner
- owner = stub name: "some_name",
- full_name: "some_name",
- tap: "homebrew/core"
- @spec.owner = owner
- assert_equal owner, @spec.owner
- end
-
- def test_resource_owner
- @spec.resource("foo") { url "foo-1.0" }
- @spec.owner = stub name: "some_name",
- full_name: "some_name",
- tap: "homebrew/core"
- assert_equal "some_name", @spec.name
- @spec.resources.each_value { |r| assert_equal @spec, r.owner }
- end
-
- def test_resource_without_version_receives_owners_version
- @spec.url("foo-42")
- @spec.resource("bar") { url "bar" }
- @spec.owner = stub name: "some_name",
- full_name: "some_name",
- tap: "homebrew/core"
- assert_version_equal "42", @spec.resource("bar").version
- end
-
- def test_option
- @spec.option("foo")
- assert @spec.option_defined?("foo")
- end
-
- def test_option_raises_when_begins_with_dashes
- assert_raises(ArgumentError) { @spec.option("--foo") }
- end
-
- def test_option_raises_when_name_empty
- assert_raises(ArgumentError) { @spec.option("") }
- end
-
- def test_cxx11_option_special_case
- @spec.option(:cxx11)
- assert @spec.option_defined?("c++11")
- refute @spec.option_defined?("cxx11")
- end
-
- def test_option_description
- @spec.option("bar", "description")
- assert_equal "description", @spec.options.first.description
- end
-
- def test_option_description_defaults_to_empty_string
- @spec.option("foo")
- assert_equal "", @spec.options.first.description
- end
-
- def test_deprecated_option
- @spec.deprecated_option("foo" => "bar")
- refute_empty @spec.deprecated_options
- assert_equal "foo", @spec.deprecated_options.first.old
- assert_equal "bar", @spec.deprecated_options.first.current
- end
-
- def test_deprecated_options
- @spec.deprecated_option(["foo1", "foo2"] => "bar1", "foo3" => ["bar2", "bar3"])
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo1", "bar1")
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo2", "bar1")
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo3", "bar2")
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo3", "bar3")
- end
-
- def test_deprecated_option_raises_when_empty
- assert_raises(ArgumentError) { @spec.deprecated_option({}) }
- end
-
- def test_depends_on
- @spec.depends_on("foo")
- assert_equal "foo", @spec.deps.first.name
- end
-
- def test_dependency_option_integration
- @spec.depends_on "foo" => :optional
- @spec.depends_on "bar" => :recommended
- assert @spec.option_defined?("with-foo")
- assert @spec.option_defined?("without-bar")
- end
-
- def test_explicit_options_override_default_dep_option_description
- @spec.option("with-foo", "blah")
- @spec.depends_on("foo" => :optional)
- assert_equal "blah", @spec.options.first.description
- end
-
- def test_patch
- @spec.patch :p1, :DATA
- assert_equal 1, @spec.patches.length
- assert_equal :p1, @spec.patches.first.strip
- end
-end
-
-class HeadSoftwareSpecTests < Homebrew::TestCase
- def setup
- super
- @spec = HeadSoftwareSpec.new
- end
-
- def test_version
- assert_version_equal "HEAD", @spec.version
- end
-
- def test_verify_download_integrity
- assert_nil @spec.verify_download_integrity(Object.new)
- end
-end
-
-class BottleSpecificationTests < Homebrew::TestCase
- def setup
- super
- @spec = BottleSpecification.new
- end
-
- def test_checksum_setters
- checksums = {
- snow_leopard_32: "deadbeef"*8,
- snow_leopard: "faceb00c"*8,
- lion: "baadf00d"*8,
- mountain_lion: "8badf00d"*8,
- }
-
- checksums.each_pair do |cat, digest|
- @spec.sha256(digest => cat)
- end
-
- checksums.each_pair do |cat, digest|
- checksum, = @spec.checksum_for(cat)
- assert_equal Checksum.new(:sha256, digest), checksum
- end
- end
-
- def test_other_setters
- double = Object.new
- %w[root_url prefix cellar rebuild].each do |method|
- @spec.send(method, double)
- assert_equal double, @spec.send(method)
- end
- end
-end | true |
Other | Homebrew | brew | 9c1db3c820f715f62f550ba1e54f16f9b89bc6ed.json | Convert JavaRequirement test to spec. | Library/Homebrew/test/os/mac/java_requirement_spec.rb | @@ -0,0 +1,34 @@
+require "requirements/java_requirement"
+require "fileutils"
+
+describe JavaRequirement do
+ subject { described_class.new(%w[1.8]) }
+ let(:java_home) { Dir.mktmpdir }
+ let(:java_home_path) { Pathname.new(java_home) }
+
+ before(:each) do
+ FileUtils.mkdir java_home_path/"bin"
+ FileUtils.touch java_home_path/"bin/java"
+ allow(subject).to receive(:preferred_java).and_return(java_home_path/"bin/java")
+ expect(subject).to be_satisfied
+ end
+
+ after(:each) { java_home_path.rmtree }
+
+ specify "Apple Java environment" do
+ expect(ENV).to receive(:prepend_path)
+ expect(ENV).to receive(:append_to_cflags)
+
+ subject.modify_build_environment
+ expect(ENV["JAVA_HOME"]).to eq(java_home)
+ end
+
+ specify "Oracle Java environment" do
+ FileUtils.mkdir java_home_path/"include"
+ expect(ENV).to receive(:prepend_path)
+ expect(ENV).to receive(:append_to_cflags).twice
+
+ subject.modify_build_environment
+ expect(ENV["JAVA_HOME"]).to eq(java_home)
+ end
+end | true |
Other | Homebrew | brew | 9c1db3c820f715f62f550ba1e54f16f9b89bc6ed.json | Convert JavaRequirement test to spec. | Library/Homebrew/test/os/mac/java_requirement_test.rb | @@ -1,31 +0,0 @@
-require "testing_env"
-require "requirements/java_requirement"
-require "fileutils"
-
-class OSMacJavaRequirementTests < Homebrew::TestCase
- def setup
- super
- @java_req = JavaRequirement.new(%w[1.8])
- @tmp_java_home = mktmpdir
- @tmp_pathname = Pathname.new(@tmp_java_home)
- FileUtils.mkdir @tmp_pathname/"bin"
- FileUtils.touch @tmp_pathname/"bin/java"
- @java_req.stubs(:preferred_java).returns(@tmp_pathname/"bin/java")
- @java_req.satisfied?
- end
-
- def test_java_env_apple
- ENV.expects(:prepend_path)
- ENV.expects(:append_to_cflags)
- @java_req.modify_build_environment
- assert_equal ENV["JAVA_HOME"], @tmp_java_home
- end
-
- def test_java_env_oracle
- FileUtils.mkdir @tmp_pathname/"include"
- ENV.expects(:prepend_path)
- ENV.expects(:append_to_cflags).twice
- @java_req.modify_build_environment
- assert_equal ENV["JAVA_HOME"], @tmp_java_home
- end
-end | true |
Other | Homebrew | brew | 1ff6846218367fc73736039d668b319acebd8cae.json | Convert StringInreplaceExtension test to spec. | Library/Homebrew/test/inreplace_spec.rb | @@ -0,0 +1,251 @@
+require "extend/string"
+require "tempfile"
+require "utils/inreplace"
+
+describe StringInreplaceExtension do
+ subject { string.extend(described_class) }
+
+ describe "#change_make_var!" do
+ context "flag" do
+ context "with spaces" do
+ let(:string) do
+ <<-EOS.undent
+ OTHER=def
+ FLAG = abc
+ FLAG2=abc
+ EOS
+ end
+
+ it "is successfully replaced" do
+ subject.change_make_var! "FLAG", "def"
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ FLAG=def
+ FLAG2=abc
+ EOS
+ end
+
+ it "is successfully appended" do
+ subject.change_make_var! "FLAG", "\\1 def"
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ FLAG=abc def
+ FLAG2=abc
+ EOS
+ end
+ end
+
+ context "with tabs" do
+ let(:string) do
+ <<-EOS.undent
+ CFLAGS\t=\t-Wall -O2
+ LDFLAGS\t=\t-lcrypto -lssl
+ EOS
+ end
+
+ it "is successfully replaced" do
+ subject.change_make_var! "CFLAGS", "-O3"
+ expect(subject).to eq <<-EOS.undent
+ CFLAGS=-O3
+ LDFLAGS\t=\t-lcrypto -lssl
+ EOS
+ end
+ end
+ end
+
+ context "empty flag between other flags" do
+ let(:string) do
+ <<-EOS.undent
+ OTHER=def
+ FLAG =
+ FLAG2=abc
+ EOS
+ end
+
+ it "is successfully replaced" do
+ subject.change_make_var! "FLAG", "def"
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ FLAG=def
+ FLAG2=abc
+ EOS
+ end
+ end
+
+ context "empty flag" do
+ let(:string) do
+ <<-EOS.undent
+ FLAG =
+ mv file_a file_b
+ EOS
+ end
+
+ it "is successfully replaced" do
+ subject.change_make_var! "FLAG", "def"
+ expect(subject).to eq <<-EOS.undent
+ FLAG=def
+ mv file_a file_b
+ EOS
+ end
+ end
+
+ context "shell-style variable" do
+ let(:string) do
+ <<-EOS.undent
+ OTHER=def
+ FLAG=abc
+ FLAG2=abc
+ EOS
+ end
+
+ it "is successfully replaced" do
+ subject.change_make_var! "FLAG", "def"
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ FLAG=def
+ FLAG2=abc
+ EOS
+ end
+ end
+ end
+
+ describe "#remove_make_var!" do
+ context "flag" do
+ context "with spaces" do
+ let(:string) do
+ <<-EOS.undent
+ OTHER=def
+ FLAG = abc
+ FLAG2 = def
+ EOS
+ end
+
+ it "is successfully removed" do
+ subject.remove_make_var! "FLAG"
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ FLAG2 = def
+ EOS
+ end
+ end
+
+ context "with tabs" do
+ let(:string) do
+ <<-EOS.undent
+ CFLAGS\t=\t-Wall -O2
+ LDFLAGS\t=\t-lcrypto -lssl
+ EOS
+ end
+
+ it "is successfully removed" do
+ subject.remove_make_var! "LDFLAGS"
+ expect(subject).to eq <<-EOS.undent
+ CFLAGS\t=\t-Wall -O2
+ EOS
+ end
+ end
+ end
+
+ context "multiple flags" do
+ let(:string) do
+ <<-EOS.undent
+ OTHER=def
+ FLAG = abc
+ FLAG2 = def
+ OTHER2=def
+ EOS
+ end
+
+ specify "are be successfully removed" do
+ subject.remove_make_var! ["FLAG", "FLAG2"]
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ OTHER2=def
+ EOS
+ end
+ end
+ end
+
+ describe "#get_make_var" do
+ context "with spaces" do
+ let(:string) do
+ <<-EOS.undent
+ CFLAGS = -Wall -O2
+ LDFLAGS = -lcrypto -lssl
+ EOS
+ end
+
+ it "extracts the value for a given variable" do
+ expect(subject.get_make_var("CFLAGS")).to eq("-Wall -O2")
+ end
+ end
+
+ context "with tabs" do
+ let(:string) do
+ <<-EOS.undent
+ CFLAGS\t=\t-Wall -O2
+ LDFLAGS\t=\t-lcrypto -lssl
+ EOS
+ end
+
+ it "extracts the value for a given variable" do
+ expect(subject.get_make_var("CFLAGS")).to eq("-Wall -O2")
+ end
+ end
+ end
+
+ describe "#sub!" do
+ let(:string) { "foo" }
+
+ it "replaces the first occurence" do
+ subject.sub!("o", "e")
+ expect(subject).to eq("feo")
+ end
+ end
+
+ describe "#gsub!" do
+ let(:string) { "foo" }
+
+ it "replaces the all occurences" do
+ subject.gsub!("o", "e") # rubocop:disable Performance/StringReplacement
+ expect(subject).to eq("fee")
+ end
+ end
+end
+
+describe Utils::Inreplace do
+ let(:file) { Tempfile.new("test") }
+
+ before(:each) do
+ file.write <<-EOS.undent
+ a
+ b
+ c
+ EOS
+ end
+
+ after(:each) { file.unlink }
+
+ it "raises error if there is nothing to replace" do
+ expect {
+ described_class.inreplace file.path, "d", "f"
+ }.to raise_error(Utils::InreplaceError)
+ end
+
+ it "raises error if there is nothing to replace" do
+ expect {
+ described_class.inreplace(file.path) do |s|
+ s.gsub!("d", "f") # rubocop:disable Performance/StringReplacement
+ end
+ }.to raise_error(Utils::InreplaceError)
+ end
+
+ it "raises error if there is nothing to replace" do
+ expect {
+ described_class.inreplace(file.path) do |s|
+ s.change_make_var! "VAR", "value"
+ s.remove_make_var! "VAR2"
+ end
+ }.to raise_error(Utils::InreplaceError)
+ end
+end | true |
Other | Homebrew | brew | 1ff6846218367fc73736039d668b319acebd8cae.json | Convert StringInreplaceExtension test to spec. | Library/Homebrew/test/inreplace_test.rb | @@ -1,119 +0,0 @@
-require "testing_env"
-require "extend/string"
-require "utils/inreplace"
-
-class InreplaceTest < Homebrew::TestCase
- def test_change_make_var
- # Replace flag
- s1 = "OTHER=def\nFLAG = abc\nFLAG2=abc"
- s1.extend(StringInreplaceExtension)
- s1.change_make_var! "FLAG", "def"
- assert_equal "OTHER=def\nFLAG=def\nFLAG2=abc", s1
- end
-
- def test_change_make_var_empty
- # Replace empty flag
- s1 = "OTHER=def\nFLAG = \nFLAG2=abc"
- s1.extend(StringInreplaceExtension)
- s1.change_make_var! "FLAG", "def"
- assert_equal "OTHER=def\nFLAG=def\nFLAG2=abc", s1
- end
-
- def test_change_make_var_empty_2
- # Replace empty flag
- s1 = "FLAG = \nmv file_a file_b"
- s1.extend(StringInreplaceExtension)
- s1.change_make_var! "FLAG", "def"
- assert_equal "FLAG=def\nmv file_a file_b", s1
- end
-
- def test_change_make_var_append
- # Append to flag
- s1 = "OTHER=def\nFLAG = abc\nFLAG2=abc"
- s1.extend(StringInreplaceExtension)
- s1.change_make_var! "FLAG", "\\1 def"
- assert_equal "OTHER=def\nFLAG=abc def\nFLAG2=abc", s1
- end
-
- def test_change_make_var_shell_style
- # Shell variables have no spaces around =
- s1 = "OTHER=def\nFLAG=abc\nFLAG2=abc"
- s1.extend(StringInreplaceExtension)
- s1.change_make_var! "FLAG", "def"
- assert_equal "OTHER=def\nFLAG=def\nFLAG2=abc", s1
- end
-
- def test_remove_make_var
- # Replace flag
- s1 = "OTHER=def\nFLAG = abc\nFLAG2 = def"
- s1.extend(StringInreplaceExtension)
- s1.remove_make_var! "FLAG"
- assert_equal "OTHER=def\nFLAG2 = def", s1
- end
-
- def test_remove_make_vars
- # Replace flag
- s1 = "OTHER=def\nFLAG = abc\nFLAG2 = def\nOTHER2=def"
- s1.extend(StringInreplaceExtension)
- s1.remove_make_var! ["FLAG", "FLAG2"]
- assert_equal "OTHER=def\nOTHER2=def", s1
- end
-
- def test_get_make_var
- s = "CFLAGS = -Wall -O2\nLDFLAGS = -lcrypto -lssl"
- s.extend(StringInreplaceExtension)
- assert_equal "-Wall -O2", s.get_make_var("CFLAGS")
- end
-
- def test_change_make_var_with_tabs
- s = "CFLAGS\t=\t-Wall -O2\nLDFLAGS\t=\t-lcrypto -lssl"
- s.extend(StringInreplaceExtension)
-
- assert_equal "-Wall -O2", s.get_make_var("CFLAGS")
-
- s.change_make_var! "CFLAGS", "-O3"
- assert_equal "CFLAGS=-O3\nLDFLAGS\t=\t-lcrypto -lssl", s
-
- s.remove_make_var! "LDFLAGS"
- assert_equal "CFLAGS=-O3\n", s
- end
-
- def test_sub_gsub
- s = "foo"
- s.extend(StringInreplaceExtension)
-
- s.sub!("f", "b")
- assert_equal "boo", s
-
- # Under current context, we are testing `String#gsub!`, so let's disable rubocop temporarily.
- s.gsub!("o", "e") # rubocop:disable Performance/StringReplacement
- assert_equal "bee", s
- end
-
- def test_inreplace_errors
- require "tempfile"
- extend(Utils::Inreplace)
-
- file = Tempfile.new("test")
-
- file.write "a\nb\nc\n"
-
- assert_raises(Utils::InreplaceError) do
- inreplace file.path, "d", "f"
- end
-
- assert_raises(Utils::InreplaceError) do
- # Under current context, we are testing `String#gsub!`, so let's disable rubocop temporarily.
- inreplace(file.path) { |s| s.gsub!("d", "f") } # rubocop:disable Performance/StringReplacement
- end
-
- assert_raises(Utils::InreplaceError) do
- inreplace(file.path) do |s|
- s.change_make_var! "VAR", "value"
- s.remove_make_var! "VAR2"
- end
- end
- ensure
- file.unlink
- end
-end | true |
Other | Homebrew | brew | 9904eae48a5e4129905b48e5fe61afbb82726a39.json | Convert FormulaPin test to spec. | Library/Homebrew/test/formula_pin_spec.rb | @@ -0,0 +1,41 @@
+require "formula_pin"
+
+describe FormulaPin do
+ subject { described_class.new(formula) }
+ let(:name) { "double" }
+ let(:formula) { double(Formula, name: name, rack: HOMEBREW_CELLAR/name) }
+
+ before(:each) do
+ formula.rack.mkpath
+
+ allow(formula).to receive(:installed_prefixes) do
+ formula.rack.directory? ? formula.rack.subdirs : []
+ end
+
+ allow(formula).to receive(:installed_kegs) do
+ formula.installed_prefixes.map { |prefix| Keg.new(prefix) }
+ end
+ end
+
+ it "is not pinnable by default" do
+ expect(subject).not_to be_pinnable
+ end
+
+ it "is pinnable if the Keg exists" do
+ (formula.rack/"0.1").mkpath
+ expect(subject).to be_pinnable
+ end
+
+ specify "#pin and #unpin" do
+ (formula.rack/"0.1").mkpath
+
+ subject.pin
+ expect(subject).to be_pinned
+ expect(HOMEBREW_PINNED_KEGS/name).to be_a_directory
+ expect(HOMEBREW_PINNED_KEGS.children.count).to eq(1)
+
+ subject.unpin
+ expect(subject).not_to be_pinned
+ expect(HOMEBREW_PINNED_KEGS).not_to be_a_directory
+ end
+end | true |
Other | Homebrew | brew | 9904eae48a5e4129905b48e5fe61afbb82726a39.json | Convert FormulaPin test to spec. | Library/Homebrew/test/formula_pin_test.rb | @@ -1,51 +0,0 @@
-require "testing_env"
-require "formula_pin"
-
-class FormulaPinTests < Homebrew::TestCase
- class FormulaDouble
- def name
- "double"
- end
-
- def rack
- HOMEBREW_CELLAR/name
- end
-
- def installed_prefixes
- rack.directory? ? rack.subdirs : []
- end
-
- def installed_kegs
- installed_prefixes.map { |d| Keg.new d }
- end
- end
-
- def setup
- super
- @f = FormulaDouble.new
- @pin = FormulaPin.new(@f)
- @f.rack.mkpath
- end
-
- def test_not_pinnable
- refute_predicate @pin, :pinnable?
- end
-
- def test_pinnable_if_kegs_exist
- (@f.rack/"0.1").mkpath
- assert_predicate @pin, :pinnable?
- end
-
- def test_unpin
- (@f.rack/"0.1").mkpath
- @pin.pin
-
- assert_predicate @pin, :pinned?
- assert_equal 1, HOMEBREW_PINNED_KEGS.children.length
-
- @pin.unpin
-
- refute_predicate @pin, :pinned?
- refute_predicate HOMEBREW_PINNED_KEGS, :directory?
- end
-end | true |
Other | Homebrew | brew | 8e0940cc2f79def7f19c01dc2a9429cf624f0c6e.json | Convert Formulary test to spec. | Library/Homebrew/test/formulary_spec.rb | @@ -0,0 +1,219 @@
+require "formula"
+require "formula_installer"
+require "utils/bottles"
+
+describe Formulary do
+ let(:formula_name) { "testball_bottle" }
+ let(:formula_path) { CoreTap.new.formula_dir/"#{formula_name}.rb" }
+ let(:formula_content) do
+ <<-EOS.undent
+ class #{subject.class_s(formula_name)} < Formula
+ url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
+ sha256 TESTBALL_SHA256
+
+ bottle do
+ cellar :any_skip_relocation
+ root_url "file://#{bottle_dir}"
+ sha256 "9abc8ce779067e26556002c4ca6b9427b9874d25f0cafa7028e05b5c5c410cb4" => :#{Utils::Bottles.tag}
+ end
+
+ def install
+ prefix.install "bin"
+ prefix.install "libexec"
+ end
+ end
+ EOS
+ end
+ let(:bottle_dir) { Pathname.new("#{TEST_FIXTURE_DIR}/bottles") }
+ let(:bottle) { bottle_dir/"testball_bottle-0.1.#{Utils::Bottles.tag}.bottle.tar.gz" }
+
+ describe "::class_s" do
+ it "replaces '+' with 'x'" do
+ expect(subject.class_s("foo++")).to eq("Fooxx")
+ end
+
+ it "converts a string to PascalCase" do
+ expect(subject.class_s("shell.fm")).to eq("ShellFm")
+ expect(subject.class_s("s-lang")).to eq("SLang")
+ expect(subject.class_s("pkg-config")).to eq("PkgConfig")
+ expect(subject.class_s("foo_bar")).to eq("FooBar")
+ end
+
+ it "replaces '@' with 'AT'" do
+ expect(subject.class_s("openssl@1.1")).to eq("OpensslAT11")
+ end
+ end
+
+ describe "::factory" do
+ before(:each) do
+ formula_path.write formula_content
+ end
+
+ it "returns a Formula" do
+ expect(subject.factory(formula_name)).to be_kind_of(Formula)
+ end
+
+ it "returns a Formula when given a fully qualified name" do
+ expect(subject.factory("homebrew/core/#{formula_name}")).to be_kind_of(Formula)
+ end
+
+ it "raises an error if the Formula cannot be found" do
+ expect {
+ subject.factory("not_existed_formula")
+ }.to raise_error(FormulaUnavailableError)
+ end
+
+ context "if the Formula has the wrong class" do
+ let(:formula_name) { "giraffe" }
+ let(:formula_content) do
+ <<-EOS.undent
+ class Wrong#{subject.class_s(formula_name)} < Formula
+ end
+ EOS
+ end
+
+ it "raises an error" do
+ expect {
+ subject.factory(formula_name)
+ }.to raise_error(FormulaClassUnavailableError)
+ end
+ end
+
+ it "returns a Formula when given a path" do
+ expect(subject.factory(formula_path)).to be_kind_of(Formula)
+ end
+
+ it "returns a Formula when given a URL" do
+ formula = shutup do
+ subject.factory("file://#{formula_path}")
+ end
+
+ expect(formula).to be_kind_of(Formula)
+ end
+
+ it "returns a Formula when given a bottle" do
+ formula = subject.factory(bottle)
+ expect(formula).to be_kind_of(Formula)
+ expect(formula.local_bottle_path).to eq(bottle.realpath)
+ end
+
+ it "returns a Formula when given an alias" do
+ alias_dir = CoreTap.instance.alias_dir
+ alias_dir.mkpath
+ alias_path = alias_dir/"foo"
+ FileUtils.ln_s formula_path, alias_path
+ result = subject.factory("foo")
+ expect(result).to be_kind_of(Formula)
+ expect(result.alias_path).to eq(alias_path.to_s)
+ end
+
+ context "with installed Formula" do
+ let(:formula) { subject.factory(formula_path) }
+ let(:installer) { FormulaInstaller.new(formula) }
+
+ it "returns a Formula when given a rack" do
+ shutup do
+ installer.install
+ end
+
+ f = subject.from_rack(formula.rack)
+ expect(f).to be_kind_of(Formula)
+ expect(f.build).to be_kind_of(Tab)
+ end
+
+ it "returns a Formula when given a Keg" do
+ shutup do
+ installer.install
+ end
+
+ keg = Keg.new(formula.prefix)
+ f = subject.from_keg(keg)
+ expect(f).to be_kind_of(Formula)
+ expect(f.build).to be_kind_of(Tab)
+ end
+ end
+
+ context "from Tap" do
+ let(:tap) { Tap.new("homebrew", "foo") }
+ let(:formula_path) { tap.path/"#{formula_name}.rb" }
+
+ it "returns a Formula when given a name" do
+ expect(subject.factory(formula_name)).to be_kind_of(Formula)
+ end
+
+ it "returns a Formula from an Alias path" do
+ alias_dir = tap.path/"Aliases"
+ alias_dir.mkpath
+ FileUtils.ln_s formula_path, alias_dir/"bar"
+ expect(subject.factory("bar")).to be_kind_of(Formula)
+ end
+
+ it "raises an error when the Formula cannot be found" do
+ expect {
+ subject.factory("#{tap}/not_existed_formula")
+ }.to raise_error(TapFormulaUnavailableError)
+ end
+
+ it "returns a Formula when given a fully qualified name" do
+ expect(subject.factory("#{tap}/#{formula_name}")).to be_kind_of(Formula)
+ end
+
+ it "raises an error if a Formula is in multiple Taps" do
+ begin
+ another_tap = Tap.new("homebrew", "bar")
+ (another_tap.path/"#{formula_name}.rb").write formula_content
+ expect {
+ subject.factory(formula_name)
+ }.to raise_error(TapFormulaAmbiguityError)
+ ensure
+ another_tap.path.rmtree
+ end
+ end
+ end
+ end
+
+ specify "::from_contents" do
+ expect(subject.from_contents(formula_name, formula_path, formula_content)).to be_kind_of(Formula)
+ end
+
+ specify "::to_rack" do
+ expect(subject.to_rack(formula_name)).to eq(HOMEBREW_CELLAR/formula_name)
+
+ (HOMEBREW_CELLAR/formula_name).mkpath
+ expect(subject.to_rack(formula_name)).to eq(HOMEBREW_CELLAR/formula_name)
+
+ expect {
+ subject.to_rack("a/b/#{formula_name}")
+ }.to raise_error(TapFormulaUnavailableError)
+ end
+
+ describe "::find_with_priority" do
+ let(:core_path) { CoreTap.new.formula_dir/"#{formula_name}.rb" }
+ let(:tap) { Tap.new("homebrew", "foo") }
+ let(:tap_path) { tap.path/"#{formula_name}.rb" }
+
+ before(:each) do
+ core_path.write formula_content
+ tap_path.write formula_content
+ end
+
+ it "prioritizes core Formulae" do
+ formula = subject.find_with_priority(formula_name)
+ expect(formula).to be_kind_of(Formula)
+ expect(formula.path).to eq(core_path)
+ end
+
+ it "prioritizes Formulae from pinned Taps" do
+ begin
+ tap.pin
+ formula = shutup do
+ subject.find_with_priority(formula_name)
+ end
+ expect(formula).to be_kind_of(Formula)
+ expect(formula.path).to eq(tap_path.realpath)
+ ensure
+ tap.pinned_symlink_path.parent.parent.rmtree
+ end
+ end
+ end
+end | true |
Other | Homebrew | brew | 8e0940cc2f79def7f19c01dc2a9429cf624f0c6e.json | Convert Formulary test to spec. | Library/Homebrew/test/formulary_test.rb | @@ -1,189 +0,0 @@
-require "testing_env"
-require "formula"
-require "formula_installer"
-require "utils/bottles"
-
-class FormularyTest < Homebrew::TestCase
- def test_class_naming
- assert_equal "ShellFm", Formulary.class_s("shell.fm")
- assert_equal "Fooxx", Formulary.class_s("foo++")
- assert_equal "SLang", Formulary.class_s("s-lang")
- assert_equal "PkgConfig", Formulary.class_s("pkg-config")
- assert_equal "FooBar", Formulary.class_s("foo_bar")
- assert_equal "OpensslAT11", Formulary.class_s("openssl@1.1")
- end
-end
-
-class FormularyFactoryTest < Homebrew::TestCase
- def setup
- super
- @name = "testball_bottle"
- @path = CoreTap.new.formula_dir/"#{@name}.rb"
- @bottle_dir = Pathname.new("#{TEST_FIXTURE_DIR}/bottles")
- @bottle = @bottle_dir/"testball_bottle-0.1.#{Utils::Bottles.tag}.bottle.tar.gz"
- @path.write <<-EOS.undent
- class #{Formulary.class_s(@name)} < Formula
- url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
- sha256 TESTBALL_SHA256
-
- bottle do
- cellar :any_skip_relocation
- root_url "file://#{@bottle_dir}"
- sha256 "9abc8ce779067e26556002c4ca6b9427b9874d25f0cafa7028e05b5c5c410cb4" => :#{Utils::Bottles.tag}
- end
-
- def install
- prefix.install "bin"
- prefix.install "libexec"
- end
- end
- EOS
- end
-
- def test_factory
- assert_kind_of Formula, Formulary.factory(@name)
- end
-
- def test_factory_with_fully_qualified_name
- assert_kind_of Formula, Formulary.factory("homebrew/core/#{@name}")
- end
-
- def test_formula_unavailable_error
- assert_raises(FormulaUnavailableError) { Formulary.factory("not_existed_formula") }
- end
-
- def test_formula_class_unavailable_error
- name = "giraffe"
- path = CoreTap.new.formula_dir/"#{name}.rb"
- path.write "class Wrong#{Formulary.class_s(name)} < Formula\nend\n"
-
- assert_raises(FormulaClassUnavailableError) { Formulary.factory(name) }
- end
-
- def test_factory_from_path
- assert_kind_of Formula, Formulary.factory(@path)
- end
-
- def test_factory_from_url
- formula = shutup { Formulary.factory("file://#{@path}") }
- assert_kind_of Formula, formula
- ensure
- formula.path.unlink
- end
-
- def test_factory_from_bottle
- formula = Formulary.factory(@bottle)
- assert_kind_of Formula, formula
- assert_equal @bottle.realpath, formula.local_bottle_path
- end
-
- def test_factory_from_alias
- alias_dir = CoreTap.instance.alias_dir
- alias_dir.mkpath
- alias_path = alias_dir/"foo"
- FileUtils.ln_s @path, alias_path
- result = Formulary.factory("foo")
- assert_kind_of Formula, result
- assert_equal alias_path.to_s, result.alias_path
- end
-
- def test_factory_from_rack_and_from_keg
- formula = Formulary.factory(@path)
- installer = FormulaInstaller.new(formula)
- shutup { installer.install }
- keg = Keg.new(formula.prefix)
- f = Formulary.from_rack(formula.rack)
- assert_kind_of Formula, f
- assert_kind_of Tab, f.build
- f = Formulary.from_keg(keg)
- assert_kind_of Formula, f
- assert_kind_of Tab, f.build
- ensure
- keg.unlink
- end
-
- def test_load_from_contents
- assert_kind_of Formula, Formulary.from_contents(@name, @path, @path.read)
- end
-
- def test_to_rack
- assert_equal HOMEBREW_CELLAR/@name, Formulary.to_rack(@name)
- (HOMEBREW_CELLAR/@name).mkpath
- assert_equal HOMEBREW_CELLAR/@name, Formulary.to_rack(@name)
- assert_raises(TapFormulaUnavailableError) { Formulary.to_rack("a/b/#{@name}") }
- end
-end
-
-class FormularyTapFactoryTest < Homebrew::TestCase
- def setup
- super
- @name = "foo"
- @tap = Tap.new "homebrew", "foo"
- @path = @tap.path/"#{@name}.rb"
- @code = <<-EOS.undent
- class #{Formulary.class_s(@name)} < Formula
- url "foo-1.0"
- end
- EOS
- @path.write @code
- end
-
- def test_factory_tap_formula
- assert_kind_of Formula, Formulary.factory(@name)
- end
-
- def test_factory_tap_alias
- alias_dir = @tap.path/"Aliases"
- alias_dir.mkpath
- FileUtils.ln_s @path, alias_dir/"bar"
- assert_kind_of Formula, Formulary.factory("bar")
- end
-
- def test_tap_formula_unavailable_error
- assert_raises(TapFormulaUnavailableError) { Formulary.factory("#{@tap}/not_existed_formula") }
- end
-
- def test_factory_tap_formula_with_fully_qualified_name
- assert_kind_of Formula, Formulary.factory("#{@tap}/#{@name}")
- end
-
- def test_factory_ambiguity_tap_formulae
- another_tap = Tap.new "homebrew", "bar"
- (another_tap.path/"#{@name}.rb").write @code
- assert_raises(TapFormulaAmbiguityError) { Formulary.factory(@name) }
- ensure
- another_tap.path.rmtree
- end
-end
-
-class FormularyTapPriorityTest < Homebrew::TestCase
- def setup
- super
- @name = "foo"
- @core_path = CoreTap.new.formula_dir/"#{@name}.rb"
- @tap = Tap.new "homebrew", "foo"
- @tap_path = @tap.path/"#{@name}.rb"
- code = <<-EOS.undent
- class #{Formulary.class_s(@name)} < Formula
- url "foo-1.0"
- end
- EOS
- @core_path.write code
- @tap_path.write code
- end
-
- def test_find_with_priority_core_formula
- formula = Formulary.find_with_priority(@name)
- assert_kind_of Formula, formula
- assert_equal @core_path, formula.path
- end
-
- def test_find_with_priority_tap_formula
- @tap.pin
- formula = shutup { Formulary.find_with_priority(@name) }
- assert_kind_of Formula, formula
- assert_equal @tap_path.realpath, formula.path
- ensure
- @tap.pinned_symlink_path.parent.parent.rmtree
- end
-end | true |
Other | Homebrew | brew | c667a43b9790be9887bf3f175d9e6ab3dad80e1a.json | audit: fix insecure mirror check when stdout is empty | Library/Homebrew/dev-cmd/audit.rb | @@ -1499,7 +1499,7 @@ def check_insecure_mirror(url)
secure_url = url.sub "http", "https"
secure_details = get_content_details(secure_url)
- return if !details[:status].start_with?("2") || !secure_details[:status].start_with?("2")
+ return if details[:status].nil? || secure_details[:status].nil? || !details[:status].start_with?("2") || !secure_details[:status].start_with?("2")
etag_match = details[:etag] && details[:etag] == secure_details[:etag]
content_length_match = details[:content_length] && details[:content_length] == secure_details[:content_length] | false |
Other | Homebrew | brew | 81a760921320b6508458d6cdbe4c73b3e01b14b3.json | bump-formula-pr: improve duplicate detection
Reduce the chance of false flagging by making sure that the existing pr
surfaced by GitHub.issues_for_formula actually contains the exact formula name
in its title. | Library/Homebrew/dev-cmd/bump-formula-pr.rb | @@ -80,7 +80,8 @@ def formula_version(formula, spec, contents = nil)
def fetch_pull_requests(formula)
GitHub.issues_for_formula(formula.name, tap: formula.tap).select do |pr|
- pr["html_url"].include?("/pull/")
+ pr["html_url"].include?("/pull/") &&
+ /(^|\s)#{Regexp.quote(formula.name)}(:|\s|$)/i =~ pr["title"]
end
rescue GitHub::RateLimitExceededError => e
opoo e.message | false |
Other | Homebrew | brew | dfa2c247e0dbdbf506f5175a1c839bfd09caecd9.json | keg: simplify code, handle exceptions. | Library/Homebrew/keg.rb | @@ -239,9 +239,7 @@ def optlinked?
def remove_opt_record
opt_record.unlink
- aliases.each do |a|
- (opt_record.parent/a).unlink
- end
+ aliases.each { |a| (opt_record.parent/a).unlink }
opt_record.parent.rmdir_if_possible
end
@@ -465,12 +463,9 @@ def remove_oldname_opt_record
end
def aliases
- formula_name = rack.basename.to_s
- aliases_path = Formula[formula_name].tap.path/"Aliases"
- result = aliases_path.children.select do |c|
- c.symlink? && c.readlink.basename(".rb").to_s == formula_name
- end
- result.map(&:basename).map(&:to_s)
+ Formula[rack.basename.to_s].aliases
+ rescue FormulaUnavailableError
+ []
end
def optlink(mode = OpenStruct.new) | false |
Other | Homebrew | brew | 14ef15f591795c517b7771c5eb01863b2b577a46.json | keg: create symlinks in opt for formula aliases | Library/Homebrew/keg.rb | @@ -239,6 +239,11 @@ def optlinked?
def remove_opt_record
opt_record.unlink
+ unless aliases.empty?
+ aliases.each do |a|
+ (opt_record.parent/a).unlink
+ end
+ end
opt_record.parent.rmdir_if_possible
end
@@ -461,9 +466,25 @@ def remove_oldname_opt_record
@oldname_opt_record = nil
end
+ def aliases
+ formula_name = rack.basename.to_s
+ aliases_path = Formula[formula_name].tap.path/"Aliases"
+ result = aliases_path.children.select do |c|
+ c.symlink? && c.readlink.basename(".rb").to_s == formula_name
+ end
+ result.map(&:basename).map(&:to_s)
+ end
+
def optlink(mode = OpenStruct.new)
opt_record.delete if opt_record.symlink? || opt_record.exist?
make_relative_symlink(opt_record, path, mode)
+ unless aliases.empty?
+ aliases.each do |a|
+ alias_opt_record = opt_record.parent/a
+ alias_opt_record.delete if alias_opt_record.symlink? || alias_opt_record.exist?
+ make_relative_symlink(alias_opt_record, opt_record, mode)
+ end
+ end
return unless oldname_opt_record
oldname_opt_record.delete | false |
Other | Homebrew | brew | f33efbe7c46d4a148af00c83dff73c14717ed0d1.json | Convert LanguageModuleRequirement test to spec. | Library/Homebrew/test/language_module_requirement_spec.rb | @@ -0,0 +1,49 @@
+require "requirements/language_module_requirement"
+
+describe LanguageModuleRequirement do
+ specify "unique dependencies are not equal" do
+ x = described_class.new(:node, "less")
+ y = described_class.new(:node, "coffee-script")
+ expect(x).not_to eq(y)
+ expect(x.hash).not_to eq(y.hash)
+ end
+
+ context "when module and import name differ" do
+ subject { described_class.new(:python, mod_name, import_name) }
+ let(:mod_name) { "foo" }
+ let(:import_name) { "bar" }
+
+ its(:message) { is_expected.to include(mod_name) }
+ its(:the_test) { is_expected.to include("import #{import_name}") }
+ end
+
+ context "when the language is Perl" do
+ it "does not satisfy invalid dependencies" do
+ expect(described_class.new(:perl, "notapackage")).not_to be_satisfied
+ end
+
+ it "satisfies valid dependencies" do
+ expect(described_class.new(:perl, "Env")).to be_satisfied
+ end
+ end
+
+ context "when the language is Python", :needs_python do
+ it "does not satisfy invalid dependencies" do
+ expect(described_class.new(:python, "notapackage")).not_to be_satisfied
+ end
+
+ it "satisfies valid dependencies" do
+ expect(described_class.new(:python, "datetime")).to be_satisfied
+ end
+ end
+
+ context "when the language is Ruby" do
+ it "does not satisfy invalid dependencies" do
+ expect(described_class.new(:ruby, "notapackage")).not_to be_satisfied
+ end
+
+ it "satisfies valid dependencies" do
+ expect(described_class.new(:ruby, "date")).to be_satisfied
+ end
+ end
+end | true |
Other | Homebrew | brew | f33efbe7c46d4a148af00c83dff73c14717ed0d1.json | Convert LanguageModuleRequirement test to spec. | Library/Homebrew/test/language_module_requirement_test.rb | @@ -1,55 +0,0 @@
-require "testing_env"
-require "requirements/language_module_requirement"
-
-class LanguageModuleRequirementTests < Homebrew::TestCase
- parallelize_me!
-
- def assert_deps_fail(spec)
- refute_predicate LanguageModuleRequirement.new(*spec.shift.reverse), :satisfied?
- end
-
- def assert_deps_pass(spec)
- assert_predicate LanguageModuleRequirement.new(*spec.shift.reverse), :satisfied?
- end
-
- def test_unique_deps_are_not_eql
- x = LanguageModuleRequirement.new(:node, "less")
- y = LanguageModuleRequirement.new(:node, "coffee-script")
- refute_eql x, y
- refute_equal x.hash, y.hash
- end
-
- def test_differing_module_and_import_name
- mod_name = "foo"
- import_name = "bar"
- l = LanguageModuleRequirement.new(:python, mod_name, import_name)
- assert_includes l.message, mod_name
- assert_includes l.the_test, "import #{import_name}"
- end
-
- def test_bad_perl_deps
- assert_deps_fail "notapackage" => :perl
- end
-
- def test_good_perl_deps
- assert_deps_pass "Env" => :perl
- end
-
- def test_bad_python_deps
- needs_python
- assert_deps_fail "notapackage" => :python
- end
-
- def test_good_python_deps
- needs_python
- assert_deps_pass "datetime" => :python
- end
-
- def test_bad_ruby_deps
- assert_deps_fail "notapackage" => :ruby
- end
-
- def test_good_ruby_deps
- assert_deps_pass "date" => :ruby
- end
-end | true |
Other | Homebrew | brew | f33efbe7c46d4a148af00c83dff73c14717ed0d1.json | Convert LanguageModuleRequirement test to spec. | Library/Homebrew/test/spec_helper.rb | @@ -33,6 +33,10 @@
if example.metadata[:needs_macos]
skip "not on macOS" unless OS.mac?
end
+
+ if example.metadata[:needs_python]
+ skip "Python not installed." unless which("python")
+ end
end
config.around(:each) do |example|
begin | true |
Other | Homebrew | brew | 81d105d9a4cbdba1072c3828d173dcaac4bcc2a6.json | Convert String test to spec. | Library/Homebrew/test/string_spec.rb | @@ -0,0 +1,49 @@
+require "extend/string"
+
+describe String do
+ describe "#undent" do
+ it "removes leading whitespace, taking the first line as reference" do
+ string = <<-EOS.undent
+ hi
+........my friend over
+ there
+ EOS
+
+ expect(string).to eq("hi\n........my friend over\n there\n")
+ end
+
+ it "removes nothing if the text is not indented" do
+ string = <<-EOS.undent
+hi
+I'm not indented
+ EOS
+
+ expect(string).to eq("hi\nI'm not indented\n")
+ end
+
+ it "can be nested" do
+ nested_string = <<-EOS.undent
+ goodbye
+ EOS
+
+ string = <<-EOS.undent
+ hello
+ #{nested_string}
+ EOS
+
+ expect(string).to eq("hello\ngoodbye\n\n")
+ end
+ end
+end
+
+describe StringInreplaceExtension do
+ subject { string.extend(described_class) }
+ let(:string) { "foobar" }
+
+ describe "#sub!" do
+ it "adds an error to #errors when no replacement was made" do
+ subject.sub! "not here", "test"
+ expect(subject.errors).to eq(['expected replacement of "not here" with "test"'])
+ end
+ end
+end | true |
Other | Homebrew | brew | 81d105d9a4cbdba1072c3828d173dcaac4bcc2a6.json | Convert String test to spec. | Library/Homebrew/test/string_test.rb | @@ -1,40 +0,0 @@
-require "testing_env"
-require "extend/string"
-
-class StringTest < Homebrew::TestCase
- def test_undent
- undented = <<-EOS.undent
- hi
-....my friend over
- there
- EOS
- assert_equal "hi\n....my friend over\nthere\n", undented
- end
-
- def test_undent_not_indented
- undented = <<-EOS.undent
-hi
-I'm not indented
- EOS
- assert_equal "hi\nI'm not indented\n", undented
- end
-
- def test_undent_nested
- nest = <<-EOS.undent
- goodbye
- EOS
-
- undented = <<-EOS.undent
- hello
- #{nest}
- EOS
-
- assert_equal "hello\ngoodbye\n\n", undented
- end
-
- def test_inreplace_sub_failure
- s = "foobar".extend StringInreplaceExtension
- s.sub! "not here", "test"
- assert_equal ['expected replacement of "not here" with "test"'], s.errors
- end
-end | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.