| 1 |
//! General build tests. |
| 2 |
//! |
| 3 |
//! More specific tests should usually go into a module based on the feature. |
| 4 |
//! This module should just have general build tests, or misc small things. |
| 5 |
|
| 6 |
use crate::prelude::*; |
| 7 |
|
| 8 |
// Simple smoke test that building works. |
| 9 |
#[test] |
| 10 |
fn basic_build() { |
| 11 |
BookTest::from_dir("build/basic_build").run("build", |cmd| { |
| 12 |
cmd.expect_stderr(str![[r#" |
| 13 |
INFO Book building has started |
| 14 |
INFO Running the html backend |
| 15 |
INFO HTML book written to `[ROOT]/book` |
| 16 |
|
| 17 |
"#]]); |
| 18 |
}); |
| 19 |
} |
| 20 |
|
| 21 |
// Ensure building fails if `create-missing` is false and one of the files does |
| 22 |
// not exist. |
| 23 |
#[test] |
| 24 |
fn failure_on_missing_file() { |
| 25 |
BookTest::from_dir("build/missing_file").run("build", |cmd| { |
| 26 |
cmd.expect_failure().expect_stderr(str![[r#" |
| 27 |
ERROR failed to read chapter `./chapter_1.md` |
| 28 |
[TAB]Caused by: [NOT_FOUND] |
| 29 |
|
| 30 |
"#]]); |
| 31 |
}); |
| 32 |
} |
| 33 |
|
| 34 |
// Ensure a missing file is created if `create-missing` is true. |
| 35 |
#[test] |
| 36 |
fn create_missing() { |
| 37 |
let test = BookTest::from_dir("build/create_missing"); |
| 38 |
assert!(test.dir.join("src/SUMMARY.md").exists()); |
| 39 |
assert!(!test.dir.join("src/chapter_1.md").exists()); |
| 40 |
test.load_book(); |
| 41 |
assert!(test.dir.join("src/chapter_1.md").exists()); |
| 42 |
} |
| 43 |
|
| 44 |
// Checks that it fails if the summary has a reserved filename. |
| 45 |
#[test] |
| 46 |
fn no_reserved_filename() { |
| 47 |
BookTest::from_dir("build/no_reserved_filename").run("build", |cmd| { |
| 48 |
cmd.expect_failure().expect_stderr(str![[r#" |
| 49 |
INFO Book building has started |
| 50 |
INFO Running the html backend |
| 51 |
ERROR Rendering failed |
| 52 |
[TAB]Caused by: print.md is reserved for internal use |
| 53 |
|
| 54 |
"#]]); |
| 55 |
}); |
| 56 |
} |
| 57 |
|
| 58 |
// Build without book.toml should be OK. |
| 59 |
#[test] |
| 60 |
fn book_toml_isnt_required() { |
| 61 |
let mut test = BookTest::init(|_| {}); |
| 62 |
std::fs::remove_file(test.dir.join("book.toml")).unwrap(); |
| 63 |
test.build(); |
| 64 |
test.check_main_file( |
| 65 |
"book/chapter_1.html", |
| 66 |
str![[r##"<h1 id="chapter-1"><a class="header" href="#chapter-1">Chapter 1</a></h1>"##]], |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
// Dest dir relative path behavior. |
| 71 |
#[test] |
| 72 |
fn dest_dir_relative_path() { |
| 73 |
let mut test = BookTest::from_dir("build/basic_build"); |
| 74 |
let current_dir = test.dir.join("work"); |
| 75 |
std::fs::create_dir_all(¤t_dir).unwrap(); |
| 76 |
test.run("build", |cmd| { |
| 77 |
cmd.args(&["--dest-dir", "foo", ".."]) |
| 78 |
.current_dir(¤t_dir) |
| 79 |
.expect_stderr(str![[r#" |
| 80 |
INFO Book building has started |
| 81 |
INFO Running the html backend |
| 82 |
INFO HTML book written to `[ROOT]/work/foo` |
| 83 |
|
| 84 |
"#]]); |
| 85 |
}); |
| 86 |
assert!(current_dir.join("foo/index.html").exists()); |
| 87 |
} |