From 79bec5f21f40fd3d54d2b317e671f2f3981a1869 Mon Sep 17 00:00:00 2001 From: calixteman Date: Tue, 15 May 2018 15:37:35 +0200 Subject: [PATCH] Merge files with same absolute path and different relative paths in the same bucket (#103) --- src/lib.rs | 50 +++++++++++++++-- src/main.rs | 11 +++- src/path_rewriting.rs | 79 ++++++++++++++------------- src/producer.rs | 1 + test/relative_path/foo/bar/oof.cpp | 0 test/relative_path/relative_path.info | 33 +++++++++++ 6 files changed, 129 insertions(+), 45 deletions(-) create mode 100644 test/relative_path/foo/bar/oof.cpp create mode 100644 test/relative_path/relative_path.info diff --git a/src/lib.rs b/src/lib.rs index bba6b6e4e..926419a87 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,10 +73,20 @@ fn merge_results(result: &mut CovResult, result2: &mut CovResult) { } } -fn add_results(mut results: Vec<(String,CovResult)>, result_map: &SyncCovResultMap) { +fn add_results(mut results: Vec<(String,CovResult)>, result_map: &SyncCovResultMap, source_dir: &Option) { let mut map = result_map.lock().unwrap(); for mut result in results.drain(..) { - match map.entry(result.0) { + let path = match source_dir { + Some(source_dir) => { + // the goal here is to be able to merge results for paths like foo/./bar and foo/bar + match fs::canonicalize(source_dir.join(&result.0)) { + Ok(p) => String::from(p.to_str().unwrap()), + Err(_) => result.0, + } + }, + None => result.0 + }; + match map.entry(path) { hash_map::Entry::Occupied(obj) => { merge_results(obj.into_mut(), &mut result.1); }, @@ -107,7 +117,7 @@ macro_rules! try_parse { }); } -pub fn consumer(working_dir: &PathBuf, result_map: &SyncCovResultMap, queue: &WorkQueue, is_llvm: bool, branch_enabled: bool) { +pub fn consumer(working_dir: &PathBuf, source_dir: &Option, result_map: &SyncCovResultMap, queue: &WorkQueue, is_llvm: bool, branch_enabled: bool) { let mut gcov_type = GcovType::Unknown; while let Some(work_item) = queue.pop() { @@ -164,7 +174,7 @@ pub fn consumer(working_dir: &PathBuf, result_map: &SyncCovResultMap, queue: &Wo } }; - add_results(new_results, result_map); + add_results(new_results, result_map, source_dir); } } @@ -172,6 +182,7 @@ pub fn consumer(working_dir: &PathBuf, result_map: &SyncCovResultMap, queue: &Wo mod tests { use super::*; use std::collections::HashMap; + use std::sync::{Arc, Mutex}; #[test] fn test_merge_results() { @@ -216,4 +227,35 @@ mod tests { assert_eq!(func.start, 2); assert_eq!(func.executed, true); } + + #[test] + fn test_merge_relative_path() { + let f = File::open("./test/relative_path/relative_path.info").expect("Failed to open lcov file"); + let file = BufReader::new(&f); + let results = parse_lcov(file, false).unwrap(); + let result_map: Arc = Arc::new(Mutex::new(HashMap::with_capacity(1))); + add_results(results, &result_map, &Some(PathBuf::from("./test/relative_path"))); + let result_map = Arc::try_unwrap(result_map).unwrap().into_inner().unwrap(); + + assert!(result_map.len() == 1); + + let cpp_file = fs::canonicalize(PathBuf::from("./test/relative_path/foo/bar/oof.cpp")).unwrap(); + let cpp_file = cpp_file.to_str().unwrap(); + let cov_result = result_map.get(cpp_file).unwrap(); + + assert_eq!(cov_result.lines, [(1,63), (2,63), (3,84), (4,42)].iter().cloned().collect()); + assert!(cov_result.functions.contains_key("myfun")); + } + + #[test] + fn test_ignore_relative_path() { + let f = File::open("./test/relative_path/relative_path.info").expect("Failed to open lcov file"); + let file = BufReader::new(&f); + let results = parse_lcov(file, false).unwrap(); + let result_map: Arc = Arc::new(Mutex::new(HashMap::with_capacity(3))); + add_results(results, &result_map, &None); + let result_map = Arc::try_unwrap(result_map).unwrap().into_inner().unwrap(); + + assert!(result_map.len() == 3); + } } diff --git a/src/main.rs b/src/main.rs index 6c3e1d5c1..88a72e9af 100755 --- a/src/main.rs +++ b/src/main.rs @@ -224,6 +224,12 @@ fn main() { prefix_dir = source_dir; } + let source_root = if source_dir != "" { + Some(fs::canonicalize(&source_dir).expect("Source directory does not exist.")) + } else { + None + }; + let tmp_dir = TempDir::new("grcov").expect("Failed to create temporary directory"); let tmp_path = tmp_dir.path().to_owned(); @@ -258,10 +264,11 @@ fn main() { let queue = Arc::clone(&queue); let result_map = Arc::clone(&result_map); let working_dir = tmp_path.join(format!("{}", i)); + let source_root = source_root.clone(); let t = thread::spawn(move || { fs::create_dir(&working_dir).expect("Failed to create working directory"); - consumer(&working_dir, &result_map, &queue, is_llvm, branch_enabled); + consumer(&working_dir, &source_root, &result_map, &queue, is_llvm, branch_enabled); }); parsers.push(t); @@ -284,7 +291,7 @@ fn main() { let path_mapping_mutex = Arc::try_unwrap(path_mapping).unwrap(); let path_mapping = path_mapping_mutex.into_inner().unwrap(); - let iterator = rewrite_paths(result_map, path_mapping, source_dir, prefix_dir, ignore_global, ignore_not_existing, to_ignore_dirs, filter_option); + let iterator = rewrite_paths(result_map, path_mapping, source_root, prefix_dir, ignore_global, ignore_not_existing, to_ignore_dirs, filter_option); if output_type == "ade" { output_activedata_etl(iterator); diff --git a/src/path_rewriting.rs b/src/path_rewriting.rs index 807847560..5838743f0 100755 --- a/src/path_rewriting.rs +++ b/src/path_rewriting.rs @@ -16,19 +16,19 @@ fn to_uppercase_first(s: &str) -> String { c.next().unwrap().to_uppercase().collect::() + c.as_str() } -pub fn rewrite_paths(result_map: CovResultMap, path_mapping: Option, source_dir: &str, prefix_dir: &str, ignore_global: bool, ignore_not_existing: bool, to_ignore_dirs: Vec, filter_option: Option) -> CovResultIter { - let source_dir = if source_dir != "" { - fs::canonicalize(&source_dir).expect("Source directory does not exist.") - } else { - PathBuf::from("") - }; - +pub fn rewrite_paths(result_map: CovResultMap, path_mapping: Option, source_dir: Option, prefix_dir: &str, ignore_global: bool, ignore_not_existing: bool, to_ignore_dirs: Vec, filter_option: Option) -> CovResultIter { let path_mapping = if path_mapping.is_some() { path_mapping.unwrap() } else { json!({}) }; + let source_dir = if source_dir.is_some() { + source_dir.unwrap() + } else { + PathBuf::from("") + }; + let mut glob_builder = GlobSetBuilder::new(); for to_ignore_dir in &to_ignore_dirs { glob_builder.add(Glob::new(to_ignore_dir).unwrap()); @@ -171,7 +171,7 @@ mod tests { fn test_rewrite_paths_basic() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "", false, false, Vec::new(), None); + let results = rewrite_paths(result_map, None, None, "", false, false, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -188,7 +188,7 @@ mod tests { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("main.cpp".to_string(), empty_result!()); result_map.insert("/usr/include/prova.h".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "", true, false, Vec::new(), None); + let results = rewrite_paths(result_map, None, None, "", true, false, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -205,7 +205,7 @@ mod tests { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("main.cpp".to_string(), empty_result!()); result_map.insert("C:\\usr\\include\\prova.h".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "", true, false, Vec::new(), None); + let results = rewrite_paths(result_map, None, None, "", true, false, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -221,7 +221,7 @@ mod tests { fn test_rewrite_paths_remove_prefix() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("/home/worker/src/workspace/main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "/home/worker/src/workspace/", false, false, Vec::new(), None); + let results = rewrite_paths(result_map, None, None, "/home/worker/src/workspace/", false, false, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -237,7 +237,7 @@ mod tests { fn test_rewrite_paths_remove_prefix() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("C:\\Users\\worker\\src\\workspace\\main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "C:\\Users\\worker\\src\\workspace\\", false, false, Vec::new(), None); + let results = rewrite_paths(result_map, None, None, "C:\\Users\\worker\\src\\workspace\\", false, false, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -253,7 +253,7 @@ mod tests { fn test_rewrite_paths_remove_prefix_with_slash() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("C:/Users/worker/src/workspace/main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "C:/Users/worker/src/workspace/", false, false, Vec::new(), None); + let results = rewrite_paths(result_map, None, None, "C:/Users/worker/src/workspace/", false, false, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -269,7 +269,7 @@ mod tests { fn test_rewrite_paths_remove_prefix_with_slash_longer_path() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("C:/Users/worker/src/workspace/main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "C:/Users/worker/src/", false, false, Vec::new(), None); + let results = rewrite_paths(result_map, None, None, "C:/Users/worker/src/", false, false, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -286,7 +286,7 @@ mod tests { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("tests/class/main.cpp".to_string(), empty_result!()); result_map.insert("tests/class/doesntexist.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, None, None, "", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -304,7 +304,7 @@ mod tests { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("tests\\class\\main.cpp".to_string(), empty_result!()); result_map.insert("tests\\class\\doesntexist.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, None, None, "", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -322,7 +322,7 @@ mod tests { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("main.cpp".to_string(), empty_result!()); result_map.insert("mydir/prova.h".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "", false, false, vec!["mydir/*".to_string()], None); + let results = rewrite_paths(result_map, None, None, "", false, false, vec!["mydir/*".to_string()], None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -339,7 +339,7 @@ mod tests { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("main.cpp".to_string(), empty_result!()); result_map.insert("mydir\\prova.h".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "", false, false, vec!["mydir/*".to_string()], None); + let results = rewrite_paths(result_map, None, None, "", false, false, vec!["mydir/*".to_string()], None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -358,7 +358,7 @@ mod tests { result_map.insert("main.cpp".to_string(), empty_result!()); result_map.insert("mydir/prova.h".to_string(), empty_result!()); result_map.insert("mydir2/prova.h".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "", false, false, vec!["mydir/*".to_string(), "mydir2/*".to_string()], None); + let results = rewrite_paths(result_map, None, None, "", false, false, vec!["mydir/*".to_string(), "mydir2/*".to_string()], None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -376,7 +376,7 @@ mod tests { result_map.insert("main.cpp".to_string(), empty_result!()); result_map.insert("mydir\\prova.h".to_string(), empty_result!()); result_map.insert("mydir2\\prova.h".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "", "", false, false, vec!["mydir/*".to_string(), "mydir2/*".to_string()], None); + let results = rewrite_paths(result_map, None, None, "", false, false, vec!["mydir/*".to_string(), "mydir2/*".to_string()], None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -392,7 +392,7 @@ mod tests { fn test_rewrite_paths_rewrite_path_using_relative_source_directory() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("class/main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "tests", "", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, None, Some(fs::canonicalize("tests").unwrap()), "", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -409,7 +409,7 @@ mod tests { fn test_rewrite_paths_rewrite_path_using_relative_source_directory() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("class\\main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "tests", "", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, None, Some(fs::canonicalize("tests").unwrap()), "", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -426,7 +426,7 @@ mod tests { fn test_rewrite_paths_rewrite_path_using_absolute_source_directory() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("class/main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, fs::canonicalize("tests").unwrap().to_str().unwrap(), "", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, None, Some(fs::canonicalize("tests").unwrap()), "", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -443,7 +443,7 @@ mod tests { fn test_rewrite_paths_rewrite_path_using_absolute_source_directory() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("class\\main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, fs::canonicalize("tests").unwrap().to_str().unwrap(), "", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, None, Some(fs::canonicalize("tests").unwrap()), "", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -460,12 +460,13 @@ mod tests { fn test_rewrite_paths_rewrite_path_and_remove_prefix() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("/home/worker/src/workspace/class/main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "tests", "/home/worker/src/workspace", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, None, Some(fs::canonicalize("tests").unwrap()), "/home/worker/src/workspace", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; assert!(abs_path.is_absolute()); assert!(abs_path.ends_with("tests/class/main.cpp")); + eprintln!("{:?}", rel_path); assert_eq!(rel_path, PathBuf::from("class/main.cpp")); assert_eq!(result, empty_result!()); } @@ -477,7 +478,7 @@ mod tests { fn test_rewrite_paths_rewrite_path_and_remove_prefix() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("C:\\Users\\worker\\src\\workspace\\class\\main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, None, "tests", "C:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, None, Some(fs::canonicalize("tests").unwrap()), "C:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -494,7 +495,7 @@ mod tests { fn test_rewrite_paths_rewrite_path_using_mapping() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("class/main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, Some(json!({"class/main.cpp": "rewritten/main.cpp"})), "", "", false, false, Vec::new(), None); + let results = rewrite_paths(result_map, Some(json!({"class/main.cpp": "rewritten/main.cpp"})), None, "", false, false, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -510,7 +511,7 @@ mod tests { fn test_rewrite_paths_rewrite_path_using_mapping() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("class\\main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, Some(json!({"class/main.cpp": "rewritten/main.cpp"})), "", "", false, false, Vec::new(), None); + let results = rewrite_paths(result_map, Some(json!({"class/main.cpp": "rewritten/main.cpp"})), None, "", false, false, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -527,7 +528,7 @@ mod tests { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("rewritten/main.cpp".to_string(), empty_result!()); result_map.insert("tests/class/main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, Some(json!({"rewritten/main.cpp": "tests/class/main.cpp", "tests/class/main.cpp": "rewritten/main.cpp"})), "", "", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, Some(json!({"rewritten/main.cpp": "tests/class/main.cpp", "tests/class/main.cpp": "rewritten/main.cpp"})), None, "", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -545,7 +546,7 @@ mod tests { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("rewritten\\main.cpp".to_string(), empty_result!()); result_map.insert("tests\\class\\main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, Some(json!({"rewritten/main.cpp": "tests/class/main.cpp", "tests/class/main.cpp": "rewritten/main.cpp"})), "", "", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, Some(json!({"rewritten/main.cpp": "tests/class/main.cpp", "tests/class/main.cpp": "rewritten/main.cpp"})), None, "", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -562,7 +563,7 @@ mod tests { fn test_rewrite_paths_rewrite_path_using_mapping_and_remove_prefix() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("/home/worker/src/workspace/rewritten/main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, Some(json!({"/home/worker/src/workspace/rewritten/main.cpp": "tests/class/main.cpp"})), "", "/home/worker/src/workspace", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, Some(json!({"/home/worker/src/workspace/rewritten/main.cpp": "tests/class/main.cpp"})), None, "/home/worker/src/workspace", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -580,7 +581,7 @@ mod tests { // Mapping with uppercase disk and prefix with uppercase disk. let mut result_map: CovResultMap = HashMap::new(); result_map.insert("C:\\Users\\worker\\src\\workspace\\rewritten\\main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, Some(json!({"C:/Users/worker/src/workspace/rewritten/main.cpp": "tests/class/main.cpp"})), "", "C:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, Some(json!({"C:/Users/worker/src/workspace/rewritten/main.cpp": "tests/class/main.cpp"})), None, "C:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -594,7 +595,7 @@ mod tests { // Mapping with lowercase disk and prefix with uppercase disk. let mut result_map: CovResultMap = HashMap::new(); result_map.insert("C:\\Users\\worker\\src\\workspace\\rewritten\\main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, Some(json!({"c:/Users/worker/src/workspace/rewritten/main.cpp": "tests/class/main.cpp"})), "", "C:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, Some(json!({"c:/Users/worker/src/workspace/rewritten/main.cpp": "tests/class/main.cpp"})), None, "C:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -608,7 +609,7 @@ mod tests { // Mapping with uppercase disk and prefix with lowercase disk. let mut result_map: CovResultMap = HashMap::new(); result_map.insert("C:\\Users\\worker\\src\\workspace\\rewritten\\main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, Some(json!({"C:/Users/worker/src/workspace/rewritten/main.cpp": "tests/class/main.cpp"})), "", "c:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, Some(json!({"C:/Users/worker/src/workspace/rewritten/main.cpp": "tests/class/main.cpp"})), None, "c:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -622,7 +623,7 @@ mod tests { // Mapping with lowercase disk and prefix with lowercase disk. let mut result_map: CovResultMap = HashMap::new(); result_map.insert("C:\\Users\\worker\\src\\workspace\\rewritten\\main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, Some(json!({"c:/Users/worker/src/workspace/rewritten/main.cpp": "tests/class/main.cpp"})), "", "c:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, Some(json!({"c:/Users/worker/src/workspace/rewritten/main.cpp": "tests/class/main.cpp"})), None, "c:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -639,7 +640,7 @@ mod tests { fn test_rewrite_paths_rewrite_path_using_mapping_and_source_directory_and_remove_prefix() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("/home/worker/src/workspace/rewritten/main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, Some(json!({"/home/worker/src/workspace/rewritten/main.cpp": "class/main.cpp"})), "tests", "/home/worker/src/workspace", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, Some(json!({"/home/worker/src/workspace/rewritten/main.cpp": "class/main.cpp"})), Some(fs::canonicalize("tests").unwrap()), "/home/worker/src/workspace", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -656,7 +657,7 @@ mod tests { fn test_rewrite_paths_rewrite_path_using_mapping_and_source_directory_and_remove_prefix() { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("C:\\Users\\worker\\src\\workspace\\rewritten\\main.cpp".to_string(), empty_result!()); - let results = rewrite_paths(result_map, Some(json!({"C:/Users/worker/src/workspace/rewritten/main.cpp": "class/main.cpp"})), "tests", "C:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); + let results = rewrite_paths(result_map, Some(json!({"C:/Users/worker/src/workspace/rewritten/main.cpp": "class/main.cpp"})), Some(fs::canonicalize("tests").unwrap()), "C:\\Users\\worker\\src\\workspace", false, true, Vec::new(), None); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -673,7 +674,7 @@ mod tests { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("covered.cpp".to_string(), covered_result!()); result_map.insert("uncovered.cpp".to_string(), uncovered_result!()); - let results = rewrite_paths(result_map, None, "", "", false, false, Vec::new(), Some(true)); + let results = rewrite_paths(result_map, None, None, "", false, false, Vec::new(), Some(true)); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; @@ -689,7 +690,7 @@ mod tests { let mut result_map: CovResultMap = HashMap::new(); result_map.insert("covered.cpp".to_string(), covered_result!()); result_map.insert("uncovered.cpp".to_string(), uncovered_result!()); - let results = rewrite_paths(result_map, None, "", "", false, false, Vec::new(), Some(false)); + let results = rewrite_paths(result_map, None, None, "", false, false, Vec::new(), Some(false)); let mut count = 0; for (abs_path, rel_path, result) in results { count += 1; diff --git a/src/producer.rs b/src/producer.rs index 000e5f92b..dc3ba4756 100755 --- a/src/producer.rs +++ b/src/producer.rs @@ -308,6 +308,7 @@ mod tests { (ItemFormat::INFO, true, "test/prova_fn_with_commas.info", true), (ItemFormat::INFO, true, "test/empty_line.info", true), (ItemFormat::INFO, true, "test/invalid_DA_record.info", true), + (ItemFormat::INFO, true, "test/relative_path/relative_path.info", false), ]; check_produced(PathBuf::from("."), &queue, expected); diff --git a/test/relative_path/foo/bar/oof.cpp b/test/relative_path/foo/bar/oof.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/test/relative_path/relative_path.info b/test/relative_path/relative_path.info new file mode 100644 index 000000000..498bfcdfe --- /dev/null +++ b/test/relative_path/relative_path.info @@ -0,0 +1,33 @@ +SF:foo/bar/oof.cpp +FN:1,myfun +FNDA:1,myfun +FNF:1 +FNH:1 +DA:1,21 +DA:2,21 +DA:4,42 +LF:2 +LH:2 +end_of_record +SF:foo/./bar/./oof.cpp +FN:1,myfun +FNDA:1,myfun +FNF:1 +FNH:1 +DA:1,21 +DA:2,21 +DA:3,42 +LF:2 +LH:2 +end_of_record +SF:foo/bar/../bar/oof.cpp +FN:1,myfun +FNDA:1,myfun +FNF:1 +FNH:1 +DA:1,21 +DA:2,21 +DA:3,42 +LF:2 +LH:2 +end_of_record