Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract test framework #793

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ members = [
"tracing-serde",
"tracing-appender",
"tracing-journald",
"tracing-test",
"examples"
]
1 change: 1 addition & 0 deletions tracing-attributes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ quote = "1"
[dev-dependencies]
tracing = { path = "../tracing", version = "0.1" }
tracing-futures = { path = "../tracing-futures", version = "0.2" }
tracing-test = { path = "../tracing-test", version = "0.1" }
tokio-test = { version = "0.2.0" }
tracing-core = { path = "../tracing-core", version = "0.1"}
async-trait = "0.1"
Expand Down
59 changes: 30 additions & 29 deletions tracing-attributes/tests/async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ async fn test_async_fn(polls: usize) -> Result<(), ()> {

#[test]
fn async_fn_only_enters_for_polls() {
let (subscriber, handle) = subscriber::mock()
.new_span(span::mock().named("test_async_fn"))
.enter(span::mock().named("test_async_fn"))
.event(event::mock().with_fields(field::mock("awaiting").with_value(&true)))
.exit(span::mock().named("test_async_fn"))
.enter(span::mock().named("test_async_fn"))
.exit(span::mock().named("test_async_fn"))
.drop_span(span::mock().named("test_async_fn"))
let (subscriber, handle) = subscriber::expect()
.new_span(span("test_async_fn"))
.enter(span("test_async_fn"))
.event(event().with_fields(field("awaiting").with_value(&true)))
.exit(span("test_async_fn"))
.enter(span("test_async_fn"))
.exit(span("test_async_fn"))
.drop_span(span("test_async_fn"))
.done()
.run_with_handle();
with_default(subscriber, || {
Expand All @@ -44,18 +44,18 @@ fn async_fn_nested() {
tracing::trace!(nested = true);
}

let span = span::mock().named("test_async_fns_nested");
let span2 = span::mock().named("test_async_fns_nested_other");
let (subscriber, handle) = subscriber::mock()
.new_span(span.clone())
.enter(span.clone())
let span1 = span("test_async_fns_nested");
let span2 = span("test_async_fns_nested_other");
let (subscriber, handle) = subscriber::expect()
.new_span(span1.clone())
.enter(span1.clone())
.new_span(span2.clone())
.enter(span2.clone())
.event(event::mock().with_fields(field::mock("nested").with_value(&true)))
.event(event().with_fields(field("nested").with_value(&true)))
.exit(span2.clone())
.drop_span(span2)
.exit(span.clone())
.drop_span(span)
.exit(span1.clone())
.drop_span(span1)
.done()
.run_with_handle();

Expand Down Expand Up @@ -118,28 +118,29 @@ fn async_fn_with_async_trait() {
}
}

let span = span::mock().named("foo");
let span2 = span::mock().named("bar");
let span3 = span::mock().named("baz");
let (subscriber, handle) = subscriber::mock()
let span1 = span("foo");
let span2 = span("bar");
let span3 = span("baz");
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone()
.with_field(field::mock("self"))
.with_field(field::mock("v")),
span1
.clone()
.with_field(field("self"))
.with_field(field("v")),
)
.enter(span.clone())
.enter(span1.clone())
.new_span(span3.clone())
.enter(span3.clone())
.event(event::mock().with_fields(field::mock("val").with_value(&2u64)))
.event(event().with_fields(field("val").with_value(&2u64)))
.exit(span3.clone())
.drop_span(span3)
.new_span(span2.clone().with_field(field::mock("self")))
.new_span(span2.clone().with_field(field("self")))
.enter(span2.clone())
.event(event::mock().with_fields(field::mock("val").with_value(&5u64)))
.event(event().with_fields(field("val").with_value(&5u64)))
.exit(span2.clone())
.drop_span(span2)
.exit(span.clone())
.drop_span(span)
.exit(span1.clone())
.drop_span(span1)
.done()
.run_with_handle();

Expand Down
58 changes: 28 additions & 30 deletions tracing-attributes/tests/destructuring.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
mod support;
use support::*;

use tracing::subscriber::with_default;
use tracing_attributes::instrument;
use tracing_test::*;

#[test]
fn destructure_tuples() {
#[instrument]
fn my_fn((arg1, arg2): (usize, usize)) {}

let span = span::mock().named("my_fn");
let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
field("arg1")
.with_value(&format_args!("1"))
.and(field::mock("arg2").with_value(&format_args!("2")))
.and(field("arg2").with_value(&format_args!("2")))
.only(),
),
)
Expand All @@ -38,16 +36,16 @@ fn destructure_nested_tuples() {
#[instrument]
fn my_fn(((arg1, arg2), (arg3, arg4)): ((usize, usize), (usize, usize))) {}

let span = span::mock().named("my_fn");
let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
field("arg1")
.with_value(&format_args!("1"))
.and(field::mock("arg2").with_value(&format_args!("2")))
.and(field::mock("arg3").with_value(&format_args!("3")))
.and(field::mock("arg4").with_value(&format_args!("4")))
.and(field("arg2").with_value(&format_args!("2")))
.and(field("arg3").with_value(&format_args!("3")))
.and(field("arg4").with_value(&format_args!("4")))
.only(),
),
)
Expand All @@ -69,12 +67,12 @@ fn destructure_refs() {
#[instrument]
fn my_fn(&arg1: &usize) {}

let span = span::mock().named("my_fn");
let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone()
.with_field(field::mock("arg1").with_value(&format_args!("1")).only()),
.with_field(field("arg1").with_value(&format_args!("1")).only()),
)
.enter(span.clone())
.exit(span.clone())
Expand All @@ -96,14 +94,14 @@ fn destructure_tuple_structs() {
#[instrument]
fn my_fn(Foo(arg1, arg2): Foo) {}

let span = span::mock().named("my_fn");
let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
field("arg1")
.with_value(&format_args!("1"))
.and(field::mock("arg2").with_value(&format_args!("2")))
.and(field("arg2").with_value(&format_args!("2")))
.only(),
),
)
Expand Down Expand Up @@ -137,14 +135,14 @@ fn destructure_structs() {
let _ = (arg1, arg2);
}

