]> git.lizzy.rs Git - rust.git/commitdiff
Use rustfmt.toml when running self_tests
authortopecongiro <seuchida@gmail.com>
Sun, 6 May 2018 07:16:58 +0000 (16:16 +0900)
committertopecongiro <seuchida@gmail.com>
Sun, 6 May 2018 07:16:58 +0000 (16:16 +0900)
src/config/config_type.rs
src/test/mod.rs

index 06c05bb9355dd52549f86489f68dbcad6ddee6da..f12d1864728df93e2a083993dc3cb190586b60f8 100644 (file)
@@ -322,8 +322,9 @@ pub(super) fn from_toml_path(file_path: &Path) -> Result<Config, Error> {
             ///
             /// Returns the `Config` to use, and the path of the project file if there was
             /// one.
-            pub(super) fn from_resolved_toml_path(dir: &Path) -> Result<(Config, Option<PathBuf>), Error> {
-
+            pub(super) fn from_resolved_toml_path(
+                dir: &Path,
+            ) -> Result<(Config, Option<PathBuf>), Error> {
                 /// Try to find a project file in the given directory and its parents.
                 /// Returns the path of a the nearest project file if one exists,
                 /// or `None` if no project file was found.
index 2680830f065674f9be8c82663021bb19102c9bdd..d1e7cbd5a64784701c2bb53ad4b02cc7b45f12e2 100644 (file)
@@ -111,7 +111,7 @@ fn write_message(msg: &str) {
 fn system_tests() {
     // Get all files in the tests/source directory.
     let files = get_test_files(Path::new("tests/source"), true);
-    let (_reports, count, fails) = check_files(files);
+    let (_reports, count, fails) = check_files(files, None);
 
     // Display results.
     println!("Ran {} system tests.", count);
@@ -123,7 +123,7 @@ fn system_tests() {
 #[test]
 fn coverage_tests() {
     let files = get_test_files(Path::new("tests/coverage/source"), true);
-    let (_reports, count, fails) = check_files(files);
+    let (_reports, count, fails) = check_files(files, None);
 
     println!("Ran {} tests in coverage mode.", count);
     assert_eq!(fails, 0, "{} tests failed", fails);
@@ -192,7 +192,7 @@ fn assert_output(source: &Path, expected_filename: &Path) {
 fn idempotence_tests() {
     // Get all files in the tests/target directory.
     let files = get_test_files(Path::new("tests/target"), true);
-    let (_reports, count, fails) = check_files(files);
+    let (_reports, count, fails) = check_files(files, None);
 
     // Display results.
     println!("Ran {} idempotent tests.", count);
@@ -213,7 +213,7 @@ fn self_tests() {
     }
     files.push(PathBuf::from("src/lib.rs"));
 
-    let (reports, count, fails) = check_files(files);
+    let (reports, count, fails) = check_files(files, Some(PathBuf::from("rustfmt.toml")));
     let mut warnings = 0;
 
     // Display results.
@@ -298,7 +298,7 @@ fn format_lines_errors_are_reported_with_tabs() {
 
 // For each file, run rustfmt and collect the output.
 // Returns the number of files checked and the number of failures.
-fn check_files(files: Vec<PathBuf>) -> (Vec<FormatReport>, u32, u32) {
+fn check_files(files: Vec<PathBuf>, opt_config: Option<PathBuf>) -> (Vec<FormatReport>, u32, u32) {
     let mut count = 0;
     let mut fails = 0;
     let mut reports = vec![];
@@ -306,7 +306,7 @@ fn check_files(files: Vec<PathBuf>) -> (Vec<FormatReport>, u32, u32) {
     for file_name in files {
         debug!("Testing '{}'...", file_name.display());
 
-        match idempotent_check(&file_name) {
+        match idempotent_check(&file_name, &opt_config) {
             Ok(ref report) if report.has_warnings() => {
                 print!("{}", report);
                 fails += 1;
@@ -385,9 +385,16 @@ pub enum IdempotentCheckError {
     Parse,
 }
 
-pub fn idempotent_check(filename: &PathBuf) -> Result<FormatReport, IdempotentCheckError> {
+pub fn idempotent_check(
+    filename: &PathBuf,
+    opt_config: &Option<PathBuf>,
+) -> Result<FormatReport, IdempotentCheckError> {
     let sig_comments = read_significant_comments(filename);
-    let config = read_config(filename);
+    let config = if let Some(ref config_file_path) = opt_config {
+        Config::from_toml_path(config_file_path).expect("rustfmt.toml not found")
+    } else {
+        read_config(filename)
+    };
     let (error_summary, file_map, format_report) = format_file(filename, &config);
     if error_summary.has_parsing_errors() {
         return Err(IdempotentCheckError::Parse);