aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide/src/diagnostics.rs58
1 files changed, 57 insertions, 1 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index 33e4f1743..4abf602ad 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -316,7 +316,10 @@ mod tests {
316 use stdx::trim_indent; 316 use stdx::trim_indent;
317 use test_utils::assert_eq_text; 317 use test_utils::assert_eq_text;
318 318
319 use crate::mock_analysis::{analysis_and_position, single_file, MockAnalysis}; 319 use crate::{
320 mock_analysis::{analysis_and_position, single_file, MockAnalysis},
321 AnalysisConfig,
322 };
320 use expect::{expect, Expect}; 323 use expect::{expect, Expect};
321 324
322 /// Takes a multi-file input fixture with annotated cursor positions, 325 /// Takes a multi-file input fixture with annotated cursor positions,
@@ -380,6 +383,54 @@ mod tests {
380 assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics); 383 assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics);
381 } 384 }
382 385
386 /// Takes a multi-file input fixture with annotated cursor position and the list of disabled diagnostics,
387 /// and checks that provided diagnostics aren't spawned during analysis.
388 fn check_disabled_diagnostics(
389 ra_fixture: &str,
390 disabled_diagnostics: impl IntoIterator<Item = String>,
391 ) {
392 let disabled_diagnostics: std::collections::HashSet<_> =
393 disabled_diagnostics.into_iter().collect();
394
395 let mock = MockAnalysis::with_files(ra_fixture);
396 let files = mock.files().map(|(it, _)| it).collect::<Vec<_>>();
397 let mut analysis = mock.analysis();
398 analysis.set_config(AnalysisConfig { disabled_diagnostics: disabled_diagnostics.clone() });
399
400 let diagnostics = files
401 .clone()
402 .into_iter()
403 .flat_map(|file_id| analysis.diagnostics(file_id, true).unwrap())
404 .collect::<Vec<_>>();
405
406 // First, we have to check that diagnostic is not emitted when it's added to the disabled diagnostics list.
407 for diagnostic in diagnostics {
408 if let Some(name) = diagnostic.name {
409 assert!(!disabled_diagnostics.contains(&name), "Diagnostic {} is disabled", name);
410 }
411 }
412
413 // Then, we must reset the config and repeat the check, so that we'll be sure that without
414 // config these diagnostics are emitted.
415 // This is required for tests to not become outdated if e.g. diagnostics name changes:
416 // without this additional run the test will pass simply because a diagnostic with an old name
417 // will no longer exist.
418 analysis.set_config(AnalysisConfig { disabled_diagnostics: Default::default() });
419
420 let diagnostics = files
421 .into_iter()
422 .flat_map(|file_id| analysis.diagnostics(file_id, true).unwrap())
423 .collect::<Vec<_>>();
424
425 assert!(
426 diagnostics
427 .into_iter()
428 .filter_map(|diag| diag.name)
429 .any(|name| disabled_diagnostics.contains(&name)),
430 "At least one of the diagnostics was not emitted even without config; are the diagnostics names correct?"
431 );
432 }
433
383 fn check_expect(ra_fixture: &str, expect: Expect) { 434 fn check_expect(ra_fixture: &str, expect: Expect) {
384 let (analysis, file_id) = single_file(ra_fixture); 435 let (analysis, file_id) = single_file(ra_fixture);
385 let diagnostics = analysis.diagnostics(file_id, true).unwrap(); 436 let diagnostics = analysis.diagnostics(file_id, true).unwrap();
@@ -814,4 +865,9 @@ struct Foo {
814 ", 865 ",
815 ) 866 )
816 } 867 }
868
869 #[test]
870 fn test_disabled_diagnostics() {
871 check_disabled_diagnostics(r#"mod foo;"#, vec!["unresolved-module".to_string()]);
872 }
817} 873}