From 79ee4b59ee35b40f68ed5fe9207be60ebf25641b Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:25:47 +0000 Subject: [PATCH] matrix-sdk-crypto: enable tracing for in-crate tests --- Cargo.lock | 2 ++ crates/matrix-sdk-crypto/Cargo.toml | 2 ++ crates/matrix-sdk-crypto/src/lib.rs | 11 +++++++++++ 3 files changed, 15 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a96a5ec4c..409c9b0be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2734,6 +2734,7 @@ dependencies = [ "bs58", "byteorder", "cfg-if", + "ctor", "ctr", "dashmap", "event-listener", @@ -2758,6 +2759,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "tracing-subscriber", "vodozemac", "zeroize", ] diff --git a/crates/matrix-sdk-crypto/Cargo.toml b/crates/matrix-sdk-crypto/Cargo.toml index 146093242..3f3421193 100644 --- a/crates/matrix-sdk-crypto/Cargo.toml +++ b/crates/matrix-sdk-crypto/Cargo.toml @@ -60,6 +60,7 @@ tokio = { version = "1.24", default-features = false, features = ["time"] } [dev-dependencies] anyhow = { workspace = true } assert_matches = "1.5.0" +ctor.workspace = true futures = { version = "0.3.21", default-features = false, features = ["executor"] } http = { workspace = true } indoc = "1.0.4" @@ -67,3 +68,4 @@ matrix-sdk-test = { version = "0.6.0", path = "../../testing/matrix-sdk-test" } proptest = { version = "1.0.0", default-features = false, features = ["std"] } # required for async_test macro tokio = { version = "1.24.2", default-features = false, features = ["macros", "rt-multi-thread"] } +tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } diff --git a/crates/matrix-sdk-crypto/src/lib.rs b/crates/matrix-sdk-crypto/src/lib.rs index 0d2b781ce..fb58a2dcd 100644 --- a/crates/matrix-sdk-crypto/src/lib.rs +++ b/crates/matrix-sdk-crypto/src/lib.rs @@ -109,3 +109,14 @@ pub mod vodozemac { /// The version of the matrix-sdk-cypto crate being used pub static VERSION: &str = env!("CARGO_PKG_VERSION"); + +// Enable tracing for tests in this crate +#[cfg(all(test, not(target_arch = "wasm32")))] +#[ctor::ctor] +fn init_logging() { + use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::from_default_env()) + .with(tracing_subscriber::fmt::layer().with_test_writer()) + .init(); +}