66
77Utilities for testing [ ` tracing ` ] and crates that uses it.
88
9+ [ ![ Crates.io] [ crates-badge ]] [ crates-url ]
10+ [ ![ Documentation] [ docs-badge ]] [ docs-url ]
911[ ![ Documentation (master)] [ docs-master-badge ]] [ docs-master-url ]
1012[ ![ MIT licensed] [ mit-badge ]] [ mit-url ]
1113[ ![ Build Status] [ actions-badge ]] [ actions-url ]
1214[ ![ Discord chat] [ discord-badge ]] [ discord-url ]
1315
1416[ Documentation] [ docs-master-url ] | [ Chat] [ discord-url ]
1517
18+ [ crates-badge ] : https://img.shields.io/crates/v/tracing-mock.svg
19+ [ crates-url ] : https://crates.io/crates/tracing-mock
20+ [ docs-badge ] : https://docs.rs/tracing-mock/badge.svg
21+ [ docs-url ] : https://docs.rs/tracing-mock/latest
1622[ docs-master-badge ] : https://img.shields.io/badge/docs-master-blue
17- [ docs-master-url ] : https://tracing-rs.netlify.com /tracing_mock
23+ [ docs-master-url ] : https://tracing.rs /tracing_mock
1824[ mit-badge ] : https://img.shields.io/badge/license-MIT-blue.svg
1925[ mit-url ] : https://github.com/tokio-rs/tracing/blob/master/tracing-mock/LICENSE
2026[ actions-badge ] : https://github.com/tokio-rs/tracing/workflows/CI/badge.svg
@@ -32,40 +38,35 @@ by code under test.
3238* Compiler support: [ requires ` rustc ` 1.63+] [ msrv ] *
3339
3440[ msrv ] : #supported-rust-versions
41+ [ `tracing` ] : https://github.com/tokio-rs/tracing
3542
3643## Usage
3744
38- ` tracing-mock ` crate provides a mock
39- [ ` Collector ` ] ( https://tracing-rs.netlify.app/tracing/#collectors )
40- that allows asserting on the order and contents of
41- [ spans] ( https://tracing-rs.netlify.app/tracing/#spans ) and
42- [ events] ( https://tracing-rs.netlify.app/tracing/#events ) .
45+ The ` tracing-mock ` crate provides a mock [ ` Subscriber ` ] [ tracing-subscriber ] that
46+ allows asserting on the order and contents of [ spans] [ tracing-spans ] and
47+ [ events] [ tracing-events ] .
4348
44- As ` tracing-mock ` isn't available on [ crates.io] ( https://crates.io/ )
45- yet, you must import it via git. When using ` tracing-mock ` with the
46- ` tracing ` ` 0.1 ` ecosystem, it is important that you also override the
47- source of any ` tracing ` crates that are transient dependencies. For
48- example, the ` Cargo.toml ` for your test crate could contain:
49+ To get started with ` tracing-mock ` , check the documentation in the
50+ [ ` subscriber ` ] [ mock-subscriber-mod ] module and [ ` MockSubscriber ` ] struct.
4951
50- ``` toml
51- [ dependencies ]
52- lib-under-test = " 1.0 " # depends on `tracing`
52+ While ` tracing-mock ` is in beta, it is recommended that an exact version is
53+ specified in the cargo manifest. Otherwise, ` cargo update ` will take the latest
54+ beta version, which may contain breaking changes compared to previous betas.
5355
54- [dev-dependencies ]
55- tracing-mock = { git = " https://github.com/tokio-rs/tracing" , branch = " v0.1.x" , version = " 0.1" }
56- tracing = { git = " https://github.com/tokio-rs/tracing" , branch = " v0.1.x" , version = " 0.1" }
56+ To do so, add the following to ` Cargo.toml ` :
5757
58- [ patch . crates-io ]
59- tracing = { git = " https://github.com/tokio-rs/tracing " , branch = " v0.1.x " }
60- tracing-core = { git = " https://github.com/tokio-rs/tracing " , branch = " v0 .1.x " }
58+ ``` toml
59+ [ dependencies ]
60+ tracing-mock = " = 0 .1.0-beta.1 "
6161```
6262
63- ## Examples
63+ [ tracing-spans ] : https://docs.rs/tracing/0.1/tracing/#spans
64+ [ tracing-events ] : https://docs.rs/tracing/0.1/tracing/#events
65+ [ tracing-subscriber ] : https://docs.rs/tracing/0.1/tracing/trait.Subscriber.html
66+ [ mock-subscriber-mod ] : https://docs.rs/tracing-mock/0.1.0-beta.1/tracing_mock/subscriber/index.html
67+ [ `MockSubscriber` ] : https://docs.rs/tracing-mock/0.1.0-beta.1/tracing_mock/subscriber/struct.MockSubscriber.html
6468
65- The following examples are for the ` master ` branch. For examples that
66- will work with ` tracing ` from [ crates.io] , please check the
67- [ v0.1.x] ( https://github.com/tokio-rs/tracing/tree/v0.1.x/tracing-mock )
68- branch.
69+ ## Examples
6970
7071Below is an example that checks that an event contains a message:
7172
@@ -87,7 +88,6 @@ with_default(subscriber, || {
8788});
8889
8990handle . assert_finished ();
90-
9191```
9292
9393Below is a slightly more complex example. ` tracing-mock ` asserts that, in order:
0 commit comments