8000 Add lcov output format by Spacetown · Pull Request #830 · gcovr/gcovr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add lcov output format #830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ms-python.vscode-pylance",
"GitHub.vscode-pull-request-github",
"EditorConfig.EditorConfig",
"sergelamikhov.lcov-lang",
"streetsidesoftware.code-spell-checker"
]
}
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ jobs:
files: ./coverage.xml
name: docker-${{ matrix.gcc }}
verbose: true
- name: Upload LCOV coverage to Codecov
if: ${{ matrix.gcc == 'clang-13' }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
env_vars: OS,PYTHON
fail_ci_if_error: true
files: ./gcovr/tests/nested/reference/${{ matrix.gcc }}/coverage.lcov
name: docker-${{ matrix.gcc }}-lcov
verbose: true
- name: Generate documentation (in container)
run: |
python3 -m nox --non-interactive --session "docker_run_compiler(${{ matrix.gcc }})" -- --session doc
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ New features and notable changes:
- Add option to report covered lines in txt report. (:issue:`836`)
- Add support for specifying files for :option:`search_paths`. (:issue:`834`)
- Use different color for partial covered lines in HTML report. (:issue:`839`)
- Add support to generate LCOV info files. (:issue:`830`)

Bug fixes and small improvements:

Expand Down
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ The ``gcovr`` command can produce different kinds of coverage reports:
- |abstract-guide-coveralls|
- machine readable JSON report in Coveralls_ format

* - |abstract-option-lcov|
- |abstract-guide-lcov|
- machine readable JSON report in LCOV_ format

Thus, gcovr can be viewed
as a command-line alternative to the lcov_ utility, which runs gcov
and generates an HTML-formatted report.
Expand Down Expand Up @@ -98,6 +102,7 @@ text summaries and XML reports.
.. |abstract-option-json-summary| replace:: ``--json-summary``
.. |abstract-option-csv| replace:: ``--csv``
.. |abstract-option-coveralls| replace:: ``--coveralls``
.. |abstract-option-lcov| replace:: ``--lcov``

.. |abstract-guide-txt| replace:: `Text Output <https://gcovr.com/en/stable/output/txt.html>`__
.. |abstract-guide-html| replace:: `HTML Output <https://gcovr.com/en/stable/output/html.html>`__
Expand All @@ -110,6 +115,7 @@ text summaries and XML reports.
.. |abstract-guide-json-summary| replace:: `JSON Output <https://gcovr.com/en/stable/output/json.html>`__
.. |abstract-guide-csv| replace:: `CSV Output <https://gcovr.com/en/stable/output/csv.html>`__
.. |abstract-guide-coveralls| replace:: `Coveralls JSON Output <https://gcovr.com/en/stable/output/coveralls.html>`__
.. |abstract-guide-lcov| replace:: `LCOV info Output <https://gcovr.com/en/stable/output/lcov.html>`__


Example HTML summary:
Expand Down
2 changes: 2 additions & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ gcovr
.. |abstract-option-json-summary| replace:: :option:`--json-summary`
.. |abstract-option-csv| replace:: :option:`--csv`
.. |abstract-option-coveralls| replace:: :option:`--coveralls`
.. |abstract-option-lcov| replace:: :option:`--lcov`

.. |abstract-guide-txt| replace:: :ref:`txt_output`
.. |abstract-guide-html| replace:: :ref:`html_output`
Expand All @@ -35,6 +36,7 @@ gcovr
.. |abstract-guide-json-summary| replace:: :ref:`json_output`
.. |abstract-guide-csv| replace:: :ref:`csv_output`
.. |abstract-guide-coveralls| replace:: :ref:`coveralls_output`
.. |abstract-guide-lcov| replace:: :ref:`lcov_output`

.. admonition:: Quick Links

Expand Down
1 change: 1 addition & 0 deletions doc/source/output/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ that are documented on the following pages.
json
csv
coveralls
lcov

You can use :ref:`multiple output formats` at the same time.
24 changes: 24 additions & 0 deletions doc/source/output/lcov.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. _lcov_output:

LCOV info Output
=====================

If you are using tools which handle LCOV info file you can get a coverage report
in a suitable info format via the :option:`--lcov<gcovr --lcov>` option::

gcovr --lcov coverage.lcov

With following option you can set user defined fields in the coverage report:

- The :option:`--lcov-comment<gcovr --lcov-comment>` defines the optional comment.
- The :option:`--lcov-test-name<gcovr --lcov-test-name>` changes the test name.

Keep in mind that the output contains the checksums of the source files. If you are
using different OSes, the line endings shall be the same.

The LCOV info format is documented at
`<https://github.com/linux-test-project/lcov/blob/07a1127c2b4390abf4a516e9763fb28a956a9ce4/man/geninfo.1#L989>`_.

.. versionadded:: NEXT
Added :option:`--lcov<gcovr --lcov>`, :option:`--lcov-comment<gcovr --lcov-comment>`
and :option:`--lcov-test-name<gcovr --lcov-test-name>`.
14 changes: 6 additions & 8 deletions gcovr/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def merge_options_and_set_defaults(
"Override current time for reproducible reports. "
"Can use `YYYY-MM-DD hh:mm:ss` or epoch notation. "
"Used by HTML, Coveralls, and Cobertura reports. "
"Default: Environment variable SOURCE_DATE_EPOCH "
"Default is taken from environment variable SOURCE_DATE_EPOCH "
"(see https://reproducible-builds.org/docs/source-date-epoch) "
"or current time."
),
Expand Down Expand Up @@ -580,7 +580,7 @@ def merge_options_and_set_defaults(
default="strict",
help=(
"The merge mode for functions coverage from different gcov files for same sourcefile."
"Default: {default!s}."
"Default is '{default!s}'."
),
),
GcovrConfigOption(
Expand All @@ -599,24 +599,23 @@ def merge_options_and_set_defaults(
group="gcov_options",
help=(
"Exclude branch coverage from lines without useful source code "
'(often, compiler-generated "dead" code). '
"Default: {default!s}."
"(often, compiler-generated 'dead' code)."
),
action="store_true",
),
GcovrConfigOption(
"exclude_function_lines",
["--exclude-function-lines"],
group="gcov_options",
help="Exclude coverage from lines defining a function. Default: {default!s}.",
help="Exclude coverage from lines defining a function.",
action="store_true",
),
GcovrConfigOption(
"exclude_noncode_lines",
["--exclude-noncode-lines"],
config="exclude-noncode-lines",
group="gcov_options",
help="Exclude coverage from lines which seem to be non-code. Default: {default!s}.",
help="Exclude coverage from lines which seem to be non-code.",
action="store_true",
const_negate=False,
),
Expand All @@ -627,8 +626,7 @@ def merge_options_and_set_defaults(
help=(
"For branch coverage, exclude branches "
"that the compiler generates for exception handling. "
'This often leads to more "sensible" coverage reports. '
"Default: {default!s}."
"This often leads to more 'sensible' coverage reports."
),
action="store_true",
),
Expand Down
14 changes: 14 additions & 0 deletions gcovr/formats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .html import HtmlHandler
from .jacoco import JaCoCoHandler
from .json import JsonHandler
from .lcov import LcovHandler
from .sonarqube import SonarqubeHandler
from .txt import TxtHandler

Expand All @@ -30,6 +31,7 @@ def get_options() -> List[GcovrConfigOption]:
*HtmlHandler.get_options(),
*JaCoCoHandler.get_options(),
*JsonHandler.get_options(),
*LcovHandler.get_options(),
*SonarqubeHandler.get_options(),
*TxtHandler.get_options(),
]
Expand Down Expand Up @@ -141,6 +143,18 @@ def write_reports(covdata: CovData, options: Options):
)
)

