diff options
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/codegen/gen_feature_docs.rs | 12 | ||||
-rw-r--r-- | xtask/tests/tidy.rs | 7 |
2 files changed, 14 insertions, 5 deletions
diff --git a/xtask/src/codegen/gen_feature_docs.rs b/xtask/src/codegen/gen_feature_docs.rs index 3f0013e82..341e67c73 100644 --- a/xtask/src/codegen/gen_feature_docs.rs +++ b/xtask/src/codegen/gen_feature_docs.rs | |||
@@ -38,7 +38,9 @@ impl Feature { | |||
38 | 38 | ||
39 | for block in comment_blocks { | 39 | for block in comment_blocks { |
40 | let id = block.id; | 40 | let id = block.id; |
41 | assert!(is_valid_feature_name(&id), "invalid feature name: {:?}", id); | 41 | if let Err(msg) = is_valid_feature_name(&id) { |
42 | panic!("invalid feature name: {:?}:\n {}", id, msg) | ||
43 | } | ||
42 | let doc = block.contents.join("\n"); | 44 | let doc = block.contents.join("\n"); |
43 | let location = Location::new(path.clone(), block.line); | 45 | let location = Location::new(path.clone(), block.line); |
44 | acc.push(Feature { id, location, doc }) | 46 | acc.push(Feature { id, location, doc }) |
@@ -49,7 +51,7 @@ impl Feature { | |||
49 | } | 51 | } |
50 | } | 52 | } |
51 | 53 | ||
52 | fn is_valid_feature_name(feature: &str) -> bool { | 54 | fn is_valid_feature_name(feature: &str) -> Result<(), String> { |
53 | 'word: for word in feature.split_whitespace() { | 55 | 'word: for word in feature.split_whitespace() { |
54 | for &short in ["to", "and"].iter() { | 56 | for &short in ["to", "and"].iter() { |
55 | if word == short { | 57 | if word == short { |
@@ -58,14 +60,14 @@ fn is_valid_feature_name(feature: &str) -> bool { | |||
58 | } | 60 | } |
59 | for &short in ["To", "And"].iter() { | 61 | for &short in ["To", "And"].iter() { |
60 | if word == short { | 62 | if word == short { |
61 | return false; | 63 | return Err(format!("Don't capitalize {:?}", word)); |
62 | } | 64 | } |
63 | } | 65 | } |
64 | if !word.starts_with(char::is_uppercase) { | 66 | if !word.starts_with(char::is_uppercase) { |
65 | return false; | 67 | return Err(format!("Capitalize {:?}", word)); |
66 | } | 68 | } |
67 | } | 69 | } |
68 | true | 70 | Ok(()) |
69 | } | 71 | } |
70 | 72 | ||
71 | impl fmt::Display for Feature { | 73 | impl fmt::Display for Feature { |
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index 02b3afc96..01f04a17c 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs | |||
@@ -38,6 +38,13 @@ fn check_code_formatting() { | |||
38 | } | 38 | } |
39 | 39 | ||
40 | #[test] | 40 | #[test] |
41 | fn smoke_test_docs_generation() { | ||
42 | // We don't commit docs to the repo, so we can just overwrite in tests. | ||
43 | codegen::generate_assists_docs(Mode::Overwrite).unwrap(); | ||
44 | codegen::generate_feature_docs(Mode::Overwrite).unwrap(); | ||
45 | } | ||
46 | |||
47 | #[test] | ||
41 | fn rust_files_are_tidy() { | 48 | fn rust_files_are_tidy() { |
42 | let mut tidy_docs = TidyDocs::default(); | 49 | let mut tidy_docs = TidyDocs::default(); |
43 | for path in rust_files(&project_root().join("crates")) { | 50 | for path in rust_files(&project_root().join("crates")) { |