24 releases (12 stable)

3.2.2 Apr 10, 2018
3.2.0 Mar 29, 2018
3.1.0 Jul 29, 2017
3.0.1-beta Mar 25, 2017
0.5.0 Jul 26, 2015

#41 in Parser tooling

Download history 24/week @ 2019-11-27 48/week @ 2019-12-04 335/week @ 2019-12-11 2/week @ 2019-12-18 28/week @ 2019-12-25 335/week @ 2020-01-08 74/week @ 2020-01-15 26/week @ 2020-01-22 5/week @ 2020-01-29 5/week @ 2020-02-05 28/week @ 2020-02-12 51/week @ 2020-02-19 91/week @ 2020-02-26 48/week @ 2020-03-04 24/week @ 2020-03-11

292 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

87KB
2K SLoC

lcov-parser

LCOV report parser for Rust.

Build Status Build Status crates.io version License

Basic usage

Create a LCOVParser object, and then parse the data.

extern crate lcov_parser;

use lcov_parser:: { LCOVParser, LCOVRecord };

fn main() {
    let content = concat!(
        "TN:test_name\n",
        "SF:/path/to/source.rs\n",
        "DA:1,2\n",
        "DA:2,1\n",
        "DA:3,5\n",
        "end_of_record\n"
    );
    let mut parser = LCOVParser::new(content.as_bytes());

    loop {
        match parser.next().expect("parse the report") {
            None => { break; },
            Some(record) => match record {
                LCOVRecord::TestName(name) => println!("Test: {}", name.unwrap()),
                LCOVRecord::SourceFile(file_name) => println!("File: {}", file_name),
                LCOVRecord::Data(data) => println!("Line: {}, Executed: {}", data.line, data.count),
                LCOVRecord::EndOfRecord => println!("Finish"),
                _ => { continue; }
            }
        }
    }
}

Parsing the file

It can also be used to parse the report file.

let mut parser = LCOVParser::from_file("../../../fixture/report.lcov").unwrap();

loop {
    match parser.next().expect("parse the report") {
        None => { break; },
        Some(record) => match record {
            LCOVRecord::SourceFile(file_name) => println!("File: {}", file_name),
            LCOVRecord::EndOfRecord => println!("Finish"),
            _ => { continue; }
        }
    }
}

Parsing all

You can parse all using the parse method.

let records = {
    let mut parser = LCOVParser::from_file("../../../fixture/report.lcov").unwrap();
    parser.parse().expect("parse the report")
};

for record in records.iter() {
    match record {
        &LCOVRecord::SourceFile(ref file_name) => println!("File: {}", file_name),
        &LCOVRecord::EndOfRecord => println!("Finish"),
        _ => { continue; }
    }
}

Merge reports

You use merge_files to merge reports.
You can save the merged report by specifying the file name.

extern crate lcov_parser;

use lcov_parser:: { merge_files };

fn main() {
    let trace_files = [
        "../../../tests/fixtures/fixture1.info",
        "../../../tests/fixtures/fixture2.info"
    ];
    let _ = match merge_files(&trace_files) {
        Ok(report) => report.save_as("/tmp/merged_report.info"),
        Err(err) => panic!(err)
    };
}

License

Licensed under either of

Dependencies

~680KB
~14K SLoC