How is --enable-code-coverage
intended to be used?
It feels like it lives in a grey area in between public interface and and implementation detail.
-
It is a documented part of the CLI, but
--help
leaves you in the dark about how to use it:$ swift test --help [...] --enable-code-coverage Test with code coverage enabled [...]
-
The Xcode 10.2 release notes provide a little more information, but still not enough to actually get the coverage information:
- The
swift test
command can generate code coverage data in a standard format suitable for consumption by other code coverage tools using the flag--enable-code-coverage
. The generated code coverage data is available inside <build-dir>/
<configuration>/codecov
. (44567442)
- The
To actually use it, one must reverse engineer two important details. Since neither is documented anywhere (that I can find), it is not clear to what extent these details should be relied on.
-
Where is the data actually?
[...]/codecov
is actually a folder containing.profdata
,.profraw
and.json
files. The.json
file seems to be the relevant one; it does contain all the information in an inspectable way. But what is it actually called? Experimentation suggests it resides at the root ofcodecov
and is named according to the declared package name. But are there any hidden surprises? What happens if the package name is not a valid filename? How is a script supposed to predict the filename and locate the file without relying on implementation details? -
How should it be loaded? The Xcode release notes state in a cryptic way that the data is in “a standard format suitable for consumption”? What is that standard format? Entering the JSON keys into a search engine leads to a comment in the LLVM source code. How stable is that format? Is it considered part of SwiftPM’s API contract? How are tools supposed to load the data without relying on implementation details?
Some of this has already been briefly mentioned over on this thread.
(To be clear, I have already figured out how to load the data. The question is only whether it can be done “properly” without assuming undocumented details. If it can’t, then the following question is what would need to be changed so that it can.)