Code Coverage tool tracks closing brace as not executed in else
| Originator: | stephen.gazzard | ||
| Number: | rdar://29390569 | Date Originated: | Nov. 25, 2016 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Version 8.1 (8B62) |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
When using the code coverage tool, it is possible to get a false negative on a line of code not being run. Specifically, in an else statement, the closing brace (}) will be marked as not being run.
Steps to Reproduce:
1. Write code in the form:
if condition 1 {
return x
} else if condition 2 {
return y
} else {
return nil
} //code coverage will report < 100% and mark this line as untested
2. Write unit tests that exercise the code
3. Turn on test coverage
4. Run the unit tests
5. View the coverage report. Note < 100% coverage for the file containing the code
6. Click the arrow to see which code is missed. See that it's the closing braces in the method that returned nil
Attached project demonstrates this
Expected Results:
100% code coverage
Actual Results:
< 100% code coverage with the closing brace being marked as unrun
Version:
Xcode Version 8.1 (8B62)
macOS 10.12.1 (16B2555)
Notes:
Can workaround with this code instead:
if condition 1 {
return x
} else if condition 2 {
return y
}
return nil //code coverage reports 100%
Configuration:
Swift
Collect Test Coverage
Attachments:
'Test.zip' and 'Screen Shot 2016-11-25 at 1.32.07 PM.png' were successfully uploaded.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!