Skip to content

Commit a795f48

Browse files
committed
Auto merge of rust-lang#16260 - Urhengulas:ide-diagnostics-refactor-tests, r=lnicola
internal: Replace only occurence of `check_expect` with `check_diagnostics` Part of rust-lang/rust-analyzer#14268.
2 parents e88788e + 03b1ecd commit a795f48

File tree

2 files changed

+6
-108
lines changed

2 files changed

+6
-108
lines changed

crates/ide-diagnostics/src/handlers/unresolved_module.rs

+6-96
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedModule) -> Option<Vec<
5858

5959
#[cfg(test)]
6060
mod tests {
61-
use expect_test::expect;
62-
63-
use crate::tests::{check_diagnostics, check_expect};
61+
use crate::tests::check_diagnostics;
6462

6563
#[test]
6664
fn unresolved_module() {
@@ -78,99 +76,11 @@ mod baz {}
7876

7977
#[test]
8078
fn test_unresolved_module_diagnostic() {
81-
check_expect(
82-
r#"mod foo;"#,
83-
expect![[r#"
84-
[
85-
Diagnostic {
86-
code: RustcHardError(
87-
"E0583",
88-
),
89-
message: "unresolved module, can't find module file: foo.rs, or foo/mod.rs",
90-
range: FileRange {
91-
file_id: FileId(
92-
0,
93-
),
94-
range: 0..8,
95-
},
96-
severity: Error,
97-
unused: false,
98-
experimental: false,
99-
fixes: Some(
100-
[
101-
Assist {
102-
id: AssistId(
103-
"create_module",
104-
QuickFix,
105-
),
106-
label: "Create module at `foo.rs`",
107-
group: None,
108-
target: 0..8,
109-
source_change: Some(
110-
SourceChange {
111-
source_file_edits: {},
112-
file_system_edits: [
113-
CreateFile {
114-
dst: AnchoredPathBuf {
115-
anchor: FileId(
116-
0,
117-
),
118-
path: "foo.rs",
119-
},
120-
initial_contents: "",
121-
},
122-
],
123-
is_snippet: false,
124-
},
125-
),
126-
trigger_signature_help: false,
127-
},
128-
Assist {
129-
id: AssistId(
130-
"create_module",
131-
QuickFix,
132-
),
133-
label: "Create module at `foo/mod.rs`",
134-
group: None,
135-
target: 0..8,
136-
source_change: Some(
137-
SourceChange {
138-
source_file_edits: {},
139-
file_system_edits: [
140-
CreateFile {
141-
dst: AnchoredPathBuf {
142-
anchor: FileId(
143-
0,
144-
),
145-
path: "foo/mod.rs",
146-
},
147-
initial_contents: "",
148-
},
149-
],
150-
is_snippet: false,
151-
},
152-
),
153-
trigger_signature_help: false,
154-
},
155-
],
156-
),
157-
main_node: Some(
158-
InFileWrapper {
159-
file_id: FileId(
160-
0,
161-
),
162-
163-
164-
165-
166-
167-
168-
,
169-
},
170-
),
171-
},
172-
]
173-
"#]],
79+
check_diagnostics(
80+
r#"
81+
mod foo;
82+
//^^^^^^^^ 💡 error: unresolved module, can't find module file: foo.rs, or foo/mod.rs
83+
"#,
17484
);
17585
}
17686
}

crates/ide-diagnostics/src/tests.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#[cfg(not(feature = "in-rust-tree"))]
22
mod sourcegen;
33

4-
use expect_test::Expect;
54
use ide_db::{
65
assists::AssistResolveStrategy, base_db::SourceDatabaseExt, LineIndexDatabase, RootDatabase,
76
};
@@ -82,17 +81,6 @@ pub(crate) fn check_no_fix(ra_fixture: &str) {
8281
assert!(diagnostic.fixes.is_none(), "got a fix when none was expected: {diagnostic:?}");
8382
}
8483

85-
pub(crate) fn check_expect(ra_fixture: &str, expect: Expect) {
86-
let (db, file_id) = RootDatabase::with_single_file(ra_fixture);
87-
let diagnostics = super::diagnostics(
88-
&db,
89-
&DiagnosticsConfig::test_sample(),
90-
&AssistResolveStrategy::All,
91-
file_id,
92-
);
93-
expect.assert_debug_eq(&diagnostics)
94-
}
95-
9684
#[track_caller]
9785
pub(crate) fn check_diagnostics(ra_fixture: &str) {
9886
let mut config = DiagnosticsConfig::test_sample();

0 commit comments

Comments
 (0)