Skip to content

Use --json-format for gcov reports to get pre-structured results #609

@MichaelChirico

Description

@MichaelChirico

h/t @aitap for highlighting this:

#604 (comment)

See docs:

https://gcc.gnu.org/onlinedocs/gcc/Invoking-Gcov.html

And thankfully we already import {jsonlite}:

jsonlite,


Currently, gcov output is parsed with regular expressions:

covr/R/compiled.R

Lines 18 to 37 in d8d33b4

re <- rex::rex(any_spaces,
capture(name = "coverage", some_of(digit, "-", "#", "=")),
":", any_spaces,
capture(name = "line", digits),
":"
)
matches <- rex::re_matches(lines, re)
# Exclude lines with no match to the pattern
lines <- lines[!is.na(matches$coverage)]
matches <- na.omit(matches)
# gcov lines which have no coverage
matches$coverage[matches$coverage == "#####"] <- 0 # nolint
# gcov lines which have parse error, so make untracked
matches$coverage[matches$coverage == "====="] <- "-"
coverage_lines <- matches$line != "0" & matches$coverage != "-"

I think it will be much more robust and extensible to use the structured JSON output instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions