From ca1f5dc713313485b13512571cd222c4e89730a3 Mon Sep 17 00:00:00 2001 From: Baptiste Fontaine Date: Mon, 20 Jul 2015 21:46:05 +0200 Subject: [PATCH] more unit tests Closes Homebrew/homebrew#42096. Signed-off-by: Baptiste Fontaine --- Library/Homebrew/test/test_caveats.rb | 27 +++++++++++++++++++ Library/Homebrew/test/test_dependencies.rb | 14 ++++++++++ Library/Homebrew/test/test_formula.rb | 24 +++++++++++++++++ Library/Homebrew/test/test_options.rb | 15 +++++++++++ .../Homebrew/test/test_version_subclasses.rb | 6 +++++ 5 files changed, 86 insertions(+) create mode 100644 Library/Homebrew/test/test_caveats.rb diff --git a/Library/Homebrew/test/test_caveats.rb b/Library/Homebrew/test/test_caveats.rb new file mode 100644 index 0000000000..5708ebc03d --- /dev/null +++ b/Library/Homebrew/test/test_caveats.rb @@ -0,0 +1,27 @@ +require 'testing_env' + +class CaveatsTests < Homebrew::TestCase + def setup + @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 diff --git a/Library/Homebrew/test/test_dependencies.rb b/Library/Homebrew/test/test_dependencies.rb index b587cd12ac..7e4812ff71 100644 --- a/Library/Homebrew/test/test_dependencies.rb +++ b/Library/Homebrew/test/test_dependencies.rb @@ -71,6 +71,20 @@ class DependenciesTests < Homebrew::TestCase refute_equal a, b refute_eql a, b end + + def test_empty + a = Dependencies.new + assert a.empty? + a << Dependency.new("foo") + refute a.empty? + end + + def test_inspect + a = Dependencies.new + assert_equal "#", a.inspect + a << Dependency.new("foo") + assert_equal "#]>", a.inspect + end end class RequirementsTests < Homebrew::TestCase diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb index 47f807333e..11886ab05c 100644 --- a/Library/Homebrew/test/test_formula.rb +++ b/Library/Homebrew/test/test_formula.rb @@ -257,4 +257,28 @@ class FormulaTests < Homebrew::TestCase 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 end diff --git a/Library/Homebrew/test/test_options.rb b/Library/Homebrew/test/test_options.rb index e9d3d08362..604727961a 100644 --- a/Library/Homebrew/test/test_options.rb +++ b/Library/Homebrew/test/test_options.rb @@ -23,6 +23,10 @@ class OptionTests < Homebrew::TestCase assert_empty @option.description assert_equal "foo", Option.new("foo", "foo").description end + + def test_inspect + assert_equal "#", @option.inspect + end end class DeprecatedOptionTests < Homebrew::TestCase @@ -121,10 +125,21 @@ class OptionsTests < Homebrew::TestCase 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.inspect + @options << Option.new("foo") + assert_equal "#]>", @options.inspect + end end diff --git a/Library/Homebrew/test/test_version_subclasses.rb b/Library/Homebrew/test/test_version_subclasses.rb index 9261a7251a..75ee2f2865 100644 --- a/Library/Homebrew/test/test_version_subclasses.rb +++ b/Library/Homebrew/test/test_version_subclasses.rb @@ -44,4 +44,10 @@ class MacOSVersionTests < Homebrew::TestCase assert_equal @v, MacOS::Version.from_symbol(:lion) assert_raises(ArgumentError) { MacOS::Version.from_symbol(:foo) } end + + def test_pretty_name + assert_equal "El Capitan", MacOS::Version.new("10.11").pretty_name + assert_equal "Mountain Lion", MacOS::Version.new("10.8").pretty_name + assert_equal "Yosemite", MacOS::Version.new("10.10").pretty_name + end end