Auto merge of #16260 - Urhengulas:ide-diagnostics-refactor-tests, r=lnicola
internal: Replace only occurence of `check_expect` with `check_diagnostics` Part of https://github.com/rust-lang/rust-analyzer/issues/14268.
This commit is contained in:
commit
a795f4836c
@ -58,9 +58,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedModule) -> Option<Vec<
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use expect_test::expect;
|
||||
|
||||
use crate::tests::{check_diagnostics, check_expect};
|
||||
use crate::tests::check_diagnostics;
|
||||
|
||||
#[test]
|
||||
fn unresolved_module() {
|
||||
@ -78,99 +76,11 @@ mod baz {}
|
||||
|
||||
#[test]
|
||||
fn test_unresolved_module_diagnostic() {
|
||||
check_expect(
|
||||
r#"mod foo;"#,
|
||||
expect![[r#"
|
||||
[
|
||||
Diagnostic {
|
||||
code: RustcHardError(
|
||||
"E0583",
|
||||
),
|
||||
message: "unresolved module, can't find module file: foo.rs, or foo/mod.rs",
|
||||
range: FileRange {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
range: 0..8,
|
||||
},
|
||||
severity: Error,
|
||||
unused: false,
|
||||
experimental: false,
|
||||
fixes: Some(
|
||||
[
|
||||
Assist {
|
||||
id: AssistId(
|
||||
"create_module",
|
||||
QuickFix,
|
||||
),
|
||||
label: "Create module at `foo.rs`",
|
||||
group: None,
|
||||
target: 0..8,
|
||||
source_change: Some(
|
||||
SourceChange {
|
||||
source_file_edits: {},
|
||||
file_system_edits: [
|
||||
CreateFile {
|
||||
dst: AnchoredPathBuf {
|
||||
anchor: FileId(
|
||||
0,
|
||||
),
|
||||
path: "foo.rs",
|
||||
},
|
||||
initial_contents: "",
|
||||
},
|
||||
],
|
||||
is_snippet: false,
|
||||
},
|
||||
),
|
||||
trigger_signature_help: false,
|
||||
},
|
||||
Assist {
|
||||
id: AssistId(
|
||||
"create_module",
|
||||
QuickFix,
|
||||
),
|
||||
label: "Create module at `foo/mod.rs`",
|
||||
group: None,
|
||||
target: 0..8,
|
||||
source_change: Some(
|
||||
SourceChange {
|
||||
source_file_edits: {},
|
||||
file_system_edits: [
|
||||
CreateFile {
|
||||
dst: AnchoredPathBuf {
|
||||
anchor: FileId(
|
||||
0,
|
||||
),
|
||||
path: "foo/mod.rs",
|
||||
},
|
||||
initial_contents: "",
|
||||
},
|
||||
],
|
||||
is_snippet: false,
|
||||
},
|
||||
),
|
||||
trigger_signature_help: false,
|
||||
},
|
||||
],
|
||||
),
|
||||
main_node: Some(
|
||||
InFileWrapper {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
value: MODULE@0..8
|
||||
MOD_KW@0..3 "mod"
|
||||
WHITESPACE@3..4 " "
|
||||
NAME@4..7
|
||||
IDENT@4..7 "foo"
|
||||
SEMICOLON@7..8 ";"
|
||||
,
|
||||
},
|
||||
),
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
check_diagnostics(
|
||||
r#"
|
||||
mod foo;
|
||||
//^^^^^^^^ 💡 error: unresolved module, can't find module file: foo.rs, or foo/mod.rs
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
#[cfg(not(feature = "in-rust-tree"))]
|
||||
mod sourcegen;
|
||||
|
||||
use expect_test::Expect;
|
||||
use ide_db::{
|
||||
assists::AssistResolveStrategy, base_db::SourceDatabaseExt, LineIndexDatabase, RootDatabase,
|
||||
};
|
||||
@ -82,17 +81,6 @@ pub(crate) fn check_no_fix(ra_fixture: &str) {
|
||||
assert!(diagnostic.fixes.is_none(), "got a fix when none was expected: {diagnostic:?}");
|
||||
}
|
||||
|
||||
pub(crate) fn check_expect(ra_fixture: &str, expect: Expect) {
|
||||
let (db, file_id) = RootDatabase::with_single_file(ra_fixture);
|
||||
let diagnostics = super::diagnostics(
|
||||
&db,
|
||||
&DiagnosticsConfig::test_sample(),
|
||||
&AssistResolveStrategy::All,
|
||||
file_id,
|
||||
);
|
||||
expect.assert_debug_eq(&diagnostics)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub(crate) fn check_diagnostics(ra_fixture: &str) {
|
||||
let mut config = DiagnosticsConfig::test_sample();
|
||||
|
Loading…
x
Reference in New Issue
Block a user