From f05f7ab082c29edd182b25c27eafd21a6d9f6862 Mon Sep 17 00:00:00 2001 From: hkalbasi Date: Tue, 18 Apr 2023 17:38:38 +0330 Subject: [PATCH] Add minicore smoke test --- crates/ide-diagnostics/src/tests.rs | 22 ++++++++- crates/ide/src/inlay_hints/chaining.rs | 12 ++--- crates/test-utils/src/fixture.rs | 21 +++++++- crates/test-utils/src/minicore.rs | 66 ++++++++++++++++++++------ 4 files changed, 97 insertions(+), 24 deletions(-) diff --git a/crates/ide-diagnostics/src/tests.rs b/crates/ide-diagnostics/src/tests.rs index afa641c733e..413689561bc 100644 --- a/crates/ide-diagnostics/src/tests.rs +++ b/crates/ide-diagnostics/src/tests.rs @@ -8,7 +8,7 @@ RootDatabase, }; use stdx::trim_indent; -use test_utils::{assert_eq_text, extract_annotations}; +use test_utils::{assert_eq_text, extract_annotations, MiniCore}; use crate::{DiagnosticsConfig, ExprFillDefaultMode, Severity}; @@ -143,3 +143,23 @@ fn test_disabled_diagnostics() { ); assert!(!diagnostics.is_empty()); } + +#[test] +fn minicore_smoke_test() { + fn check(minicore: MiniCore) { + let source = minicore.source_code(); + let mut config = DiagnosticsConfig::test_sample(); + // This should be ignored since we conditionaly remove code which creates single item use with braces + config.disabled.insert("unnecessary-braces".to_string()); + check_diagnostics_with_config(config, &source); + } + + // Checks that there is no diagnostic in minicore for each flag. + for flag in MiniCore::available_flags() { + eprintln!("Checking minicore flag {flag}"); + check(MiniCore::from_flags([flag])); + } + // And one time for all flags, to check codes which are behind multiple flags + prevent name collisions + eprintln!("Checking all minicore flags"); + check(MiniCore::from_flags(MiniCore::available_flags())) +} diff --git a/crates/ide/src/inlay_hints/chaining.rs b/crates/ide/src/inlay_hints/chaining.rs index 6db9b8b5443..069edaed665 100644 --- a/crates/ide/src/inlay_hints/chaining.rs +++ b/crates/ide/src/inlay_hints/chaining.rs @@ -444,7 +444,7 @@ fn main() { file_id: FileId( 1, ), - range: 5805..5813, + range: 5768..5776, }, ), tooltip: "", @@ -457,7 +457,7 @@ fn main() { file_id: FileId( 1, ), - range: 5837..5841, + range: 5800..5804, }, ), tooltip: "", @@ -478,7 +478,7 @@ fn main() { file_id: FileId( 1, ), - range: 5805..5813, + range: 5768..5776, }, ), tooltip: "", @@ -491,7 +491,7 @@ fn main() { file_id: FileId( 1, ), - range: 5837..5841, + range: 5800..5804, }, ), tooltip: "", @@ -512,7 +512,7 @@ fn main() { file_id: FileId( 1, ), - range: 5805..5813, + range: 5768..5776, }, ), tooltip: "", @@ -525,7 +525,7 @@ fn main() { file_id: FileId( 1, ), - range: 5837..5841, + range: 5800..5804, }, ), tooltip: "", diff --git a/crates/test-utils/src/fixture.rs b/crates/test-utils/src/fixture.rs index 29ab21ac1db..05f32f8e51e 100644 --- a/crates/test-utils/src/fixture.rs +++ b/crates/test-utils/src/fixture.rs @@ -254,10 +254,19 @@ fn parse_meta_line(meta: &str) -> Fixture { } impl MiniCore { + const RAW_SOURCE: &str = include_str!("./minicore.rs"); + fn has_flag(&self, flag: &str) -> bool { self.activated_flags.iter().any(|it| it == flag) } + pub fn from_flags<'a>(flags: impl IntoIterator) -> Self { + MiniCore { + activated_flags: flags.into_iter().map(|x| x.to_owned()).collect(), + valid_flags: Vec::new(), + } + } + #[track_caller] fn assert_valid_flag(&self, flag: &str) { if !self.valid_flags.iter().any(|it| it == flag) { @@ -278,13 +287,21 @@ fn parse(line: &str) -> MiniCore { res } + pub fn available_flags() -> impl Iterator { + let lines = MiniCore::RAW_SOURCE.split_inclusive('\n'); + lines + .map_while(|x| x.strip_prefix("//!")) + .skip_while(|line| !line.contains("Available flags:")) + .skip(1) + .map(|x| x.split_once(':').unwrap().0.trim()) + } + /// Strips parts of minicore.rs which are flagged by inactive flags. /// /// This is probably over-engineered to support flags dependencies. pub fn source_code(mut self) -> String { let mut buf = String::new(); - let raw_mini_core = include_str!("./minicore.rs"); - let mut lines = raw_mini_core.split_inclusive('\n'); + let mut lines = MiniCore::RAW_SOURCE.split_inclusive('\n'); let mut implications = Vec::new(); diff --git a/crates/test-utils/src/minicore.rs b/crates/test-utils/src/minicore.rs index 308dc5892e5..2f0c086092e 100644 --- a/crates/test-utils/src/minicore.rs +++ b/crates/test-utils/src/minicore.rs @@ -32,8 +32,9 @@ //! iterator: option //! iterators: iterator, fn //! non_zero: -//! option: +//! option: panic //! ord: eq, option +//! panic: //! pin: //! range: //! result: @@ -191,6 +192,12 @@ pub enum Infallible {} // endregion:infallible } +// region:drop +pub mod mem { + pub fn drop(_x: T) {} +} +// endregion:drop + pub mod ops { // region:coerce_unsized mod unsize { @@ -315,12 +322,6 @@ unsafe impl SliceIndex<[T]> for usize { pub use self::index::{Index, IndexMut}; // endregion:index - // region:drop - pub mod mem { - pub fn drop(_x: T) {} - } - // endregion:drop - // region:range mod range { #[lang = "RangeFull"] @@ -473,12 +474,24 @@ pub trait Try: FromResidual { impl Try for ControlFlow { type Output = C; type Residual = ControlFlow; - fn from_output(output: Self::Output) -> Self {} - fn branch(self) -> ControlFlow {} + fn from_output(output: Self::Output) -> Self { + ControlFlow::Continue(output) + } + fn branch(self) -> ControlFlow { + match self { + ControlFlow::Continue(x) => ControlFlow::Continue(x), + ControlFlow::Break(x) => ControlFlow::Break(ControlFlow::Break(x)), + } + } } impl FromResidual for ControlFlow { - fn from_residual(residual: ControlFlow) -> Self {} + fn from_residual(residual: ControlFlow) -> Self { + match residual { + ControlFlow::Break(b) => ControlFlow::Break(b), + ControlFlow::Continue(_) => loop {}, + } + } } // region:option impl Try for Option { @@ -499,6 +512,7 @@ impl FromResidual for Option { fn from_residual(x: Option) -> Self { match x { None => None, + Some(_) => loop {}, } } } @@ -527,6 +541,7 @@ impl> FromResidual> for Result { fn from_residual(residual: Result) -> Self { match residual { Err(e) => Err(From::from(e)), + Ok(_) => loop {}, } } } @@ -840,8 +855,6 @@ fn next(&mut self) -> Option { mod traits { mod iterator { - use super::super::Take; - pub trait Iterator { type Item; #[lang = "next"] @@ -903,7 +916,7 @@ pub struct IntoIter { type Item = T; type IntoIter = IntoIter; fn into_iter(self) -> I { - IntoIter { data: self, range: IndexRange { start: 0, end: self.len() } } + IntoIter { data: self, range: IndexRange { start: 0, end: loop {} } } } } impl Iterator for IntoIter { @@ -919,16 +932,38 @@ fn next(&mut self) -> Option { } // endregion:iterator -// region:derive +// region:panic +mod panic { + pub macro panic_2021 { + ($($t:tt)+) => ( + /* Nothing yet */ + ), + } +} +// endregion:panic + mod macros { + // region:panic + #[macro_export] + #[rustc_builtin_macro(std_panic)] + macro_rules! panic { + ($($arg:tt)*) => { + /* compiler built-in */ + }; + } + + pub(crate) use panic; + // endregion:panic + + // region:derive pub(crate) mod builtin { #[rustc_builtin_macro] pub macro derive($item:item) { /* compiler built-in */ } } + // endregion:derive } -// endregion:derive // region:non_zero pub mod num { @@ -983,6 +1018,7 @@ pub mod v1 { ops::{Fn, FnMut, FnOnce}, // :fn option::Option::{self, None, Some}, // :option result::Result::{self, Err, Ok}, // :result + panic, // :panic }; }