|
From: Rohrbach, M. <may...@am...> - 2025-01-22 17:28:22
|
Hello Cobertura dev community, Recently my team has been running into issues using Cobertura to represent coverage for our iOS (Swift) code base due to fact that Xcode expands closures and counts their executable lines when calculating coverage. See e.g., https://forums.developer.apple.com/forums/thread/720166 for an example of the issue, and https://docs.swift.org/swift-book/documentation/the-swift-programming-language/closures/ for general context on closures (i.e., anonymous functions or lambdas). Initially, we logged an issue with the library we were using for converting our results from Xcode -> Cobertura format (https://github.com/a7ex/xcresultparser/issues/50) but the discussion on this thread made me wonder whether it is even possible to represent closures in Cobertura, since the “executable lines” in this case do not correspond 1:1 with lines in a code file and in fact Xcode seemingly does not report on what specific “lines” are being covered within a closure, just the start line and number of covered vs total executable lines. To take one specific example within our code base, we have a class that has 226 executable lines according to Xcode, with 77 lines of closures – but the file itself only has 182 lines. It’s not clear whether this type of situation is possible for Cobertura to represent given that we clearly cannot point to specific executable lines within the file for the additional 77 lines from closures that Xcode is considering. It is perhaps worth noting that Sonar runs into the exact same issue, which makes me wonder if it is a fundamental difference in how Xcode is representing coverage versus the standard employed by other coverage frameworks: https://sonarsource.atlassian.net/browse/SONARSWIFT-560 So, my question would be, is there currently any way to accurately represent executable lines from anonymous functions like Swift closures in Cobertura? Any input would be appreciated. Thanks! May R |