test_pretty_log/lib.rs
1// Copyright (C) 2019-2023 Daniel Mueller <deso@posteo.net>
2// SPDX-License-Identifier: (Apache-2.0 OR MIT)
3
4#![deny(missing_docs)]
5
6//! A crate providing a replacement #[[macro@test]] attribute that
7//! initializes logging and/or tracing infrastructure before running
8//! tests.
9//!
10//! This crate was forked from [test-log](https://github.com/d-e-s-o/test-log)
11
12/// A procedural macro for the `test` attribute.
13///
14/// The attribute can be used to define a test that has the `tracing`
15/// crates initialized (depending on the features used).
16///
17/// # Example
18///
19/// Specify the attribute on a per-test basis:
20/// ```rust
21/// # // doctests seemingly run in a slightly different environment where
22/// # // `super`, which is what our macro makes use of, is not available.
23/// # // By having a fake module here we work around that problem.
24/// # #[cfg(feature = "log")]
25/// # mod fordoctest {
26/// # use logging::info;
27/// # // Note that no test would actually run, regardless of `no_run`,
28/// # // because we do not invoke the function.
29/// #[test_pretty_log::test]
30/// fn it_works() {
31/// info!("Checking whether it still works...");
32/// assert_eq!(2 + 2, 4);
33/// info!("Looks good!");
34/// }
35/// # }
36/// ```
37///
38/// It can be very convenient to convert over all tests by overriding
39/// the `#[test]` attribute on a per-module basis:
40/// ```rust,no_run
41/// # mod fordoctest {
42/// use test_pretty_log::test;
43///
44/// #[test]
45/// fn it_still_works() {
46/// // ...
47/// }
48/// # }
49/// ```
50///
51/// You can also wrap another attribute. For example, suppose you use
52/// [`#[tokio::test]`](https://docs.rs/tokio/1.4.0/tokio/attr.test.html)
53/// to run async tests:
54/// ```
55/// # mod fordoctest {
56/// use test_pretty_log::test;
57///
58/// #[test(tokio::test)]
59/// async fn it_still_works() {
60/// // ...
61/// }
62/// # }
63/// ```
64pub use test_pretty_log_macros::test;
65
66#[doc(hidden)]
67pub mod runtime;
68
69#[doc(hidden)]
70pub use tracing_subscriber;