Skip to content

Commit

Permalink
unit tests: Also enable mz-ore::test macro in ore directory
Browse files Browse the repository at this point in the history
Requires detection of whether we are inside mz-ore currently in the
macro
  • Loading branch information
def- committed Jun 1, 2023
1 parent 6ef7bbc commit 61d69a8
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 57 deletions.
6 changes: 3 additions & 3 deletions src/ore/src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,17 @@ macro_rules! assert_contains {

#[cfg(test)]
mod tests {
#[test]
#[mz_test_macro::test]
fn test_assert_contains_str() {
assert_contains!("hello", "ello");
}

#[test]
#[mz_test_macro::test]
fn test_assert_contains_slice() {
assert_contains!(&[1, 2, 3], 2);
}

#[test]
#[mz_test_macro::test]
#[should_panic(expected = "assertion failed: `left.contains(right)`:
left: `\"hello\"`
right: `\"yellow\"`")]
Expand Down
22 changes: 11 additions & 11 deletions src/ore/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ mod tests {

use super::SegmentedBytes;

#[test]
#[mz_test_macro::test]
fn test_empty() {
let s = SegmentedBytes::default();

Expand Down Expand Up @@ -351,7 +351,7 @@ mod tests {
assert_eq!(bytes_read, 0);
}

#[test]
#[mz_test_macro::test]
fn test_bytes_buf() {
let mut s = SegmentedBytes::from(vec![0, 1, 2, 3, 4, 5, 6, 7]);

Expand All @@ -366,7 +366,7 @@ mod tests {
assert_eq!(s.chunk(), &[6, 7]);
}

#[test]
#[mz_test_macro::test]
fn test_bytes_buf_multi() {
let segments = vec![vec![0, 1, 2, 3], vec![4, 5, 6, 7], vec![8, 9, 10, 11]];
let mut s: SegmentedBytes<2> = segments.into_iter().collect();
Expand Down Expand Up @@ -406,7 +406,7 @@ mod tests {
assert_eq!(s.chunk(), &[13, 14, 15]);
}

#[test]
#[mz_test_macro::test]
fn test_io_read() {
let s = SegmentedBytes::from(vec![0, 1, 2, 3, 4, 5, 6, 7]);
let mut reader = s.reader();
Expand Down Expand Up @@ -448,7 +448,7 @@ mod tests {
assert_eq!(buf, [2, 3, 4, 5]);
}

#[test]
#[mz_test_macro::test]
fn test_io_read_multi() {
let segments = vec![vec![0, 1, 2, 3], vec![4, 5, 6, 7, 8, 9], vec![10, 11]];
let s: SegmentedBytes<2> = segments.into_iter().collect();
Expand Down Expand Up @@ -491,7 +491,7 @@ mod tests {
assert_eq!(buf, &[6, 7, 8, 9, 10, 11]);
}

#[test]
#[mz_test_macro::test]
fn test_multi() {
let segments = vec![vec![0, 1, 2, 3], vec![4, 5, 6, 7, 8, 9], vec![10, 11]];
let mut s: SegmentedBytes<2> = segments.into_iter().collect();
Expand Down Expand Up @@ -530,7 +530,7 @@ mod tests {
assert_eq!(buf, [6, 7, 8, 9, 10, 11, 0, 0]);
}

#[test]
#[mz_test_macro::test]
fn test_single_empty_segment() {
let s = SegmentedBytes::from(Vec::<u8>::new());

Expand All @@ -548,7 +548,7 @@ mod tests {
assert_eq!(buf, [0, 0, 0, 0]);
}

#[test]
#[mz_test_macro::test]
fn test_middle_segment_empty() {
let segments = vec![vec![1, 2], vec![], vec![3, 4, 5, 6]];
let mut s: SegmentedBytes = segments.clone().into_iter().collect();
Expand Down Expand Up @@ -589,7 +589,7 @@ mod tests {
assert_eq!(buf, [5, 6, 5, 6]);
}

#[test]
#[mz_test_macro::test]
fn test_last_segment_empty() {
let segments = vec![vec![1, 2], vec![3, 4, 5, 6], vec![]];
let mut s: SegmentedBytes = segments.clone().into_iter().collect();
Expand Down Expand Up @@ -642,7 +642,7 @@ mod tests {
}

proptest! {
#[test]
#[mz_test_macro::test]
#[cfg_attr(miri, ignore)] // slow
fn proptest_copy_to_bytes(segments: Vec<Vec<u8>>, num_bytes: usize) {
let contiguous: Vec<u8> = segments.clone().into_iter().flatten().collect();
Expand All @@ -658,7 +658,7 @@ mod tests {
prop_assert_eq!(copied_c, copied_s);
}

#[test]
#[mz_test_macro::test]
#[cfg_attr(miri, ignore)] // slow
fn proptest_read_to_end(segments: Vec<Vec<u8>>) {
let contiguous: Vec<u8> = segments.clone().into_iter().flatten().collect();
Expand Down
2 changes: 1 addition & 1 deletion src/ore/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl CastLossy<u64> for f64 {
}
}

#[test]
#[mz_test_macro::test]
fn test_try_cast_from() {
let f64_i64_cases = vec![
(0.0, Some(0)),
Expand Down
4 changes: 2 additions & 2 deletions src/ore/src/cgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ mod tests {

use super::{CgroupEntry, Mountinfo};

#[test]
#[mz_test_macro::test]
fn test_cgroup_from_line() {
// cgroups v2
assert_eq!(
Expand Down Expand Up @@ -206,7 +206,7 @@ mod tests {
);
}

#[test]
#[mz_test_macro::test]
fn test_mountinfo_from_line() {
// Mount with optional field (master:305)
assert_eq!(Mountinfo::from_line("863 758 0:63 / / rw,relatime master:305 - overlay overlay rw,seclabel,lowerdir=/var/lib/docker/overlay2/l/SUKWDHL7W7YZCJ6YI66I7Z5PR2:/var/lib/docker/overlay2/l/ORL2I23UNUGM7FYF4BSL5JUCAB:/var/lib/docker/overlay2/l/LLKK3J2EHGPF5IGGDSAQGRFHLV:/var/lib/docker/overlay2/l/JEQIUQIQTVNRBAGCU7SLV4KK4K:/var/lib/docker/overlay2/l/5DS7KSJCA7BHWAYWII7BI5DBC5:/var/lib/docker/overlay2/l/ZAGXZ62GNFPZFLNUDZ3JOZIMYR:/var/lib/docker/overlay2/l/6WVXMD372IA24ZXRWGGTIPEQPA,upperdir=/var/lib/docker/overlay2/5c7734eb769484f3469b234181365466eb30bcd7f31c912f4250c8d701637ee4/diff,workdir=/var/lib/docker/overlay2/5c7734eb769484f3469b234181365466eb30bcd7f31c912f4250c8d701637ee4/work".to_owned()),
Expand Down
4 changes: 2 additions & 2 deletions src/ore/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ mod tests {

use super::*;

#[test]
#[mz_test_macro::test]
fn basic_usage() {
let error = anyhow!("root");
let error = error.context("context");
assert_eq!(error.to_string_with_causes(), "context: root");
}

#[test]
#[mz_test_macro::test]
fn basic_usage_with_arc() {
// The reason for this signature is that our Plan errors have a `cause` field like this:
// ```
Expand Down
12 changes: 6 additions & 6 deletions src/ore/src/id_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ mod tests {

use super::*;

#[test]
#[mz_test_macro::test]
fn test_id_alloc() {
let ida = IdAllocator::new(3, 5);
let id3 = ida.alloc().unwrap();
Expand All @@ -291,7 +291,7 @@ mod tests {
}
}

#[test]
#[mz_test_macro::test]
fn test_static_id_sorting() {
let ida = IdAllocator::new(0, 0);
let id0 = ida.alloc().unwrap();
Expand All @@ -304,7 +304,7 @@ mod tests {
assert!(id0 < id1);
}

#[test]
#[mz_test_macro::test]
fn test_id_reuse() {
let allocator = IdAllocator::new(10, 13);

Expand All @@ -328,7 +328,7 @@ mod tests {
assert_eq!(*id_c, 10);
}

#[test]
#[mz_test_macro::test]
fn test_display() {
let allocator = IdAllocator::<u32>::new(65_000, 65_101);

Expand All @@ -342,7 +342,7 @@ mod tests {
assert_eq!(id_display, val_display);
}

#[test]
#[mz_test_macro::test]
fn test_map_lookup() {
let allocator = IdAllocator::<u32>::new(99, 101);

Expand All @@ -360,7 +360,7 @@ mod tests {
}

#[cfg(feature = "serde")]
#[test]
#[mz_test_macro::test]
fn test_serialization() {
let allocator = IdAllocator::<u32>::new(42, 43);

Expand Down
2 changes: 1 addition & 1 deletion src/ore/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<I> IteratorExt for I where I: Iterator {}
mod tests {
use crate::iter::IteratorExt;

#[test]
#[mz_test_macro::test]
fn test_all_equal() {
let empty: [i64; 0] = [];
assert!(empty.iter().all_equal());
Expand Down
4 changes: 2 additions & 2 deletions src/ore/src/metrics/delete_on_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ mod test {

use super::*;

#[test]
#[mz_test_macro::test]
fn dropping_counters() {
let reg = MetricsRegistry::new();
let vec: IntCounterVec = reg.register(metric!(
Expand Down Expand Up @@ -432,7 +432,7 @@ mod test {
assert_eq!(metrics.len(), 0);
}

#[test]
#[mz_test_macro::test]
fn dropping_gauges() {
let reg = MetricsRegistry::new();
let vec: IntGaugeVec = reg.register(metric!(
Expand Down
4 changes: 2 additions & 2 deletions src/ore/src/metrics/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use super::*;

#[test]
#[mz_test_macro::test]
fn metrics_registry() {
let reg = MetricsRegistry::new();
let counter: IntCounter = reg.register(metric!(
Expand All @@ -28,7 +28,7 @@ fn metrics_registry() {
assert_eq!(readings.len(), 1);
}

#[test]
#[mz_test_macro::test]
fn thirdparty_metric_vecs() {
let reg = MetricsRegistry::new();
let cv: raw::IntCounterVec = reg.register(metric!(
Expand Down
2 changes: 1 addition & 1 deletion src/ore/src/netio/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ mod tests {

use super::*;

#[test]
#[mz_test_macro::test]
fn test_parse() {
for (input, expected) in [
("/valid/path", Ok(SocketAddr::Unix(UnixSocketAddr::from_pathname("/valid/path").unwrap()))),
Expand Down
2 changes: 1 addition & 1 deletion src/ore/src/now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod tests {

use super::to_datetime;

#[test]
#[mz_test_macro::test]
fn test_to_datetime() {
let test_cases = [
(
Expand Down
2 changes: 1 addition & 1 deletion src/ore/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mod tests {

use super::PathExt;

#[test]
#[mz_test_macro::test]
fn test_clean() {
// These test cases are imported from the Go standard library.
for (input, output) in &[
Expand Down
2 changes: 1 addition & 1 deletion src/ore/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ mod test {

use super::*;

#[test]
#[mz_test_macro::test]
fn prints_error_chain() {
let error = anyhow!("root");
let error = error.context("context");
Expand Down
Loading

0 comments on commit 61d69a8

Please sign in to comment.