Skip to content

Commit 0bffdf2

Browse files
Disable all source-gen tests at compile time
1 parent 5f3f428 commit 0bffdf2

File tree

12 files changed

+63
-5
lines changed

12 files changed

+63
-5
lines changed

crates/ide-assists/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ hir = { path = "../hir", version = "0.0.0" }
2626
test-utils = { path = "../test-utils" }
2727
sourcegen = { path = "../sourcegen" }
2828
expect-test = "1.4.0"
29+
30+
[features]
31+
in-rust-tree = []

crates/ide-assists/src/tests/sourcegen.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
//! Generates `assists.md` documentation.
22
3+
#[cfg(not(feature = "in-rust-tree"))]
34
use std::{fmt, fs, path::Path};
45

6+
#[cfg(not(feature = "in-rust-tree"))]
57
use test_utils::project_root;
68

9+
#[cfg(not(feature = "in-rust-tree"))]
710
#[test]
811
fn sourcegen_assists_docs() {
912
let assists = Assist::collect();
@@ -59,20 +62,24 @@ r#####"
5962
fs::write(dst, contents).unwrap();
6063
}
6164
}
65+
66+
#[cfg(not(feature = "in-rust-tree"))]
6267
#[derive(Debug)]
6368
struct Section {
6469
doc: String,
6570
before: String,
6671
after: String,
6772
}
6873

74+
#[cfg(not(feature = "in-rust-tree"))]
6975
#[derive(Debug)]
7076
struct Assist {
7177
id: String,
7278
location: sourcegen::Location,
7379
sections: Vec<Section>,
7480
}
7581

