Running doc and unit tests for nostd

Hi there. I've got a nostd staticlib project and I was hoping to be able to run doc and unit tests for it. My goal isn't to run the tests on the target hardware, but locally given the desire to test logic only.

Is this possible? If I try to cargo test on my project then I receive:

error[E0463]: can't find crate for `test`

I'm presuming that this has something to do with declaring nostd. I note that the cortex-m project is able to run tests (I cloned and tested), yet it also declares nostd.

Thanks for any help.

You can replace #![no_std] with #![cfg_attr(not(test), no_std)] to disable no_std for test.

2 Likes

Thanks - unfortunately if I do that then I get:

error[E0463]: can't find crate for `std`
  |
  = note: the `thumbv7em-none-eabihf` target may not be installed

(note - I do have thumbv7em-none-eabihf installed)

Why do you build the test binary for the thumb target? You said you want to test logic locally.

Ah yes - I see now that I've got a .cargo/config file that declares a default build target. Performing cargo test --target x86_64-apple-darwin does indeed work. Yay! Looks as though a "host" target can't easily be provided for when I want to test though, so I'll now re-work my project to remove the default thumb target.

1 Like