summaryrefslogtreecommitdiff
path: root/test/rake
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-25 03:52:46 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-25 03:52:46 +0000
commit26143970c1300d09f9063ff77ba9b4d15472b9c8 (patch)
treec55dcca7c6efc1c0d1d38fd1cb6cfc8bfc815df2 /test/rake
parent5940b1f6fc6745e4cb7516345a24b9b45567d21b (diff)
rake/cpu_counter.rb: use Etc.nprocessors
* lib/rake/cpu_counter.rb (count): prefer Etc.nprocessors, which is hundreds times faster. * test/rake/test_rake_cpu_counter.rb: add tests for features, and remove useless tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rake')
-rw-r--r--test/rake/test_rake_cpu_counter.rb74
1 files changed, 46 insertions, 28 deletions
diff --git a/test/rake/test_rake_cpu_counter.rb b/test/rake/test_rake_cpu_counter.rb
index ccf21d8ba6..87d0601c6c 100644
--- a/test/rake/test_rake_cpu_counter.rb
+++ b/test/rake/test_rake_cpu_counter.rb
@@ -8,43 +8,61 @@ class TestRakeCpuCounter < Rake::TestCase
@cpu_counter = Rake::CpuCounter.new
end
- def test_count_via_win32
- if Rake::Win32.windows? then
- assert_kind_of Numeric, @cpu_counter.count_via_win32
- else
- assert_nil @cpu_counter.count_via_win32
- end
+ def test_count
+ num = @cpu_counter.count
+ skip 'cannot count CPU' if num == nil
+ assert_kind_of Numeric, num
+ assert_operator num, :>=, 1
end
- def test_in_path_command
- with_ruby_in_path do |ruby|
- assert_equal ruby, @cpu_counter.in_path_command(ruby)
- end
- rescue Errno::ENOENT => e
- raise unless e.message =~ /\bwhich\b/
+ 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
- skip 'cannot find which for this test'
+ 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)
end
- def test_run
- with_ruby_in_path do |ruby|
- assert_equal 7, @cpu_counter.run(ruby, '-e', 'puts 3 + 4')
+ class TestClassMethod < Rake::TestCase
+ def setup
+ super
+
+ @klass = Class.new(Rake::CpuCounter)
end
- end
- def with_ruby_in_path
- ruby = File.basename Gem.ruby
- ruby_dir = File.dirname Gem.ruby
+ def test_count
+ @klass.class_eval do
+ def count; 8; end
+ end
+ assert_equal(8, @klass.count)
+ end
- begin
- orig_path, ENV['PATH'] =
- ENV['PATH'], [ruby_dir, *ENV['PATH']].join(File::PATH_SEPARATOR)
+ 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
- yield ruby
- ensure
- ENV['PATH'] = orig_path
+ 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)
end
end
-
end
-