mirror of
https://github.com/rust-lang/mdBook.git
synced 2025-12-27 09:05:40 -05:00
This switches to using the tracing crate instead of log. Tracing provides a lot of nice features which we can take advantage of moving forward. This also adjusts the output fairly significantly. This includes: - Switched the environment variable from RUST_LOG to MDBOOK_LOG. - Dropped the timestamp. I experimented with various different time displays, but ultimately decided to omit it for now. I don't think I've ever found it to be useful, and it takes up a very significant amount of space. It could potentially be useful for basic profiling, but I think there are other, better mechanisms for that. We could consider leveraging tracing itself for doing some basic profiling (like using something like tracing-chrome). - Dropped the target unless MDBOOK_LOG is set. The target tends to be pretty noisy, and doesn't really convey much information unless you are debugging or otherwise trying to adjust the log output. - Added color. - Slightly reworked the way the error cause trace is displayed. - Slightly changed the way html5ever filtering is done, as well as add handlebars to the list since they both are very noisy. You can override this now by explicitly listing them as targets. I still expect that mdbook will eventually change how it displays things to the console, possibly switching away from tracing and printing things itself. However, that is a larger project for the future.
90 lines
2.3 KiB
Rust
90 lines
2.3 KiB
Rust
//! Tests for the `mdbook test` command.
|
|
|
|
use crate::prelude::*;
|
|
|
|
// Simple test for passing tests.
|
|
#[test]
|
|
fn passing_tests() {
|
|
BookTest::from_dir("test/passing_tests").run("test", |cmd| {
|
|
cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#"
|
|
INFO Testing chapter 'Intro': "intro.md"
|
|
INFO Testing chapter 'Passing 1': "passing1.md"
|
|
INFO Testing chapter 'Passing 2': "passing2.md"
|
|
|
|
"#]]);
|
|
});
|
|
}
|
|
|
|
// Test for a test failure
|
|
#[test]
|
|
fn failing_tests() {
|
|
BookTest::from_dir("test/failing_tests").run("test", |cmd| {
|
|
cmd.expect_code(101)
|
|
.expect_stdout(str![[""]])
|
|
// This redacts a large number of lines that come from rustdoc and
|
|
// libtest. If the output from those ever changes, then it would not
|
|
// make it possible to test against different versions of Rust. This
|
|
// still includes a little bit of output, so if that is a problem,
|
|
// add more redactions.
|
|
.expect_stderr(str![[r#"
|
|
INFO Testing chapter 'Failing Tests': "failing.md"
|
|
ERROR rustdoc returned an error:
|
|
|
|
--- stdout
|
|
|
|
...
|
|
test failing.md - Failing_Tests (line 3) ... FAILED
|
|
...
|
|
thread [..] panicked at failing.md:3:1:
|
|
fail
|
|
...
|
|
INFO Testing chapter 'Failing Include': "failing_include.md"
|
|
ERROR rustdoc returned an error:
|
|
|
|
--- stdout
|
|
...
|
|
test failing_include.md - Failing_Include (line 3) ... FAILED
|
|
...
|
|
thread [..] panicked at failing_include.md:3:1:
|
|
failing!
|
|
...
|
|
ERROR One or more tests failed
|
|
|
|
"#]]);
|
|
});
|
|
}
|
|
|
|
// Test with a specific chapter.
|
|
#[test]
|
|
fn test_individual_chapter() {
|
|
let mut test = BookTest::from_dir("test/passing_tests");
|
|
test.run("test -c", |cmd| {
|
|
cmd.args(&["Passing 1"])
|
|
.expect_stdout(str![[""]])
|
|
.expect_stderr(str![[r#"
|
|
INFO Testing chapter 'Passing 1': "passing1.md"
|
|
|
|
"#]]);
|
|
})
|
|
// Can also be a source path.
|
|
.run("test -c passing2.md", |cmd| {
|
|
cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#"
|
|
INFO Testing chapter 'Passing 2': "passing2.md"
|
|
|
|
"#]]);
|
|
});
|
|
}
|
|
|
|
// Unknown chapter name.
|
|
#[test]
|
|
fn chapter_not_found() {
|
|
BookTest::from_dir("test/passing_tests").run("test -c bogus", |cmd| {
|
|
cmd.expect_failure()
|
|
.expect_stdout(str![[""]])
|
|
.expect_stderr(str![[r#"
|
|
ERROR Chapter not found: bogus
|
|
|
|
"#]]);
|
|
});
|
|
}
|