Skip to content

Commit a163af4

Browse files
committed
refactor: replace Result with assert! in bitmap tests
BytesHelper::test_access() returned a result that was always immediately unwrapped. Just assert in the function directly instead. Signed-off-by: Patrick Roy <[email protected]>
1 parent b03b103 commit a163af4

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

src/bitmap/mod.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ pub(crate) mod tests {
122122

123123
use std::marker::PhantomData;
124124
use std::mem::size_of_val;
125-
use std::result::Result;
126125
use std::sync::atomic::Ordering;
127126

128127
use crate::{Bytes, VolatileMemory};
@@ -165,12 +164,6 @@ pub(crate) mod tests {
165164
assert!(range_is_dirty(&s, 0, dirty_len));
166165
}
167166

168-
#[derive(Debug)]
169-
pub enum TestAccessError {
170-
RangeCleanCheck,
171-
RangeDirtyCheck,
172-
}
173-
174167
// A helper object that implements auxiliary operations for testing `Bytes` implementations
175168
// in the context of dirty bitmap tracking.
176169
struct BytesHelper<F, G, M> {
@@ -209,21 +202,15 @@ pub(crate) mod tests {
209202
dirty_offset: usize,
210203
dirty_len: usize,
211204
op: Op,
212-
) -> Result<(), TestAccessError>
205+
)
213206
where
214207
Op: Fn(&M, A),
215208
{
216-
if !self.check_range(bytes, dirty_offset, dirty_len, true) {
217-
return Err(TestAccessError::RangeCleanCheck);
218-
}
209+
assert!(self.check_range(bytes, dirty_offset, dirty_len, true));
219210

220211
op(bytes, self.address(dirty_offset));
221212

222-
if !self.check_range(bytes, dirty_offset, dirty_len, false) {
223-
return Err(TestAccessError::RangeDirtyCheck);
224-
}
225-
226-
Ok(())
213+
assert!(self.check_range(bytes, dirty_offset, dirty_len, false));
227214
}
228215
}
229216

@@ -256,29 +243,25 @@ pub(crate) mod tests {
256243
// Test `write`.
257244
h.test_access(bytes, dirty_offset, BUF_SIZE, |m, addr| {
258245
assert_eq!(m.write(buf.as_slice(), addr).unwrap(), BUF_SIZE)
259-
})
260-
.unwrap();
246+
});
261247
dirty_offset += step;
262248

263249
// Test `write_slice`.
264250
h.test_access(bytes, dirty_offset, BUF_SIZE, |m, addr| {
265251
m.write_slice(buf.as_slice(), addr).unwrap()
266-
})
267-
.unwrap();
252+
});
268253
dirty_offset += step;
269254

270255
// Test `write_obj`.
271256
h.test_access(bytes, dirty_offset, size_of_val(&val), |m, addr| {
272257
m.write_obj(val, addr).unwrap()
273-
})
274-
.unwrap();
258+
});
275259
dirty_offset += step;
276260

277261
// Test `store`.
278262
h.test_access(bytes, dirty_offset, size_of_val(&val), |m, addr| {
279263
m.store(val, addr, Ordering::Relaxed).unwrap()
280-
})
281-
.unwrap();
264+
});
282265
}
283266

284267
// This function and the next are currently conditionally compiled because we only use

0 commit comments

Comments
 (0)