aboutsummaryrefslogtreecommitdiff
path: root/rust/hello-world/GETTING_STARTED.md
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2020-12-26 17:48:38 +0000
committerFederico Igne <git@federicoigne.com>2021-11-03 18:55:08 +0000
commit02481656966b0a8dfc95cf3c22bcc049660ff7d4 (patch)
tree8e39798fcaf27931d91c2088423fd4e97adcfc2d /rust/hello-world/GETTING_STARTED.md
parent4e2052c4d792540c2f742b2c2a081b11117ed41d (diff)
downloadexercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.tar.gz
exercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.zip
Move Rust exercises in a subdirectory
Diffstat (limited to 'rust/hello-world/GETTING_STARTED.md')
-rw-r--r--rust/hello-world/GETTING_STARTED.md92
1 files changed, 92 insertions, 0 deletions
diff --git a/rust/hello-world/GETTING_STARTED.md b/rust/hello-world/GETTING_STARTED.md
new file mode 100644
index 0000000..5eeea95
--- /dev/null
+++ b/rust/hello-world/GETTING_STARTED.md
@@ -0,0 +1,92 @@
1# Getting Started
2
3These exercises lean on Test-Driven Development (TDD), but they're not
4an exact match.
5
6The following steps assume that you are in the same directory as the exercise.
7
8You must have rust installed.
9Follow the [Installation chapter in the Rust book](https://doc.rust-lang.org/book/ch01-01-installation.html).
10The [Rust language section](http://exercism.io/languages/rust)
11section from exercism is also useful.
12
13## Step 1
14
15Run the test suite. It can be run with `cargo`, which is installed with rust.
16
17```
18$ cargo test
19```
20
21This will compile the `hello-world` crate and run the test, which fails.
22
23```
24running 1 test
25test test_hello_world ... FAILED
26
27failures:
28
29---- test_hello_world stdout ----
30thread 'test_hello_world' panicked at 'assertion failed: `(left == right)`
31(left: `"Hello, World!"`, right: `"Goodbye, World!"`)', tests/hello-world.rs:5
32
33failures:
34 test_hello_world
35
36test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
37```
38
39### Understanding Test Failures
40
41The `test_hello_world` failure states that it is expecting the value,
42`"Hello, World!"`, to be returned from `hello()`.
43The left side of the assertion (at line 5) should be equal to the right side.
44
45```
46---- test_hello_world stdout ----
47thread 'test_hello_world' panicked at 'assertion failed: `(left == right)`
48(left: `"Hello, World!"`, right: `"Goodbye, World!"`)', tests/hello-world.rs:5
49```
50
51### Fixing the Error
52
53To fix it, open up `src/lib.rs` and change the `hello` function to return
54`"Hello, World!"` instead of `"Goodbye, World!"`.
55
56```rust
57pub fn hello() -> &'static str {
58 "Hello, World!"
59}
60```
61
62## Step 2
63
64Run the test again. This time, it will pass.
65
66```
67running 0 tests
68
69test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
70
71 Running target/debug/deps/hello_world-bd1f06dc726ef14f
72
73running 1 test
74test test_hello_world ... ok
75
76test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
77
78 Doc-tests hello-world
79
80running 0 tests
81
82test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
83```
84
85## Submit
86
87Once the test is passing, you can submit your code with the following
88command:
89
90```
91$ exercism submit src/lib.rs
92```