-
Notifications
You must be signed in to change notification settings - Fork 324
feat(test): add a test utils crate to make log initialization possible everywhere #5521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bnjbvr
merged 8 commits into
matrix-org:main
from
multisme:feature/Solve_matrix_sk_common_not_settingg_up_a_test_tracing_subscriber
Aug 14, 2025
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c167ba6
Create a crate that allows the use of init_tracing_for_test par any c…
multisme eed14b4
change the version number of accuracy
multisme 7b953cf
Update the Cargo toml file
multisme 069cd73
Remove duplicated key
multisme b723ed8
Test tracing invocation
multisme 6a59a35
Move the init_tracing call to lib.rs
multisme 12afc31
Linting
multisme bcf77cf
up version to 0.13.0
bnjbvr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#![cfg(test)] | ||
|
||
matrix_sdk_test::init_tracing_for_tests!(); | ||
matrix_sdk_test_utils::init_tracing_for_tests!(); | ||
|
||
mod helpers; | ||
mod tests; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
homepage = "https://github.com/matrix-org/matrix-rust-sdk" | ||
keywords = ["matrix", "chat", "messaging", "ruma"] | ||
license = "Apache-2.0" | ||
name = "matrix-sdk-test-utils" | ||
version = "0.1.0" | ||
edition = "2024" | ||
rust-version.workspace = true | ||
|
||
[package.metadata.release] | ||
release = true | ||
|
||
[target.'cfg(not(target_family = "wasm"))'.dependencies] | ||
ctor = "0.2.9" | ||
tracing-subscriber = { workspace = true, features = ["env-filter"] } | ||
|
||
[lints] | ||
workspace = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Utils function for the test helpers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/// Initialize a tracing subscriber if the target architecture is not WASM. | ||
/// | ||
/// Uses a sensible default filter that can be overridden through the `RUST_LOG` | ||
/// environment variable and runs once before all tests by using the [`ctor`] | ||
/// crate. | ||
/// | ||
/// Invoke this macro once per compilation unit (`lib.rs`, `tests/*.rs`, | ||
/// `tests/*/main.rs`). | ||
#[macro_export] | ||
macro_rules! init_tracing_for_tests { | ||
() => { | ||
#[cfg(not(target_family = "wasm"))] | ||
#[$crate::__macro_support::ctor] | ||
fn init_logging() { | ||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; | ||
use $crate::__macro_support::tracing_subscriber; | ||
|
||
tracing_subscriber::registry() | ||
.with(tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { | ||
// Output is only printed for failing tests, but still we shouldn't overload | ||
// the output with unnecessary info. When debugging a specific test, it's easy | ||
// to override this default by setting the `RUST_LOG` environment variable. | ||
// | ||
// Since tracing_subscriber does prefix matching, the `matrix_sdk=` directive | ||
// takes effect for all the main crates (`matrix_sdk_base`, `matrix_sdk_crypto` | ||
// and so on). | ||
"info,matrix_sdk=debug".into() | ||
})) | ||
.with(tracing_subscriber::fmt::layer().with_test_writer()) | ||
.init(); | ||
} | ||
}; | ||
} | ||
|
||
#[doc(hidden)] | ||
pub mod __macro_support { | ||
#[cfg(not(target_family = "wasm"))] | ||
pub use ctor::ctor; | ||
#[cfg(not(target_family = "wasm"))] | ||
pub use tracing_subscriber; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.