Skip to content

internal: Replace only occurence of check_expect with check_diagnostics #16260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 6 additions & 96 deletions crates/ide-diagnostics/src/handlers/unresolved_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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: [email protected]
[email protected] "mod"
[email protected] " "
[email protected]
[email protected] "foo"
[email protected] ";"
,
},
),
},
]
"#]],
check_diagnostics(
r#"
mod foo;
//^^^^^^^^ 💡 error: unresolved module, can't find module file: foo.rs, or foo/mod.rs
"#,
);
}
}
12 changes: 0 additions & 12 deletions crates/ide-diagnostics/src/tests.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -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();
Expand Down