mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
Add cargo file tidy test
This commit is contained in:
parent
85e1f0905a
commit
e73ffbf1e5
@ -10,8 +10,8 @@ edition = "2018"
|
||||
cargo-fuzz = true
|
||||
|
||||
[dependencies]
|
||||
syntax = { path = ".." }
|
||||
text_edit = { path = "../../text_edit" }
|
||||
syntax = { path = "..", version = "0.0.0" }
|
||||
text_edit = { path = "../../text_edit", version = "0.0.0" }
|
||||
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" }
|
||||
|
||||
# Prevent this from interfering with workspaces
|
||||
|
@ -38,19 +38,13 @@ pub fn rust_files() -> impl Iterator<Item = PathBuf> {
|
||||
rust_files_in(&project_root().join("crates"))
|
||||
}
|
||||
|
||||
pub fn rust_files_in(path: &Path) -> impl Iterator<Item = PathBuf> {
|
||||
let iter = WalkDir::new(path);
|
||||
return iter
|
||||
.into_iter()
|
||||
.filter_entry(|e| !is_hidden(e))
|
||||
.map(|e| e.unwrap())
|
||||
.filter(|e| !e.file_type().is_dir())
|
||||
.map(|e| e.into_path())
|
||||
.filter(|path| path.extension().map(|it| it == "rs").unwrap_or(false));
|
||||
pub fn cargo_files() -> impl Iterator<Item = PathBuf> {
|
||||
files_in(&project_root(), "toml")
|
||||
.filter(|path| path.file_name().map(|it| it == "Cargo.toml").unwrap_or(false))
|
||||
}
|
||||
|
||||
fn is_hidden(entry: &DirEntry) -> bool {
|
||||
entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false)
|
||||
}
|
||||
pub fn rust_files_in(path: &Path) -> impl Iterator<Item = PathBuf> {
|
||||
files_in(path, "rs")
|
||||
}
|
||||
|
||||
pub fn run_rustfmt(mode: Mode) -> Result<()> {
|
||||
@ -120,3 +114,18 @@ fn date_iso() -> Result<String> {
|
||||
fn is_release_tag(tag: &str) -> bool {
|
||||
tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit())
|
||||
}
|
||||
|
||||
fn files_in(path: &Path, ext: &'static str) -> impl Iterator<Item = PathBuf> {
|
||||
let iter = WalkDir::new(path);
|
||||
return iter
|
||||
.into_iter()
|
||||
.filter_entry(|e| !is_hidden(e))
|
||||
.map(|e| e.unwrap())
|
||||
.filter(|e| !e.file_type().is_dir())
|
||||
.map(|e| e.into_path())
|
||||
.filter(move |path| path.extension().map(|it| it == ext).unwrap_or(false));
|
||||
|
||||
fn is_hidden(entry: &DirEntry) -> bool {
|
||||
entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ use std::{
|
||||
|
||||
use xshell::{cmd, read_file};
|
||||
use xtask::{
|
||||
cargo_files,
|
||||
codegen::{self, Mode},
|
||||
project_root, run_rustfmt, rust_files,
|
||||
};
|
||||
@ -93,6 +94,32 @@ fn rust_files_are_tidy() {
|
||||
tidy_docs.finish();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cargo_files_are_tidy() {
|
||||
for cargo in cargo_files() {
|
||||
let mut section = None;
|
||||
for (line_no, text) in read_file(&cargo).unwrap().lines().enumerate() {
|
||||
let text = text.trim();
|
||||
if text.starts_with("[") {
|
||||
section = Some(text);
|
||||
continue;
|
||||
}
|
||||
if !section.map(|it| it.starts_with("[dependencies")).unwrap_or(false) {
|
||||
continue;
|
||||
}
|
||||
let text: String = text.split_whitespace().collect();
|
||||
if text.contains("path=") && !text.contains("version") {
|
||||
panic!(
|
||||
"\ncargo internal dependencies should have version.\n\
|
||||
{}:{}\n",
|
||||
cargo.display(),
|
||||
line_no + 1
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_merge_commits() {
|
||||
let stdout = cmd!("git rev-list --merges --invert-grep --author 'bors\\[bot\\]' HEAD~19..")
|
||||
|
Loading…
Reference in New Issue
Block a user