Skip to content

Commit eb903b4

Browse files
committed
Guide: update Testing output and fix contents to match
1 parent 6a22454 commit eb903b4

File tree

1 file changed

+66
-49
lines changed

1 file changed

+66
-49
lines changed

src/doc/guide.md

Lines changed: 66 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,15 +2921,11 @@ it `false`, so this test should fail. Let's try it!
29212921
```{notrust,ignore}
29222922
$ cargo test
29232923
Compiling testing v0.0.1 (file:///home/you/projects/testing)
2924-
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: code is never used: `main`, #[warn(dead_code)] on by default
2924+
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: function is never used: `main`, #[warn(dead_code)] on by default
29252925
/home/you/projects/testing/src/main.rs:1 fn main() {
29262926
/home/you/projects/testing/src/main.rs:2 println!("Hello, world!")
29272927
/home/you/projects/testing/src/main.rs:3 }
2928-
2929-
running 0 tests
2930-
2931-
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2932-
2928+
Running target/lib-654ce120f310a3a5
29332929
29342930
running 1 test
29352931
test foo ... FAILED
@@ -2946,7 +2942,7 @@ failures:
29462942
29472943
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
29482944
2949-
task '<main>' failed at 'Some tests failed', /home/you/src/rust/src/libtest/lib.rs:242
2945+
task '<main>' failed at 'Some tests failed', /home/you/src/rust/src/libtest/lib.rs:243
29502946
```
29512947

29522948
Lots of output! Let's break this down:
@@ -2960,7 +2956,7 @@ You can run all of your tests with `cargo test`. This runs both your tests in
29602956
`tests`, as well as the tests you put inside of your crate.
29612957

29622958
```{notrust,ignore}
2963-
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: code is never used: `main`, #[warn(dead_code)] on by default
2959+
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: function is never used: `main`, #[warn(dead_code)] on by default
29642960
/home/you/projects/testing/src/main.rs:1 fn main() {
29652961
/home/you/projects/testing/src/main.rs:2 println!("Hello, world!")
29662962
/home/you/projects/testing/src/main.rs:3 }
@@ -2974,18 +2970,8 @@ We'll turn this lint off for just this function soon. For now, just ignore this
29742970
output.
29752971

29762972
```{notrust,ignore}
2977-
running 0 tests
2978-
2979-
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2980-
```
2973+
Running target/lib-654ce120f310a3a5
29812974
2982-
Wait a minute, zero tests? Didn't we define one? Yup. This output is from
2983-
attempting to run the tests in our crate, of which we don't have any.
2984-
You'll note that Rust reports on several kinds of tests: passed, failed,
2985-
ignored, and measured. The 'measured' tests refer to benchmark tests, which
2986-
we'll cover soon enough!
2987-
2988-
```{notrust,ignore}
29892975
running 1 test
29902976
test foo ... FAILED
29912977
```
@@ -3008,7 +2994,7 @@ failures:
30082994
30092995
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
30102996
3011-
task '<main>' failed at 'Some tests failed', /home/you/src/rust/src/libtest/lib.rs:242
2997+
task '<main>' failed at 'Some tests failed', /home/you/src/rust/src/libtest/lib.rs:243
30122998
```
30132999

30143000
After all the tests run, Rust will show us any output from our failed tests.
@@ -3029,24 +3015,25 @@ And then try to run our tests again:
30293015
```{notrust,ignore}
30303016
$ cargo test
30313017
Compiling testing v0.0.1 (file:///home/you/projects/testing)
3032-
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: code is never used: `main`, #[warn(dead_code)] on by default
3033-
/home/you/projects/testing/src/main.rs:1 fn main() {
3034-
/home/you/projects/testing/src/main.rs:2 println!("Hello, world");
3035-
/home/you/projects/testing/src/main.rs:3 }
3036-
3037-
running 0 tests
3038-
3039-
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
3040-
3018+
Running target/lib-654ce120f310a3a5
30413019
30423020
running 1 test
30433021
test foo ... ok
30443022
30453023
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
3024+
3025+
Running target/testing-6d7518593c7c3ee5
3026+
3027+
running 0 tests
3028+
3029+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
30463030
```
30473031

