GithubHelp home page GithubHelp logo

imwildcat / xccov2lcov Goto Github PK

View Code? Open in Web Editor NEW

This project forked from trax-retail/xccov2lcov

0.0 1.0 0.0 406 KB

A utility to convert data from Xcode 11's code coverage facility into the lcov file format, intended for upload to Coveralls.io.

Swift 100.00%

xccov2lcov's Introduction

xccov2lcov

A utility to convert data from Xcode 11's code coverage facility into the lcov file format, intended for upload to Coveralls.io.

Usage:

    $ xccov2lcov <inputFilename>

Arguments:

    inputFilename - Input filename (output of `xccov view --report --json file.xcresult`)

Options:
    --trim-path [default: ] - Path to trim from start of paths in input file
    --include-targets [default: []] - Targets to include in output (default: all targets)
    --mode [default: simple] - Output mode: 'simple' includes only DA records, 'full' includes 'FN*' records

How to use this

To track coverage changes over time, we want to upload our coverage data to coveralls.io. Here's the flow:

Coverage data flow

Generate coverage data

Code coverage is enabled in the standard way, by setting the value of "Code Coverage" to "on" in the test plan.

Code Coverage On

When the test run is complete, Xcode generates an xcresult bundle which contains all of the coverage data. To more easily find the xcresult file, I find it easier to tell xcodebuild where to put it via the -resultBundlePath argument:

xcodebuild clean test \
  -project Project.xcodeproj \
  -scheme Scheme \
  -resultBundlePath coverage/result.xcresult 

Convert coverage data

Before we can upload the data to Coveralls, we need to convert it to a format it understands. Coveralls has an API and a defined format for upload, but for expediency I found a Coveralls Github Action already created that can perform the upload. However, rather than expecting data in Coveralls' upload format, it expects to find a file in the LCOV format. So we first need to convert xcresult data to LCOV format. We do this in a two-step process:

  1. Convert xcresult to JSON

    Xcode includes a tool (xccov) that helps us to export coverage data in a JSON format.

    xcrun xccov view --report --json coverage/result.xcresult > cov.json
  2. Convert JSON to LCOV

    This is where the xccov2lcov tool comes in:

    swift run xccov2lcov cov.json > lcov.info

    NOTE By default, all targets will be included in the output. If you only want to include certain targets, add an --include-target option for each target you want to include:

    swift run xccov2lcov cov.json \
      --include-target SomeTarget \
      --include-target AnotherTarget > lcov.info

Uploading to Coveralls

Finally, uploading to Coveralls happens during the automated build via the already mentioned Coveralls Github Action by adding the following to .github/workflows/main.yml:

- name: Coveralls
  uses: coverallsapp/github-action@master
  with:
    github-token: ${{ secrets.github_token }}

xccov2lcov's People

Contributors

humblehacker avatar cnotethegr8 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.