-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add #[test_log(default_log_filter = "___")]
Users can now specify a default_log_filter via #[test_log(default_log_filter = "foo")] which will be used when RUST_LOG is not specified. Please note that because env_logger / tracing is initialized globally, it is possible that this value will be ignored if they have already been initialized by a different test. Fixes: #25
- Loading branch information
1 parent
e1d5d67
commit c6c137d
Showing
4 changed files
with
161 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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,14 @@ | ||
//! Use this file for iterating on the derive code. You can view the | ||
//! expanded code for any given configuration by updating this file and | ||
//! running: | ||
//! | ||
//! ```sh | ||
//! cargo expand --tests --example main | ||
//! ``` | ||
#[test_log::test] | ||
fn works() { | ||
assert_eq!(2 + 2, 4); | ||
} | ||
|
||
fn main() {} |
This file contains 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 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,22 @@ | ||
//! This test needs to be defined in a separate file because it depends | ||
//! on global state (logger) and can't be run in parallel/the same | ||
//! process with other tests to avoid flakiness (other tests | ||
//! initializing `env_logger` first). | ||
#![cfg(feature = "log")] | ||
|
||
use std::env; | ||
|
||
use logging::log_enabled; | ||
use logging::Level; | ||
|
||
|
||
#[test_log::test(tokio::test)] | ||
#[test_log(default_log_filter = "debug")] | ||
async fn with_inner_test_attribute_and_default_log_filter_defined() { | ||
// Check that RUST_LOG isn't set, because that could affect the | ||
// outcome of this test since we're checking that we fallback to | ||
// "debug" if no RUST_LOG is set. | ||
assert!(env::var(env_logger::DEFAULT_FILTER_ENV).is_err()); | ||
assert!(log_enabled!(Level::Debug)); | ||
} |
This file contains 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