diff options
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/dependencies.rb | 29 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_external_deps.rb | 169 |
2 files changed, 49 insertions, 149 deletions
diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb index 3d92d45e6..06fa4b5d0 100644 --- a/Library/Homebrew/dependencies.rb +++ b/Library/Homebrew/dependencies.rb @@ -36,7 +36,7 @@ class DependencyCollector when Array @deps << Dependency.new(key, value) when *LANGUAGE_MODULES - @external_deps << LanguageModuleDependency.new(key, value) + @external_deps << LanguageModuleDependency.new(value, key) else # :optional, :recommended, :build, :universal and "32bit" are predefined @deps << Dependency.new(key, [value]) @@ -92,9 +92,10 @@ end # A dependency on a language-specific module. class LanguageModuleDependency < Requirement - def initialize module_name, type + def initialize language, module_name, import_name=nil + @language = language @module_name = module_name - @type = type + @import_name = import_name || module_name end def fatal?; true; end @@ -105,26 +106,26 @@ class LanguageModuleDependency < Requirement def message; <<-EOS.undent Unsatisfied dependency: #{@module_name} - Homebrew does not provide #{@type.to_s.capitalize} dependencies; install with: + Homebrew does not provide #{@language.to_s.capitalize} dependencies; install with: #{command_line} #{@module_name} EOS end def the_test - case @type - when :chicken then %W{/usr/bin/env csi -e (use #{@module_name})} - when :jruby then %W{/usr/bin/env jruby -rubygems -e require\ '#{@module_name}'} - when :lua then %W{/usr/bin/env luarocks show #{@module_name}} - when :node then %W{/usr/bin/env node -e require('#{@module_name}');} - when :perl then %W{/usr/bin/env perl -e use\ #{@module_name}} - when :python then %W{/usr/bin/env python -c import\ #{@module_name}} - when :ruby then %W{/usr/bin/env ruby -rubygems -e require\ '#{@module_name}'} - when :rbx then %W{/usr/bin/env rbx -rubygems -e require\ '#{@module_name}'} + case @language + when :chicken then %W{/usr/bin/env csi -e (use #{@import_name})} + when :jruby then %W{/usr/bin/env jruby -rubygems -e require\ '#{@import_name}'} + when :lua then %W{/usr/bin/env luarocks show #{@import_name}} + when :node then %W{/usr/bin/env node -e require('#{@import_name}');} + when :perl then %W{/usr/bin/env perl -e use\ #{@import_name}} + when :python then %W{/usr/bin/env python -c import\ #{@import_name}} + when :ruby then %W{/usr/bin/env ruby -rubygems -e require\ '#{@import_name}'} + when :rbx then %W{/usr/bin/env rbx -rubygems -e require\ '#{@import_name}'} end end def command_line - case @type + case @language when :chicken then "chicken-install" when :jruby then "jruby -S gem install" when :lua then "luarocks install" diff --git a/Library/Homebrew/test/test_external_deps.rb b/Library/Homebrew/test/test_external_deps.rb index ed6ce60ba..2d955dc26 100644 --- a/Library/Homebrew/test/test_external_deps.rb +++ b/Library/Homebrew/test/test_external_deps.rb @@ -9,194 +9,93 @@ require 'formula_installer' require 'utils' -class BadPerlBall <TestBall - depends_on "notapackage" => :perl - - def initialize name=nil - super "uses_perl_ball" - end -end - -class GoodPerlBall <TestBall - depends_on "ENV" => :perl - - def initialize name=nil - super "uses_perl_ball" - end -end - -class BadPythonBall <TestBall - depends_on "notapackage" => :python - - def initialize name=nil - super "uses_python_ball" - end -end - -class GoodPythonBall <TestBall - depends_on "datetime" => :python - - def initialize name=nil - super "uses_python_ball" - end -end - -class BadRubyBall <TestBall - depends_on "notapackage" => :ruby - - def initialize name=nil - super "uses_ruby_ball" - end -end - -class GoodRubyBall <TestBall - depends_on "date" => :ruby - - def initialize name=nil - super "uses_ruby_ball" - end -end - -class BadJRubyBall <TestBall - depends_on "notapackage" => :jruby - - def initialize name=nil - super "uses_jruby_ball" - end -end - -class GoodJRubyBall <TestBall - depends_on "date" => :jruby - - def initialize name=nil - super "uses_jruby_ball" - end -end - -class BadChickenBall <TestBall - depends_on "notapackage" => :chicken - - def initialize name=nil - super "uses_chicken_ball" - end -end - -class GoodChickenBall <TestBall - depends_on "extras" => :chicken - - def initialize name=nil - super "uses_chicken_ball" - end -end - -class BadRubiniusBall <TestBall - depends_on "notapackage" => :rbx - - def initialize name=nil - super "uses_rubinius_ball" - end -end - -class GoodRubiniusBall <TestBall - depends_on "date" => :rbx - - def intialize - super "uses_rubinius_ball" - end -end - -class BadNodeBall <TestBall - depends_on "notapackage" => :node - - def initialize - super "uses_node_ball" - end -end +class ExternalDepsTests < Test::Unit::TestCase + def check_deps_fail specs + d = DependencyCollector.new + specs.each do |key, value| + d.add key => value + end -class GoodNodeBall <TestBall - depends_on "util" => :node + # Should have found a dep + assert d.external_deps.size == 1 - def initialize - super "uses_node_balls" + d.external_deps do |dep| + assert !d.satisfied? + end end -end - -class ExternalDepsTests < Test::Unit::TestCase - def check_deps_fail f - assert_raises(UnsatisfiedRequirement) do - f.new.external_deps.each do |dep| - raise UnsatisfiedRequirement.new(f, dep) unless dep.satisfied? - end + def check_deps_pass specs + d = DependencyCollector.new + specs.each do |key, value| + d.add key => value end - end - def check_deps_pass f - assert_nothing_raised do - f.new.external_deps.each do |dep| - raise UnsatisfiedRequirement.new(f, dep) unless dep.satisfied? - end + # Should have found a dep + assert d.external_deps.size == 1 + + d.external_deps do |dep| + assert d.satisfied? end end def test_bad_perl_deps - check_deps_fail BadPerlBall + check_deps_fail "notapackage" => :perl end def test_good_perl_deps - check_deps_pass GoodPerlBall + check_deps_pass "ENV" => :perl end def test_bad_python_deps - check_deps_fail BadPythonBall + check_deps_fail "notapackage" => :python end def test_good_python_deps - check_deps_pass GoodPythonBall + check_deps_pass "datetime" => :python end def test_bad_ruby_deps - check_deps_fail BadRubyBall + check_deps_fail "notapackage" => :ruby end def test_good_ruby_deps - check_deps_pass GoodRubyBall + check_deps_pass "date" => :ruby end # Only run these next two tests if jruby is installed. def test_bad_jruby_deps - check_deps_fail BadJRubyBall unless `/usr/bin/which jruby`.chomp.empty? + check_deps_fail "notapackage" => :jruby if which('jruby') end def test_good_jruby_deps - check_deps_pass GoodJRubyBall unless `/usr/bin/which jruby`.chomp.empty? + check_deps_pass "date" => :jruby if which('jruby') end # Only run these next two tests if rubinius is installed. def test_bad_rubinius_deps - check_deps_fail BadRubiniusBall unless `/usr/bin/which rbx`.chomp.empty? + check_deps_fail "notapackage" => :rbx if which('rbx') end def test_good_rubinius_deps - check_deps_pass GoodRubiniusBall unless `/usr/bin/which rbx`.chomp.empty? + check_deps_pass "date" => :rbx if which('rbx') end # Only run these next two tests if chicken scheme is installed. def test_bad_chicken_deps - check_deps_fail BadChickenBall unless `/usr/bin/which csc`.chomp.empty? + check_deps_fail "notapackage" => :chicken if which('csc') end def test_good_chicken_deps - check_deps_pass GoodChickenBall unless `/usr/bin/which csc`.chomp.empty? + check_deps_pass "extras" => :chicken if which('csc') end # Only run these next two tests if node.js is installed. def test_bad_node_deps - check_deps_fail BadNodeBall unless `/usr/bin/which node`.chomp.empty? + check_deps_fail "notapackage" => :node if which('node') end def test_good_node_deps - check_deps_pass GoodNodeBall unless `/usr/bin/which node`.chomp.empty? + check_deps_pass "util" => :node if which('node') end end |
