### 13.7 Code Coverage

GPS provides a tight integration with Gcov, the GNU code coverage utility.

Code coverage information can be computed from, loaded and visualized in GPS. This can be done file by file, for each files of the current project, project by project (in case of dependencies) or for the entire project hierarchy currently used in GPS.

Once computed then loaded, the coverage information is summarized in a graphical report (shaped as a tree-view with percentage bars for each item) and used to decorate source code through mechanisms such as line highlighting or coverage annotations.

All the coverage related operations are reachable via the `Tools->Coverage` menu.

In order to be loaded in GPS, the coverage information need to be computed before, using the `Tools->Coverage->Gcov->Compute coverage files` menu for instance.

At each attempt, GPS automatically tries to load the needed information and reports errors for missing or corrupted `.gcov` files.

To be able to produce coverage information from Gcov, your project must have been compiled with the `-fprofile-arcs` and `-ftest-coverage`" switches, respectively "Instrument arcs" and "Code coverage" entries in The Project Properties Editor, and run once.

#### 13.7.1 Coverage Menu

The `Tools->Coverage` menu has a number of entries, depending on the context:

`Gcov->Compute coverage files`
  Generates the `.gcov` files of current and properly compiled and run projects.
`Gcov->Remove coverage files`
  Deletes all the `.gcov` of current projects.
`Show report`
  Open a new window summarizing the coverage information currently loaded in GPS.
`Load data for all projects`
  Load or re-load the coverage information of every projects and subprojects.
`Load data for project `XXX``
  Load or re-load the coverage information of the project `XXX`.
`Load data for `xxxxxxxx.xxx``
  Load or re-load the coverage information of the specified source file.
`Clear coverage from memory`
  Drop every coverage information loaded in GPS.

#### 13.7.2 The Contextual Menu

When clicking on a project, file or subprogram entity (including the entities listed in the coverage report), you have access to a `Coverage` submenu.

This submenu contains the following entries, adapted to the entity selected. For instance, if you click on a file, you will have:

`Show coverage information`
  Append an annotation column to the left side of the current source editor. This column indicates which lines are covered and which aren't. Unexecuted lines are also listed in the The Locations View.
`Hide coverage information`
  Withdraw from the current source editor a previously set coverage annotation column and clear The Locations View from the eventually listed uncovered lines.
`Load data for `xxxxxxxx.xxx``
  Load or re-load the coverage information of the specified source file.
`Remove data of `xxxxxxxx.xxx``
  Remove the coverage information of the specified source file from GPS memory.
`Show Coverage report`
  Open a new window summarizing the coverage information. (This entry appears only if the contextual menu has been created from outside of the Coverage Report.)

#### 13.7.3 The Coverage Report

When coverage information is loaded, a graphical coverage report is displayed. This report contains a tree of Projects, Files and Subprograms with corresponding coverage information for each node in sided columns.

The contextual menus generated on this widget contain, in addition to the regular entries, some specific Coverage Report entries.

These entries allow you to expand or fold the tree, and also to display flat lists of files or subprograms instead of the tree. A flat list of file will look like:

GPS and Gcov both support many different programming languages, and so code coverage features are available in GPS for many languages. But, note that subprogram coverage details are not available for every supported languages.

Note also that if you change the current main project in GPS, using the `Project->Open` menu for instance, you will also drop every loaded coverage information as they are related to the working project.