From 1db78f18ff7d0eb1ceea836cbc6981a21c841562 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 5 Oct 2020 11:42:06 -0700 Subject: [PATCH 1/5] core: fix linked list tests reusing Registrations Signed-off-by: Eliza Weisman --- tracing-core/src/callsite.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tracing-core/src/callsite.rs b/tracing-core/src/callsite.rs index 77efb3fbf7..9b3e7bb438 100644 --- a/tracing-core/src/callsite.rs +++ b/tracing-core/src/callsite.rs @@ -279,7 +279,6 @@ mod tests { #[derive(Eq, PartialEq)] struct Cs1; static CS1: Cs1 = Cs1; - static REG1: Registration = Registration::new(&CS1); impl Callsite for Cs1 { fn set_interest(&self, _interest: Interest) {} @@ -290,7 +289,6 @@ mod tests { struct Cs2; static CS2: Cs2 = Cs2; - static REG2: Registration = Registration::new(&CS2); impl Callsite for Cs2 { fn set_interest(&self, _interest: Interest) {} @@ -301,6 +299,9 @@ mod tests { #[test] fn linked_list_push() { + static REG1: Registration = Registration::new(&CS1); + static REG2: Registration = Registration::new(&CS2); + let linked_list = LinkedList::new(); linked_list.push(®1); @@ -328,6 +329,8 @@ mod tests { #[test] #[should_panic] fn linked_list_repeated() { + static REG1: Registration = Registration::new(&CS1); + let linked_list = LinkedList::new(); linked_list.push(®1); From 128c9e5715f299ac75a046639d27de2320e81a3f Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 5 Oct 2020 11:43:36 -0700 Subject: [PATCH 2/5] core: simplify test callsites Signed-off-by: Eliza Weisman --- tracing-core/src/callsite.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/tracing-core/src/callsite.rs b/tracing-core/src/callsite.rs index 9b3e7bb438..829ac7faff 100644 --- a/tracing-core/src/callsite.rs +++ b/tracing-core/src/callsite.rs @@ -276,21 +276,11 @@ impl LinkedList { mod tests { use super::*; - #[derive(Eq, PartialEq)] - struct Cs1; - static CS1: Cs1 = Cs1; + struct TestCallsite; + static CS1: TestCallsite = TestCallsite; + static CS2: TestCallsite = TestCallsite; - impl Callsite for Cs1 { - fn set_interest(&self, _interest: Interest) {} - fn metadata(&self) -> &Metadata<'_> { - unimplemented!("not needed for this test") - } - } - - struct Cs2; - static CS2: Cs2 = Cs2; - - impl Callsite for Cs2 { + impl Callsite for TestCallsite { fn set_interest(&self, _interest: Interest) {} fn metadata(&self) -> &Metadata<'_> { unimplemented!("not needed for this test") From 8cb25a47e82939d1dfa1ad9f436821d2eb23a3ca Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 5 Oct 2020 12:10:11 -0700 Subject: [PATCH 3/5] add test for pushing a bunch of stuff Signed-off-by: Eliza Weisman --- tracing-core/src/callsite.rs | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tracing-core/src/callsite.rs b/tracing-core/src/callsite.rs index 829ac7faff..e8a520f278 100644 --- a/tracing-core/src/callsite.rs +++ b/tracing-core/src/callsite.rs @@ -316,6 +316,60 @@ mod tests { }); } + #[test] + fn linked_list_push_several() { + static REG1: Registration = Registration::new(&CS1); + static REG2: Registration = Registration::new(&CS2); + static REG3: Registration = Registration::new(&CS1); + static REG4: Registration = Registration::new(&CS2); + + let linked_list = LinkedList::new(); + + fn expect<'a>( + callsites: &'a mut Vec<&'static Registration>, + ) -> impl FnMut(&'static Registration) + 'a { + move |reg: &'static Registration| { + let ptr = callsites + .pop() + .expect("list contained more than the expected number of registrations!"); + assert!( + ptr::eq(reg, ptr), + "Registration pointers need to match ({:?} != {:?})", + reg, + ptr + ); + } + } + + linked_list.push(®1); + linked_list.push(®2); + let mut callsites = vec![®1, ®2]; + linked_list.for_each(expect(&mut callsites)); + assert!( + callsites.is_empty(), + "some registrations were expected but not present: {:?}", + callsites + ); + + linked_list.push(®3); + let mut callsites = vec![®1, ®2, ®3]; + linked_list.for_each(expect(&mut callsites)); + assert!( + callsites.is_empty(), + "some registrations were expected but not present: {:?}", + callsites + ); + + linked_list.push(®4); + let mut callsites = vec![®1, ®2, ®3, ®4]; + linked_list.for_each(expect(&mut callsites)); + assert!( + callsites.is_empty(), + "some registrations were expected but not present: {:?}", + callsites + ); + } + #[test] #[should_panic] fn linked_list_repeated() { From 35f5a49449798c1413662bb56320c102868489ba Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 5 Oct 2020 14:03:45 -0700 Subject: [PATCH 4/5] fixup new test Signed-off-by: Eliza Weisman --- tracing-core/src/callsite.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tracing-core/src/callsite.rs b/tracing-core/src/callsite.rs index e8a520f278..574779206c 100644 --- a/tracing-core/src/callsite.rs +++ b/tracing-core/src/callsite.rs @@ -326,14 +326,15 @@ mod tests { let linked_list = LinkedList::new(); fn expect<'a>( - callsites: &'a mut Vec<&'static Registration>, + callsites: &'a mut impl Iterator, ) -> impl FnMut(&'static Registration) + 'a { move |reg: &'static Registration| { let ptr = callsites - .pop() + .next() .expect("list contained more than the expected number of registrations!"); + assert!( - ptr::eq(reg, ptr), + ptr::eq(dbg!(reg), dbg!(ptr)), "Registration pointers need to match ({:?} != {:?})", reg, ptr @@ -343,28 +344,31 @@ mod tests { linked_list.push(®1); linked_list.push(®2); - let mut callsites = vec![®1, ®2]; + let regs = [®2, ®1]; + let mut callsites = regs.iter().map(|x| *x); linked_list.for_each(expect(&mut callsites)); assert!( - callsites.is_empty(), + callsites.next().is_none(), "some registrations were expected but not present: {:?}", callsites ); linked_list.push(®3); - let mut callsites = vec![®1, ®2, ®3]; + let regs = [®3, ®2, ®1]; + let mut callsites = regs.iter().map(|x| *x); linked_list.for_each(expect(&mut callsites)); assert!( - callsites.is_empty(), + callsites.next().is_none(), "some registrations were expected but not present: {:?}", callsites ); linked_list.push(®4); - let mut callsites = vec![®1, ®2, ®3, ®4]; + let regs = [®4, ®3, ®2, ®1]; + let mut callsites = regs.iter().map(|x| *x); linked_list.for_each(expect(&mut callsites)); assert!( - callsites.is_empty(), + callsites.next().is_none(), "some registrations were expected but not present: {:?}", callsites ); From e90c19cd8156f2dd6058b4e7aff21f9ba048f9d5 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 5 Oct 2020 14:58:28 -0700 Subject: [PATCH 5/5] clippy, etc --- tracing-core/src/callsite.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tracing-core/src/callsite.rs b/tracing-core/src/callsite.rs index 574779206c..7098adefad 100644 --- a/tracing-core/src/callsite.rs +++ b/tracing-core/src/callsite.rs @@ -334,7 +334,7 @@ mod tests { .expect("list contained more than the expected number of registrations!"); assert!( - ptr::eq(dbg!(reg), dbg!(ptr)), + ptr::eq(reg, ptr), "Registration pointers need to match ({:?} != {:?})", reg, ptr @@ -345,7 +345,7 @@ mod tests { linked_list.push(®1); linked_list.push(®2); let regs = [®2, ®1]; - let mut callsites = regs.iter().map(|x| *x); + let mut callsites = regs.iter().copied(); linked_list.for_each(expect(&mut callsites)); assert!( callsites.next().is_none(), @@ -355,7 +355,7 @@ mod tests { linked_list.push(®3); let regs = [®3, ®2, ®1]; - let mut callsites = regs.iter().map(|x| *x); + let mut callsites = regs.iter().copied(); linked_list.for_each(expect(&mut callsites)); assert!( callsites.next().is_none(), @@ -365,7 +365,7 @@ mod tests { linked_list.push(®4); let regs = [®4, ®3, ®2, ®1]; - let mut callsites = regs.iter().map(|x| *x); + let mut callsites = regs.iter().copied(); linked_list.for_each(expect(&mut callsites)); assert!( callsites.next().is_none(),