Skip to content

Commit e6bcf06

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 4420366 commit e6bcf06

File tree

5 files changed

+385
-8
lines changed

5 files changed

+385
-8
lines changed

Diff for: Cargo.toml

+3
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"

Diff for: src/drain.rs

+1
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<{}, {}>",

Diff for: src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ impl<H, T> HeaderVec<H, T> {
138138
/// HeaderVec`, this is the method is always exact and can be slightly faster than the non
139139
/// mutable `len()`.
140140
#[cfg(feature = "atomic_append")]
141+
#[mutants::skip]
141142
#[inline(always)]
142143
pub fn len_exact(&mut self) -> usize {
143144
*self.header_mut().len.get_mut()
144145
}
145146
#[cfg(not(feature = "atomic_append"))]
147+
#[mutants::skip]
146148
#[inline(always)]
147149
pub fn len_exact(&mut self) -> usize {
148150
self.header_mut().len
@@ -152,11 +154,13 @@ impl<H, T> HeaderVec<H, T> {
152154
/// produce racy results in case another thread atomically appended to
153155
/// `&self`. Nevertheless it is always safe to use.
154156
#[cfg(feature = "atomic_append")]
157+
#[mutants::skip]
155158
#[inline(always)]
156159
pub fn len(&self) -> usize {
157160
self.len_atomic_relaxed()
158161
}
159162
#[cfg(not(feature = "atomic_append"))]
163+
#[mutants::skip]
160164
#[inline(always)]
161165
pub fn len(&self) -> usize {
162166
self.header().len
@@ -168,11 +172,13 @@ impl<H, T> HeaderVec<H, T> {
168172
/// atomically appends data to this `HeaderVec` while we still work with the result of
169173
/// this method.
170174
#[cfg(not(feature = "atomic_append"))]
175+
#[mutants::skip]
171176
#[inline(always)]
172177
pub fn len_strict(&self) -> usize {
173178
self.header().len
174179
}
175180
#[cfg(feature = "atomic_append")]
181+
#[mutants::skip]
176182
#[inline(always)]
177183
pub fn len_strict(&self) -> usize {
178184
self.len_atomic_acquire()
@@ -283,6 +289,7 @@ impl<H, T> HeaderVec<H, T> {
283289
}
284290

285291
/// Reserves capacity for exactly `additional` more elements to be inserted in the given `HeaderVec`.
292+
#[mutants::skip]
286293
#[inline]
287294
pub fn reserve_exact(&mut self, additional: usize) {
288295
self.reserve_intern(additional, true, &mut None);
@@ -291,6 +298,7 @@ impl<H, T> HeaderVec<H, T> {
291298
/// Reserves capacity for exactly `additional` more elements to be inserted in the given `HeaderVec`.
292299
/// This method must be used when `HeaderVecWeak` are used. It takes a closure that is responsible for
293300
/// updating the weak references as additional parameter.
301+
#[mutants::skip]
294302
#[inline]
295303
pub fn reserve_exact_with_weakfix(&mut self, additional: usize, weak_fixup: WeakFixupFn) {
296304
self.reserve_intern(additional, true, &mut Some(weak_fixup));
@@ -329,6 +337,7 @@ impl<H, T> HeaderVec<H, T> {
329337
}
330338

331339
/// Resizes the vector hold exactly `self.len()` elements.
340+
#[mutants::skip]
332341
#[inline(always)]
333342
pub fn shrink_to_fit(&mut self) {
334343
self.shrink_to(0);
@@ -337,6 +346,7 @@ impl<H, T> HeaderVec<H, T> {
337346
/// Resizes the vector hold exactly `self.len()` elements.
338347
/// This method must be used when `HeaderVecWeak` are used. It takes a closure that is responsible for
339348
/// updating the weak references as additional parameter.
349+
#[mutants::skip]
340350
#[inline(always)]
341351
pub fn shrink_to_fit_with_weakfix(&mut self, weak_fixup: WeakFixupFn) {
342352
self.shrink_to_with_weakfix(0, weak_fixup);
@@ -564,6 +574,7 @@ impl<H, T> HeaderVec<H, T> {
564574
///
565575
/// [`clear`]: HeaderVec::clear
566576
/// [`drain`]: HeaderVec::drain
577+
#[mutants::skip]
567578
pub fn truncate(&mut self, len: usize) {
568579
unsafe {
569580
let old_len = self.len_exact();
@@ -609,6 +620,7 @@ impl<H, T> HeaderVec<H, T> {
609620
}
610621

611622
/// Gives the offset in units of T (as if the pointer started at an array of T) that the slice actually starts at.
623+
#[mutants::skip]
612624
#[inline(always)]
613625
const fn offset() -> usize {
614626
// The first location, in units of size_of::<T>(), that is after the header
@@ -1054,6 +1066,7 @@ where
10541066
H: Debug,
10551067
T: Debug,
10561068
{
1069+
#[mutants::skip]
10571070
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
10581071
f.debug_struct("HeaderVec")
10591072
.field("header", &self.header().head)

Diff for: src/splice.rs

+2
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)