Don't fail when a LCOV info file contains empty lines

This commit is contained in:
Marco Castelluccio 2017-12-22 17:26:19 +01:00
Родитель c4d7b4e390
Коммит ac3b4c8126
3 изменённых файлов: 155 добавлений и 2 удалений

Просмотреть файл

@ -23,9 +23,16 @@ pub fn call_parse_llvm_gcno(working_dir: &str, file_stem: &str) {
fn remove_newline(l: &mut Vec<u8>) {
loop {
let last = *l.last().unwrap();
if last != b'\n' && last != b'\r' {
let last = {
let last = l.last();
if last.is_none() {
break;
}
*last.unwrap()
};
if last != b'\n' && last != b'\r' {
break;
}
l.pop();
@ -317,6 +324,29 @@ pub fn parse_gcov(gcov_path: &Path) -> Vec<(String,CovResult)> {
mod tests {
use super::*;
#[test]
fn test_remove_newline() {
let mut l = "Marco".as_bytes().to_vec();
remove_newline(&mut l);
assert_eq!(l, "Marco".as_bytes().to_vec());
let mut l = "Marco\n".as_bytes().to_vec();
remove_newline(&mut l);
assert_eq!(l, "Marco".as_bytes().to_vec());
let mut l = "Marco\r".as_bytes().to_vec();
remove_newline(&mut l);
assert_eq!(l, "Marco".as_bytes().to_vec());
let mut l = "Marco\r\n".as_bytes().to_vec();
remove_newline(&mut l);
assert_eq!(l, "Marco".as_bytes().to_vec());
let mut l = "\r\n".as_bytes().to_vec();
remove_newline(&mut l);
assert_eq!(l, "".as_bytes().to_vec());
}
#[test]
fn test_lcov_parser() {
let f = File::open("./test/prova.info").expect("Failed to open lcov file");
@ -383,6 +413,27 @@ mod tests {
assert_eq!(func.executed, true);
}
#[test]
fn test_lcov_parser_regression() {
let f = File::open("./test/empty_line.info").expect("Failed to open lcov file");
let file = BufReader::new(&f);
let results = parse_lcov(file, true);
assert_eq!(results.len(), 1);
let (ref source_name, ref result) = results[0];
assert_eq!(source_name, "aFile.js");
assert_eq!(result.lines, [(7,1),(9,1),(10,1),(12,2),(13,1),(16,1),(17,1),(18,2),(19,1),(21,1),(22,0),(23,0),(24,0),(28,1),(29,0),(30,0),(32,0),(33,0),(34,0),(35,0),(37,0),(39,0),(41,0),(42,0),(44,0),(45,0),(46,0),(47,0),(49,0),(50,0),(51,0),(52,0),(53,0),(54,0),(55,0),(56,0),(59,0),(60,0),(61,0),(63,0),(65,0),(67,1),(68,2),(70,1),(74,1),(75,1),(76,1),(77,1),(78,1),(83,1),(84,1),(90,1),(95,1),(96,1),(97,1),(98,1),(99,1)].iter().cloned().collect());
assert!(result.functions.contains_key("MainProcessSingleton"));
let func = result.functions.get("MainProcessSingleton").unwrap();
assert_eq!(func.start, 15);
assert_eq!(func.executed, true);
assert!(result.functions.contains_key("cubic-bezier(0.0, 0.0, 1.0, 1.0)"));
let func = result.functions.get("cubic-bezier(0.0, 0.0, 1.0, 1.0)").unwrap();
assert_eq!(func.start, 95);
assert_eq!(func.executed, true);
}
#[test]
fn test_parser_old_gcov_with_encoding_different_from_utf8() {
let (source_name, result) = parse_old_gcov(Path::new("./test/non-utf-8.gcov"), false);

Просмотреть файл

@ -290,6 +290,7 @@ mod tests {
(ItemFormat::INFO, true, "test/1494603973-2977-7.info", true),
(ItemFormat::INFO, true, "test/prova.info", true),
(ItemFormat::INFO, true, "test/prova_fn_with_commas.info", true),
(ItemFormat::INFO, true, "test/empty_line.info", true),
];
check_produced(PathBuf::from("."), &queue, expected);

101
test/empty_line.info Normal file
Просмотреть файл

@ -0,0 +1,101 @@
TN:aFile
SF:aFile.js
FN:1,top-level
FN:15,MainProcessSingleton
FN:21,logConsoleMessage
FN:28,addSearchEngine
FN:59,addSearchEngine/<
FN:67,observe
FN:95,cubic-bezier(0.0, 0.0, 1.0, 1.0)
FNDA:1,top-level
FNDA:1,MainProcessSingleton
FNDA:2,observe
FNDA:3,cubic-bezier(0.0, 0.0, 1.0, 1.0)
FNF:6
FNH:3
BRDA:34,0,0,-
BRDA:34,0,1,-
BRDA:34,1,0,-
BRDA:34,1,1,-
BRDA:34,2,0,-
BRDA:34,2,1,-
BRDA:41,3,0,-
BRDA:41,3,1,-
BRDA:44,4,0,-
BRDA:44,4,1,-
BRDA:44,5,0,-
BRDA:44,5,1,-
BRDA:60,0,0,-
BRDA:60,0,1,-
BRDA:63,1,0,-
BRDA:63,1,1,-
BRDA:68,0,0,1
BRDA:68,0,1,1
BRDA:68,1,0,1
BRDA:68,1,1,-
BRF:20
BRH:3
DA:7,1
DA:9,1
DA:10,1
DA:12,1
DA:13,1
DA:12,1
DA:16,1
DA:17,1
DA:18,1
DA:19,1
DA:18,1
DA:21,1
DA:28,1
DA:67,1
DA:90,1
DA:22,0
DA:23,0
DA:24,0
DA:29,0
DA:30,0
DA:32,0
DA:33,0
DA:34,0
DA:35,0
DA:37,0
DA:39,0
DA:41,0
DA:42,0
DA:44,0
DA:45,0
DA:46,0
DA:47,0
DA:49,0
DA:50,0
DA:51,0
DA:52,0
DA:53,0
DA:54,0
DA:53,0
DA:55,0
DA:56,0
DA:65,0
DA:59,0
DA:60,0
DA:61,0
DA:63,0
DA:68,2
DA:70,1
DA:74,1
DA:75,1
DA:76,1
DA:77,1
DA:78,1
DA:83,1
DA:84,1
DA:95,1
DA:96,1
DA:97,1
DA:98,1
DA:99,1
LF:60
LH:29
end_of_record