Crate lcov2

Source
Expand description

A library for generating and writing LCOV files, and converting them to HTML format.

§Examples

§Writing an LCOV file

This example will write an info file with a single record for a test file with two lines and a single function. (imagine main() has a lot of empty space!)

use lcov::{Records, Record};
use std::fs::write;

let mut records = Records::default();
let test_record = records.get_or_insert_mut(Path::new("/path/to/test.c"));
test_record.add_function_if_not_exists(1, 32, "main");
test_record.increment_function_data("main");
test_record.add_line_if_not_exists(1);
test_record.add_line_if_not_exists(32);
test_record.increment_line(1);
test_record.increment_line(32);
write("test.info", records.to_string()).unwrap();

§Reading an LCOV file

This example will read an info file.

use lcov::Records;
use std::fs::read_to_string;

let contents = read_to_string("test.info").unwrap();
let records = Records::from_str(&contents).unwrap();

§Generating an HTML report

This example will generate an HTML report from the records in a format that looks very much like LCOV style (not an exact match).

use lcov::Records;
use std::fs::{read_to_string, write};

let contents = read_to_string("test.info").unwrap();
let records = Records::from_str(&contents).unwrap();
write("test.html", records.to_html().unwrap()).unwrap();

Modules§

error

Structs§

BranchDataRecordEntry
Branch coverage information
BranchesFoundRecordEntry
The number of branches found
BranchesHitRecordEntry
The number of branches hit
EndOfRecordEntry
The end of the record section
FunctionDataRecordEntry
A list of execution counts for each instrumented function
FunctionRecordEntry
A list of line numbers for each function name found in the source file
FunctionsFoundRecordEntry
The number of functions found
FunctionsHitRecordEntry
The number of functions hit
LineRecordEntry
Execution count for an instrumented line (i.e. a line which resulted in executable code – there may not be a record for every source line)
LinesFoundRecordEntry
Number of instrumented lines
LinesHitRecordEntry
Number of lines with a non-zero execution count
Record
A single record section, which contains information about a single source file for a single test
Records
A collection of record sections read from a file
SourceFileRecordEntry
For each source file referenced in the .gcda file, there is a section containing filename and coverage data
TestNameRecordEntry
If available, a tracefile begins with the testname
VersionRecordEntry
An optional source code version ID