From aa69b671b347a7b22daa5bbad7d166fdab45e3e1 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Wed, 13 Mar 2013 02:07:01 -0500 Subject: Use a priority queue to select compilers The existing case-statement with nested if-statements is gross and hard to extend. Replacing it with a priority queue simplifies the logic and makes it very easy to add new compilers to the fails_with system, which we will likely want to do in the future. --- Library/Homebrew/test/test_compiler_queue.rb | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Library/Homebrew/test/test_compiler_queue.rb (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/test_compiler_queue.rb b/Library/Homebrew/test/test_compiler_queue.rb new file mode 100644 index 000000000..6dee1ab37 --- /dev/null +++ b/Library/Homebrew/test/test_compiler_queue.rb @@ -0,0 +1,38 @@ +require 'testing_env' +require 'compilers' + +class CompilerQueueTests < Test::Unit::TestCase + FakeCompiler = Struct.new(:name, :priority) + + def setup + @q = CompilerQueue.new + end + + def test_shovel_returns_self + assert_same @q, (@q << Object.new) + end + + def test_empty + assert @q.empty? + end + + def test_queues_items + a = FakeCompiler.new(:foo, 0) + b = FakeCompiler.new(:bar, 0) + @q << a << b + assert_equal a, @q.pop + assert_equal b, @q.pop + assert_nil @q.pop + end + + def test_pops_items_by_priority + a = FakeCompiler.new(:foo, 0) + b = FakeCompiler.new(:bar, 0.5) + c = FakeCompiler.new(:baz, 1) + @q << a << b << c + assert_equal c, @q.pop + assert_equal b, @q.pop + assert_equal a, @q.pop + assert_nil @q.pop + end +end -- cgit v1.2.3