Simplify the `format!` macro used in the tests by using
`CString::try_from_fmt` and directly `unwrap()`ing.
This will allow us to change both `unwrap()`s here in order to showcase
the `?` operator support now that the tests are KUnit ones.
Reviewed-by: David Gow <davidgow@google.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
[ Split from the next commit as suggested by Tamir. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
mod tests {
use super::*;
- struct String(CString);
-
- impl String {
- fn from_fmt(args: fmt::Arguments<'_>) -> Self {
- String(CString::try_from_fmt(args).unwrap())
- }
- }
-
- impl Deref for String {
- type Target = str;
-
- fn deref(&self) -> &str {
- self.0.to_str().unwrap()
- }
- }
-
macro_rules! format {
($($f:tt)*) => ({
- &*String::from_fmt(::kernel::fmt!($($f)*))
+ CString::try_from_fmt(::kernel::fmt!($($f)*)).unwrap().to_str().unwrap()
})
}