From e73ffbf1e59eb05fe8ffe73ce4e1833295c588a5 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 3 Feb 2021 22:01:09 +0800 Subject: Add cargo file tidy test --- xtask/tests/tidy.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'xtask/tests') diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index 9a6933b09..cb83e07fd 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs @@ -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..") -- cgit v1.2.3