about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEdwin Cheng <edwin0cheng@gmail.com>2021-02-03 22:01:09 +0800
committerEdwin Cheng <edwin0cheng@gmail.com>2021-02-03 22:01:09 +0800
commite73ffbf1e59eb05fe8ffe73ce4e1833295c588a5 (patch)
tree48f6079b55d32e13f355443aa82a5278a9c68a23
parent85e1f0905aae762b8d64b52e76bbc6aa5915894b (diff)
downloadrust-e73ffbf1e59eb05fe8ffe73ce4e1833295c588a5.tar.gz
rust-e73ffbf1e59eb05fe8ffe73ce4e1833295c588a5.zip
Add cargo file tidy test
-rw-r--r--crates/syntax/fuzz/Cargo.toml4
-rw-r--r--xtask/src/lib.rs33
-rw-r--r--xtask/tests/tidy.rs27
3 files changed, 50 insertions, 14 deletions
diff --git a/crates/syntax/fuzz/Cargo.toml b/crates/syntax/fuzz/Cargo.toml
index 32c40d1b95c..e22cd6b0c5d 100644
--- a/crates/syntax/fuzz/Cargo.toml
+++ b/crates/syntax/fuzz/Cargo.toml
@@ -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
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs
index 16b06b853b8..b19985fb238 100644
--- a/xtask/src/lib.rs
+++ b/xtask/src/lib.rs
@@ -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)
+    }
+}
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs
index 9a6933b094d..cb83e07fd1b 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,
 };
@@ -94,6 +95,32 @@ fn rust_files_are_tidy() {
 }
 
 #[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..")
         .read()