Hello there, I have this situation:
Two modules, device.rs
and tests.rs
. So in my main.rs
, I have:
mod device;
#[cfg(test)]
mod tests;
fn main() {
// ...
}
In device.rs
, I have a Device
struct
with its impl
:
pub struct Device {
// ...
}
impl Device {
fn virt_to_phys_addr(mut virt_addr: u32) -> PhysAddr {
// ...
}
}
I want to test virt_to_phys_addr()
in impl Device
, so in my tests.rs
, I have:
use crate::device::Device;
#[test]
fn virt_to_phys_addr() {
assert_eq!(2 + 2, 4);
Device::virt_to_phys_addr(0x80000000);
}
But I have this error:
error[E0624]: associated function `virt_to_phys_addr` is private
--> src/tests.rs:6:13
|
6 | Device::virt_to_phys_addr(0x80000000);
| ^^^^^^^^^^^^^^^^^ private associated function
I don't want to mark Device::virt_to_phys_addr()
pub
just for the test, I don't want to move it outside of Device
impl
.
My finds on Google tell "don't test private functions" or "you should not care about implementation details", which does not help.
So how can I test private static method only changing tho content of tests.rs
.
Thanks in advance for the help all! Have a nice day!