New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-9145] No coverage generated for functions in extensions #51641
Comments
cc @vedantk |
Comment by Steve Riggins (JIRA) I have opened Radar 45468318 for this issue, and it covers a couple others. However in short: class FilePrivateSwiftClass {
@discardableResult public class func steveWasHere(value: Int) -> Bool {
return classHelper(value: value)
}
fileprivate class func classHelper(value: Int) -> Bool {
if value >= 42 {
return true
}
return false
}
} class helper gets coverage data. If I then: extension FilePrivateSwiftClass {
@discardableResult public class func wyattWasHere(value: Int) -> Bool {
return wyattClassHelper(value: value)
}
fileprivate class func wyattClassHelper(value: Int) -> Bool {
if value >= 42 {
return true
}
return false
}
} wyattClassHelper does not. I can even make it public and test it directly, and it will not get coverage data. It's as if the code does not exist. Now for the fun part: Remove the test calling wyattWasHere, and wyattClassHelper still has no coverage. However, comment out wyattWasHere, and now wyattClassHelper shows red with no coverage. |
Comment by Steve Riggins (JIRA) Is there any followup on this? Our code coverage is being severely impacted by the changes in 10 (in addition we are seeing random runs report 0% for some files, but that is a different bug and once I have an isolated, reproducible case, will file that issue) |
Comment by Oleg Danu (JIRA) Are there any updates here? Since I upgraded to XCode 11.4, the code coverage regressed the same way as described above. Basically, it looks like only some of the class variable definitions get coverage and none of the functions are covered at all, with 100% per file coverage. |
Comment by Wes Campaigne (JIRA) For anyone encountering issues like this: Make sure your testing build configs are set to use "incremental" Swift compilation mode, and not "whole module". The coverage data generated in whole module mode seems to just ignore most Swift code. |
Note some fixes for WMO + coverage are landing in Xcode 12.2, if this still repros easily can someone test that version to see if it's fixed |
@keith will do! |
Comment by Oleg Danu (JIRA) Setting Swift Compilation Mode to `Incremental` on the Tests target didn't solve the issue for me, on XCode 12.0 |
Comment by Wes Campaigne (JIRA) @keith Thanks for the tip! Looks like (for at least one simple test case) WMO + coverage is working in Xcode 12.2 beta 3 where it wasn't in Xcode 12.1. |
Seems to be fixed on Xcode 12.3 and onward (haven't tried on 12.2). |
AFAICT this is fixed in Xcode 12.4 (maybe earlier too but I didn't test). Although we are using `-num-threads 0` currently since we found this also solved this issue in the past with WMO (I'm not recommending this but just a tip if folks hit this again in the future). Thanks everyone! |
Attachment: Download
Environment
Xcode 10.0, Xcode 10.1 (10B61). Swift 4.2, Xcode 11.4
Additional Detail from JIRA
md5: 7c7ba01e0abdb033ab8272758f7d9824
Issue Description:
In the example below there is no coverage data produced for
extensionMethodGeneric()
method.If
return r.extensionMethodGeneric()
is commented out (e.g. replace withreturn 0
), coverage forextensionMethodGeneric()
is gathered as expected (0 hits).Upd: issue also reproduces if instead of a generic type a regular struct is used.
The text was updated successfully, but these errors were encountered: