From 25c0ecfd63270939aef8102e11afea161915f8c2 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sat, 13 Apr 2013 17:40:13 -0500 Subject: [PATCH] Add tests for formula spec selection These tests document the relative precedence of the stable, bottle, devel, and head specifications, and the conditions that can influence which is selected (e.g. command-line flags). --- Library/Homebrew/test/test_bottles.rb | 22 ----- .../test/test_formula_spec_selection.rb | 99 +++++++++++++++++++ 2 files changed, 99 insertions(+), 22 deletions(-) delete mode 100644 Library/Homebrew/test/test_bottles.rb create mode 100644 Library/Homebrew/test/test_formula_spec_selection.rb diff --git a/Library/Homebrew/test/test_bottles.rb b/Library/Homebrew/test/test_bottles.rb deleted file mode 100644 index 5c18cc6819..0000000000 --- a/Library/Homebrew/test/test_bottles.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'testing_env' -require 'test/testball' - -class BottleTests < Test::Unit::TestCase - def test_bottle_spec_selection - f = SnowLeopardBottleSpecTestBall.new - - assert_equal case MacOS.cat - when :snow_leopard then f.bottle - else f.stable - end, f.active_spec - - f = LionBottleSpecTestBall.new - assert_equal case MacOS.cat - when :lion then f.bottle - else f.stable - end, f.active_spec - - f = AllCatsBottleSpecTestBall.new - assert_equal f.bottle, f.active_spec - end -end diff --git a/Library/Homebrew/test/test_formula_spec_selection.rb b/Library/Homebrew/test/test_formula_spec_selection.rb new file mode 100644 index 0000000000..73cf97ad2b --- /dev/null +++ b/Library/Homebrew/test/test_formula_spec_selection.rb @@ -0,0 +1,99 @@ +require 'testing_env' +require 'formula' + +class FormulaSpecSelectionTests < Test::Unit::TestCase + def formula(*args, &block) + @_f = Class.new(Formula, &block).new(*args) + end + + def assert_spec_selected(spec) + assert_equal @_f.send(spec), @_f.active_spec + end + + def test_selects_head_when_requested + ARGV.stubs(:build_head?).returns(true) + + formula do + url 'foo-1.0' + devel { url 'foo-1.1a' } + head 'foo' + end + + assert_spec_selected :head + end + + def test_selects_devel_when_requested + ARGV.stubs(:build_devel?).returns(true) + + formula do + url 'foo-1.0' + devel { url 'foo-1.1a' } + head 'foo' + end + + assert_spec_selected :devel + end + + def test_selects_bottle_when_available + formula do + def install_bottle?(*); true; end + + url 'foo-1.0' + bottle do + { + :snow_leopard_32 => 'deadbeef'*5, + :snow_leopard => 'faceb00c'*5, + :lion => 'baadf00d'*5, + :mountain_lion => '8badf00d'*5, + }.each_pair do |cat, val| + sha1(val => cat) + end + end + end + + assert_spec_selected :bottle + end + + def test_selects_stable_by_default + formula do + url 'foo-1.0' + devel { url 'foo-1.1a' } + head 'foo' + end + + assert_spec_selected :stable + end + + def test_selects_stable_when_exclusive + formula do + url 'foo-1.0' + end + + assert_spec_selected :stable + end + + def test_selects_devel_before_head + formula do + devel { url 'foo-1.1a' } + head 'foo' + end + + assert_spec_selected :devel + end + + def test_selects_devel_when_exclusive + formula do + devel { url 'foo-1.1a' } + end + + assert_spec_selected :devel + end + + def test_selects_head_when_exclusive + formula do + head 'foo' + end + + assert_spec_selected :head + end +end