82+
#[cfg(not(feature = "in-rust-tree"))]
7683
impl Assist {
7784
fn collect() -> Vec<Assist> {
7885
let handlers_dir = project_root().join("crates/ide-assists/src/handlers");
@@ -104,9 +111,11 @@ impl Assist {
104111
while lines.peek().is_some() {
105112
let doc = take_until(lines.by_ref(), "```").trim().to_string();
106113
assert!(
107-
(doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.')) || assist.sections.len() > 0,
114+
(doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.'))
115+
|| assist.sections.len() > 0,
108116
"\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n",
109-
&assist.id, doc,
117+
&assist.id,
118+
doc,
110119
);
111120

112121
let before = take_until(lines.by_ref(), "```");
@@ -135,6 +144,7 @@ impl Assist {
135144
}
136145
}
137146

147+
#[cfg(not(feature = "in-rust-tree"))]
138148
impl fmt::Display for Assist {
139149
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
140150
let _ = writeln!(
@@ -169,13 +179,15 @@ impl fmt::Display for Assist {
169179
}
170180
}
171181

182+
#[cfg(not(feature = "in-rust-tree"))]
172183
fn hide_hash_comments(text: &str) -> String {
173184
text.split('\n') // want final newline
174185
.filter(|&it| !(it.starts_with("# ") || it == "#"))
175186
.map(|it| format!("{}\n", it))
176187
.collect()
177188
}
178189

190+
#[cfg(not(feature = "in-rust-tree"))]
179191
fn reveal_hash_comments(text: &str) -> String {
180192
text.split('\n') // want final newline
181193
.map(|it| {

crates/ide-diagnostics/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ expect-test = "1.4.0"
2929

3030
test-utils = { path = "../test-utils" }
3131
sourcegen = { path = "../sourcegen" }
32+
33+
[features]
34+
in-rust-tree = []

crates/ide-diagnostics/src/tests/sourcegen.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
//! Generates `assists.md` documentation.
22
3+
#[cfg(not(feature = "in-rust-tree"))]
34
use std::{fmt, fs, io, path::PathBuf};
45

6+
#[cfg(not(feature = "in-rust-tree"))]
57
use sourcegen::project_root;
68

9+
#[cfg(not(feature = "in-rust-tree"))]
710
#[test]
811
fn sourcegen_diagnostic_docs() {
912
let diagnostics = Diagnostic::collect().unwrap();
@@ -14,13 +17,15 @@ fn sourcegen_diagnostic_docs() {
1417
fs::write(&dst, &contents).unwrap();
1518
}
1619

20+
#[cfg(not(feature = "in-rust-tree"))]
1721
#[derive(Debug)]
1822
struct Diagnostic {
1923
id: String,
2024
location: sourcegen::Location,
2125
doc: String,
2226
}
2327

28+
#[cfg(not(feature = "in-rust-tree"))]
2429
impl Diagnostic {
2530
fn collect() -> io::Result<Vec<Diagnostic>> {
2631
let handlers_dir = project_root().join("crates/ide-diagnostics/src/handlers");
@@ -51,6 +56,7 @@ impl Diagnostic {
5156
}
5257
}
5358

59+
#[cfg(not(feature = "in-rust-tree"))]
5460
fn is_valid_diagnostic_name(diagnostic: &str) -> Result<(), String> {
5561
let diagnostic = diagnostic.trim();
5662
if diagnostic.find(char::is_whitespace).is_some() {
@@ -66,6 +72,7 @@ fn is_valid_diagnostic_name(diagnostic: &str) -> Result<(), String> {
6672
Ok(())
6773
}
6874

75+
#[cfg(not(feature = "in-rust-tree"))]
6976
impl fmt::Display for Diagnostic {
7077
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7178
writeln!(f, "=== {}\n**Source:** {}\n{}", self.id, self.location, self.doc)

crates/ide/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ toolchain = { path = "../toolchain", version = "0.0.0" }
4242
[dev-dependencies]
4343
test-utils = { path = "../test-utils" }
4444
expect-test = "1.4.0"
45+
46+
[features]
47+
in-rust-tree = ["ide-assists/in-rust-tree", "ide-diagnostics/in-rust-tree"]

crates/rust-analyzer/Cargo.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,9 @@ mbe = { path = "../mbe" }
8484
[features]
8585
jemalloc = ["jemallocator", "profile/jemalloc"]
8686
force-always-assert = ["always-assert/force"]
87-
in-rust-tree = ["proc-macro-srv/sysroot-abi"]
87+
in-rust-tree = [
88+
"proc-macro-srv/sysroot-abi",
89+
"sourcegen/in-rust-tree",
90+
"ide/in-rust-tree",
91+
"syntax/in-rust-tree"
92+
]

crates/rust-analyzer/tests/slow-tests/sourcegen.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Generates `assists.md` documentation.
22
3+
#[cfg(not(feature = "in-rust-tree"))]
34
use std::{fmt, fs, io, path::PathBuf};
45

6+
#[cfg(not(feature = "in-rust-tree"))]
57
#[test]
68
fn sourcegen_feature_docs() {
79
let features = Feature::collect().unwrap();
@@ -17,13 +19,15 @@ fn sourcegen_feature_docs() {
1719
fs::write(&dst, &contents).unwrap();
1820
}
1921

22+
#[cfg(not(feature = "in-rust-tree"))]
2023
#[derive(Debug)]
2124
struct Feature {
2225
id: String,
2326
location: sourcegen::Location,
2427
doc: String,
2528
}
2629

30+
#[cfg(not(feature = "in-rust-tree"))]
2731
impl Feature {
2832
fn collect() -> io::Result<Vec<Feature>> {
2933
let crates_dir = sourcegen::project_root().join("crates");
@@ -54,6 +58,7 @@ impl Feature {
5458
}
5559
}
5660

61+
#[cfg(not(feature = "in-rust-tree"))]
5762
fn is_valid_feature_name(feature: &str) -> Result<(), String> {
5863
'word: for word in feature.split_whitespace() {
5964
for short in ["to", "and"] {
@@ -73,6 +78,7 @@ fn is_valid_feature_name(feature: &str) -> Result<(), String> {
7378
Ok(())
7479
}
7580

81+
#[cfg(not(feature = "in-rust-tree"))]
7682
impl fmt::Display for Feature {
7783
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7884
writeln!(f, "=== {}\n**Source:** {}\n{}", self.id, self.location, self.doc)

crates/rust-analyzer/tests/slow-tests/tidy.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ use std::{
33
path::{Path, PathBuf},
44
};
55

6-
use xshell::{cmd, Shell};
6+
use xshell::Shell;
77

8+
#[cfg(not(feature = "in-rust-tree"))]
9+
use xshell::cmd;
10+
11+
#[cfg(not(feature = "in-rust-tree"))]
812
#[test]
913
fn check_code_formatting() {
1014
let sh = &Shell::new().unwrap();
@@ -168,6 +172,7 @@ See https://github.com/rust-lang/rust-clippy/issues/5537 for discussion.
168172
}
169173
}
170174

175+
#[cfg(not(feature = "in-rust-tree"))]
171176
#[test]
172177
fn check_licenses() {
173178
let sh = &Shell::new().unwrap();

crates/sourcegen/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ doctest = false
1111

1212
[dependencies]
1313
xshell = "0.2.2"
14+
15+
[features]
16+
in-rust-tree = []

crates/syntax/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ ungrammar = "1.16.1"
3434

3535
test-utils = { path = "../test-utils" }
3636
sourcegen = { path = "../sourcegen" }
37+
38+
[features]
39+
in-rust-tree = []

crates/syntax/src/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
mod sourcegen_ast;
21
mod ast_src;
2+
#[cfg(not(feature = "in-rust-tree"))]
3+
mod sourcegen_ast;
34

45
use std::{
56
fs,

crates/syntax/src/tests/ast_src.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Defines input for code generation process.
22
3+
#[cfg(not(feature = "in-rust-tree"))]
34
pub(crate) struct KindsSrc<'a> {
45
pub(crate) punct: &'a [(&'a str, &'a str)],
56
pub(crate) keywords: &'a [&'a str],
@@ -9,6 +10,7 @@ pub(crate) struct KindsSrc<'a> {
910
pub(crate) nodes: &'a [&'a str],
1011
}
1112

13+
#[cfg(not(feature = "in-rust-tree"))]
1214
pub(crate) const KINDS_SRC: KindsSrc<'_> = KindsSrc {
1315
punct: &[
1416
(";", "SEMICOLON"),
@@ -216,13 +218,15 @@ pub(crate) const KINDS_SRC: KindsSrc<'_> = KindsSrc {
216218
],
217219
};
218220

221+
#[cfg(not(feature = "in-rust-tree"))]
219222
#[derive(Default, Debug)]
220223
pub(crate) struct AstSrc {
221224
pub(crate) tokens: Vec<String>,
222225
pub(crate) nodes: Vec<AstNodeSrc>,
223226
pub(crate) enums: Vec<AstEnumSrc>,
224227
}
225228

229+
#[cfg(not(feature = "in-rust-tree"))]
226230
#[derive(Debug)]
227231
pub(crate) struct AstNodeSrc {
228232
pub(crate) doc: Vec<String>,
@@ -231,18 +235,21 @@ pub(crate) struct AstNodeSrc {
231235
pub(crate) fields: Vec<Field>,
232236
}
233237

238+
#[cfg(not(feature = "in-rust-tree"))]
234239
#[derive(Debug, Eq, PartialEq)]
235240
pub(crate) enum Field {
236241
Token(String),
237242
Node { name: String, ty: String, cardinality: Cardinality },
238243
}
239244

245+
#[cfg(not(feature = "in-rust-tree"))]
240246
#[derive(Debug, Eq, PartialEq)]
241247
pub(crate) enum Cardinality {
242248
Optional,
243249
Many,
244250
}
245251

252+
#[cfg(not(feature = "in-rust-tree"))]
246253
#[derive(Debug)]
247254
pub(crate) struct AstEnumSrc {
248255
pub(crate) doc: Vec<String>,

0 commit comments

Comments
 (0)