From 131f66fd692c3d9ea0d7ee03baf699e0c899abb0 Mon Sep 17 00:00:00 2001 From: calixteman Date: Tue, 30 Oct 2018 20:23:50 +0100 Subject: [PATCH] Sort ignore_dirs before building GlobSet (#223) This is needed to work around https://github.com/BurntSushi/ripgrep/issues/1079. --- src/path_rewriting.rs | 97 +++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/src/path_rewriting.rs b/src/path_rewriting.rs index ec6742a33..134a4b215 100755 --- a/src/path_rewriting.rs +++ b/src/path_rewriting.rs @@ -175,10 +175,15 @@ pub fn rewrite_paths( source_dir: Option, prefix_dir: Option, ignore_not_existing: bool, - to_ignore_dirs: Vec, + mut to_ignore_dirs: Vec, filter_option: Option, ) -> CovResultIter { let mut glob_builder = GlobSetBuilder::new(); + + // workaround for bug: https://github.com/BurntSushi/ripgrep/issues/1079 + // Some filters foo/* are ignored when not sorted + to_ignore_dirs.sort_unstable(); + for to_ignore_dir in to_ignore_dirs { glob_builder.add(Glob::new(&to_ignore_dir).unwrap()); } @@ -533,53 +538,63 @@ mod tests { #[cfg(unix)] #[test] fn test_rewrite_paths_ignore_multiple_directories() { - 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!()); - result_map.insert("mydir2/prova.h".to_string(), empty_result!()); - let results = rewrite_paths( - result_map, - None, - None, - None, - false, - vec!["mydir/*".to_string(), "mydir2/*".to_string()], - None, - ); - let mut count = 0; - for (abs_path, rel_path, result) in results { - count += 1; - assert_eq!(abs_path, PathBuf::from("main.cpp")); - assert_eq!(rel_path, PathBuf::from("main.cpp")); - assert_eq!(result, empty_result!()); + let mut ignore_dirs = vec!["mydir/*".to_string(), "mydir2/*".to_string()]; + for _ in 0..2 { + // we run the test twice, one with ignore_dirs and the other with ignore_dirs.reverse() + 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!()); + result_map.insert("mydir2/prova.h".to_string(), empty_result!()); + let results = rewrite_paths( + result_map, + None, + None, + None, + false, + ignore_dirs.clone(), + None, + ); + let mut count = 0; + for (abs_path, rel_path, result) in results { + count += 1; + assert_eq!(abs_path, PathBuf::from("main.cpp")); + assert_eq!(rel_path, PathBuf::from("main.cpp")); + assert_eq!(result, empty_result!()); + } + assert_eq!(count, 1); + ignore_dirs.reverse(); } - assert_eq!(count, 1); } #[cfg(windows)] #[test] fn test_rewrite_paths_ignore_multiple_directories() { - 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!()); - result_map.insert("mydir2\\prova.h".to_string(), empty_result!()); - let results = rewrite_paths( - result_map, - None, - None, - None, - false, - vec!["mydir/*".to_string(), "mydir2/*".to_string()], - None, - ); - let mut count = 0; - for (abs_path, rel_path, result) in results { - count += 1; - assert_eq!(abs_path, PathBuf::from("main.cpp")); - assert_eq!(rel_path, PathBuf::from("main.cpp")); - assert_eq!(result, empty_result!()); + let mut ignore_dirs = vec!["mydir/*".to_string(), "mydir2/*".to_string()]; + for _ in 0..2 { + // we run the test twice, one with ignore_dirs and the other with ignore_dirs.reverse() + 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!()); + result_map.insert("mydir2\\prova.h".to_string(), empty_result!()); + let results = rewrite_paths( + result_map, + None, + None, + None, + false, + ignore_dirs.clone(), + None, + ); + let mut count = 0; + for (abs_path, rel_path, result) in results { + count += 1; + assert_eq!(abs_path, PathBuf::from("main.cpp")); + assert_eq!(rel_path, PathBuf::from("main.cpp")); + assert_eq!(result, empty_result!()); + } + assert_eq!(count, 1); + ignore_dirs.reverse(); } - assert_eq!(count, 1); } #[test]