Skip to content

Commit

Permalink
fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Oct 19, 2021
1 parent a65a203 commit 530624a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions tracing-subscriber/src/field/delimited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ where
}

#[cfg(test)]
#[cfg(all(test, feature = "alloc"))]
mod test {
use super::*;
use crate::field::test_util::*;
Expand Down
3 changes: 2 additions & 1 deletion tracing-subscriber/src/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,11 @@ pub struct RecordFieldsMarker {
_p: (),
}

#[cfg(test)]
#[cfg(all(test, feature = "alloc"))]
#[macro_use]
pub(in crate::field) mod test_util {
use super::*;
pub(in crate::field) use alloc::string::String;
use tracing_core::{
callsite::Callsite,
field::{Field, Value},
Expand Down
32 changes: 15 additions & 17 deletions tracing-subscriber/src/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ feature! {

#[doc(hidden)]
#[inline]
unsafe fn downcast_raw(&self, id: TypeId) -> std::option::Option<NonNull<()>> {
unsafe fn downcast_raw(&self, id: TypeId) -> Option<NonNull<()>> {
self.deref().downcast_raw(id)
}
};
Expand Down Expand Up @@ -1153,8 +1153,6 @@ where
/// If this returns `None`, then no span exists for that ID (either it has
/// closed or the ID is invalid).
#[inline]
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub fn metadata(&self, id: &span::Id) -> Option<&'static Metadata<'static>>
where
C: for<'lookup> LookupSpan<'lookup>,
Expand Down Expand Up @@ -1320,7 +1318,6 @@ impl Identity {

#[cfg(test)]
pub(crate) mod tests {

use super::*;

pub(crate) struct NopCollector;
Expand Down Expand Up @@ -1358,15 +1355,16 @@ pub(crate) mod tests {
/// A subscriber that holds a string.
///
/// Used to test that pointers returned by downcasting are actually valid.
struct StringSubscriber(String);
struct StringSubscriber(&'static str);
impl<C: Collect> Subscribe<C> for StringSubscriber {}
struct StringSubscriber2(String);

struct StringSubscriber2(&'static str);
impl<C: Collect> Subscribe<C> for StringSubscriber2 {}

struct StringSubscriber3(String);
struct StringSubscriber3(&'static str);
impl<C: Collect> Subscribe<C> for StringSubscriber3 {}

pub(crate) struct StringCollector(String);
pub(crate) struct StringCollector(&'static str);

impl Collect for StringCollector {
fn register_callsite(&self, _: &'static Metadata<'static>) -> Interest {
Expand Down Expand Up @@ -1421,31 +1419,31 @@ pub(crate) mod tests {
let s = NopSubscriber
.and_then(NopSubscriber)
.and_then(NopSubscriber)
.with_collector(StringCollector("collector".into()));
.with_collector(StringCollector("collector"));
let collector =
<dyn Collect>::downcast_ref::<StringCollector>(&s).expect("collector should downcast");
assert_eq!(&collector.0, "collector");
assert_eq!(collector.0, "collector");
}

#[test]
fn downcasts_to_subscriber() {
let s = StringSubscriber("subscriber_1".into())
.and_then(StringSubscriber2("subscriber_2".into()))
.and_then(StringSubscriber3("subscriber_3".into()))
let s = StringSubscriber("subscriber_1")
.and_then(StringSubscriber2("subscriber_2"))
.and_then(StringSubscriber3("subscriber_3"))
.with_collector(NopCollector);
let subscriber = <dyn Collect>::downcast_ref::<StringSubscriber>(&s)
.expect("subscriber 2 should downcast");
assert_eq!(&subscriber.0, "subscriber_1");
assert_eq!(subscriber.0, "subscriber_1");
let subscriber = <dyn Collect>::downcast_ref::<StringSubscriber2>(&s)
.expect("subscriber 2 should downcast");
assert_eq!(&subscriber.0, "subscriber_2");
assert_eq!(subscriber.0, "subscriber_2");
let subscriber = <dyn Collect>::downcast_ref::<StringSubscriber3>(&s)
.expect("subscriber 3 should downcast");
assert_eq!(&subscriber.0, "subscriber_3");
assert_eq!(subscriber.0, "subscriber_3");
}

#[test]
#[cfg(feature = "registry")]
#[cfg(all(feature = "registry", feature = "std"))]
fn context_event_span() {
use std::sync::{Arc, Mutex};
let last_event_span = Arc::new(Mutex::new(None));
Expand Down
1 change: 1 addition & 0 deletions tracing-subscriber/tests/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "std")]
mod support;
use self::support::*;
use tracing_subscriber::prelude::*;
Expand Down

0 comments on commit 530624a

Please sign in to comment.