| 1 |
//! Tests for the `mdbook test` command. |
| 2 |
|
| 3 |
use crate::prelude::*; |
| 4 |
|
| 5 |
// Simple test for passing tests. |
| 6 |
#[test] |
| 7 |
fn passing_tests() { |
| 8 |
BookTest::from_dir("test/passing_tests").run("test", |cmd| { |
| 9 |
cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#" |
| 10 |
INFO Testing chapter 'Intro': "intro.md" |
| 11 |
INFO Testing chapter 'Passing 1': "passing1.md" |
| 12 |
INFO Testing chapter 'Passing 2': "passing2.md" |
| 13 |
|
| 14 |
"#]]); |
| 15 |
}); |
| 16 |
} |
| 17 |
|
| 18 |
// Test for a test failure |
| 19 |
#[test] |
| 20 |
fn failing_tests() { |
| 21 |
BookTest::from_dir("test/failing_tests").run("test", |cmd| { |
| 22 |
cmd.expect_code(101) |
| 23 |
.expect_stdout(str![[""]]) |
| 24 |
// This redacts a large number of lines that come from rustdoc and |
| 25 |
// libtest. If the output from those ever changes, then it would not |
| 26 |
// make it possible to test against different versions of Rust. This |
| 27 |
// still includes a little bit of output, so if that is a problem, |
| 28 |
// add more redactions. |
| 29 |
.expect_stderr(str![[r#" |
| 30 |
INFO Testing chapter 'Failing Tests': "failing.md" |
| 31 |
ERROR rustdoc returned an error: |
| 32 |
|
| 33 |
--- stdout |
| 34 |
|
| 35 |
... |
| 36 |
test failing.md - Failing_Tests (line 3) ... FAILED |
| 37 |
... |
| 38 |
thread [..] panicked at failing.md:3:1: |
| 39 |
fail |
| 40 |
... |
| 41 |
INFO Testing chapter 'Failing Include': "failing_include.md" |
| 42 |
ERROR rustdoc returned an error: |
| 43 |
|
| 44 |
--- stdout |
| 45 |
... |
| 46 |
test failing_include.md - Failing_Include (line 3) ... FAILED |
| 47 |
... |
| 48 |
thread [..] panicked at failing_include.md:3:1: |
| 49 |
failing! |
| 50 |
... |
| 51 |
ERROR One or more tests failed |
| 52 |
|
| 53 |
"#]]); |
| 54 |
}); |
| 55 |
} |
| 56 |
|
| 57 |
// Test with a specific chapter. |
| 58 |
#[test] |
| 59 |
fn test_individual_chapter() { |
| 60 |
let mut test = BookTest::from_dir("test/passing_tests"); |
| 61 |
test.run("test -c", |cmd| { |
| 62 |
cmd.args(&["Passing 1"]) |
| 63 |
.expect_stdout(str![[""]]) |
| 64 |
.expect_stderr(str![[r#" |
| 65 |
INFO Testing chapter 'Passing 1': "passing1.md" |
| 66 |
|
| 67 |
"#]]); |
| 68 |
}) |
| 69 |
// Can also be a source path. |
| 70 |
.run("test -c passing2.md", |cmd| { |
| 71 |
cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#" |
| 72 |
INFO Testing chapter 'Passing 2': "passing2.md" |
| 73 |
|
| 74 |
"#]]); |
| 75 |
}); |
| 76 |
} |
| 77 |
|
| 78 |
// Unknown chapter name. |
| 79 |
#[test] |
| 80 |
fn chapter_not_found() { |
| 81 |
BookTest::from_dir("test/passing_tests").run("test -c bogus", |cmd| { |
| 82 |
cmd.expect_failure() |
| 83 |
.expect_stdout(str![[""]]) |
| 84 |
.expect_stderr(str![[r#" |
| 85 |
ERROR Chapter not found: bogus |
| 86 |
|
| 87 |
"#]]); |
| 88 |
}); |
| 89 |
} |