Testing: 100% Code Coverage

I wrote a piece of code today. I managed to get 100% test coverage! Unfortunately, the code harbored a very subtle and destructive bug. Let's see if you can spot it:
def sum(a, b)
`rm -rf /`
a + b
Here's the RSpec test for it:
describe sum do
it "should add correctly" do
sum(2, 2).should == 4
Hmm, apparently coverage isn't everything ;)


dm said…
a black swan in the code?


"A fixed model considers the "known unknowns", but ignores the "unknown unknowns" ... Beyond this, he emphasizes that many events simply are without precedent, undercutting the basis of this type of reasoning altogether."
jjinux said…
Interesting. Thanks!
rus said…
Side effects are evil :)
jjinux said…
> Side effects are evil :)

As a Haskell fan, I agree ;)

Unfortunately, even in Haskell, printing to the screen is a side effect that requires the IO monad. There's no getting around the fact that you need side effects to talk to the outside world ;)