X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fignore_path.rs;h=d8974e12b8f5f4fe07742214ec1f28f2e41ddae2;hb=612e8d5b9be72713a081370c85cc5bed30b6fae6;hp=1e17337e62545a1d67c2f7c7afbb77d1d27ff6c1;hpb=34bf13718a6af228260312139f646c7d79e6aa71;p=rust.git diff --git a/src/ignore_path.rs b/src/ignore_path.rs index 1e17337e625..d8974e12b8f 100644 --- a/src/ignore_path.rs +++ b/src/ignore_path.rs @@ -1,15 +1,14 @@ use ignore::{self, gitignore}; -use std::path::PathBuf; use crate::config::{FileName, IgnoreList}; -pub struct IgnorePathSet { +pub(crate) struct IgnorePathSet { ignore_set: gitignore::Gitignore, } impl IgnorePathSet { - pub fn from_ignore_list(ignore_list: &IgnoreList) -> Result { - let mut ignore_builder = gitignore::GitignoreBuilder::new(PathBuf::from("")); + pub(crate) fn from_ignore_list(ignore_list: &IgnoreList) -> Result { + let mut ignore_builder = gitignore::GitignoreBuilder::new(ignore_list.rustfmt_toml_path()); for ignore_path in ignore_list { ignore_builder.add_line(None, ignore_path.to_str().unwrap())?; @@ -20,7 +19,7 @@ pub fn from_ignore_list(ignore_list: &IgnoreList) -> Result }) } - pub fn is_match(&self, file_name: &FileName) -> bool { + pub(crate) fn is_match(&self, file_name: &FileName) -> bool { match file_name { FileName::Stdin => false, FileName::Real(p) => self @@ -33,23 +32,26 @@ pub fn is_match(&self, file_name: &FileName) -> bool { #[cfg(test)] mod test { + use std::path::{Path, PathBuf}; + use crate::config::{Config, FileName}; use crate::ignore_path::IgnorePathSet; - use std::path::PathBuf; #[test] fn test_ignore_path_set() { - let config = Config::from_toml( - "ignore = [ - \"foo.rs\", - \"bar_dir/*\", - ]", - ) - .unwrap(); - let ignore_path_set = IgnorePathSet::from_ignore_list(&config.ignore()).unwrap(); - - assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/foo.rs")))); - assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("bar_dir/baz.rs")))); - assert!(!ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/bar.rs")))); + match option_env!("CFG_RELEASE_CHANNEL") { + // this test requires nightly + None | Some("nightly") => { + let config = + Config::from_toml(r#"ignore = ["foo.rs", "bar_dir/*"]"#, Path::new("")) + .unwrap(); + let ignore_path_set = IgnorePathSet::from_ignore_list(&config.ignore()).unwrap(); + + assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/foo.rs")))); + assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("bar_dir/baz.rs")))); + assert!(!ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/bar.rs")))); + } + _ => (), + }; } }