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.
50 lines
1.5 KiB
Rust
50 lines
1.5 KiB
Rust
//! Tests for the HTML redirect feature.
|
|
|
|
use crate::prelude::*;
|
|
use snapbox::file;
|
|
|
|
// Basic check of redirects.
|
|
#[test]
|
|
fn redirects_are_emitted_correctly() {
|
|
BookTest::from_dir("redirects/redirects_are_emitted_correctly")
|
|
.check_file(
|
|
"book/overview.html",
|
|
file!["redirects/redirects_are_emitted_correctly/expected/overview.html"],
|
|
)
|
|
.check_file(
|
|
"book/nested/page.html",
|
|
file!["redirects/redirects_are_emitted_correctly/expected/nested/page.html"],
|
|
);
|
|
}
|
|
|
|
// Invalid redirect with only fragments.
|
|
#[test]
|
|
fn redirect_removed_with_fragments_only() {
|
|
BookTest::from_dir("redirects/redirect_removed_with_fragments_only").run("build", |cmd| {
|
|
cmd.expect_failure().expect_stderr(str![[r#"
|
|
INFO Book building has started
|
|
INFO Running the html backend
|
|
ERROR Rendering failed
|
|
[TAB]Caused by: Unable to emit redirects
|
|
[TAB]Caused by: redirect entry for `old-file.html` only has source paths with `#` fragments
|
|
There must be an entry without the `#` fragment to determine the default destination.
|
|
|
|
"#]]);
|
|
});
|
|
}
|
|
|
|
// Invalid redirect for an existing page.
|
|
#[test]
|
|
fn redirect_existing_page() {
|
|
BookTest::from_dir("redirects/redirect_existing_page").run("build", |cmd| {
|
|
cmd.expect_failure().expect_stderr(str![[r#"
|
|
INFO Book building has started
|
|
INFO Running the html backend
|
|
ERROR Rendering failed
|
|
[TAB]Caused by: redirect found for existing chapter at `/chapter_1.html`
|
|
Either delete the redirect or remove the chapter.
|
|
|
|
"#]]);
|
|
});
|
|
}
|