Skip to content

Commit 6a0925c

Browse files
committed
Update GETTING_STARTED.md to match simplified exercise
Closes exercism#265.
1 parent f1d8625 commit 6a0925c

File tree

1 file changed

+27
-97
lines changed

1 file changed

+27
-97
lines changed

exercises/hello-world/GETTING_STARTED.md

Lines changed: 27 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -18,141 +18,71 @@ Run the test suite. It can be run with `cargo`, which is installed with rust.
1818
$ cargo test
1919
```
2020

21-
This will fail, complaining that `hello-world` could not compile.
21+
This will compile the library and run the test, which fails.
2222

23-
To fix this, create a new directory called `src`.
24-
Create a new file called, `lib.rs`, inside the `src` directory.
25-
26-
## Step 2
27-
28-
Run the test again. It will give you a new error, another compile error.
29-
Our `lib.rs` does not contain any code, specifically the `hello()`
30-
function that our test is looking for.
31-
32-
### Fixing the Error
33-
34-
To fix it, open up the `src/lib.rs` file and add the following code:
35-
36-
```rust
37-
pub fn hello(name: Option<&str>) -> String {
38-
"".to_string()
39-
}
4023
```
41-
42-
Our test is looking for the `hello()` function from the `hello_world`
43-
crate. `lib.rs`, by default, is our crate root and our test
44-
is looking for the `hello()` function there.
45-
46-
The code we are adding to `lib.rs` defines a public function (`pub fn`) that is called "hello".
47-
The function accepts a `name` as an optional argument (`Option`).
48-
The function returns a `String`.
49-
We start by returning an empty string (`"".to_string()`).
50-
51-
## Step 3
52-
53-
Run the test again.
54-
55-
This time, code compilation will pass and we receive actual test failures.
56-
57-
```
58-
running 3 tests
59-
test test_other_same_name ... ignored
60-
test test_sample_name ... ignored
61-
test test_no_name ... FAILED
24+
running 1 test
25+
test test_hello_world ... FAILED
6226
6327
failures:
6428
65-
---- test_no_name stdout ----
66-
thread 'test_no_name' panicked at 'assertion failed: `(left == right)`
67-
(left: `"Hello, World!"`, right: `""`)', tests/hello-world.rs:5
68-
29+
---- test_hello_world stdout ----
30+
thread 'test_hello_world' panicked at 'assertion failed: `(left == right)`
31+
(left: `"Hello, World!"`, right: `"Goodbye, World!"`)', tests/hello-world.rs:5
6932
7033
failures:
71-
test_no_name
34+
test_hello_world
7235
73-
test result: FAILED. 0 passed; 1 failed; 2 ignored; 0 measured
36+
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
7437
```
7538

7639
### Understanding Test Failures
7740

78-
Only one of the tests runs (`test_no_name`) and it fails. The other
79-
tests are ignored (more on that later).
80-
81-
The `test_no_name` failure states that it is expecting the value,
82-
`"Hello, World!"`, to be returned from `hello("")`.
41+
The `test_hello_world` failure states that it is expecting the value,
42+
`"Hello, World!"`, to be returned from `hello()`.
8343
The left side of the assertion (at line 5) should be equal to the right side.
8444

8545
```
86-
---- test_no_name stdout ----
87-
thread 'test_no_name' panicked at 'assertion failed: `(left == right)`
88-
(left: `"Hello, World!"`, right: `""`)', tests/hello-world.rs:5
46+
---- test_hello_world stdout ----
47+
thread 'test_hello_world' panicked at 'assertion failed: `(left == right)`
48+
(left: `"Hello, World!"`, right: `"Goodbye, World!"`)', tests/hello-world.rs:5
8949
```
9050

91-
To fix it, let's return `"Hello, World!"`, instead of an empty string
92-
(`""`) inside our `hello` function.
51+
To fix it, open up `src/lib.rs` and change the `hello` function to return
52+
`"Hello, World!"` instead of "Goodbye, World!".
9353

9454
```rust
95-
pub fn hello(name: Option<&str>) -> String {
96-
"Hello, World!".to_string()
55+
pub fn hello() -> &'static str {
56+
"Hello, World!"
9757
}
9858
```
9959

100-
## Step 4
60+
## Step 2
10161

10262
Run the test again. This time, it will pass.
10363

10464
```
105-
running 3 tests
106-
test test_other_same_name ... ignored
107-
test test_sample_name ... ignored
108-
test test_no_name ... ok
109-
110-
test result: ok. 1 passed; 0 failed; 2 ignored; 0 measured
111-
112-
Doc-tests hello-world
113-
11465
running 0 tests
11566
11667
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
117-
```
118-
119-
You may have noticed compiler warnings earlier:
120-
121-
```
122-
Compiling hello-world v0.0.0
123-
(file:////exercism/exercises/rust/hello-world)
124-
src/lib.rs:1:14: 1:18 warning: unused variable: `name`, #[warn(unused_variables)] on by default
125-
src/lib.rs:1 pub fn hello(name: Option<&str>) -> String {
126-
^~~~
127-
```
128-
129-
Our `hello` function does not use the `name` argument so the
130-
compiler is letting us know that we could potentially remove the
131-
argument from our function (it likes "clean code").
132-
133-
As we make the rest of the tests pass, we will find that we need the `name`
134-
argument, so don't delete it.
13568
136-
Activate the next test. Open the `tests/hello-world.rs` file.
137-
Delete the `#[ignore]` line for the `test_sample_name` test.
69+
Running target/debug/deps/hello_world-bd1f06dc726ef14f
13870
139-
## Step 5
71+
running 1 test
72+
test test_hello_world ... ok
14073
141-
Run the test suite again. Read the test failure and make the test pass.
74+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
14275
143-
As a reminder, the [rust book](http://doc.rust-lang.org/stable/book/README.html)
144-
is a good reference for understanding rust.
145-
The cargo output may also have hints to help you, depending on the errors you get.
146-
For example, `rustc --explain E0425` will explain unresolved name errors.
76+
Doc-tests hello-world
14777
148-
## Wash, Rinse, Repeat
78+
running 0 tests
14979
150-
Delete one `#[ignore]` at a time, and make each test pass before you move to
151-
the next one.
80+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
81+
```
15282

15383
## Submit
15484

155-
When everything is passing, you can submit your code with the following
85+
Once the test is passing, you can submit your code with the following
15686
command:
15787

15888
```

0 commit comments

Comments
 (0)