|
| 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 | +[TIMESTAMP] [INFO] (mdbook::book): Testing chapter 'Intro': "intro.md" |
| 11 | +[TIMESTAMP] [INFO] (mdbook::book): Testing chapter 'Passing 1': "passing1.md" |
| 12 | +[TIMESTAMP] [INFO] (mdbook::book): 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 | +[TIMESTAMP] [INFO] (mdbook::book): Testing chapter 'Failing Tests': "failing.md" |
| 31 | +[TIMESTAMP] [ERROR] (mdbook::book): rustdoc returned an error: |
| 32 | +
|
| 33 | +--- stdout |
| 34 | +
|
| 35 | +... |
| 36 | +test failing.md - Failing_Tests (line 3) ... FAILED |
| 37 | +... |
| 38 | +thread 'main' panicked at failing.md:3:1: |
| 39 | +fail |
| 40 | +... |
| 41 | +[TIMESTAMP] [INFO] (mdbook::book): Testing chapter 'Failing Include': "failing_include.md" |
| 42 | +[TIMESTAMP] [ERROR] (mdbook::book): rustdoc returned an error: |
| 43 | +
|
| 44 | +--- stdout |
| 45 | +... |
| 46 | +test failing_include.md - Failing_Include (line 3) ... FAILED |
| 47 | +... |
| 48 | +thread 'main' panicked at failing_include.md:3:1: |
| 49 | +failing! |
| 50 | +... |
| 51 | +[TIMESTAMP] [ERROR] (mdbook::utils): Error: One or more tests failed |
| 52 | +
|
| 53 | +"#]]); |
| 54 | + }); |
| 55 | +} |
0 commit comments