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: move subscriber mock from tracing-subscriber tests #2369

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tracing-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ publish = false
[dependencies]
tracing = { path = "../tracing", version = "0.2", default-features = false }
tracing-core = { path = "../tracing-core", version = "0.2", default-features = false }
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3", default-features = false, optional = true }
tokio-test = { version = "0.4.2", optional = true }

# Fix minimal-versions; tokio-test fails with otherwise acceptable 0.1.0
Expand Down
21 changes: 3 additions & 18 deletions tracing-mock/src/collector.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(missing_docs)]
use super::{
use crate::{
event::MockEvent,
expectation::Expect,
field as mock_field,
span::{MockSpan, NewSpan},
};
Expand All @@ -20,22 +21,6 @@ use tracing::{
Collect, Event, Metadata,
};

#[derive(Debug, Eq, PartialEq)]
pub enum Expect {
Event(MockEvent),
FollowsFrom {
consequence: MockSpan,
cause: MockSpan,
},
Enter(MockSpan),
Exit(MockSpan),
CloneSpan(MockSpan),
DropSpan(MockSpan),
Visit(MockSpan, mock_field::Expect),
NewSpan(NewSpan),
Nothing,
}

struct SpanState {
name: &'static str,
refs: usize,
Expand Down Expand Up @@ -469,7 +454,7 @@ where
}

impl MockHandle {
pub fn new(expected: Arc<Mutex<VecDeque<Expect>>>, name: String) -> Self {
pub(crate) fn new(expected: Arc<Mutex<VecDeque<Expect>>>, name: String) -> Self {
Self(expected, name)
}

Expand Down
21 changes: 21 additions & 0 deletions tracing-mock/src/expectation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::{
event::MockEvent,
field,
span::{MockSpan, NewSpan},
};

#[derive(Debug, Eq, PartialEq)]
pub(crate) enum Expect {
Event(MockEvent),
FollowsFrom {
consequence: MockSpan,
cause: MockSpan,
},
Enter(MockSpan),
Exit(MockSpan),
CloneSpan(MockSpan),
DropSpan(MockSpan),
Visit(MockSpan, field::Expect),
NewSpan(NewSpan),
Nothing,
}
4 changes: 4 additions & 0 deletions tracing-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ use std::{

pub mod collector;
pub mod event;
mod expectation;
pub mod field;
mod metadata;
pub mod span;

#[cfg(feature = "tracing-subscriber")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably also globally enable the doc_cfg feature flag for this crate so that the feature flags show up in RustDoc, but we can do that separately when we actually...add documentation...before releasing.

pub mod subscriber;

#[derive(Debug, Eq, PartialEq)]
pub enum Parent {
ContextualRoot,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![allow(missing_docs, dead_code)]
pub use tracing_mock::{collector, event, field, span};

use self::{
collector::{Expect, MockHandle},
use crate::{
collector::MockHandle,
event::MockEvent,
expectation::Expect,
field,
span::{MockSpan, NewSpan},
};
use tracing_core::{
Expand All @@ -21,22 +21,18 @@ use std::{
sync::{Arc, Mutex},
};

pub mod subscriber {
use super::ExpectSubscriberBuilder;

pub fn mock() -> ExpectSubscriberBuilder {
ExpectSubscriberBuilder {
expected: Default::default(),
name: std::thread::current()
.name()
.map(String::from)
.unwrap_or_default(),
}
pub fn mock() -> ExpectSubscriberBuilder {
ExpectSubscriberBuilder {
expected: Default::default(),
name: std::thread::current()
.name()
.map(String::from)
.unwrap_or_default(),
}
}

pub fn named(name: impl std::fmt::Display) -> ExpectSubscriberBuilder {
mock().named(name)
}
pub fn named(name: impl std::fmt::Display) -> ExpectSubscriberBuilder {
mock().named(name)
}

pub struct ExpectSubscriberBuilder {
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ thread_local = { version = "1.1.4", optional = true }

[dev-dependencies]
tracing = { path = "../tracing", version = "0.2" }
tracing-mock = { path = "../tracing-mock" }
tracing-mock = { path = "../tracing-mock", features = ["tracing-subscriber"] }
log = "0.4.17"
tracing-log = { path = "../tracing-log", version = "0.2" }
criterion = { version = "0.3.6", default_features = false }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![cfg(feature = "registry")]
mod support;
use self::support::*;
use tracing::Level;
use tracing_mock::{
collector, event,
subscriber::{self, ExpectSubscriber},
};
use tracing_subscriber::{filter::LevelFilter, prelude::*};

#[test]
Expand Down
5 changes: 1 addition & 4 deletions tracing-subscriber/tests/env_filter/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#![cfg(feature = "env-filter")]

#[path = "../support.rs"]
mod support;
use self::support::*;

mod per_subscriber;

use tracing::{self, collect::with_default, Level};
use tracing_mock::{collector, event, field, span};
use tracing_subscriber::{
filter::{EnvFilter, LevelFilter},
prelude::*,
Expand Down
1 change: 1 addition & 0 deletions tracing-subscriber/tests/env_filter/per_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! `subscriber` filter).
#![cfg(feature = "registry")]
use super::*;
use tracing_mock::{event, field, span, subscriber};

#[test]
fn level_filter_event() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![cfg(feature = "registry")]
mod support;
use self::support::*;
use tracing::{Collect, Level, Metadata};
use tracing_mock::{
collector, event,
subscriber::{self, ExpectSubscriber},
};
use tracing_subscriber::{filter::DynFilterFn, prelude::*, subscribe::Context};

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#![cfg(feature = "registry")]
mod support;
use self::support::*;

use std::{
collections::HashMap,
sync::{Arc, Mutex},
};
use tracing::{Collect, Level};
use tracing_mock::{event, subscriber};
use tracing_subscriber::{filter, prelude::*};

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#![cfg(feature = "registry")]
mod support;
use self::support::*;

use std::{
collections::HashMap,
sync::{Arc, Mutex},
};
use tracing::{Collect, Level};
use tracing_mock::{event, subscriber};
use tracing_subscriber::{filter, prelude::*};

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use tracing_mock::subscriber::ExpectSubscriber;

#[test]
fn filters_span_scopes() {
Expand Down
4 changes: 1 addition & 3 deletions tracing-subscriber/tests/subscriber_filters/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#![cfg(feature = "registry")]
#[path = "../support.rs"]
mod support;
use self::support::*;
mod filter_scopes;
mod per_event;
mod targets;
mod trees;
mod vec;

use tracing::{level_filters::LevelFilter, Level};
use tracing_mock::{collector, event, span, subscriber};
use tracing_subscriber::{filter, prelude::*, Subscribe};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/tests/subscriber_filters/per_event.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::support::*;
use tracing::Level;
use tracing_mock::{event, subscriber};
use tracing_subscriber::{field::Visit, prelude::*, subscribe::Filter};

struct FilterEvent;
Expand Down
1 change: 1 addition & 0 deletions tracing-subscriber/tests/subscriber_filters/trees.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use tracing_mock::subscriber::ExpectSubscriber;

#[test]
fn basic_trees() {
Expand Down
1 change: 1 addition & 0 deletions tracing-subscriber/tests/subscriber_filters/vec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;
use tracing::Collect;
use tracing_mock::subscriber::ExpectSubscriber;

#[test]
fn with_filters_unboxed() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![cfg(feature = "registry")]
mod support;
use self::support::*;
use tracing::Level;
use tracing_mock::{
collector, event,
subscriber::{self, ExpectSubscriber},
};
use tracing_subscriber::{filter::DynFilterFn, prelude::*};

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#![cfg(feature = "registry")]
mod support;
use self::support::*;

use std::{
collections::HashMap,
sync::{Arc, Mutex},
};
use tracing::{Collect, Level};
use tracing_mock::{
event,
subscriber::{self, ExpectSubscriber},
};
use tracing_subscriber::{filter, prelude::*};

#[test]
Expand Down