From fe4f39dcee409c8b9b164f20d86024ae02a792b2 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 13 Jan 2013 20:05:09 -0600 Subject: Split up dependency test coverage The DependencyCollector tests are really integration tests, while the rest are closer to real unit tests. Split them up so that the tests can be run in isolation on a per-class basis. --- Library/Homebrew/test/test_dependencies.rb | 83 ---------- Library/Homebrew/test/test_dependency.rb | 51 +++++++ Library/Homebrew/test/test_dependency_collector.rb | 170 +++++++++++++++++++++ Library/Homebrew/test/test_requirement.rb | 28 ++++ Library/Homebrew/test/test_requirements.rb | 154 ------------------- 5 files changed, 249 insertions(+), 237 deletions(-) create mode 100644 Library/Homebrew/test/test_dependency.rb create mode 100644 Library/Homebrew/test/test_dependency_collector.rb create mode 100644 Library/Homebrew/test/test_requirement.rb delete mode 100644 Library/Homebrew/test/test_requirements.rb diff --git a/Library/Homebrew/test/test_dependencies.rb b/Library/Homebrew/test/test_dependencies.rb index 68c4043cb..acf613b3d 100644 --- a/Library/Homebrew/test/test_dependencies.rb +++ b/Library/Homebrew/test/test_dependencies.rb @@ -1,40 +1,6 @@ require 'testing_env' -require 'test/testball' require 'dependencies' -module DependencyCollectorTestExtension - def find_dependency(name) - deps.find { |dep| dep.name == name } - end -end - -class DependencyCollectorTests < Test::Unit::TestCase - def setup - @d = DependencyCollector.new.extend(DependencyCollectorTestExtension) - end - - def test_dependency_creation - @d.add 'foo' => :build - @d.add 'bar' => ['--universal', :optional] - assert_not_nil @d.find_dependency('foo') - assert_equal 2, @d.find_dependency('bar').tags.length - end - - def test_dependency_tags - assert Dependency.new('foo', :build).build? - assert Dependency.new('foo', [:build, :optional]).optional? - assert Dependency.new('foo', [:universal]).options.include? '--universal' - assert_empty Dependency.new('foo').tags - end - - def test_no_duplicate_dependencies - @d.add 'foo' - @d.add 'foo' => :build - assert_equal 1, @d.deps.count - assert_empty @d.find_dependency('foo').tags - end -end - class DependenciesTests < Test::Unit::TestCase def setup @deps = Dependencies.new @@ -71,52 +37,3 @@ class DependenciesTests < Test::Unit::TestCase assert_instance_of Array, @deps.to_ary end end - -class DependableTests < Test::Unit::TestCase - def setup - @tags = ["foo", "bar", :build] - @dep = Struct.new(:tags).new(@tags).extend(Dependable) - end - - def test_options - assert_equal %w{--foo --bar}.sort, @dep.options.sort - end - - def test_interrogation - assert @dep.build? - assert !@dep.optional? - assert !@dep.recommended? - end -end - -class DependencyTests < Test::Unit::TestCase - def test_accepts_single_tag - dep = Dependency.new("foo", "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_equality - foo1 = Dependency.new("foo") - foo2 = Dependency.new("foo") - bar = Dependency.new("bar") - assert_equal foo1, foo2 - assert foo1.eql?(foo2) - assert_not_equal foo1, bar - assert !foo1.eql?(bar) - end -end diff --git a/Library/Homebrew/test/test_dependency.rb b/Library/Homebrew/test/test_dependency.rb new file mode 100644 index 000000000..a043c1bd5 --- /dev/null +++ b/Library/Homebrew/test/test_dependency.rb @@ -0,0 +1,51 @@ +require 'testing_env' +require 'dependencies' + +class DependableTests < Test::Unit::TestCase + def setup + @tags = ["foo", "bar", :build] + @dep = Struct.new(:tags).new(@tags).extend(Dependable) + end + + def test_options + assert_equal %w{--foo --bar}.sort, @dep.options.sort + end + + def test_interrogation + assert @dep.build? + assert !@dep.optional? + assert !@dep.recommended? + end +end + +class DependencyTests < Test::Unit::TestCase + def test_accepts_single_tag + dep = Dependency.new("foo", "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_equality + foo1 = Dependency.new("foo") + foo2 = Dependency.new("foo") + bar = Dependency.new("bar") + assert_equal foo1, foo2 + assert foo1.eql?(foo2) + assert_not_equal foo1, bar + assert !foo1.eql?(bar) + end +end diff --git a/Library/Homebrew/test/test_dependency_collector.rb b/Library/Homebrew/test/test_dependency_collector.rb new file mode 100644 index 000000000..ded49f91f --- /dev/null +++ b/Library/Homebrew/test/test_dependency_collector.rb @@ -0,0 +1,170 @@ +require 'testing_env' +require 'dependencies' +require 'extend/set' + +module DependencyCollectorTestExtension + def find_dependency(name) + deps.find { |dep| dep.name == name } + end + + def find_requirement(klass) + requirements.find { |req| klass === req } + end +end + +class DependencyCollectorTests < Test::Unit::TestCase + def setup + @d = DependencyCollector.new.extend(DependencyCollectorTestExtension) + end + + def test_dependency_creation + @d.add 'foo' => :build + @d.add 'bar' => ['--universal', :optional] + assert_not_nil @d.find_dependency('foo') + assert_equal 2, @d.find_dependency('bar').tags.length + end + + def test_dependency_tags + assert Dependency.new('foo', :build).build? + assert Dependency.new('foo', [:build, :optional]).optional? + assert Dependency.new('foo', [:universal]).options.include? '--universal' + assert_empty Dependency.new('foo').tags + end + + def test_no_duplicate_dependencies + @d.add 'foo' + @d.add 'foo' => :build + assert_equal 1, @d.deps.count + assert_empty @d.find_dependency('foo').tags + end + + def test_requirement_creation + @d.add :x11 + assert_not_nil @d.find_requirement(X11Dependency) + end + + def test_no_duplicate_requirements + 2.times { @d.add :x11 } + assert_equal 1, @d.requirements.length + end + + def test_requirement_tags + @d.add :x11 => '2.5.1' + @d.add :xcode => :build + assert_empty @d.find_requirement(X11Dependency).tags + assert @d.find_requirement(XcodeDependency).build? + end + + def test_x11_no_tag + @d.add :x11 + assert_empty @d.find_requirement(X11Dependency).tags + end + + def test_x11_min_version + @d.add :x11 => '2.5.1' + assert_equal '2.5.1', @d.find_requirement(X11Dependency).min_version + end + + def test_x11_tag + @d.add :x11 => :optional + assert @d.find_requirement(X11Dependency).optional? + end + + def test_x11_min_version_and_tag + @d.add :x11 => ['2.5.1', :optional] + dep = @d.find_requirement(X11Dependency) + assert_equal '2.5.1', dep.min_version + assert dep.optional? + 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 + + # Should have found a dep + assert d.requirements.size == 1 + + d.requirements do |req| + assert !d.satisfied? + end + end + + def check_deps_pass specs + d = DependencyCollector.new + specs.each do |key, value| + d.add key => value + end + + # Should have found a dep + assert d.requirements.size == 1 + + d.requirements do |req| + assert d.satisfied? + end + end + + + def test_bad_perl_deps + check_deps_fail "notapackage" => :perl + end + + def test_good_perl_deps + check_deps_pass "ENV" => :perl + end + + def test_bad_python_deps + check_deps_fail "notapackage" => :python + end + + def test_good_python_deps + check_deps_pass "datetime" => :python + end + + def test_bad_ruby_deps + check_deps_fail "notapackage" => :ruby + end + + def test_good_ruby_deps + check_deps_pass "date" => :ruby + end + + # Only run these next two tests if jruby is installed. + def test_bad_jruby_deps + check_deps_fail "notapackage" => :jruby if which('jruby') + end + + def test_good_jruby_deps + 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 "notapackage" => :rbx if which('rbx') + end + + def test_good_rubinius_deps + 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 "notapackage" => :chicken if which('csc') + end + + def test_good_chicken_deps + 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 "notapackage" => :node if which('node') + end + + def test_good_node_deps + check_deps_pass "util" => :node if which('node') + end +end diff --git a/Library/Homebrew/test/test_requirement.rb b/Library/Homebrew/test/test_requirement.rb new file mode 100644 index 000000000..fabada066 --- /dev/null +++ b/Library/Homebrew/test/test_requirement.rb @@ -0,0 +1,28 @@ +require 'testing_env' +require 'dependencies' + +class RequirementTests < Test::Unit::TestCase + def test_accepts_single_tag + dep = Requirement.new("bar") + assert_equal %w{bar}, dep.tags + end + + def test_accepts_multiple_tags + dep = Requirement.new(%w{bar baz}) + assert_equal %w{bar baz}.sort, dep.tags.sort + dep = Requirement.new(*%w{bar baz}) + assert_equal %w{bar baz}.sort, dep.tags.sort + end + + def test_preserves_symbol_tags + dep = Requirement.new(:build) + assert_equal [:build], dep.tags + end + + def test_accepts_symbol_and_string_tags + dep = Requirement.new([:build, "bar"]) + assert_equal [:build, "bar"], dep.tags + dep = Requirement.new(:build, "bar") + assert_equal [:build, "bar"], dep.tags + end +end diff --git a/Library/Homebrew/test/test_requirements.rb b/Library/Homebrew/test/test_requirements.rb deleted file mode 100644 index c8a8e1ba8..000000000 --- a/Library/Homebrew/test/test_requirements.rb +++ /dev/null @@ -1,154 +0,0 @@ -require 'testing_env' -require 'test/testball' -require 'dependencies' - -class DependencyCollector - def find_requirement(klass) - requirements.find do |req| - klass === req - end - end -end - -class RequirementTests < Test::Unit::TestCase - def setup - @d = DependencyCollector.new - end - - def test_requirement_creation - @d.add :x11 - assert_not_nil @d.find_requirement(X11Dependency) - end - - - def test_no_duplicate_requirements - 2.times { @d.add :x11 } - assert_equal 1, @d.requirements.length - end -end - -class RequirementTagTests < Test::Unit::TestCase - def setup - @d = DependencyCollector.new - end - - def test_requirement_tags - @d.add :x11 => '2.5.1' - @d.add :xcode => :build - assert_empty @d.find_requirement(X11Dependency).tags - assert @d.find_requirement(XcodeDependency).build? - end - - def test_x11_no_tag - @d.add :x11 - assert_empty @d.find_requirement(X11Dependency).tags - end - - def test_x11_min_version - @d.add :x11 => '2.5.1' - assert_equal '2.5.1', @d.find_requirement(X11Dependency).min_version - end - - def test_x11_tag - @d.add :x11 => :optional - assert @d.find_requirement(X11Dependency).optional? - end - - def test_x11_min_version_and_tag - @d.add :x11 => ['2.5.1', :optional] - dep = @d.find_requirement(X11Dependency) - assert_equal '2.5.1', dep.min_version - assert dep.optional? - 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 - - # Should have found a dep - assert d.requirements.size == 1 - - d.requirements do |req| - assert !d.satisfied? - end - end - - def check_deps_pass specs - d = DependencyCollector.new - specs.each do |key, value| - d.add key => value - end - - # Should have found a dep - assert d.requirements.size == 1 - - d.requirements do |req| - assert d.satisfied? - end - end - - - def test_bad_perl_deps - check_deps_fail "notapackage" => :perl - end - - def test_good_perl_deps - check_deps_pass "ENV" => :perl - end - - def test_bad_python_deps - check_deps_fail "notapackage" => :python - end - - def test_good_python_deps - check_deps_pass "datetime" => :python - end - - def test_bad_ruby_deps - check_deps_fail "notapackage" => :ruby - end - - def test_good_ruby_deps - check_deps_pass "date" => :ruby - end - - # Only run these next two tests if jruby is installed. - def test_bad_jruby_deps - check_deps_fail "notapackage" => :jruby if which('jruby') - end - - def test_good_jruby_deps - 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 "notapackage" => :rbx if which('rbx') - end - - def test_good_rubinius_deps - 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 "notapackage" => :chicken if which('csc') - end - - def test_good_chicken_deps - 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 "notapackage" => :node if which('node') - end - - def test_good_node_deps - check_deps_pass "util" => :node if which('node') - end -end -- cgit v1.2.3