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
Prev Previous commit
Next Next commit
Rename subscriber::mock() to subscriber::expect()
  • Loading branch information
GeorgeHahn committed Jul 10, 2020
commit 634372fca7c655591c4fef6d0bb5d4fc3b8379c2
6 changes: 3 additions & 3 deletions tracing-attributes/tests/async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn test_async_fn(polls: usize) -> Result<(), ()> {

#[test]
fn async_fn_only_enters_for_polls() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span("test_async_fn"))
.enter(span("test_async_fn"))
.event(event::mock().with_fields(field::mock("awaiting").with_value(&true)))
Expand Down Expand Up @@ -46,7 +46,7 @@ fn async_fn_nested() {

let span1 = span("test_async_fns_nested");
let span2 = span("test_async_fns_nested_other");
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span1.clone())
.enter(span1.clone())
.new_span(span2.clone())
Expand Down Expand Up @@ -121,7 +121,7 @@ fn async_fn_with_async_trait() {
let span1 = span("foo");
let span2 = span("bar");
let span3 = span("baz");
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span1
.clone()
Expand Down
12 changes: 6 additions & 6 deletions tracing-attributes/tests/destructuring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn destructure_tuples() {

let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
Expand Down Expand Up @@ -38,7 +38,7 @@ fn destructure_nested_tuples() {

let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
Expand Down Expand Up @@ -69,7 +69,7 @@ fn destructure_refs() {

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()),
Expand All @@ -96,7 +96,7 @@ fn destructure_tuple_structs() {

let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
Expand Down Expand Up @@ -137,7 +137,7 @@ fn destructure_structs() {

let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
Expand Down Expand Up @@ -182,7 +182,7 @@ fn destructure_everything() {

let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
Expand Down
4 changes: 2 additions & 2 deletions tracing-attributes/tests/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn err() -> Result<u8, TryFromIntError> {
#[test]
fn test() {
let span = span("err");
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span.clone())
.enter(span.clone())
.event(event::mock().at_level(Level::ERROR))
Expand All @@ -42,7 +42,7 @@ async fn err_async(polls: usize) -> Result<u8, TryFromIntError> {
#[test]
fn test_async() {
let span = span("err_async");
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span.clone())
.enter(span.clone())
.event(
Expand Down
2 changes: 1 addition & 1 deletion tracing-attributes/tests/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn empty_field() {
}

fn run_test<F: FnOnce() -> T, T>(span1: NewSpan, fun: F) {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span1)
.enter(anonymous_span())
.exit(anonymous_span())
Expand Down
10 changes: 5 additions & 5 deletions tracing-attributes/tests/instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn override_everything() {
let span2 = span("my_other_fn")
.at_level(Level::DEBUG)
.with_target("my_target");
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span1.clone())
.enter(span1.clone())
.exit(span1.clone())
Expand Down Expand Up @@ -49,7 +49,7 @@ fn fields() {
let span2 = span("my_fn")
.at_level(Level::DEBUG)
.with_target("my_target");
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span1.clone().with_field(
field::mock("arg1")
Expand Down Expand Up @@ -97,7 +97,7 @@ fn skip() {
let span2 = span("my_fn")
.at_level(Level::DEBUG)
.with_target("my_target");
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span1
.clone()
Expand Down Expand Up @@ -139,7 +139,7 @@ fn generics() {

let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
Expand Down Expand Up @@ -172,7 +172,7 @@ fn methods() {

let span = span("my_fn");

let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("self")
Expand Down
4 changes: 2 additions & 2 deletions tracing-attributes/tests/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn named_levels() {

#[instrument(level = "eRrOr")]
fn error() {}
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span("trace").at_level(Level::TRACE))
.enter(span("trace").at_level(Level::TRACE))
.exit(span("trace").at_level(Level::TRACE))
Expand Down Expand Up @@ -65,7 +65,7 @@ fn numeric_levels() {

#[instrument(level = 5)]
fn error() {}
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span("trace").at_level(Level::TRACE))
.enter(span("trace").at_level(Level::TRACE))
.exit(span("trace").at_level(Level::TRACE))
Expand Down
6 changes: 3 additions & 3 deletions tracing-attributes/tests/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn custom_name_no_equals() {}

#[test]
fn default_name_test() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span("default_name"))
.enter(span("default_name"))
.exit(span("default_name"))
Expand All @@ -32,7 +32,7 @@ fn default_name_test() {

#[test]
fn custom_name_test() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span("my_name"))
.enter(span("my_name"))
.exit(span("my_name"))
Expand All @@ -48,7 +48,7 @@ fn custom_name_test() {

#[test]
fn custom_name_no_equals_test() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span("my_other_name"))
.enter(span("my_other_name"))
.exit(span("my_other_name"))
Expand Down
4 changes: 2 additions & 2 deletions tracing-attributes/tests/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod my_mod {

#[test]
fn default_targets() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span("default_target").with_target(module_path!()))
.enter(span("default_target").with_target(module_path!()))
.exit(span("default_target").with_target(module_path!()))
Expand All @@ -42,7 +42,7 @@ fn default_targets() {

#[test]
fn custom_targets() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.new_span(span("custom_target").with_target("my_target"))
.enter(span("custom_target").with_target("my_target"))
.exit(span("custom_target").with_target("my_target"))
Expand Down
12 changes: 6 additions & 6 deletions tracing-futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ mod tests {

#[test]
fn future_enter_exit_is_reasonable() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.enter(span("foo"))
.exit(span("foo"))
.enter(span("foo"))
Expand All @@ -550,7 +550,7 @@ mod tests {

#[test]
fn future_error_ends_span() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.enter(span("foo"))
.exit(span("foo"))
.enter(span("foo"))
Expand All @@ -570,7 +570,7 @@ mod tests {

#[test]
fn stream_enter_exit_is_reasonable() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.enter(span("foo"))
.exit(span("foo"))
.enter(span("foo"))
Expand All @@ -593,7 +593,7 @@ mod tests {

#[test]
fn span_follows_future_onto_threadpool() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.enter(span("a"))
.enter(span("b"))
.exit(span("b"))
Expand Down Expand Up @@ -631,7 +631,7 @@ mod tests {

#[test]
fn stream_enter_exit_is_reasonable() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.enter(span("foo"))
.exit(span("foo"))
.enter(span("foo"))
Expand All @@ -654,7 +654,7 @@ mod tests {

#[test]
fn sink_enter_exit_is_reasonable() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.enter(span("foo"))
.exit(span("foo"))
.enter(span("foo"))
Expand Down
4 changes: 2 additions & 2 deletions tracing-futures/tests/std_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tracing_futures::Instrument;

#[test]
fn enter_exit_is_reasonable() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.enter(span("foo"))
.exit(span("foo"))
.enter(span("foo"))
Expand All @@ -23,7 +23,7 @@ fn enter_exit_is_reasonable() {

#[test]
fn error_ends_span() {
let (subscriber, handle) = subscriber::mock()
let (subscriber, handle) = subscriber::expect()
.enter(span("foo"))
.exit(span("foo"))
.enter(span("foo"))
Expand Down
6 changes: 3 additions & 3 deletions tracing-subscriber/tests/field_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tracing_test::*;
#[test]
fn field_filter_events() {
let filter: EnvFilter = "[{thing}]=debug".parse().expect("filter should parse");
let (subscriber, finished) = subscriber::mock()
let (subscriber, finished) = subscriber::expect()
.event(
event::mock()
.at_level(Level::INFO)
Expand Down Expand Up @@ -36,7 +36,7 @@ fn field_filter_spans() {
let filter: EnvFilter = "[{enabled=true}]=debug"
.parse()
.expect("filter should parse");
let (subscriber, finished) = subscriber::mock()
let (subscriber, finished) = subscriber::expect()
.enter(span("span1"))
.event(
event::mock()
Expand Down Expand Up @@ -79,7 +79,7 @@ fn record_after_created() {
let filter: EnvFilter = "[{enabled=true}]=debug"
.parse()
.expect("filter should parse");
let (subscriber, finished) = subscriber::mock()
let (subscriber, finished) = subscriber::expect()
.enter(span("span"))
.exit(span("span"))
.record(span("span"), field::mock("enabled").with_value(&true))
Expand Down
12 changes: 6 additions & 6 deletions tracing-subscriber/tests/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tracing_test::*;
#[test]
fn level_filter_event() {
let filter: EnvFilter = "info".parse().expect("filter should parse");
let (subscriber, finished) = subscriber::mock()
let (subscriber, finished) = subscriber::expect()
.event(event::mock().at_level(Level::INFO))
.event(event::mock().at_level(Level::WARN))
.event(event::mock().at_level(Level::ERROR))
Expand All @@ -32,7 +32,7 @@ fn same_name_spans() {
let filter: EnvFilter = "[foo{bar}]=trace,[foo{baz}]=trace"
.parse()
.expect("filter should parse");
let (subscriber, finished) = subscriber::mock()
let (subscriber, finished) = subscriber::expect()
.new_span(
span("foo")
.at_level(Level::TRACE)
Expand All @@ -57,7 +57,7 @@ fn same_name_spans() {
#[test]
fn level_filter_event_with_target() {
let filter: EnvFilter = "info,stuff=debug".parse().expect("filter should parse");
let (subscriber, finished) = subscriber::mock()
let (subscriber, finished) = subscriber::expect()
.event(event::mock().at_level(Level::INFO))
.event(event::mock().at_level(Level::DEBUG).with_target("stuff"))
.event(event::mock().at_level(Level::WARN).with_target("stuff"))
Expand Down Expand Up @@ -86,7 +86,7 @@ fn not_order_dependent() {
// this test reproduces tokio-rs/tracing#623

let filter: EnvFilter = "stuff=debug,info".parse().expect("filter should parse");
let (subscriber, finished) = subscriber::mock()
let (subscriber, finished) = subscriber::expect()
.event(event::mock().at_level(Level::INFO))
.event(event::mock().at_level(Level::DEBUG).with_target("stuff"))
.event(event::mock().at_level(Level::WARN).with_target("stuff"))
Expand Down Expand Up @@ -120,7 +120,7 @@ fn add_directive_enables_event() {
// overwrite with a more specific directive
filter = filter.add_directive("hello=trace".parse().expect("directive should parse"));

let (subscriber, finished) = subscriber::mock()
let (subscriber, finished) = subscriber::expect()
.event(event::mock().at_level(Level::INFO).with_target("hello"))
.event(event::mock().at_level(Level::TRACE).with_target("hello"))
.done()
Expand All @@ -140,7 +140,7 @@ fn span_name_filter_is_dynamic() {
let filter: EnvFilter = "info,[cool_span]=debug"
.parse()
.expect("filter should parse");
let (subscriber, finished) = subscriber::mock()
let (subscriber, finished) = subscriber::expect()
.event(event::mock().at_level(Level::INFO))
.enter(span("cool_span"))
.event(event::mock().at_level(Level::DEBUG))
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/tests/filter_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn log_is_enabled() {
let filter: EnvFilter = "filter_log::my_module=info"
.parse()
.expect("filter should parse");
let (subscriber, finished) = subscriber::mock()
let (subscriber, finished) = subscriber::expect()
.event(event::mock().at_level(Level::INFO))
.event(event::mock().at_level(Level::WARN))
.event(event::mock().at_level(Level::ERROR))
Expand Down
Loading