Fix test using create_missing
This commit is contained in:
parent
282fdaa3ac
commit
e17ce64f2b
|
@ -404,7 +404,10 @@ fn load_chapter<P: AsRef<Path>>(
|
|||
if !location.exists() && !link_location.is_absolute() {
|
||||
src_dir = src_dir_fallback;
|
||||
location = src_dir.join(link_location);
|
||||
debug!("Falling back to {}", location.display());
|
||||
debug!(
|
||||
"Falling back to default translation in path \"{}\"",
|
||||
location.display()
|
||||
);
|
||||
}
|
||||
if !location.exists() && cfg.build.create_missing {
|
||||
create_missing(&location, &link)
|
||||
|
@ -586,7 +589,10 @@ more text.
|
|||
fn cant_load_a_nonexistent_chapter() {
|
||||
let link = Link::new("Chapter 1", "/foo/bar/baz.md");
|
||||
|
||||
let got = load_chapter(&link, "", "", Vec::new(), &Config::default());
|
||||
let mut cfg = Config::default();
|
||||
cfg.build.create_missing = false;
|
||||
|
||||
let got = load_chapter(&link, "", "", Vec::new(), &cfg);
|
||||
assert!(got.is_err());
|
||||
}
|
||||
|
||||
|
|
|
@ -188,7 +188,8 @@ async fn serve(
|
|||
// Redirect root to the default translation directory, if serving a localized book.
|
||||
// NOTE: This can't be `/{lang_ident}`, or the static assets won't get loaded.
|
||||
// BUG: Redirects get cached if you change the --language parameter,
|
||||
// meaning you'll get a 404 unless you disable cache in the developer tools.
|
||||
// meaning you'll get a 404 unless you disable the cache in Developer
|
||||
// Tools.
|
||||
let index_for_language = format!("/{}/index.html", lang_ident)
|
||||
.parse::<Uri>()
|
||||
.unwrap();
|
||||
|
@ -211,6 +212,7 @@ async fn serve(
|
|||
// The fallback route for 404 errors
|
||||
let fallback_route = warp::fs::file(build_dir.join(file_404))
|
||||
.map(|reply| warp::reply::with_status(reply, warp::http::StatusCode::NOT_FOUND));
|
||||
|
||||
let routes = livereload.or(book_route).or(fallback_route);
|
||||
warp::serve(routes).run(address).await;
|
||||
};
|
||||
|
|
|
@ -297,9 +297,9 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the fallback source directory of a book. For example, if chapters
|
||||
/// are missing in a localization, the links will gracefully degrade to the
|
||||
/// files that exist in this directory.
|
||||
/// Get the fallback source directory of a book. If chapters/sections are
|
||||
/// missing in a localization, any links to them will gracefully degrade to
|
||||
/// the files that exist in this directory.
|
||||
pub fn get_fallback_src_path(&self) -> PathBuf {
|
||||
match self.language.default_language() {
|
||||
// Languages have been specified, assume directory structure with
|
||||
|
@ -417,7 +417,7 @@ impl<'de> Deserialize<'de> for Config {
|
|||
|
||||
if default_languages != 1 {
|
||||
return Err(D::Error::custom(
|
||||
"If languages are specified, exactly one must be set as 'default'",
|
||||
"If [languages] table is specified, exactly one entry must be set as 'default'",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -784,7 +784,7 @@ pub struct LanguageConfig(pub HashMap<String, Language>);
|
|||
pub struct Language {
|
||||
/// Human-readable name of the language.
|
||||
pub name: String,
|
||||
/// If true, this language is the default. There can only be one default
|
||||
/// If true, this language is the default. There must be exactly one default
|
||||
/// language in the config.
|
||||
pub default: bool,
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use mdbook::MDBook;
|
|||
#[test]
|
||||
fn mdbook_can_correctly_test_a_passing_book() {
|
||||
let temp = DummyBook::new().with_passing_test(true).build().unwrap();
|
||||
let mut md = MDBook::load(temp.path()).unwrap();
|
||||
let md = MDBook::load(temp.path()).unwrap();
|
||||
|
||||
let result = md.test(vec![]);
|
||||
assert!(
|
||||
|
@ -20,7 +20,7 @@ fn mdbook_can_correctly_test_a_passing_book() {
|
|||
#[test]
|
||||
fn mdbook_detects_book_with_failing_tests() {
|
||||
let temp = DummyBook::new().with_passing_test(false).build().unwrap();
|
||||
let mut md = MDBook::load(temp.path()).unwrap();
|
||||
let md = MDBook::load(temp.path()).unwrap();
|
||||
|
||||
assert!(md.test(vec![]).is_err());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue