From a1940d8c75bee8c319e7e7f19607bdc4b01c28d4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 19:23:37 +0300 Subject: internal: check diagnostics in all files and not just the first one --- crates/ide/src/diagnostics/inactive_code.rs | 16 +++++++++------- crates/ide/src/diagnostics/macro_error.rs | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'crates/ide/src/diagnostics') diff --git a/crates/ide/src/diagnostics/inactive_code.rs b/crates/ide/src/diagnostics/inactive_code.rs index afe333204..d9d3e88c1 100644 --- a/crates/ide/src/diagnostics/inactive_code.rs +++ b/crates/ide/src/diagnostics/inactive_code.rs @@ -37,11 +37,16 @@ pub(super) fn inactive_code( #[cfg(test)] mod tests { - use crate::diagnostics::tests::check_diagnostics_with_inactive_code; + use crate::{diagnostics::tests::check_diagnostics_with_config, DiagnosticsConfig}; + + pub(crate) fn check(ra_fixture: &str) { + let config = DiagnosticsConfig::default(); + check_diagnostics_with_config(config, ra_fixture) + } #[test] fn cfg_diagnostics() { - check_diagnostics_with_inactive_code( + check( r#" fn f() { // The three g̶e̶n̶d̶e̶r̶s̶ statements: @@ -69,7 +74,6 @@ fn f() { //^^^^^^^^^^^ code is inactive due to #[cfg] directives: a is disabled } "#, - true, ); } @@ -77,7 +81,7 @@ fn f() { fn inactive_item() { // Additional tests in `cfg` crate. This only tests disabled cfgs. - check_diagnostics_with_inactive_code( + check( r#" #[cfg(no)] pub fn f() {} //^^^^^^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: no is disabled @@ -91,7 +95,6 @@ fn f() { #[cfg(feature = "std")] use std; //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: feature = "std" is disabled "#, - true, ); } @@ -99,7 +102,7 @@ fn f() { #[test] fn inactive_via_cfg_attr() { cov_mark::check!(cfg_attr_active); - check_diagnostics_with_inactive_code( + check( r#" #[cfg_attr(not(never), cfg(no))] fn f() {} //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: no is disabled @@ -111,7 +114,6 @@ fn f() { #[cfg_attr(not(never), inline, cfg(no))] fn h() {} //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: no is disabled "#, - true, ); } } diff --git a/crates/ide/src/diagnostics/macro_error.rs b/crates/ide/src/diagnostics/macro_error.rs index 8cc8cfb48..d76a3a094 100644 --- a/crates/ide/src/diagnostics/macro_error.rs +++ b/crates/ide/src/diagnostics/macro_error.rs @@ -14,7 +14,12 @@ pub(super) fn macro_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroError) -> #[cfg(test)] mod tests { - use crate::diagnostics::tests::{check_diagnostics, check_no_diagnostics}; + use crate::{ + diagnostics::tests::{ + check_diagnostics, check_diagnostics_with_config, check_no_diagnostics, + }, + DiagnosticsConfig, + }; #[test] fn builtin_macro_fails_expansion() { @@ -31,7 +36,14 @@ macro_rules! include { () => {} } #[test] fn include_macro_should_allow_empty_content() { - check_diagnostics( + let mut config = DiagnosticsConfig::default(); + + // FIXME: This is a false-positive, the file is actually linked in via + // `include!` macro + config.disabled.insert("unlinked-file".to_string()); + + check_diagnostics_with_config( + config, r#" //- /lib.rs #[rustc_builtin_macro] -- cgit v1.2.3