我写这个是因为能够解析 swift test --enable-code-coverage
生成的代码覆盖率报告的工具出乎意料地难以找到。
这个库有一个非常小巧且直接的接口。我还没有时间在这里的 README 文件中写关于它的内容,但是看看可执行目标如何使用库目标应该会很有启发性。
这个工具旨在从你项目的根文件夹运行。可执行文件可以在任何地方,但当前工作目录很重要,为了让工具能够准确识别哪些文件是你项目的一部分,哪些文件是依赖项目的一部分。
OVERVIEW: Analyze Code Coverage Metrics
Ingest Code Coverage Metrics provided by `swift test --enable-code-coverage` and provide some high level analysis.
USAGE: swift-test-codecov <options>
ARGUMENTS:
<codecov-filepath> The location of the JSON file output by `swift test --enable-code-coverage`.
You will find this in the build directory.
For example, if you've just performed a debug build, the file will be located at `./.build/debug/codecov/<package-name>.json`.
OPTIONS:
--project-name <project-name>
The name of the target project.
If specified, used to determine which source files being tested are outside of this project (local dependencies).
-m, --metric <metric> The metric over which to aggregate. One of lines, functions, instantiations (default: lines)
-v, --minimum <minimum-coverage>
The minimum coverage percentage allowed. A value between 0 and 100. Coverage below the minimum will result in exit code 1. (default: 0.0)
--explain-failure/--no-explain-failure
Determines whether a message will be displayed if the minimum coverage threshold was not met. (The `json` print-format will never display messages and will always be parsable
JSON.) (default: true)
-p, --print-format <print-format>
Set the print format. One of minimal, numeric, table, json (default: minimal)
-s, --sort <sort> Set the sort order for the coverage table. One of filename, +cov, -cov (default: filename)
--dependencies/--no-dependencies
Determines whether dependencies are included in code coverage calculation. (default: false)
--tests/--no-tests Determines whether test files are included in coverage calculation. (default: false)
-x, --exclude-path <regex>
Regex pattern of full file paths to exclude in coverage calculation.
If specified, used to determine which source files being tested should be excluded. (Example value "View\.swift|Mock\.swift" excludes all files with names ending with `View` or `Mock`.)
If the regular expression cannot be parsed by the system, the application will exit with code 1. An error message will be printed unless the `print-format` is set to `json`, in which case an
empty object (`{}`) will be printed.
--warn-missing-tests/--no-warn-missing-tests
Determines whether a warning will be displayed if no coverage data is available. (The `json` print-format will never display messages and will always be parsable JSON.)
(default: true)
-h, --help Show help information.
运行 docker build -t swift-test-codecov .
来构建 Docker 镜像。
运行 sudo make install
来安装。
运行 sudo make uninstall
来卸载。