In Xcode 10 I was able to get detailed coverage data by using `xccov` tool by calling:
- `xcrun xccov view --file-list` - to get all the paths to sources files
- `xcrun xccov view --file <path_to_source_file> <path_to_xcresult>` - to get line coverage data for the given file.
Looks like in Xcode 11 we should be able to get the same level of details by using `xcrun xccov view --report --files-for-target` and `xcrun xccov view --report --functions-for-file` but it does not work that way.
First issue I expirienced is mangled swift method names. When the `xcresult` file is created while running xcodebuild, the functions names are mangled.
Name Coverage
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------
CodeCoverageDemo.app 47.46% (28/59)
/Users/miwanicki1/TestProjects/CodeCoverageDemo/CodeCoverageDemo/SceneDelegate.swift 34.48% (10/29)
$s16CodeCoverageDemo13SceneDelegateC5scene_13willConnectTo7optionsySo7UISceneC_So0K7SessionCSo0K17ConnectionOptionsCtF 100.00% (6/6)
$s16CodeCoverageDemo13SceneDelegateC18sceneDidDisconnectyySo7UISceneCF 0.00% (0/6
Surprisingly, the issue does not occure when the tests are run in the Xcode.
Second issue is that when using the new xccov with `--report`, I do not get the line-level coverage for an idividual source file. `--files-for-target` seems to return only an overview of the function coverage without enumerating the lines and branches.
2019-10-15 11:55:38.950 xccov[19041:170343] Requested but did not find extension point with identifier Xcode.IDEFoundation.IDEResultKitSerializationConverter
/Users/miwanicki1/TestProjects/CodeCoverageDemo/CodeCoverageDemo/MathDemo.swift:
ID Name Range Coverage
-- ----------------------------------------------- ------- ------------
0 $s16CodeCoverageDemo04MathC0C3addyS2i_SitF {5, 6} 83.33% (5/6)
1 $s16CodeCoverageDemo04MathC0C5minusyS2i_SitF {12, 3} 0.00% (0/3)
2 $s16CodeCoverageDemo04MathC0C8multipleyS2i_SitF {16, 3} 0.00% (0/3)
Anyone had similar problems? What's the recommended way to get the line-level parsable coverage report similar to the format below where 1 means the lines was executed once, 0 the line wasn't executed.
1| func add(_ a: Int, _ b: Int) -> Int {
1| if a < 10 {
1| return a + b
1| }
0| if a == 20 {
0| return 1
0| }
0| if a == 30 {
0| return 2
0| }
0|
0| return a + 2 * b
1| }