I've create a project on Xcode 7 that generates code coverage data.
Inside its DerivedData folder, I can run llvm-cov show
:
/usr/local/opt/llvm/bin/llvm-cov show -instr-profile Build/Intermediates/CodeCoverage/testetestes/Coverage.profdata Build/Intermediates/CodeCoverage/testetestes/Products/Debug-iphonesimulator/testetestes.framework/testetestes
This will produce an output like this:
/Users/marcelofabri/Desktop/testetestes/testetestes/Example.swift:
| 1|//
| 2|// Example.swift
| 3|// testetestes
| 4|//
| 5|// Created by Marcelo Fabri on 09/06/15.
| 6|// Copyright © 2015 Marcelo Fabri. All rights reserved.
| 7|//
| 8|
| 9|import UIKit
| 10|
| 11|class Example: NSObject {
1| 12| func testando() {
1| 13| if let url = NSURL(string: "dasdas") {
1| 14| print("ae \(url)")
0| 15| } else {
0| 16| print("oi")
0| 17| }
1| 18| }
| 19|}
/Users/marcelofabri/Desktop/testetestes/testetestes/OutraClasse.swift:
| 1|//
| 2|// OutraClasse.swift
| 3|// testetestes
| 4|//
| 5|// Created by Marcelo Fabri on 18/06/15.
| 6|// Copyright © 2015 Marcelo Fabri. All rights reserved.
| 7|//
| 8|
| 9|import UIKit
| 10|
| 11|class OutraClasse: NSObject {
| 12|
1| 13| func outroTestando() {
1| 14| if let numero = Int("123") {
1| 15| print("ae \(numero)")
0| 16| } else {
0| 17| print("oi")
0| 18| }
1| 19| }
| 20|
| 21|}
However, I'd like to get .gcov
files, since it's what most tools use. Is there a way to do this without parsing the output and creating .gcov
file manually?
According to Apple gcov is not a part of Xcode 7 coverage support. Gcov was gcc legacy that stayed around till appearance of replacement. Apparently they dropped legacy gcov file format support in favor of new intermediate format — profdata. I did research on my own and didn't find any tools that converts profdata back to gcov, however there is Slather from Venom. Slather is able to generate coverage reports in Gutter JSON, Cobertura XML, HTML and plain test. It also able to provide integration with popular service like Coveralls. Currently it works also only with gcov, but they have issue opened and PR request pending for support of profdata. They usually move fast, so it likely soon will be merged into master.
Also if you will decide to write your own tool there are multiple approaches that you may consider for reviewing: