Skip to content

Commit 2b79d70

Browse files
committed
test: update proptests for fallible operations
1 parent e6775d1 commit 2b79d70

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

stacks-common/src/util/lru_cache.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ mod tests {
318318
flushed.push((*k, v));
319319
Ok::<(), ()>(())
320320
})
321-
.unwrap();
321+
.expect("cache corrupted")
322+
.expect("flush failed");
322323

323324
assert_eq!(flushed, vec![(1, 1)]);
324325

@@ -331,7 +332,8 @@ mod tests {
331332
flushed.push((*k, v));
332333
Ok::<(), ()>(())
333334
})
334-
.unwrap();
335+
.expect("cache corrupted")
336+
.expect("flush failed");
335337

336338
assert_eq!(flushed, vec![(2, 2), (1, 3)]);
337339
}
@@ -351,7 +353,8 @@ mod tests {
351353
flushed.push((*k, v));
352354
Ok::<(), ()>(())
353355
})
354-
.unwrap();
356+
.expect("cache corrupted")
357+
.expect("flush failed");
355358

356359
assert_eq!(flushed, [(3, 3), (2, 2)]);
357360
}
@@ -390,10 +393,10 @@ mod property_tests {
390393
let mut cache = LruCache::new(10);
391394
for op in ops {
392395
match op {
393-
CacheOp::Insert(v) => { cache.insert(v, v); }
394-
CacheOp::Get(v) => { cache.get(&v); }
395-
CacheOp::InsertClean(v) => { cache.insert_clean(v, v); }
396-
CacheOp::Flush => { cache.flush(|_, _| Ok::<(), ()>(())).unwrap(); }
396+
CacheOp::Insert(v) => { cache.insert(v, v).expect("cache corrupted"); }
397+
CacheOp::Get(v) => { cache.get(&v).expect("cache corrupted"); }
398+
CacheOp::InsertClean(v) => { cache.insert_clean(v, v).expect("cache corrupted"); }
399+
CacheOp::Flush => { cache.flush(|_, _| Ok::<(), ()>(())).expect("cache corrupted").expect("flush failed"); }
397400
}
398401
}
399402
}
@@ -403,7 +406,7 @@ mod property_tests {
403406
let capacity = 10;
404407
let mut cache = LruCache::new(capacity);
405408
for op in ops {
406-
cache.insert(op, op);
409+
cache.insert(op, op).expect("cache corrupted");
407410
prop_assert!(cache.cache.len() <= capacity);
408411
prop_assert!(cache.order.len() <= capacity);
409412
}
@@ -414,10 +417,10 @@ mod property_tests {
414417
let mut cache = LruCache::new(10);
415418
for op in ops {
416419
match op {
417-
CacheOp::Insert(v) => { cache.insert(v, v); }
418-
CacheOp::Get(v) => { cache.get(&v); }
419-
CacheOp::InsertClean(v) => { cache.insert_clean(v, v); }
420-
CacheOp::Flush => { cache.flush(|_, _| Ok::<(), ()>(())).unwrap(); }
420+
CacheOp::Insert(v) => { cache.insert(v, v).expect("cache corrupted"); }
421+
CacheOp::Get(v) => { cache.get(&v).expect("cache corrupted"); }
422+
CacheOp::InsertClean(v) => { cache.insert_clean(v, v).expect("cache corrupted"); }
423+
CacheOp::Flush => { cache.flush(|_, _| Ok::<(), ()>(())).expect("cache corrupted").expect("flush failed"); }
421424
}
422425
// Verify linked list integrity
423426
if !cache.order.is_empty() {

0 commit comments

Comments
 (0)