3048-
Nice! Our test passes, as we expected. Let's get rid of that warning for our `main`
3049-
function. Change your `src/main.rs` to look like this:
3032+
Nice! Our test passes, as we expected. Note how we didn't get the
3033+
`main` warning this time? This is because `src/main.rs` didn't
3034+
need recompiling, but we'll get that warning again if we
3035+
change (and recompile) that file. Let's get rid of that
3036+
warning; change your `src/main.rs` to look like this:
30503037

30513038
```{rust}
30523039
#[cfg(not(test))]
@@ -3062,21 +3049,24 @@ our tests, it sets things up so that `cfg(test)` is true. But we want to only
30623049
include `main` when it's _not_ true. So we use `not` to negate things:
30633050
`cfg(not(test))` will only compile our code when the `cfg(test)` is false.
30643051

3065-
With this attribute, we won't get the warning:
3052+
With this attribute we won't get the warning (even
3053+
though `src/main.rs` gets recompiled this time):
30663054

30673055
```{notrust,ignore}
30683056
$ cargo test
30693057
Compiling testing v0.0.1 (file:///home/you/projects/testing)
3070-
3071-
running 0 tests
3072-
3073-
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
3074-
3058+
Running target/lib-654ce120f310a3a5
30753059
30763060
running 1 test
30773061
test foo ... ok
30783062
30793063
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
3064+
3065+
Running target/testing-6d7518593c7c3ee5
3066+
3067+
running 0 tests
3068+
3069+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
30803070
```
30813071

30823072
Nice. Okay, let's write a real test now. Change your `tests/lib.rs`
@@ -3156,21 +3146,30 @@ Let's give it a run:
31563146
```{ignore,notrust}
31573147
$ cargo test
31583148
Compiling testing v0.0.1 (file:///home/you/projects/testing)
3149+
Running target/lib-654ce120f310a3a5
3150+
3151+
running 1 test
3152+
test math_checks_out ... ok
3153+
3154+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
3155+
3156+
Running target/testing-6d7518593c7c3ee5
31593157
31603158
running 0 tests
31613159
31623160
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
31633161
3162+
Running target/testing-8a94b31f7fd2e8fe
31643163
31653164
running 0 tests
31663165
31673166
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
31683167
3168+
Doc-tests testing
31693169
3170-
running 1 test
3171-
test math_checks_out ... ok
3170+
running 0 tests
31723171
3173-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
3172+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
31743173
```
31753174

31763175
Great! One test passed. We've got an integration test showing that our public
@@ -3196,21 +3195,30 @@ If you run `cargo test`, you should get the same output:
31963195
```{ignore,notrust}
31973196
$ cargo test
31983197
Compiling testing v0.0.1 (file:///home/you/projects/testing)
3198+
Running target/lib-654ce120f310a3a5
3199+
3200+
running 1 test
3201+
test math_checks_out ... ok
3202+
3203+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
3204+
3205+
Running target/testing-6d7518593c7c3ee5
31993206
32003207
running 0 tests
32013208
32023209
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
32033210
3211+
Running target/testing-8a94b31f7fd2e8fe
32043212
32053213
running 0 tests
32063214
32073215
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
32083216
3217+
Doc-tests testing
32093218
3210-
running 1 test
3211-
test math_checks_out ... ok
3219+
running 0 tests
32123220
3213-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
3221+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
32143222
```
32153223

32163224
If we tried to write a test for these two new functions, it wouldn't
@@ -3283,23 +3291,32 @@ Let's give it a shot:
32833291
```{ignore,notrust}
32843292
$ cargo test
32853293
Compiling testing v0.0.1 (file:///home/you/projects/testing)
3294+
Running target/lib-654ce120f310a3a5
3295+
3296+
running 1 test
3297+
test math_checks_out ... ok
3298+
3299+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
3300+
3301+
Running target/testing-6d7518593c7c3ee5
3302+
3303+
running 0 tests
3304+
3305+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
3306+
3307+
Running target/testing-8a94b31f7fd2e8fe
32863308
32873309
running 2 tests
32883310
test test::test_times_four ... ok
32893311
test test::test_add_three ... ok
32903312
32913313
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured
32923314
3315+
Doc-tests testing
32933316
32943317
running 0 tests
32953318
32963319
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
3297-
3298-
3299-
running 1 test
3300-
test math_checks_out ... ok
3301-
3302-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
33033320
```
33043321

33053322
Cool! We now have two tests of our internal functions. You'll note that there

0 commit comments

Comments
 (0)