Debian Codegraph @

tests/testsuite/redirects.rs

raw
1 //! Tests for the HTML redirect feature.
2
3 use crate::prelude::*;
4 use snapbox::file;
5
6 // Basic check of redirects.
7 #[test]
8 fn redirects_are_emitted_correctly() {
9 BookTest::from_dir("redirects/redirects_are_emitted_correctly")
10 .check_file(
11 "book/overview.html",
12 file!["redirects/redirects_are_emitted_correctly/expected/overview.html"],
13 )
14 .check_file(
15 "book/nested/page.html",
16 file!["redirects/redirects_are_emitted_correctly/expected/nested/page.html"],
17 );
18 }
19
20 // Invalid redirect with only fragments.
21 #[test]
22 fn redirect_removed_with_fragments_only() {
23 BookTest::from_dir("redirects/redirect_removed_with_fragments_only").run("build", |cmd| {
24 cmd.expect_failure().expect_stderr(str![[r#"
25 INFO Book building has started
26 INFO Running the html backend
27 ERROR Rendering failed
28 [TAB]Caused by: Unable to emit redirects
29 [TAB]Caused by: redirect entry for `old-file.html` only has source paths with `#` fragments
30 There must be an entry without the `#` fragment to determine the default destination.
31
32 "#]]);
33 });
34 }
35
36 // Invalid redirect for an existing page.
37 #[test]
38 fn redirect_existing_page() {
39 BookTest::from_dir("redirects/redirect_existing_page").run("build", |cmd| {
40 cmd.expect_failure().expect_stderr(str![[r#"
41 INFO Book building has started
42 INFO Running the html backend
43 ERROR Rendering failed
44 [TAB]Caused by: redirect found for existing chapter at `/chapter_1.html`
45 Either delete the redirect or remove the chapter.
46
47 "#]]);
48 });
49 }