if options.lcov:
generators.append(
(
[options.lcov],
LcovHandler(options).write_report,
lambda: LOGGER.warning(
"LCOV output skipped - "
"consider providing an output file with `--lcov=OUTPUT`."
),
)
)

if options.sonarqube:
generators.append(
(
Expand Down
5 changes: 1 addition & 4 deletions gcovr/formats/cobertura/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ def get_options() -> List[GcovrConfigOption]:
"cobertura_pretty",
["--cobertura-pretty", "--xml-pretty"],
group="output_options",
help=(
"Pretty-print the Cobertura XML report. "
"Implies --cobertura. Default: {default!s}."
),
help=("Pretty-print the Cobertura XML report. Implies --cobertura."),
action="store_true",
),
GcovrConfigOption(
Expand Down
5 changes: 1 addition & 4 deletions gcovr/formats/coveralls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ def get_options() -> List[GcovrConfigOption]:
"coveralls_pretty",
["--coveralls-pretty"],
group="output_options",
help=(
"Pretty-print the coveralls report. "
"Implies --coveralls. Default: {default!s}."
),
help=("Pretty-print the coveralls report. Implies --coveralls."),
action="store_true",
),
]
Expand Down
9 changes: 4 additions & 5 deletions gcovr/formats/gcov/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_options() -> List[GcovrConfigOption]:
"gcov_files",
["-g", "--gcov-use-existing-files", "--use-gcov-files"],
group="gcov_options",
help="Use existing gcov files for analysis. Default: {default!s}.",
help="Use existing gcov files for analysis.",
action="store_true",
),
GcovrConfigOption(
Expand All @@ -69,7 +69,7 @@ def get_options() -> List[GcovrConfigOption]:
"Ignore errors from invoking GCOV command "
"instead of exiting with an error. "
"A report will be shown on stderr. "
"Default: {default!s}."
"Default is '{default!s}'."
),
type=str,
action="append",
Expand All @@ -90,7 +90,7 @@ def get_options() -> List[GcovrConfigOption]:
"Skip lines with parse errors in GCOV files "
"instead of exiting with an error. "
"A report will be shown on stderr. "
"Default: {default!s}."
"Default is '{default!s}'."
),
type=str,
action="append",
Expand Down Expand Up @@ -170,7 +170,6 @@ def get_options() -> List[GcovrConfigOption]:
"Keep gcov files after processing. "
"This applies both to files that were generated by gcovr, "
"or were supplied via the --gcov-use-existing-files option. "
"Default: {default!s}."
),
action="store_true",
),
Expand All @@ -179,7 +178,7 @@ def get_options() -> List[GcovrConfigOption]:
["-d", "--gcov-delete", "--delete"],
config="delete-gcov-files",
group="gcov_options",
help="Delete gcda files after processing. Default: {default!s}.",
help="Delete gcda files after processing.",
action="store_true",
),
GcovrConfigOption(
Expand Down
5 changes: 1 addition & 4 deletions gcovr/formats/jacoco/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ def get_options() -> List[GcovrConfigOption]:
"jacoco_pretty",
["--jacoco-pretty"],
group="output_options",
help=(
"Pretty-print the JaCoCo XML report. "
"Implies --jacoco. Default: {default!s}."
),
help=("Pretty-print the JaCoCo XML report. Implies --jacoco."),
action="store_true",
),
]
Expand Down
7 changes: 2 additions & 5 deletions gcovr/formats/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_options() -> List[GcovrConfigOption]:
"json_pretty",
["--json-pretty"],
group="output_options",
help="Pretty-print the JSON report. Implies --json. Default: {default!s}.",
help="Pretty-print the JSON report. Implies --json.",
action="store_true",
),
GcovrConfigOption(
Expand All @@ -72,10 +72,7 @@ def get_options() -> List[GcovrConfigOption]:
"json_summary_pretty",
["--json-summary-pretty"],
group="output_options",
help=(
"Pretty-print the JSON SUMMARY report."
"Implies --json-summary. Default: {default!s}."
),
help="Pretty-print the JSON SUMMARY report. Implies --json-summary.",
action="store_true",
),
GcovrConfigOption(
Expand Down
65 changes: 65 additions & 0 deletions gcovr/formats/lcov/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- coding:utf-8 -*-

# ************************** Copyrights and license ***************************
#
# This file is part of gcovr 6.0+master, a parsing and reporting tool for gcov.
# https://gcovr.com/en/stable
#
# _____________________________________________________________________________
#
# Copyright (c) 2013-2023 the gcovr authors
# Copyright (c) 2013 Sandia Corporation.
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
#
# This software is distributed under the 3-clause BSD License.
# For more information, see the README.rst file.
#
# ****************************************************************************

from typing import List

from ...options import GcovrConfigOption, OutputOrDefault
from ...formats.base import BaseHandler

from ...coverage import CovData


class LcovHandler(BaseHandler):
def get_options() -> List[GcovrConfigOption]:
return [
GcovrConfigOption(
"lcov",
["--lcov"],
group="output_options",
metavar="OUTPUT",
help=(
"Generate a LCOV info file. "
"OUTPUT is optional and defaults to --output."
),
nargs="?",
type=OutputOrDefault,
default=None,
const=OutputOrDefault(None),
),
GcovrConfigOption(
"lcov_comment",
["--lcov-comment"],
group="output_options",
metavar="COMMENT",
help="The comment used in LCOV file.",
),
GcovrConfigOption(
"lcov_test_name",
["--lcov-test-name"],
group="output_options",
metavar="NAME",
help="The name used for TN in LCOV file. Default is '{default!s}'.",
default="GCOVR report",
),
]

def write_report(self, covdata: CovData, output_file: str) -> None:
from .write import write_report

write_report(covdata, output_file, self.options)
Loading
0