Skip to content

Commit fdde5a6

Browse files
committed
rust: str: convert rusttest tests into KUnit
In general, we should aim to test as much as possible within the actual kernel, and not in the build host. Thus convert these `rusttest` tests into KUnit tests. Reviewed-by: David Gow <[email protected]> Acked-by: Danilo Krummrich <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent c4c0574 commit fdde5a6

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

rust/kernel/str.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::alloc::{flags::*, AllocError, KVec};
66
use core::fmt::{self, Write};
77
use core::ops::{self, Deref, DerefMut, Index};
88

9-
use crate::error::{code::*, Error};
9+
use crate::prelude::*;
1010

1111
/// Byte string without UTF-8 validity guarantee.
1212
#[repr(transparent)]
@@ -572,8 +572,7 @@ macro_rules! c_str {
572572
}};
573573
}
574574

575-
#[cfg(test)]
576-
#[expect(clippy::items_after_test_module)]
575+
#[kunit_tests(rust_kernel_str)]
577576
mod tests {
578577
use super::*;
579578

@@ -622,11 +621,10 @@ mod tests {
622621
}
623622

624623
#[test]
625-
#[should_panic]
626-
fn test_cstr_to_str_panic() {
624+
fn test_cstr_to_str_invalid_utf8() {
627625
let bad_bytes = b"\xc3\x28\0";
628626
let checked_cstr = CStr::from_bytes_with_nul(bad_bytes).unwrap();
629-
checked_cstr.to_str().unwrap();
627+
assert!(checked_cstr.to_str().is_err());
630628
}
631629

632630
#[test]

0 commit comments

Comments
 (0)