6
6
7
7
Utilities for testing [ ` tracing ` ] and crates that uses it.
8
8
9
+ [ ![ Crates.io] [ crates-badge ]] [ crates-url ]
10
+ [ ![ Documentation] [ docs-badge ]] [ docs-url ]
9
11
[ ![ Documentation (master)] [ docs-master-badge ]] [ docs-master-url ]
10
12
[ ![ MIT licensed] [ mit-badge ]] [ mit-url ]
11
13
[ ![ Build Status] [ actions-badge ]] [ actions-url ]
12
14
[ ![ Discord chat] [ discord-badge ]] [ discord-url ]
13
15
14
16
[ Documentation] [ docs-master-url ] | [ Chat] [ discord-url ]
15
17
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
16
22
[ 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
18
24
[ mit-badge ] : https://img.shields.io/badge/license-MIT-blue.svg
19
25
[ mit-url ] : https://github.com/tokio-rs/tracing/blob/master/tracing-mock/LICENSE
20
26
[ actions-badge ] : https://github.com/tokio-rs/tracing/workflows/CI/badge.svg
@@ -32,40 +38,35 @@ by code under test.
32
38
* Compiler support: [ requires ` rustc ` 1.63+] [ msrv ] *
33
39
34
40
[ msrv ] : #supported-rust-versions
41
+ [ `tracing` ] : https://github.com/tokio-rs/tracing
35
42
36
43
## Usage
37
44
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 ] .
43
48
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.
49
51
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.
53
55
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 ` :
57
57
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 "
61
61
```
62
62
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
64
68
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
69
70
70
71
Below is an example that checks that an event contains a message:
71
72
@@ -87,7 +88,6 @@ with_default(subscriber, || {
87
88
});
88
89
89
90
handle . assert_finished ();
90
-
91
91
```
92
92
93
93
Below is a slightly more complex example. ` tracing-mock ` asserts that, in order:
0 commit comments