Add cargo file tidy test

This commit is contained in:
Edwin Cheng 2021-02-03 22:01:09 +08:00
parent 85e1f0905a
commit e73ffbf1e5
3 changed files with 50 additions and 14 deletions

View file

@ -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..")