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