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

**URL:** <https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098>\
**Category:** help\
**Created:** [March 17, 2022, 11:34am UTC](https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098 "2022-03-17T11:34:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![TornaxO7](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/tornaxo7/32/26051_2.png) [@TornaxO7](https://users.rust-lang.org/u/TornaxO7)\
**Post date:** [March 17, 2022, 11:34am UTC](https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098/1 "2022-03-17T11:34:45Z")

</div>

Hello! I've the following setup (assuming we're the `src` directory):

`main.rs`:

> ****
>
> ```rust
> #![no_std]
> #![no_main]
> #![feature(const_ptr_offset)]
> 
> use os_clone2;
> 
> #[no_mangle]
> pub extern "C" fn os_clone2_entry() -> ! {
> loop {}
> }
> 
> ```

`lib.rs`

> ****
>
> ```rust
> #![no_std]
> #![no_main]
> #![feature(const_ptr_offset)]
> #![feature(custom_test_frameworks)]
> #![test_runner(test_runner)]
> 
> use core::panic::PanicInfo;
> 
> #[panic_handler]
> fn panic(_info: &PanicInfo) -> ! {
> loop {}
> }
> 
> fn test_runner(_test: &[&i32]) {
> loop {}
> }
> 
> ```

`.cargo/config.toml`

> ****
>
> ```toml
> [build]
> target = "target.json"
> 
> [unstable]
> build-std = ["core", "compiler_builtins"]
> build-std-features = ["compiler-builtins-mem"]
> 
> ```

`target.json`

> ****
>
> ```json
> {
> "llvm-target": "x86_64-unknown-none",
> "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
> "arch": "x86_64",
> "target-endian": "little",
> "target-pointer-width": "64",
> "target-c-int-width": "32",
> "os": "none",
> "executables": true,
> "linker-flavor": "ld.lld",
> "linker": "rust-lld",
> "panic-strategy": "abort",
> "disable-redzone": true,
> "features": "-mmx,-sse,+soft-float"
> }
> 
> ```

`Cargo.toml`

> ****
>
> ```toml
> [package]
> name = "os_clone2"
> version = "0.1.0"
> edition = "2021"
> 
> # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
> 
> [dependencies]
> 
> ```

(I've configered `rustup` to use the `nightly` channel) If I run `cargo clean && cargo build -Zbuild-std && cargo test` then I'm getting the following error message:

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

```

But shouldn't it work according to [this page](https://doc.rust-lang.org/unstable-book/language-features/custom-test-frameworks.html)? What am I doing wrong?

## Edit

I created [a test repository](https://github.com/TornaxO7/rust_test_framework) where you can get the exact same project to test with. Just run `cargo test` with the nightly version with `rustup`.

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/bjorn3/32/5255_2.png) [@bjorn3](https://users.rust-lang.org/u/bjorn3)\
**Post date:** [March 17, 2022, 11:37am UTC](https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098/2 "2022-03-17T11:37:00Z")

</div>

~~Libtest doesn't run on baremetal targets as it needs support for threads and terminal output. You may want to look at the custom\_test\_frameworks feature. See [Testing | Writing an OS in Rust](https://os.phil-opp.com/testing/) for an example on how to use it to test a kernel.~~ My bad. Looks like you are already using them.

---

<div class="post-metadata">

**Author:** ![TornaxO7](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/tornaxo7/32/26051_2.png) [@TornaxO7](https://users.rust-lang.org/u/TornaxO7)\
**Post date:** [March 17, 2022, 11:38am UTC](https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098/3 "2022-03-17T11:38:26Z")

</div>

Yes and I'm wondering why I'm still getting this error message.

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/bjorn3/32/5255_2.png) [@bjorn3](https://users.rust-lang.org/u/bjorn3)\
**Post date:** [March 17, 2022, 11:40am UTC](https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098/4 "2022-03-17T11:40:34Z")

</div>

It looks like you need `#![reexport_test_harness_main = "test_main"]` and then call the `test_main` function to run the tests. (you can use any name instead of test\_main. just be consistent.)

---

<div class="post-metadata">

**Author:** ![TornaxO7](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/tornaxo7/32/26051_2.png) [@TornaxO7](https://users.rust-lang.org/u/TornaxO7)\
**Post date:** [March 17, 2022, 11:48am UTC](https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098/5 "2022-03-17T11:48:07Z")

</div>

I only changed the `main.rs` now to:

```rust
#![no_std]
#![no_main]
#![feature(const_ptr_offset)]
#![reexport_test_harness_main = "test_main"]

use os_clone2;

#[no_mangle]
pub extern "C" fn os_clone2_entry() -> ! {
    #[cfg(test)]
    test_main();

    loop {}
}

```

But I'm still getting the same error.

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/bjorn3/32/5255_2.png) [@bjorn3](https://users.rust-lang.org/u/bjorn3)\
**Post date:** [March 17, 2022, 11:51am UTC](https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098/6 "2022-03-17T11:51:03Z")

</div>

I'm afraid I can't help any further.

---

<div class="post-metadata">

**Author:** ![TornaxO7](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/tornaxo7/32/26051_2.png) [@TornaxO7](https://users.rust-lang.org/u/TornaxO7)\
**Post date:** [March 17, 2022, 11:52am UTC](https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098/7 "2022-03-17T11:52:50Z")

</div>

Ok, but still thank you for your answers! 🙂

---

<div class="post-metadata">

**Author:** ![TornaxO7](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/tornaxo7/32/26051_2.png) [@TornaxO7](https://users.rust-lang.org/u/TornaxO7)\
**Post date:** [March 17, 2022, 11:59am UTC](https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098/8 "2022-03-17T11:59:38Z")

</div>

I added a link to a repo which contains my test code if it can help you.

---

<div class="post-metadata">

**Author:** ![TornaxO7](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/tornaxo7/32/26051_2.png) [@TornaxO7](https://users.rust-lang.org/u/TornaxO7)\
**Post date:** [March 18, 2022, 10:44am UTC](https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098/9 "2022-03-18T10:44:58Z")

</div>

Ok, I got it running. All you need to do is adding the following lines to your `main.rs`:

> ****
>
> ```rust
> #![reexport_test_harness_main = "test_main"]
> #![feature(custom_test_frameworks)]
> #![test_runner(test_runner)]
> 
> ```

`lib.rs`

> ****
>
> ```rust
> #![feature(custom_test_frameworks)]
> #![test_runner(test_runner)]
> 
> ```

And most importantly: You can run it only on your given target machine, otherwise you'll get a segmentation fault!

I also updated the code in my test repository.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [June 16, 2022, 10:45am UTC](https://users.rust-lang.org/t/error-e0463-cant-find-crate-for-test/73098/10 "2022-06-16T10:45:45Z")

</div>

Closed on June 16, 2022, 10:45am UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
