test_log/lib.rs
1// Copyright (C) 2019-2025 Daniel Mueller <deso@posteo.net>
2// SPDX-License-Identifier: (Apache-2.0 OR MIT)
3
4#![deny(missing_docs)]
5#![allow(clippy::test_attr_in_doctest)]
6
7//! A crate providing a replacement #[[macro@test]] attribute that
8//! initializes logging and/or tracing infrastructure before running
9//! tests.
10
11/// A procedural macro for the `test` attribute.
12///
13/// The attribute can be used to define a test that has the `env_logger`
14/// and/or `tracing` crates initialized (depending on the features used).
15///
16/// # Example
17///
18/// Specify the attribute on a per-test basis:
19/// ```rust
20/// # use logging::info;
21/// # // Note that no test would actually run, regardless of `no_run`,
22/// # // because we do not invoke the function.
23/// #[test_log::test]
24/// fn it_works() {
25/// info!("Checking whether it still works...");
26/// assert_eq!(2 + 2, 4);
27/// info!("Looks good!");
28/// }
29/// ```
30///
31/// It can be very convenient to convert over all tests by overriding
32/// the `#[test]` attribute on a per-module basis:
33/// ```rust
34/// use test_log::test;
35///
36/// #[test]
37/// fn it_still_works() {
38/// // ...
39/// }
40/// ```
41///
42/// The crate also supports stacking with other `#[test]` attributes.
43/// For example, you can stack
44/// [`#[tokio::test]`](https://docs.rs/tokio/1.45.1/tokio/attr.test.html)
45/// on top of this crate's `#[test]` attribute and test `async`
46/// functionality this way:
47///
48/// ```rust
49/// #[tokio::test]
50/// #[test_log::test]
51/// async fn it_still_works() {
52/// // ...
53/// }
54/// ```
55///
56/// Note that stacking `#[test]` attributes this way requires some minimal
57/// level of cooperation from the other crate to work properly (see
58/// [#46](https://github.com/d-e-s-o/test-log/pull/46) for details), but as
59/// a fallback a wrapping style can be used as well:
60/// ```rust
61/// use test_log::test;
62///
63/// #[test(tokio::test)]
64/// async fn it_also_works() {
65/// // ...
66/// }
67/// ```
68pub use test_log_macros::test;
69
70#[cfg(feature = "trace")]
71#[doc(hidden)]
72pub use tracing_subscriber;
73
74#[cfg(feature = "log")]
75#[doc(hidden)]
76pub use env_logger;