2014-07-14 23:07:37 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
|
|
|
|
|
|
|
class TestRakeCpuCounter < Rake::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cpu_counter = Rake::CpuCounter.new
|
|
|
|
end
|
|
|
|
|
2014-10-24 23:52:46 -04:00
|
|
|
def test_count
|
|
|
|
num = @cpu_counter.count
|
|
|
|
skip 'cannot count CPU' if num == nil
|
|
|
|
assert_kind_of Numeric, num
|
|
|
|
assert_operator num, :>=, 1
|
2014-07-14 23:07:37 -04:00
|
|
|
end
|
|
|
|
|
2014-10-24 23:52:46 -04:00
|
|
|
def test_count_with_default_nil
|
|
|
|
def @cpu_counter.count; nil; end
|
|
|
|
assert_equal(8, @cpu_counter.count_with_default(8))
|
|
|
|
assert_equal(4, @cpu_counter.count_with_default)
|
|
|
|
end
|
2014-07-14 23:07:37 -04:00
|
|
|
|
2014-10-24 23:52:46 -04:00
|
|
|
def test_count_with_default_raise
|
|
|
|
def @cpu_counter.count; raise; end
|
|
|
|
assert_equal(8, @cpu_counter.count_with_default(8))
|
|
|
|
assert_equal(4, @cpu_counter.count_with_default)
|
2014-07-14 23:07:37 -04:00
|
|
|
end
|
|
|
|
|
2014-10-24 23:52:46 -04:00
|
|
|
class TestClassMethod < Rake::TestCase
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@klass = Class.new(Rake::CpuCounter)
|
2014-07-14 23:07:37 -04:00
|
|
|
end
|
|
|
|
|
2014-10-24 23:52:46 -04:00
|
|
|
def test_count
|
|
|
|
@klass.class_eval do
|
|
|
|
def count; 8; end
|
|
|
|
end
|
|
|
|
assert_equal(8, @klass.count)
|
|
|
|
end
|
2014-07-14 23:07:37 -04:00
|
|
|
|
2014-10-24 23:52:46 -04:00
|
|
|
def test_count_nil
|
|
|
|
counted = false
|
|
|
|
@klass.class_eval do
|
|
|
|
define_method(:count) do
|
|
|
|
counted = true
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_equal(4, @klass.count)
|
|
|
|
assert_equal(true, counted)
|
|
|
|
end
|
2014-07-14 23:07:37 -04:00
|
|
|
|
2014-10-24 23:52:46 -04:00
|
|
|
def test_count_raise
|
|
|
|
counted = false
|
|
|
|
@klass.class_eval do
|
|
|
|
define_method(:count) do
|
|
|
|
counted = true
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_equal(4, @klass.count)
|
|
|
|
assert_equal(true, counted)
|
2014-07-14 23:07:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|