From aad911fb0cd772e809270be3e0a526d4738b9dd5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 18 Aug 2020 17:20:10 +0200 Subject: Speedup ty tests Closes #5792 --- crates/hir_ty/src/tests.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs index c953925ec..91c9d38c5 100644 --- a/crates/hir_ty/src/tests.rs +++ b/crates/hir_ty/src/tests.rs @@ -8,7 +8,7 @@ mod method_resolution; mod macros; mod display_source_code; -use std::sync::Arc; +use std::{env, sync::Arc}; use base_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt}; use expect::Expect; @@ -22,12 +22,14 @@ use hir_def::{ AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, }; use hir_expand::{db::AstDatabase, InFile}; -use stdx::format_to; +use stdx::{format_to, RacyFlag}; use syntax::{ algo, ast::{self, AstNode}, SyntaxNode, }; +use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry}; +use tracing_tree::HierarchicalLayer; use crate::{ db::HirDatabase, display::HirDisplay, infer::TypeMismatch, test_db::TestDB, InferenceResult, Ty, @@ -37,9 +39,12 @@ use crate::{ // against snapshots of the expected results using expect. Use // `env UPDATE_EXPECT=1 cargo test -p hir_ty` to update the snapshots. -fn setup_tracing() -> tracing::subscriber::DefaultGuard { - use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry}; - use tracing_tree::HierarchicalLayer; +fn setup_tracing() -> Option { + static ENABLE: RacyFlag = RacyFlag::new(); + if !ENABLE.get(|| env::var("CHALK_DEBUG").is_ok()) { + return None; + } + let filter = EnvFilter::from_env("CHALK_DEBUG"); let layer = HierarchicalLayer::default() .with_indent_lines(true) @@ -47,7 +52,7 @@ fn setup_tracing() -> tracing::subscriber::DefaultGuard { .with_indent_amount(2) .with_writer(std::io::stderr); let subscriber = Registry::default().with(filter).with(layer); - tracing::subscriber::set_default(subscriber) + Some(tracing::subscriber::set_default(subscriber)) } fn check_types(ra_fixture: &str) { -- cgit v1.2.3