rust-lang / rust-lang/rust-by-example

the first example 'cargo test' can not work

Open
#1,665 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Handlebars
Stars
8.1k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

https://doc.rust-lang.org/stable/rust-by-example/testing/unit_testing.html

I just do copy the first unit test sample into a file named t.rs, then run 'cargo test', it report error.

After read the book, I change the process to

cargo new --lib add
cd add
vim src/lib.rs  ## copy & paste the example code here
cargo test   # it works now.

My suggestion is do a brief description about how to play the 'unittest' code, to let those readers who still not read the book can also complete the examples.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the unit-testing example at the linked Rust by Example page and compare the standalone t.rs workflow with the cargo new --lib add workflow described in the issue. Add a brief explanation of the required Cargo project setup so readers can run the example with cargo test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.