let span = span::mock().named("my_fn");
let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
field("arg1")
.with_value(&format_args!("1"))
.and(field::mock("arg2").with_value(&format_args!("2")))
.and(field("arg2").with_value(&format_args!("2")))
.only(),
),
)
Expand Down Expand Up @@ -182,16 +180,16 @@ fn destructure_everything() {
let _ = (arg1, arg2, arg3, arg4);
}

let span = span::mock().named("my_fn");
let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
field("arg1")
.with_value(&format_args!("1"))
.and(field::mock("arg2").with_value(&format_args!("2")))
.and(field::mock("arg3").with_value(&format_args!("3")))
.and(field::mock("arg4").with_value(&format_args!("4")))
.and(field("arg2").with_value(&format_args!("2")))
.and(field("arg3").with_value(&format_args!("3")))
.and(field("arg4").with_value(&format_args!("4")))
.only(),
),
)
Expand Down
16 changes: 8 additions & 8 deletions tracing-attributes/tests/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fn err() -> Result<u8, TryFromIntError> {

#[test]
fn test() {
let span = span::mock().named("err");
let (subscriber, handle) = subscriber::mock()
let span = span("err");
let (subscriber, handle) = subscriber::expect()
.new_span(span.clone())
.enter(span.clone())
.event(event::mock().at_level(Level::ERROR))
.event(event().at_level(Level::ERROR))
.exit(span.clone())
.drop_span(span)
.done()
Expand All @@ -41,18 +41,18 @@ async fn err_async(polls: usize) -> Result<u8, TryFromIntError> {

#[test]
fn test_async() {
let span = span::mock().named("err_async");
let (subscriber, handle) = subscriber::mock()
let span = span("err_async");
let (subscriber, handle) = subscriber::expect()
.new_span(span.clone())
.enter(span.clone())
.event(
event::mock()
.with_fields(field::mock("awaiting").with_value(&true))
event()
.with_fields(field("awaiting").with_value(&true))
.at_level(Level::TRACE),
)
.exit(span.clone())
.enter(span.clone())
.event(event::mock().at_level(Level::ERROR))
.event(event().at_level(Level::ERROR))
.exit(span.clone())
.drop_span(span)
.done()
Expand Down
Loading