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

mock: backport tracing-mock to v0.1.x #3132

Merged
merged 9 commits into from
Nov 20, 2024
24 changes: 13 additions & 11 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
name: cargo check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Check
run: cargo check --all --tests --benches
Expand All @@ -46,7 +46,7 @@ jobs:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
Expand All @@ -58,7 +58,7 @@ jobs:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
- tracing
- tracing-subscriber
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: install cargo-hack
uses: taiki-e/install-action@cargo-hack
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:
- 1.63.0
- stable
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: install Rust nightly
uses: dtolnay/rust-toolchain@nightly
- name: "install Rust ${{ matrix.toolchain }}"
Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: "install Rust ${{ matrix.rust }}"
uses: dtolnay/rust-toolchain@master
with:
Expand Down Expand Up @@ -252,7 +252,7 @@ jobs:
- tracing-tower
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-unknown-unknown
Expand All @@ -268,9 +268,11 @@ jobs:
subcrate:
- tracing
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: actions/checkout@v4
- name: Install Rust 1.81
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.81
target: wasm32-unknown-unknown
- name: install test runner for wasm
uses: taiki-e/install-action@wasm-pack
Expand All @@ -283,7 +285,7 @@ jobs:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: "Test log support"
run: cargo test
Expand Down Expand Up @@ -315,4 +317,4 @@ jobs:
- test-wasm
- test-features-stable
steps:
- run: exit 0
- run: exit 0
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"tracing-mock",
"tracing-subscriber",
"tracing-serde",
"tracing-test",
"tracing-appender",
"tracing-journald",
"examples"
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "tracing-examples"
version = "0.0.0"
publish = false
edition = "2018"
rust-version = "1.63.0"
rust-version = "1.64.0"

[features]
default = []
Expand Down
17 changes: 14 additions & 3 deletions tracing-attributes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,25 @@ async-await = []

[dependencies]
proc-macro2 = "1.0.60"
syn = { version = "2.0", default-features = false, features = ["full", "parsing", "printing", "visit-mut", "clone-impls", "extra-traits", "proc-macro"] }
syn = { version = "2.0", default-features = false, features = [
"full",
"parsing",
"printing",
"visit-mut",
"clone-impls",
"extra-traits",
"proc-macro",
] }
quote = "1.0.20"

[dev-dependencies]
tracing = { path = "../tracing", version = "0.1.35" }
tracing-mock = { path = "../tracing-mock", features = ["tokio-test"] }
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", features = ["env-filter"] }
tracing-mock = { path = "../tracing-mock" }
tokio-test = "0.4.2"
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", features = [
"env-filter",
] }
tracing-test = { path = "../tracing-test" }
async-trait = "0.1.67"
trybuild = "1.0.64"
rustversion = "1.0.9"
Expand Down
21 changes: 11 additions & 10 deletions tracing-attributes/tests/async_fn.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use tracing_mock::*;

use std::convert::Infallible;
use std::{future::Future, pin::Pin, sync::Arc};

use tracing::subscriber::with_default;
use tracing_attributes::instrument;
use tracing_mock::{expect, subscriber};
use tracing_test::{block_on_future, PollN};

