Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is a closing brace showing no code coverage?

I've got a Swift function for which Xcode is showing 0 passes in code coverage. The line is a closing brace (highlighted in red below).

Is this a bug in Xcode? If not, what condition do I need to hit to run that line? I thought I was covering all paths through this method.

Code with un-covered line

like image 981
Dov Avatar asked Jan 05 '16 22:01

Dov


1 Answers

Pretty sure this is a bug (feature?) of Xcode code coverage. The issue boils down to the return statement not allowing it to fall down to the empty else statement, thus indicating the code is not executed. The return statements throw a wrench into whatever they are doing to count the lines of code.

In the instance of your try/catch block, you don't really have much choice there to prevent the empty execution.

As an experiment, remove the return statement and find a better way to catch the writeToURL statement so it doesn't execute in an error/catch statement. That will likely give you clean code coverage for that line.

like image 106
Bill Burgess Avatar answered Jan 05 '23 03:01

Bill Burgess