Skip to content

Commit

Permalink
Fix count_via_win32 on non-win32
Browse files Browse the repository at this point in the history
When rake does not recognize your platform in CpuCounter it tries all
known methods.  If your platform is not a windows platform you will not
have win32ole so a LoadError was raised but not rescued.

Now the LoadError is rescued so rake can try alternate mechanisms.

See #261
  • Loading branch information
drbrain committed Mar 25, 2014
1 parent 5ea79c0 commit 02a5801
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rake/cpu_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def count_via_win32
wmi = WIN32OLE.connect("winmgmts://")
cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") # TODO count hyper-threaded in this
cpu.to_enum.first.NumberOfCores
rescue StandardError
rescue StandardError, LoadError
nil
end

Expand Down
8 changes: 8 additions & 0 deletions test/test_rake_cpu_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ def setup
@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
end

def test_in_path_command
with_ruby_in_path do |ruby|
assert_equal ruby, @cpu_counter.in_path_command(ruby)
Expand Down

0 comments on commit 02a5801

Please sign in to comment.