I'm working on adding no_std support to a library of mine, but a large number of tests contain one or two lines each that use ToString
and/or format!
. At the moment, I'm wrapping these lines in #[cfg(feature = "std")] { ... }
so that they're simply ignored when testing with the std
feature disabled, but then I ran into problems when I got to some other tests that use rstest, which depends on std.
In an issue about no_std support in rstest, the maintainer stated:
Ok, I did some research and tried to understand better what mean to test something that use
#![no_std]
and my conclusion is that doesn't have any sense ... you cannot start test runner and write any assert withoutstd
library so when run your test you already have anstd
dependency.
Is this true? Are "truly no_std" tests impossible? Should I always feel free to use std in tests even when the non-test code is no_std? I know I can use std via #[cfg(test)] extern crate std;
, but is this wise?