Skip to content

Commit 37d4252

Browse files
Merge #940
940: check for newlines in test r=Alexhuszagh a=Emilgardis Co-authored-by: Emil Gardström <[email protected]>
2 parents d526484 + e76760d commit 37d4252

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

rustfmt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ use_field_init_shorthand = true
66
reorder_impl_items = true
77
edition = "2021"
88
newline_style = "Unix"
9-
format_code_in_doc_comments = true
9+
format_code_in_doc_comments = true

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,7 @@ pub(crate) fn warn_host_version_mismatch(
583583
rustc_commit: &str,
584584
msg_info: &mut MessageInfo,
585585
) -> Result<VersionMatch> {
586-
let host_commit = (&host_version_meta.short_version_string)
587-
.splitn(3, ' ')
588-
.nth(2);
586+
let host_commit = host_version_meta.short_version_string.splitn(3, ' ').nth(2);
589587
let rustc_commit_date = rustc_commit
590588
.split_once(' ')
591589
.and_then(|x| x.1.strip_suffix(')'));

src/tests.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use std::{
88
use once_cell::sync::OnceCell;
99
use rustc_version::VersionMeta;
1010

11+
use crate::ToUtf8;
12+
1113
static WORKSPACE: OnceCell<PathBuf> = OnceCell::new();
1214

1315
/// Returns the cargo workspace for the manifest
@@ -26,19 +28,22 @@ pub fn get_cargo_workspace() -> &'static Path {
2628
pub fn walk_dir<'a>(
2729
root: &'_ Path,
2830
skip: &'a [impl AsRef<OsStr>],
31+
ext: impl for<'s> Fn(Option<&'s std::ffi::OsStr>) -> bool + 'static,
2932
) -> impl Iterator<Item = Result<walkdir::DirEntry, walkdir::Error>> + 'a {
30-
walkdir::WalkDir::new(root).into_iter().filter_entry(|e| {
31-
if skip
32-
.iter()
33-
.map(|s| -> &std::ffi::OsStr { s.as_ref() })
34-
.any(|dir| e.file_name() == dir)
35-
{
36-
return false;
37-
} else if e.file_type().is_dir() {
38-
return true;
39-
}
40-
e.path().extension() == Some("md".as_ref())
41-
})
33+
walkdir::WalkDir::new(root)
34+
.into_iter()
35+
.filter_entry(move |e| {
36+
if skip
37+
.iter()
38+
.map(|s| -> &std::ffi::OsStr { s.as_ref() })
39+
.any(|dir| e.file_name() == dir)
40+
{
41+
return false;
42+
} else if e.file_type().is_dir() {
43+
return true;
44+
}
45+
ext(e.path().extension())
46+
})
4247
}
4348

4449
#[test]
@@ -124,3 +129,21 @@ release: {version}
124129
"1.0.0-nightly (22222222 2022-02-02)",
125130
);
126131
}
132+
133+
#[test]
134+
fn check_newlines() -> crate::Result<()> {
135+
for file in walk_dir(get_cargo_workspace(), &[".git", "target"], |_| true) {
136+
let file = file?;
137+
if !file.file_type().is_file() {
138+
continue;
139+
}
140+
assert!(
141+
crate::file::read(file.path())
142+
.unwrap_or_else(|_| String::from("\n"))
143+
.ends_with('\n'),
144+
"file {:?} does not end with a newline",
145+
file.path().to_utf8()?
146+
);
147+
}
148+
Ok(())
149+
}

src/tests/toml.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fn toml_check() -> Result<(), Box<dyn std::error::Error>> {
2525
"CODE_OF_CONDUCT.md",
2626
"CHANGELOG.md",
2727
],
28+
|p| p == Some("md".as_ref()),
2829
);
2930

3031
for dir_entry in walk {

0 commit comments

Comments
 (0)