]> git.lizzy.rs Git - rust.git/blobdiff - src/ignore_path.rs
Merge commit 'c4416f20dcaec5d93077f72470e83e150fb923b1' into sync-rustfmt
[rust.git] / src / ignore_path.rs
index 6299aedf4a755199870f88c4d6f73ac2f44411b3..d955949496a67c7214902c39cc174952e6fb883c 100644 (file)
@@ -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<Self, ignore::Error> {
-        let mut ignore_builder = gitignore::GitignoreBuilder::new(PathBuf::from(""));
+    pub(crate) fn from_ignore_list(ignore_list: &IgnoreList) -> Result<Self, ignore::Error> {
+        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<Self, ignore::Error>
         })
     }
 
-    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,21 @@ pub fn is_match(&self, file_name: &FileName) -> bool {
 
 #[cfg(test)]
 mod test {
-    use crate::config::{Config, FileName};
-    use crate::ignore_path::IgnorePathSet;
-    use std::path::PathBuf;
+    use rustfmt_config_proc_macro::nightly_only_test;
 
+    #[nightly_only_test]
     #[test]
     fn test_ignore_path_set() {
-        match option_env!("CFG_RELEASE_CHANNEL") {
-            // this test requires nightly
-            None | Some("nightly") => {
-                let config = Config::from_toml(r#"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"))));
-            }
-            _ => (),
-        };
+        use crate::config::{Config, FileName};
+        use crate::ignore_path::IgnorePathSet;
+        use std::path::{Path, PathBuf};
+
+        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"))));
     }
 }