evanphx / benchmark-ips

Provides iteration per second benchmarking for Ruby
MIT License
1.72k stars 97 forks source link

Fix broken hold! when results file didn't exist #107

Closed ivoanjo closed 3 years ago

ivoanjo commented 3 years ago

In ed5c005071, the fix to allow the held results to be empty broke use of hold! when no pre-existing file existed.

This is because File.zero? of a non-existing file returns false, and thus in load_held_results the early return would not happen, resulting in a failed attempt to parse the non-existing file:

$ ruby examples/hold.rb
Traceback (most recent call last):
    3: from examples/hold.rb:22:in `<main>'
    2: from ~/ruby/benchmark-ips/lib/benchmark/ips.rb:58:in `ips'
    1: from ~/ruby/benchmark-ips/lib/benchmark/ips/job.rb:193:in `load_held_results'
~/ruby/benchmark-ips/lib/benchmark/ips/job.rb:193:in `read': No such file or directory @ rb_sysopen - temp_results (Errno::ENOENT)

the full fix here is to check that both:

nateberkopec commented 3 years ago

Cheers!

nateberkopec commented 3 years ago

Released as 2.8.4

ivoanjo commented 3 years ago

Thanks for the speedy review/release as well! Happy to contribute :blush:

nateberkopec commented 3 years ago

Thanks for submitting a bug report as a PR! With tests! It's like Christmas came early!