swift-test-codecov

我编写这个工具的原因是,能够读取 swift test --enable-code-coverage 生成的代码覆盖率报告的工具,竟然出乎意料地难以找到。

使用方法

库 (Library)

这个库有一个相当小巧且直观的接口。我还没有时间在 README 中详细描述它,但是查看可执行目标如何使用库目标,应该可以提供相当多的信息。

工具 (Tool)

这个工具旨在从你的项目根目录运行。可执行文件可以在任何地方,但当前工作目录对于工具准确识别哪些文件是你的项目的一部分,哪些文件是依赖项项目的一部分非常重要。

USAGE: swift-test-codecov <codecov-filepath> [--metric <metric>] [--minimum <minimum-coverage>] [--print-format <print-format>] [--sort <sort>] [--dependencies] [--no-dependencies] [--tests] [--no-tests]

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:
  -m, --metric <metric>   The metric over which to aggregate. One of lines, functions, instantiations (default: lines)
  -v, --minimum <minimum-coverage>
                          The minimum coverage allowed. A value between 0 and 100. Coverage below the minimum will result in
                          exit code 1. (default: 0)
  -p, --print-format <print-format>
                          Set the print format. One of minimal, 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)
  -h, --help              Show help information.

构建 Docker 镜像

运行 docker build -t swift-test-codecov . 来构建 Docker 镜像。