Skip to main content

Reports on (previously run) coverage results for a commit.

Project description

This allows you to assess the coverage of changes you have in a repo. It is intended for use, when preparing to push code up for review upstream.

Usage

As a prerequisite to using this script, run coverage in the repo, to produce coverage report files in a ‘cover’ directory at the root of the repo’s tree. This coverage should be done on the code that will be upstreamed (either what is in the working directory, or what has been committed to the local repo).

Behavior

Assuming you have a repo with uncommitted changes, you can run the command as follows:

commit_coverage /opt/stack/networking-cisco

The argument must be the root of a git repo that has coverage data in a ‘cover’ subdirectory.

By default, this will create diffs comparing the working directory, to the latest commit (HEAD), with (up to) three lines of context. That output will be checked against coverage data and a report produced. Here’s what the output looks like:

devstack/csr1kv/cisco_neutron (No coverage data)

networking_cisco/apps/saf/agent/dfa_agent.py (No added/changed lines)

networking_cisco/apps/saf/server/dfa_server.py (run=1, mis=1, par=0, ign=0) 47%
   32 run  import time
   33
   34
   35 run +from networking_cisco._i18n import _LE, _LI, _LW
   36 run  from oslo_serialization import jsonutils
   37
   38

  382              # it is created by openstack.
  383 run          part_name = self.cfg.dcnm.default_partition_name
  384 par          if len(':'.join((proj_name, part_name))) > 32:
  385 mis +            LOG.error(_LE('Invalid project name length: %s. The length of '
  386                                'org:part name is greater than 32'),
  387                            len(':'.join((proj_name, part_name))))
  388 mis              return

Each file from the diff will be reported. If the file was not processed by the coverage test, or there were no added or changed lines in the diff for the file, this will be reported, as shown in the first two files.

For files with coverage data and added/changes lines, the output will look like the third file. Each line number from the diff is shown, with the coverage status, which can be:

  • ‘run’ The line was invoked as part of coverage run

  • ‘mis’ The line was not invoked during coverage

  • ‘par’ The line was partially covered

  • ‘ ‘ The line was not considered for coverage (e.g. blank, non-executable)

Next, if the line was added/changed, a ‘+’ is shown. If it was a context line for the diff region, a ‘ ‘ is shown. Deleted lines are not shown. After that, the source code is show.

Next to the filename is summary information, ONLY for lines that were added or changed. In the example, there was one line run and one missing in the change set (lines with a plus sign). At the end, we can see the overall coverage report for the FILE - 47% in this example.

There are a few knobs that you can use with this script. First, you can change the number of context lines shown by using the –context argument. The default is three, and can be zero or more. Note: if a diff region is at the start or end of a file, there may be fewer or no context lines.

Second, you can select which commits are used for the diff calculation, by specifying the –which argument. The default is ‘working’, which will do a diff between the working directory and latest commit (HEAD). Instead, you can provide ‘committed’, which will compare the current commit against the previous commit (HEAD^..HEAD). Otherwise, you can provide the commit versions to use for the diff, just make sure that the most recent corresponds to the coverage report. For example, you can do:

cd /opt/stack/neutron
commit_coverage --context 5 --which HEAD~5..HEAD~ .

This runs the tool on a neutron repo, shows more context lines, and will do a diff between HEAD~5 and HEAD~ commits.

You can use the -h option to see what the arguments are for this script.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

commit-coverage-0.7.tar.gz (6.9 kB view details)

Uploaded Source

File details

Details for the file commit-coverage-0.7.tar.gz.

File metadata

File hashes

Hashes for commit-coverage-0.7.tar.gz
Algorithm Hash digest
SHA256 20a373cca16996cc33680f4589a8a33c10a388c8f2919ca545a27110712c1389
MD5 872ac118bf1931876a59e5cb509f9458
BLAKE2b-256 ed5648c9426bbb26bf7851421a83a805575a2151f9f4d2d1072e9f3bc83932d7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page