Skip to content

Commit 9ae8cbb

Browse files
committed
Add mutant testing
This adds tests/mutants.rs which was created by githup copilot assistance. Note: This file is partially is generated with github copilot assistance. The *only* objective here is to generate coverage over all code paths to make 'cargo mutants' pass. Then the main test suite should pass 'cargo +nightly miri test'. Unless otherwise noted the tests here are not extensively reviewed for semantic correctness. Eventually human reviewed tests here should be moved to other unit tests. Hard to test side effects and functions that are trivially correct and are marked with #[mutants::skip].
1 parent d453f62 commit 9ae8cbb

File tree

5 files changed

+379
-8
lines changed

5 files changed

+379
-8
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ xmacro = "0.2.0"
2222
# include debug info for flamgraph and other profiling tools
2323
[profile.bench]
2424
debug = true
25+
26+
[dependencies]
27+
mutants = "0.0.3"

src/drain.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub struct Drain<'a, H, T> {
3939
}
4040

4141
impl<H: fmt::Debug, T: fmt::Debug> fmt::Debug for Drain<'_, H, T> {
42+
#[mutants::skip]
4243
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4344
f.debug_struct(&format!(
4445
"Drain<{}, {}>",

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ impl<H, T> HeaderVec<H, T> {
285285
}
286286

287287
/// Reserves capacity for exactly `additional` more elements to be inserted in the given `HeaderVec`.
288+
#[mutants::skip]
288289
#[inline]
289290
pub fn reserve_exact(&mut self, additional: usize) {
290291
self.reserve_intern(additional, true, &mut None);
@@ -293,6 +294,7 @@ impl<H, T> HeaderVec<H, T> {
293294
/// Reserves capacity for exactly `additional` more elements to be inserted in the given `HeaderVec`.
294295
/// This method must be used when `HeaderVecWeak` are used. It takes a closure that is responsible for
295296
/// updating the weak references as additional parameter.
297+
#[mutants::skip]
296298
#[inline]
297299
pub fn reserve_exact_with_weakfix(&mut self, additional: usize, weak_fixup: WeakFixupFn) {
298300
self.reserve_intern(additional, true, &mut Some(weak_fixup));
@@ -331,6 +333,7 @@ impl<H, T> HeaderVec<H, T> {
331333
}
332334

333335
/// Resizes the vector hold exactly `self.len()` elements.
336+
#[mutants::skip]
334337
#[inline(always)]
335338
pub fn shrink_to_fit(&mut self) {
336339
self.shrink_to(0);
@@ -339,6 +342,7 @@ impl<H, T> HeaderVec<H, T> {
339342
/// Resizes the vector hold exactly `self.len()` elements.
340343
/// This method must be used when `HeaderVecWeak` are used. It takes a closure that is responsible for
341344
/// updating the weak references as additional parameter.
345+
#[mutants::skip]
342346
#[inline(always)]
343347
pub fn shrink_to_fit_with_weakfix(&mut self, weak_fixup: WeakFixupFn) {
344348
self.shrink_to_with_weakfix(0, weak_fixup);
@@ -566,6 +570,7 @@ impl<H, T> HeaderVec<H, T> {
566570
///
567571
/// [`clear`]: HeaderVec::clear
568572
/// [`drain`]: HeaderVec::drain
573+
#[mutants::skip]
569574
pub fn truncate(&mut self, len: usize) {
570575
unsafe {
571576
let old_len = self.len_exact();
@@ -611,6 +616,7 @@ impl<H, T> HeaderVec<H, T> {
611616
}
612617

613618
/// Gives the offset in units of T (as if the pointer started at an array of T) that the slice actually starts at.
619+
#[mutants::skip]
614620
#[inline(always)]
615621
const fn offset() -> usize {
616622
// The first location, in units of size_of::<T>(), that is after the header
@@ -1056,6 +1062,7 @@ where
10561062
H: Debug,
10571063
T: Debug,
10581064
{
1065+
#[mutants::skip]
10591066
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
10601067
f.debug_struct("HeaderVec")
10611068
.field("header", &self.header().head)

src/splice.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ where
5555
I: Iterator + fmt::Debug,
5656
I::Item: fmt::Debug,
5757
{
58+
#[mutants::skip]
5859
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5960
f.debug_struct(&format!(
6061
"Splice<{}, {}>",
@@ -70,6 +71,7 @@ where
7071

7172
impl<H, I: Iterator> Drop for Splice<'_, H, I> {
7273
#[track_caller]
74+
#[mutants::skip]
7375
fn drop(&mut self) {
7476
self.drain.by_ref().for_each(drop);
7577
// At this point draining is done and the only remaining tasks are splicing

0 commit comments

Comments
 (0)