#[instrument]
async fn test_async_fn(polls: usize) -> Result<(), ()> {
Expand Down Expand Up @@ -199,8 +200,8 @@ fn async_fn_with_async_trait() {
let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone()
.with_field(expect::field("self"))
.with_field(expect::field("v")),
.with_fields(expect::field("self"))
.with_fields(expect::field("v")),
)
.enter(span.clone())
.new_span(span3.clone())
Expand All @@ -210,7 +211,7 @@ fn async_fn_with_async_trait() {
.enter(span3.clone())
.exit(span3.clone())
.drop_span(span3)
.new_span(span2.clone().with_field(expect::field("self")))
.new_span(span2.clone().with_fields(expect::field("self")))
.enter(span2.clone())
.event(expect::event().with_fields(expect::field("val").with_value(&5u64)))
.exit(span2.clone())
Expand Down Expand Up @@ -260,7 +261,7 @@ fn async_fn_with_async_trait_and_fields_expressions() {
let span = expect::span().named("call");
let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("_v")
.with_value(&5usize)
.and(expect::field("test").with_value(&tracing::field::debug(10)))
Expand Down Expand Up @@ -330,21 +331,21 @@ fn async_fn_with_async_trait_and_fields_expressions_with_generic_parameter() {
let span4 = expect::span().named("sync_fun");
let (subscriber, handle) = subscriber::mock()
/*.new_span(span.clone()
.with_field(
.with_fields(
expect::field("Self").with_value(&"TestImpler")))
.enter(span.clone())
.exit(span.clone())
.drop_span(span)*/
.new_span(
span2
.clone()
.with_field(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
.with_fields(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
)
.enter(span2.clone())
.new_span(
span4
.clone()
.with_field(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
.with_fields(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
)
.enter(span4.clone())
.exit(span4.clone())
Expand All @@ -357,7 +358,7 @@ fn async_fn_with_async_trait_and_fields_expressions_with_generic_parameter() {
.new_span(
span3
.clone()
.with_field(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
.with_fields(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
)
.enter(span3.clone())
.exit(span3.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 @@ -11,7 +11,7 @@ fn destructure_tuples() {

let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("arg1")
.with_value(&format_args!("1"))
.and(expect::field("arg2").with_value(&format_args!("2")))
Expand Down Expand Up @@ -40,7 +40,7 @@ fn destructure_nested_tuples() {

let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("arg1")
.with_value(&format_args!("1"))
.and(expect::field("arg2").with_value(&format_args!("2")))
Expand Down Expand Up @@ -72,7 +72,7 @@ fn destructure_refs() {
let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone()
.with_field(expect::field("arg1").with_value(&1usize).only()),
.with_fields(expect::field("arg1").with_value(&1usize).only()),
)
.enter(span.clone())
.exit(span.clone())
Expand All @@ -98,7 +98,7 @@ fn destructure_tuple_structs() {

let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("arg1")
.with_value(&format_args!("1"))
.and(expect::field("arg2").with_value(&format_args!("2")))
Expand Down Expand Up @@ -139,7 +139,7 @@ fn destructure_structs() {

let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("arg1")
.with_value(&format_args!("1"))
.and(expect::field("arg2").with_value(&format_args!("2")))
Expand Down Expand Up @@ -184,7 +184,7 @@ fn destructure_everything() {

let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("arg1")
.with_value(&format_args!("1"))
.and(expect::field("arg2").with_value(&format_args!("2")))
Expand Down
3 changes: 2 additions & 1 deletion tracing-attributes/tests/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use tracing_attributes::instrument;
use tracing_mock::*;
use tracing_subscriber::filter::EnvFilter;
use tracing_subscriber::layer::SubscriberExt;
use tracing_test::{block_on_future, PollN};

use std::convert::TryFrom;
use std::num::TryFromIntError;
Expand Down Expand Up @@ -159,7 +160,7 @@ fn impl_trait_return_type() {
let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone()
.with_field(expect::field("x").with_value(&10usize).only()),
.with_fields(expect::field("x").with_value(&10usize).only()),
)
.enter(span.clone())
.exit(span.clone())
Expand Down
18 changes: 9 additions & 9 deletions tracing-attributes/tests/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl HasField {

#[test]
fn fields() {
let span = expect::span().with_field(
let span = expect::span().with_fields(
expect::field("foo")
.with_value(&"bar")
.and(expect::field("dsa").with_value(&true))
Expand All @@ -60,7 +60,7 @@ fn fields() {

#[test]
fn expr_field() {
let span = expect::span().with_field(
let span = expect::span().with_fields(
expect::field("s")
.with_value(&"hello world")
.and(expect::field("len").with_value(&"hello world".len()))
Expand All @@ -73,7 +73,7 @@ fn expr_field() {

#[test]
fn two_expr_fields() {
let span = expect::span().with_field(
let span = expect::span().with_fields(
expect::field("s")
.with_value(&"hello world")
.and(expect::field("s.len").with_value(&"hello world".len()))
Expand All @@ -87,7 +87,7 @@ fn two_expr_fields() {

#[test]
fn clashy_expr_field() {
let span = expect::span().with_field(
let span = expect::span().with_fields(
// Overriding the `s` field should record `s` as a `Display` value,
// rather than as a `Debug` value.
expect::field("s")
Expand All @@ -99,7 +99,7 @@ fn clashy_expr_field() {
fn_clashy_expr_field("hello world");
});

let span = expect::span().with_field(expect::field("s").with_value(&"s").only());
let span = expect::span().with_fields(expect::field("s").with_value(&"s").only());
run_test(span, || {
fn_clashy_expr_field2("hello world");
});
Expand All @@ -108,7 +108,7 @@ fn clashy_expr_field() {
#[test]
fn self_expr_field() {
let span =
expect::span().with_field(expect::field("my_field").with_value(&"hello world").only());
expect::span().with_fields(expect::field("my_field").with_value(&"hello world").only());
run_test(span, || {
let has_field = HasField {
my_field: "hello world",
Expand All @@ -119,7 +119,7 @@ fn self_expr_field() {

#[test]
fn parameters_with_fields() {
let span = expect::span().with_field(
let span = expect::span().with_fields(
expect::field("foo")
.with_value(&"bar")
.and(expect::field("param").with_value(&1u32))
Expand All @@ -132,15 +132,15 @@ fn parameters_with_fields() {

#[test]
fn empty_field() {
let span = expect::span().with_field(expect::field("foo").with_value(&"bar").only());
let span = expect::span().with_fields(expect::field("foo").with_value(&"bar").only());
run_test(span, || {
fn_empty_field();
});
}

#[test]
fn string_field() {
let span = expect::span().with_field(expect::field("s").with_value(&"hello world").only());
let span = expect::span().with_fields(expect::field("s").with_value(&"hello world").only());
run_test(span, || {
fn_string(String::from("hello world"));
});
Expand Down
3 changes: 2 additions & 1 deletion tracing-attributes/tests/follows_from.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use tracing::{subscriber::with_default, Id, Level, Span};
use tracing_attributes::instrument;
use tracing_mock::*;
use tracing_mock::{expect, subscriber};
use tracing_test::block_on_future;

#[instrument(follows_from = causes, skip(causes))]
fn with_follows_from_sync(causes: impl IntoIterator<Item = impl Into<Option<Id>>>) {}
Expand Down
Loading
Loading