Skip to content

Commit

Permalink
rename fields::mock() to fields::field()
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeHahn committed Jul 10, 2020
1 parent 2b178ca commit 70331f8
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 140 deletions.
14 changes: 7 additions & 7 deletions tracing-attributes/tests/async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn async_fn_only_enters_for_polls() {
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)))
.event(event::mock().with_fields(field("awaiting").with_value(&true)))
.exit(span("test_async_fn"))
.enter(span("test_async_fn"))
.exit(span("test_async_fn"))
Expand Down Expand Up @@ -51,7 +51,7 @@ fn async_fn_nested() {
.enter(span1.clone())
.new_span(span2.clone())
.enter(span2.clone())
.event(event::mock().with_fields(field::mock("nested").with_value(&true)))
.event(event::mock().with_fields(field("nested").with_value(&true)))
.exit(span2.clone())
.drop_span(span2)
.exit(span1.clone())
Expand Down Expand Up @@ -125,18 +125,18 @@ fn async_fn_with_async_trait() {
.new_span(
span1
.clone()
.with_field(field::mock("self"))
.with_field(field::mock("v")),
.with_field(field("self"))
.with_field(field("v")),
)
.enter(span1.clone())
.new_span(span3.clone())
.enter(span3.clone())
.event(event::mock().with_fields(field::mock("val").with_value(&2u64)))
.event(event::mock().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::mock().with_fields(field("val").with_value(&5u64)))
.exit(span2.clone())
.drop_span(span2)
.exit(span1.clone())
Expand Down
30 changes: 15 additions & 15 deletions tracing-attributes/tests/destructuring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ fn destructure_tuples() {
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 @@ -41,11 +41,11 @@ fn destructure_nested_tuples() {
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 @@ -72,7 +72,7 @@ fn destructure_refs() {
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 @@ -99,9 +99,9 @@ fn destructure_tuple_structs() {
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 @@ -140,9 +140,9 @@ fn destructure_structs() {
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 @@ -185,11 +185,11 @@ fn destructure_everything() {
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
2 changes: 1 addition & 1 deletion tracing-attributes/tests/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn test_async() {
.enter(span.clone())
.event(
event::mock()
.with_fields(field::mock("awaiting").with_value(&true))
.with_fields(field("awaiting").with_value(&true))
.at_level(Level::TRACE),
)
.exit(span.clone())
Expand Down
31 changes: 15 additions & 16 deletions tracing-attributes/tests/fields.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use tracing::subscriber::with_default;
use tracing_attributes::instrument;
use tracing_test::field::mock;
use tracing_test::span::NewSpan;
use tracing_test::*;

Expand Down Expand Up @@ -44,10 +43,10 @@ impl HasField {
#[test]
fn fields() {
let span = anonymous_span().with_field(
mock("foo")
field("foo")
.with_value(&"bar")
.and(mock("dsa").with_value(&true))
.and(mock("num").with_value(&1))
.and(field("dsa").with_value(&true))
.and(field("num").with_value(&1))
.only(),
);
run_test(span, || {
Expand All @@ -58,9 +57,9 @@ fn fields() {
#[test]
fn expr_field() {
let span = anonymous_span().with_field(
mock("s")
field("s")
.with_value(&tracing::field::debug("hello world"))
.and(mock("len").with_value(&"hello world".len()))
.and(field("len").with_value(&"hello world".len()))
.only(),
);
run_test(span, || {
Expand All @@ -71,10 +70,10 @@ fn expr_field() {
#[test]
fn two_expr_fields() {
let span = anonymous_span().with_field(
mock("s")
field("s")
.with_value(&tracing::field::debug("hello world"))
.and(mock("s.len").with_value(&"hello world".len()))
.and(mock("s.is_empty").with_value(&false))
.and(field("s.len").with_value(&"hello world".len()))
.and(field("s.is_empty").with_value(&false))
.only(),
);
run_test(span, || {
Expand All @@ -87,24 +86,24 @@ fn clashy_expr_field() {
let span1 = anonymous_span().with_field(
// Overriding the `s` field should record `s` as a `Display` value,
// rather than as a `Debug` value.
mock("s")
field("s")
.with_value(&tracing::field::display("hello world"))
.and(mock("s.len").with_value(&"hello world".len()))
.and(field("s.len").with_value(&"hello world".len()))
.only(),
);
run_test(span1, || {
fn_clashy_expr_field(&"hello world");
});

let span1 = anonymous_span().with_field(mock("s").with_value(&"s").only());
let span1 = anonymous_span().with_field(field("s").with_value(&"s").only());
run_test(span1, || {
fn_clashy_expr_field2(&"hello world");
});
}

#[test]
fn self_expr_field() {
let span = anonymous_span().with_field(mock("my_field").with_value(&"hello world").only());
let span = anonymous_span().with_field(field("my_field").with_value(&"hello world").only());
run_test(span, || {
let has_field = HasField {
my_field: "hello world",
Expand All @@ -116,9 +115,9 @@ fn self_expr_field() {
#[test]
fn parameters_with_fields() {
let span = anonymous_span().with_field(
mock("foo")
field("foo")
.with_value(&"bar")
.and(mock("param").with_value(&format_args!("1")))
.and(field("param").with_value(&format_args!("1")))
.only(),
);
run_test(span, || {
Expand All @@ -128,7 +127,7 @@ fn parameters_with_fields() {

#[test]
fn empty_field() {
let span = anonymous_span().with_field(mock("foo").with_value(&"bar").only());
let span = anonymous_span().with_field(field("foo").with_value(&"bar").only());
run_test(span, || {
fn_empty_field();
});
Expand Down
20 changes: 10 additions & 10 deletions tracing-attributes/tests/instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ fn fields() {
let (subscriber, handle) = subscriber::expect()
.new_span(
span1.clone().with_field(
field::mock("arg1")
field("arg1")
.with_value(&format_args!("2"))
.and(field::mock("arg2").with_value(&format_args!("false")))
.and(field("arg2").with_value(&format_args!("false")))
.only(),
),
)
Expand All @@ -63,9 +63,9 @@ fn fields() {
.drop_span(span1)
.new_span(
span2.clone().with_field(
field::mock("arg1")
field("arg1")
.with_value(&format_args!("3"))
.and(field::mock("arg2").with_value(&format_args!("true")))
.and(field("arg2").with_value(&format_args!("true")))
.only(),
),
)
Expand Down Expand Up @@ -101,15 +101,15 @@ fn skip() {
.new_span(
span1
.clone()
.with_field(field::mock("arg1").with_value(&format_args!("2")).only()),
.with_field(field("arg1").with_value(&format_args!("2")).only()),
)
.enter(span1.clone())
.exit(span1.clone())
.drop_span(span1)
.new_span(
span2
.clone()
.with_field(field::mock("arg1").with_value(&format_args!("3")).only()),
.with_field(field("arg1").with_value(&format_args!("3")).only()),
)
.enter(span2.clone())
.exit(span2.clone())
Expand Down Expand Up @@ -142,9 +142,9 @@ fn generics() {
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("arg1")
field("arg1")
.with_value(&format_args!("Foo"))
.and(field::mock("arg2").with_value(&format_args!("false"))),
.and(field("arg2").with_value(&format_args!("false"))),
),
)
.enter(span.clone())
Expand Down Expand Up @@ -175,9 +175,9 @@ fn methods() {
let (subscriber, handle) = subscriber::expect()
.new_span(
span.clone().with_field(
field::mock("self")
field("self")
.with_value(&format_args!("Foo"))
.and(field::mock("arg1").with_value(&format_args!("42"))),
.and(field("arg1").with_value(&format_args!("42"))),
),
)
.enter(span.clone())
Expand Down
10 changes: 5 additions & 5 deletions tracing-subscriber/tests/field_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ fn field_filter_events() {
.event(
event::mock()
.at_level(Level::INFO)
.with_fields(field::mock("thing")),
.with_fields(field("thing")),
)
.event(
event::mock()
.at_level(Level::DEBUG)
.with_fields(field::mock("thing")),
.with_fields(field("thing")),
)
.done()
.run_with_handle();
Expand All @@ -41,7 +41,7 @@ fn field_filter_spans() {
.event(
event::mock()
.at_level(Level::INFO)
.with_fields(field::mock("something")),
.with_fields(field("something")),
)
.exit(span("span1"))
.enter(span("span2"))
Expand All @@ -50,7 +50,7 @@ fn field_filter_spans() {
.event(
event::mock()
.at_level(Level::DEBUG)
.with_fields(field::mock("something")),
.with_fields(field("something")),
)
.exit(span("span3"))
.done()
Expand Down Expand Up @@ -82,7 +82,7 @@ fn record_after_created() {
let (subscriber, finished) = subscriber::expect()
.enter(span("span"))
.exit(span("span"))
.record(span("span"), field::mock("enabled").with_value(&true))
.record(span("span"), field("enabled").with_value(&true))
.enter(span("span"))
.event(event::mock().at_level(Level::DEBUG))
.exit(span("span"))
Expand Down
12 changes: 2 additions & 10 deletions tracing-subscriber/tests/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,8 @@ fn same_name_spans() {
.parse()
.expect("filter should parse");
let (subscriber, finished) = subscriber::expect()
.new_span(
span("foo")
.at_level(Level::TRACE)
.with_field(field::mock("bar")),
)
.new_span(
span("foo")
.at_level(Level::TRACE)
.with_field(field::mock("baz")),
)
.new_span(span("foo").at_level(Level::TRACE).with_field(field("bar")))
.new_span(span("foo").at_level(Level::TRACE).with_field(field("baz")))
.done()
.run_with_handle();
let subscriber = subscriber.with(filter);
Expand Down
16 changes: 4 additions & 12 deletions tracing-subscriber/tests/same_len_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ fn same_num_fields_event() {
.event(
event::mock()
.at_level(Level::TRACE)
.with_fields(field::mock("foo")),
.with_fields(field("foo")),
)
.event(
event::mock()
.at_level(Level::TRACE)
.with_fields(field::mock("bar")),
.with_fields(field("bar")),
)
.done()
.run_with_handle();
Expand All @@ -56,16 +56,8 @@ fn same_num_fields_and_name_len() {
.parse()
.expect("filter should parse");
let (subscriber, finished) = subscriber::expect()
.new_span(
span("foo")
.at_level(Level::TRACE)
.with_field(field::mock("bar")),
)
.new_span(
span("baz")
.at_level(Level::TRACE)
.with_field(field::mock("boz")),
)
.new_span(span("foo").at_level(Level::TRACE).with_field(field("bar")))
.new_span(span("baz").at_level(Level::TRACE).with_field(field("boz")))
.done()
.run_with_handle();
let subscriber = subscriber.with(filter);
Expand Down
2 changes: 1 addition & 1 deletion tracing-test/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub enum MockValue {
Any,
}

pub fn mock<K>(name: K) -> MockField
pub fn field<K>(name: K) -> MockField
where
String: From<K>,
{
Expand Down
Loading

0 comments on commit 70331f8

Please sign in to comment.