Repository: cross-rs/cross
Pull request #940 (2022-07-11 18:31:16)

check for newlines in test


Patch:
diff --git a/rustfmt.yml b/rustfmt.yml
index bddf895..fdd7eb4 100644
--- a/rustfmt.yml
+++ b/rustfmt.yml
@@ -6,4 +6,4 @@ use_field_init_shorthand = true
 reorder_impl_items = true
 edition = "2021"
 newline_style = "Unix"
-format_code_in_doc_comments = true
\ No newline at end of file
+format_code_in_doc_comments = true
diff --git a/src/lib.rs b/src/lib.rs
index e7f25c8..31f6d8f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -583,9 +583,7 @@ pub(crate) fn warn_host_version_mismatch(
     rustc_commit: &str,
     msg_info: &mut MessageInfo,
 ) -> Result<VersionMatch> {
-    let host_commit = (&host_version_meta.short_version_string)
-        .splitn(3, ' ')
-        .nth(2);
+    let host_commit = host_version_meta.short_version_string.splitn(3, ' ').nth(2);
     let rustc_commit_date = rustc_commit
         .split_once(' ')
         .and_then(|x| x.1.strip_suffix(')'));


Test patch:
diff --git a/src/tests.rs b/src/tests.rs
index 16f2436..4dc02ea 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -8,6 +8,8 @@ use std::{
 use once_cell::sync::OnceCell;
 use rustc_version::VersionMeta;
 
+use crate::ToUtf8;
+
 static WORKSPACE: OnceCell<PathBuf> = OnceCell::new();
 
 /// Returns the cargo workspace for the manifest
@@ -26,19 +28,22 @@ pub fn get_cargo_workspace() -> &'static Path {
 pub fn walk_dir<'a>(
     root: &'_ Path,
     skip: &'a [impl AsRef<OsStr>],
+    ext: impl for<'s> Fn(Option<&'s std::ffi::OsStr>) -> bool + 'static,
 ) -> impl Iterator<Item = Result<walkdir::DirEntry, walkdir::Error>> + 'a {
-    walkdir::WalkDir::new(root).into_iter().filter_entry(|e| {
-        if skip
-            .iter()
-            .map(|s| -> &std::ffi::OsStr { s.as_ref() })
-            .any(|dir| e.file_name() == dir)
-        {
-            return false;
-        } else if e.file_type().is_dir() {
-            return true;
-        }
-        e.path().extension() == Some("md".as_ref())
-    })
+    walkdir::WalkDir::new(root)
+        .into_iter()
+        .filter_entry(move |e| {
+            if skip
+                .iter()
+                .map(|s| -> &std::ffi::OsStr { s.as_ref() })
+                .any(|dir| e.file_name() == dir)
+            {
+                return false;
+            } else if e.file_type().is_dir() {
+                return true;
+            }
+            ext(e.path().extension())
+        })
 }
 
 #[test]
@@ -124,3 +129,21 @@ release: {version}
         "1.0.0-nightly (22222222 2022-02-02)",
     );
 }
+
+#[test]
+fn check_newlines() -> crate::Result<()> {
+    for file in walk_dir(get_cargo_workspace(), &[".git", "target"], |_| true) {
+        let file = file?;
+        if !file.file_type().is_file() {
+            continue;
+        }
+        assert!(
+            crate::file::read(file.path())
+                .unwrap_or_else(|_| String::from("\n"))
+                .ends_with('\n'),
+            "file {:?} does not end with a newline",
+            file.path().to_utf8()?
+        );
+    }
+    Ok(())
+}
diff --git a/src/tests/toml.rs b/src/tests/toml.rs
index d917ea9..377bdb7 100644
--- a/src/tests/toml.rs
+++ b/src/tests/toml.rs
@@ -25,6 +25,7 @@ fn toml_check() -> Result<(), Box<dyn std::error::Error>> {
             "CODE_OF_CONDUCT.md",
             "CHANGELOG.md",
         ],
+        |p| p == Some("md".as_ref()),
     );
 
     for dir_entry in walk {