I want to chime in here because I strive for this but there are cases where you simply cannot get 100% coverage. An example I recently ran into: consider code where you open a file (assume successfully), and then you do something with the IO object in a try/catch block. Here’s the concrete example in my case:
function savegraph(fn::AbstractString, g::AbstractGraph, gname::AbstractString,
format::LGCompressedFormat)
io = open(fn, "w")
try
io = GzipCompressorStream(io)
return savegraph(io, g, gname, LightGraphs.LGFormat())
catch
rethrow()
finally
close(io)
end
...
How do you reliably test that try/catch
block? You could, I suppose, induce a race condition whereby the disk gets filled up between the time the file is opened for writing and the time savegraph
is called, but that seems to be a crazy solution to get a couple of lines of code coverage that tests a system level failure.